MCPcopy
hub / github.com/InstaPy/InstaPy / check_image

Function check_image

instapy/clarifai_util.py:10–101  ·  view source on GitHub ↗
(
    browser,
    clarifai_api_key,
    img_tags,
    img_tags_skip_if_contain,
    logger,
    clarifai_models,
    workflow,
    probability,
    full_match=False,
    check_video=False,
    proxy=None,
    picture_url=None,
)

Source from the content-addressed store, hash-verified

8
9
10def check_image(
11 browser,
12 clarifai_api_key,
13 img_tags,
14 img_tags_skip_if_contain,
15 logger,
16 clarifai_models,
17 workflow,
18 probability,
19 full_match=False,
20 check_video=False,
21 proxy=None,
22 picture_url=None,
23):
24 try:
25 """Uses the link to the image to check for invalid content in the
26 image.
27 If a workflow has been selected, get list of tags from Clarifai API
28 by checking link against models included in the workflow. If a workflow
29 hasn't been provided, InstaPy will check images against given model(
30 s)"""
31 clarifai_api = ClarifaiApp(api_key=clarifai_api_key)
32 clarifai_tags = []
33
34 if proxy is not None:
35 clarifai_api.api.session.proxies = {"https": proxy}
36 # Set req image or video source URL to given one or get it from
37 # current page
38 if picture_url is None:
39 source_link = get_source_link(browser)
40 else:
41 source_link = [picture_url]
42
43 # No image in page
44 if not source_link:
45 return True, [], []
46
47 # Check image using workflow if provided. If no workflow,
48 # check image using model(s)
49 if workflow:
50 clarifai_workflow = Workflow(clarifai_api.api, workflow_id=workflow[0])
51 # If source is video, checks keyframe against models as video
52 # inputs not supported when using workflows
53 if source_link[0].endswith("mp4"):
54 clarifai_response = clarifai_workflow.predict_by_url(source_link[1])
55 else:
56 clarifai_response = clarifai_workflow.predict_by_url(source_link[0])
57
58 for response in clarifai_response["results"][0]["outputs"]:
59 results = get_clarifai_tags(response, probability)
60 clarifai_tags.extend(results)
61 else:
62 for model in clarifai_models:
63 clarifai_response = get_clarifai_response(
64 clarifai_api, model, source_link, check_video
65 )
66 results = get_clarifai_tags(
67 clarifai_response["outputs"][0], probability

Callers 1

query_clarifaiMethod · 0.85

Calls 4

get_source_linkFunction · 0.85
get_clarifai_tagsFunction · 0.85
get_clarifai_responseFunction · 0.85
given_tags_in_resultFunction · 0.85

Tested by

no test coverage detected