Spaces:
Runtime error
Runtime error
Update ads from images
Browse files- ai_tasks/headlines_for_images.py +10 -11
- ai_tasks/text_summary.py +1 -1
- control_flow/main.py +15 -12
ai_tasks/headlines_for_images.py
CHANGED
@@ -6,11 +6,11 @@ from utils.io import print_system
|
|
6 |
|
7 |
|
8 |
PROMPT = """
|
9 |
-
Your goal is to find
|
10 |
-
The
|
11 |
-
So you must consider
|
12 |
You should consider the content of the website. The content of the images has been labeled.
|
13 |
-
You will create a headline for
|
14 |
|
15 |
Summary of the website:
|
16 |
{summary}
|
@@ -18,26 +18,25 @@ Summary of the website:
|
|
18 |
Image urls, with labels and dimensions:
|
19 |
{images}
|
20 |
|
21 |
-
Dimensions for the
|
22 |
|
23 |
-
Use the folliowing format.
|
24 |
|
25 |
Why the image was chosen:
|
26 |
Url:
|
27 |
Headline:
|
28 |
-
|
29 |
-
Target dimensions: It can be more than one
|
30 |
"""
|
31 |
|
32 |
|
33 |
def get_headlines_for_images(
|
34 |
-
summary: str, dimensions:
|
35 |
) -> str:
|
36 |
-
print_system("Generating
|
37 |
instructions = PROMPT.format(
|
38 |
summary=summary,
|
39 |
images=json.dumps(image_labels, indent=2),
|
40 |
dimensions=dimensions,
|
41 |
)
|
42 |
messages = [{"role": "user", "content": instructions}]
|
43 |
-
return llm.next(messages
|
|
|
6 |
|
7 |
|
8 |
PROMPT = """
|
9 |
+
Your goal is to find the best image that can be used as an ad for a website.
|
10 |
+
The ad must have certain dimensions but the image can be edited or cut.
|
11 |
+
So you must consider an image that is suited to fit those dimensions after editing.
|
12 |
You should consider the content of the website. The content of the images has been labeled.
|
13 |
+
You will create a headline for the ad.
|
14 |
|
15 |
Summary of the website:
|
16 |
{summary}
|
|
|
18 |
Image urls, with labels and dimensions:
|
19 |
{images}
|
20 |
|
21 |
+
Dimensions for the ad: {dimensions}.
|
22 |
|
23 |
+
Use the folliowing format.
|
24 |
|
25 |
Why the image was chosen:
|
26 |
Url:
|
27 |
Headline:
|
28 |
+
Original dimensions:
|
|
|
29 |
"""
|
30 |
|
31 |
|
32 |
def get_headlines_for_images(
|
33 |
+
summary: str, dimensions: str, image_labels: List[Dict]
|
34 |
) -> str:
|
35 |
+
print_system("Generating ad from images...")
|
36 |
instructions = PROMPT.format(
|
37 |
summary=summary,
|
38 |
images=json.dumps(image_labels, indent=2),
|
39 |
dimensions=dimensions,
|
40 |
)
|
41 |
messages = [{"role": "user", "content": instructions}]
|
42 |
+
return llm.next(messages)
|
ai_tasks/text_summary.py
CHANGED
@@ -14,4 +14,4 @@ def summarize_text(text: str) -> str:
|
|
14 |
print_system("Summarizing text...")
|
15 |
instructions = PROMPT.format(text=text)
|
16 |
messages = [{"role": "user", "content": instructions}]
|
17 |
-
return llm.next(messages
|
|
|
14 |
print_system("Summarizing text...")
|
15 |
instructions = PROMPT.format(text=text)
|
16 |
messages = [{"role": "user", "content": instructions}]
|
17 |
+
return llm.next(messages)
|
control_flow/main.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from typing import Dict
|
|
|
2 |
|
3 |
from ai import image
|
4 |
from ai_tasks.headlines_for_images import get_headlines_for_images
|
@@ -10,33 +11,35 @@ from code_tasks.text_in_url import get_text_from_url
|
|
10 |
from utils.io import print_assistant, print_system, user_input
|
11 |
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
|
22 |
def run():
|
23 |
url = user_input("URL: ")
|
|
|
24 |
|
25 |
# Code tasks (most code was generated by ChatGPT-4)
|
26 |
print_system("Getting URL data...")
|
27 |
text = get_text_from_url(url)
|
28 |
images = get_images_from_url(url)
|
29 |
-
image_info = run_parallel_jobs(get_image_info, images, max=
|
|
|
30 |
|
31 |
# AI tasks
|
32 |
summary = summarize_text(text)
|
33 |
print_assistant(summary)
|
34 |
-
headlines = get_headlines_for_images(summary,
|
35 |
print_assistant(headlines)
|
36 |
|
37 |
-
headlines_prompts = generate_headlines(summary, DIMENSIONS)
|
38 |
-
print_system("Generating AI images...")
|
39 |
-
run_parallel_jobs(gen_image, headlines_prompts)
|
40 |
|
41 |
|
42 |
def gen_image(input: Dict[str, str]) -> None:
|
|
|
1 |
from typing import Dict
|
2 |
+
import json
|
3 |
|
4 |
from ai import image
|
5 |
from ai_tasks.headlines_for_images import get_headlines_for_images
|
|
|
11 |
from utils.io import print_assistant, print_system, user_input
|
12 |
|
13 |
|
14 |
+
"""
|
15 |
+
"300x50",
|
16 |
+
"300x250",
|
17 |
+
"300x600",
|
18 |
+
"728x90",
|
19 |
+
"160x600",
|
20 |
+
"""
|
21 |
|
22 |
|
23 |
def run():
|
24 |
url = user_input("URL: ")
|
25 |
+
dimensions = user_input("Dimensions: ")
|
26 |
|
27 |
# Code tasks (most code was generated by ChatGPT-4)
|
28 |
print_system("Getting URL data...")
|
29 |
text = get_text_from_url(url)
|
30 |
images = get_images_from_url(url)
|
31 |
+
image_info = run_parallel_jobs(get_image_info, images, max=20)
|
32 |
+
print_system(json.dumps(image_info, indent=2))
|
33 |
|
34 |
# AI tasks
|
35 |
summary = summarize_text(text)
|
36 |
print_assistant(summary)
|
37 |
+
headlines = get_headlines_for_images(summary, dimensions, image_info)
|
38 |
print_assistant(headlines)
|
39 |
|
40 |
+
# headlines_prompts = generate_headlines(summary, DIMENSIONS)
|
41 |
+
# print_system("Generating AI images...")
|
42 |
+
# run_parallel_jobs(gen_image, headlines_prompts)
|
43 |
|
44 |
|
45 |
def gen_image(input: Dict[str, str]) -> None:
|