-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
84 lines (64 loc) · 2.26 KB
/
Copy pathmain.py
File metadata and controls
84 lines (64 loc) · 2.26 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from app.llms.research_planner import research_planner
from app.llms.summarizer import summarizer
from app.research.search import search
from app.research.fetch import fetch
from app.research.clean import clean
from app.llms.writer import writer
from app.llms.style_controller import style_summarizer
from app.utils.image_renderer import render_blog
from app.utils.validate_images import validate_images
def main():
user_prompt = (
"Write me a blog about my trip to Disney. "
"Start from when I left and go backwards. "
"My favorite ride was the Incredicoaster, "
"while my kids loved Guardians of the Galaxy. "
"I want a lot of emotions and vivid imagery of our excitement."
)
user_images = [
{
"image_id": "image_1",
"caption": "Test image (opening emotional anchor)"
}
]
# Research LLM called (research_planner.py)
research_scope: dict = research_planner(user_prompt)
print("\n=== RESEARCH SCOPE ===")
print(research_scope)
# Start searching for URL's (search.py)
search_queries = research_scope.get("search_queries", [])
search_queries = search_queries[:2]
all_urls: list[str] = []
for query in search_queries:
urls = search(query, 2)
all_urls.extend(urls)
print("\n=== SEARCH RESULTS (URLS) ===")
print(all_urls)
# Fetch (fetch.py) -> clean (clean.py) -> summarize (summarizer.py)
print("\n=== FETCH + CLEAN PREVIEW ===")
summaries = []
for url in all_urls:
#fetch URL's htlm code
html = fetch(url)
if html is None:
print("Fetch failed.")
continue
# clean text
text = clean(html)
#Summarizer text
try:
summary = summarizer(text)
summaries.append(summary)
print(summary["key_points"])
except Exception as e:
print("Summarizer Failed, skipping source")
continue
print("\n=== Blog Post ===")
style_spec = style_summarizer(user_prompt)
print(style_spec)
blog = writer(summaries, user_prompt, style_spec, user_images)
validate_images(blog, user_images)
rendered = render_blog(blog, user_images)
print(rendered)
if __name__ == "__main__":
main()