Spaces:
Runtime error
Runtime error
Update ai images
Browse files- ai_tasks/headlines_ai_images.py +14 -16
- ai_tasks/headlines_for_images.py +1 -1
- control_flow/main.py +12 -15
ai_tasks/headlines_ai_images.py
CHANGED
@@ -7,11 +7,11 @@ from utils.io import print_system
|
|
7 |
|
8 |
|
9 |
PROMPT = """
|
10 |
-
Your goal is to create an ad
|
11 |
-
You will rely on an AI image generator to create
|
12 |
|
13 |
-
|
14 |
-
Pick a dimension to map to from this list: 256x256, 512x512, 1024x1024.
|
15 |
Create a headline.
|
16 |
Consider that the headlines will be edited on top of the generated images.
|
17 |
|
@@ -20,20 +20,18 @@ Here is the summary of the website:
|
|
20 |
|
21 |
Generate a JSON in the following format:
|
22 |
```
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
}}
|
30 |
-
]
|
31 |
```
|
32 |
"""
|
33 |
|
34 |
|
35 |
-
def
|
36 |
-
print_system("Generating
|
37 |
instructions = PROMPT.format(
|
38 |
summary=summary,
|
39 |
dimensions=dimensions,
|
@@ -42,8 +40,8 @@ def generate_headlines(summary: str, dimensions: List[str]) -> List[Dict[str, st
|
|
42 |
return _parse_output(llm.next(messages, temperature=0))
|
43 |
|
44 |
|
45 |
-
def _parse_output(assistant_message: str) ->
|
46 |
# Might throw
|
47 |
-
match = re.search(
|
48 |
json_request = match.group(0) # type: ignore
|
49 |
return json.loads(json_request)
|
|
|
7 |
|
8 |
|
9 |
PROMPT = """
|
10 |
+
Your goal is to create an ad with the following dimensions: {dimensions}.
|
11 |
+
You will rely on an AI image generator to create an image for you.
|
12 |
|
13 |
+
Create a prompt to be used by the AI image generator.
|
14 |
+
Pick a dimension to map to from this list: 256x256, 512x512, 1024x1024. The AI image will have these dimensions.
|
15 |
Create a headline.
|
16 |
Consider that the headlines will be edited on top of the generated images.
|
17 |
|
|
|
20 |
|
21 |
Generate a JSON in the following format:
|
22 |
```
|
23 |
+
{{
|
24 |
+
"ad_dimension":
|
25 |
+
"dimension_to_map":
|
26 |
+
"headline":
|
27 |
+
"prompt":
|
28 |
+
}}
|
|
|
|
|
29 |
```
|
30 |
"""
|
31 |
|
32 |
|
33 |
+
def generate_headline_and_prompt(summary: str, dimensions: str) -> Dict[str, str]:
|
34 |
+
print_system("Generating headline for website...")
|
35 |
instructions = PROMPT.format(
|
36 |
summary=summary,
|
37 |
dimensions=dimensions,
|
|
|
40 |
return _parse_output(llm.next(messages, temperature=0))
|
41 |
|
42 |
|
43 |
+
def _parse_output(assistant_message: str) -> Dict[str, str]:
|
44 |
# Might throw
|
45 |
+
match = re.search("({.*})", assistant_message, re.DOTALL)
|
46 |
json_request = match.group(0) # type: ignore
|
47 |
return json.loads(json_request)
|
ai_tasks/headlines_for_images.py
CHANGED
@@ -29,7 +29,7 @@ Original dimensions:
|
|
29 |
"""
|
30 |
|
31 |
|
32 |
-
def
|
33 |
summary: str, dimensions: str, image_labels: List[Dict]
|
34 |
) -> str:
|
35 |
print_system("Generating ad from images...")
|
|
|
29 |
"""
|
30 |
|
31 |
|
32 |
+
def get_headline_for_image(
|
33 |
summary: str, dimensions: str, image_labels: List[Dict]
|
34 |
) -> str:
|
35 |
print_system("Generating ad from images...")
|
control_flow/main.py
CHANGED
@@ -2,8 +2,8 @@ from typing import Dict
|
|
2 |
import json
|
3 |
|
4 |
from ai import image
|
5 |
-
from ai_tasks.headlines_for_images import
|
6 |
-
from ai_tasks.headlines_ai_images import
|
7 |
from ai_tasks.text_summary import summarize_text
|
8 |
from code_tasks.custom import get_image_info, run_parallel_jobs
|
9 |
from code_tasks.images_in_url import get_images_from_url
|
@@ -34,17 +34,14 @@ def run():
|
|
34 |
# AI tasks
|
35 |
summary = summarize_text(text)
|
36 |
print_assistant(summary)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
print_system(f"Prompt: {input['prompt']}")
|
48 |
-
print_assistant(input["ad_dimension"])
|
49 |
-
print_assistant(input["headline"])
|
50 |
print_assistant(ai_image)
|
|
|
2 |
import json
|
3 |
|
4 |
from ai import image
|
5 |
+
from ai_tasks.headlines_for_images import get_headline_for_image
|
6 |
+
from ai_tasks.headlines_ai_images import generate_headline_and_prompt
|
7 |
from ai_tasks.text_summary import summarize_text
|
8 |
from code_tasks.custom import get_image_info, run_parallel_jobs
|
9 |
from code_tasks.images_in_url import get_images_from_url
|
|
|
34 |
# AI tasks
|
35 |
summary = summarize_text(text)
|
36 |
print_assistant(summary)
|
37 |
+
# Pick an image and generate a headline
|
38 |
+
# headlines = get_headline_for_image(summary, dimensions, image_info)
|
39 |
+
# print_assistant(headlines)
|
40 |
+
# Generate a headline and an image
|
41 |
+
headline_prompt = generate_headline_and_prompt(summary, dimensions)
|
42 |
+
print_system("Generating AI images...")
|
43 |
+
ai_image = image.urls(headline_prompt["prompt"], size=headline_prompt["dimension_to_map"])[0]
|
44 |
+
print_system(f"Prompt: {headline_prompt['prompt']}")
|
45 |
+
print_assistant(headline_prompt["ad_dimension"])
|
46 |
+
print_assistant(headline_prompt["headline"])
|
|
|
|
|
|
|
47 |
print_assistant(ai_image)
|