MCPcopy
hub / github.com/InstaPy/InstaPy / get_clarifai_response

Function get_clarifai_response

instapy/clarifai_util.py:141–185  ·  view source on GitHub ↗

Compiles a list of tags from Clarifai using the chosen models. First checks the value of each item in the models list against a dictionary. If the model value provided does not match one of the keys in the dictionary below, model value is used in clarifai_api.models.get(). Useful for

(clarifai_api, clarifai_model, source_link, check_video)

Source from the content-addressed store, hash-verified

139
140
141def get_clarifai_response(clarifai_api, clarifai_model, source_link, check_video):
142 """Compiles a list of tags from Clarifai using the chosen models.
143 First checks the value of each item in the models list against a
144 dictionary. If the model value provided does not match one of the
145 keys in the dictionary below, model value is used in
146 clarifai_api.models.get(). Useful for custom models."""
147 # List of models which support video inputs
148 video_models = ["apparel", "food", "general", "nsfw", "travel", "wedding"]
149 clarifai_models = {
150 "general": "general-v1.3",
151 "nsfw": "nsfw-v1.0",
152 "apparel": "apparel",
153 "celebrity": "celeb-v1.3",
154 "color": "color",
155 "demographics": "demographics",
156 "food": "food-items-v1.0",
157 "landscape quality": "Landscape Quality",
158 "logo": "logo",
159 "moderation": "moderation",
160 "portrait quality": "Portrait Quality",
161 "textures": "Textures & Patterns",
162 "travel": "travel-v1.0",
163 "weddings": "weddings-v1.0",
164 }
165
166 model = clarifai_api.models.get(
167 clarifai_models.get(clarifai_model.lower(), clarifai_model)
168 )
169 # Get response from Clarifai API
170 # If source is video, model accepts video inputs and check_video is
171 # True, analyze content of frames in video
172 if (
173 check_video
174 and source_link[0].endswith("mp4")
175 and clarifai_model.lower() in video_models
176 ):
177 response = model.predict_by_url(source_link[0], is_video=True)
178 # If source is video but model does not accept video inputs or
179 # check_video is False, analyze content of keyframe
180 elif source_link[0].endswith("mp4"):
181 response = model.predict_by_url(source_link[1])
182 else:
183 response = model.predict_by_url(source_link[0])
184
185 return response
186
187
188def get_clarifai_tags(clarifai_response, probability):

Callers 1

check_imageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected