File size: 763 Bytes
1352a28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# works with uploaded image URLs

from moderator_mc import moderate_image  # uses moderate-content api
from caption import caption_from_url  # generates captions
from vector_search import topic_from_caption


def process_image(image_url):

    # Call the moderation function
    moderation_result = moderate_image(image_url)

    # If the moderator returns True, return "moderated"
    # if moderation_result:  #for azure
    if moderation_result == 3:  # mc api
        return "moderated"

    # If the moderator returns False, pass the URL to the captioner function
    else:
        image_caption = caption_from_url(image_url)
        topic = topic_from_caption(image_caption)
        answer = f"Caption: {image_caption}. Topic: {topic}"
        return answer