-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (49 loc) · 1.72 KB
/
main.py
File metadata and controls
59 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from dotenv import load_dotenv
from data.datafetch import retrieve_relevant_meme
from scraper.get_news_source import get_news_article
from utils.image import (
convert_to_base_64_string,
add_captions_to_image,
)
from utils.llm_queries import (
different_scenarios,
get_image_caption_from_llm,
create_metaphor_labels,
detect_objects_in_image,
)
load_dotenv()
def send_to_logs(log, log_area, completed=None):
if completed:
log_area.update(label=log)
log_area.update(label=log)
def create_upload_file(image: bytes, news_url: str, log_area):
send_to_logs("grabbing news article...", log_area)
news_information = get_news_article(news_url)
if news_information is None:
return
send_to_logs("grabbing image descriptions and captions...", log_area)
image_text = convert_to_base_64_string(image)
meme_information = get_image_caption_from_llm(image_text)
relevant_meme_description = retrieve_relevant_meme(
meme_information.image_description
)
send_to_logs("Grabbing Metaphors...", log_area)
scenarios = different_scenarios(
meme_information, relevant_meme_description, news_information
)
send_to_logs("Looking for objects", log_area)
object_coordinates = detect_objects_in_image(
image, meme_information.physical_items_in_image
)
send_to_logs("Creating labels...", log_area)
metaphor_labels = create_metaphor_labels(
object_coordinates,
image_text,
scenarios.funny_scenarios,
news_information,
meme_information,
)
print(metaphor_labels)
send_to_logs("Finishing up...", log_area)
final_image_path = add_captions_to_image(metaphor_labels, image)
return final_image_path