Commit
·
2d84b2a
1
Parent(s):
8fd5ca8
feat: postcard generator
Browse files
app.py
CHANGED
@@ -8,36 +8,73 @@ from tools.visit_webpage import VisitWebpageTool
|
|
8 |
from tools.web_search import DuckDuckGoSearchTool
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
-
search_tool = DuckDuckGoSearchTool()
|
12 |
-
visit_webpage_tool = VisitWebpageTool()
|
13 |
|
14 |
-
|
15 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
16 |
@tool
|
17 |
-
def
|
18 |
-
|
19 |
-
) -> str: # it's import to specify the return type
|
20 |
-
"""A tool that
|
21 |
Args:
|
22 |
-
|
23 |
"""
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
@tool
|
28 |
-
def
|
29 |
-
|
|
|
|
|
30 |
Args:
|
31 |
-
|
|
|
32 |
"""
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
final_answer = FinalAnswerTool()
|
@@ -64,10 +101,8 @@ agent = CodeAgent(
|
|
64 |
model=model,
|
65 |
tools=[
|
66 |
final_answer,
|
67 |
-
|
68 |
-
|
69 |
-
visit_webpage_tool,
|
70 |
-
get_design_specs_for_year,
|
71 |
image_generation_tool,
|
72 |
], ## add your tools here (don't remove final answer)
|
73 |
max_steps=6,
|
|
|
8 |
from tools.web_search import DuckDuckGoSearchTool
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
|
|
11 |
|
|
|
|
|
12 |
@tool
|
13 |
+
def get_color_palette_based_on_emotion(emotion: str) -> str:
|
14 |
+
"""A tool that creates the color palette of a given emotion.
|
|
|
|
|
15 |
Args:
|
16 |
+
emotion: the emotion to create the color palette of.
|
17 |
"""
|
18 |
+
model = HfApiModel(
|
19 |
+
max_tokens=2096,
|
20 |
+
temperature=0.5,
|
21 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
22 |
+
custom_role_conversions=None,
|
23 |
+
)
|
24 |
+
|
25 |
+
messages = [
|
26 |
+
{
|
27 |
+
"role": "system",
|
28 |
+
"content": (
|
29 |
+
"ROLE: you are a cute color palette generator. "
|
30 |
+
"TASK: take the emotion and create a color palette which will complement the emotion. Use only pastel colors. "
|
31 |
+
"OUTPUT: a list of 6 colors in hex format. "
|
32 |
+
"CONSTRAINTS: Do not add any words or explanations. Just return the list of colors."
|
33 |
+
),
|
34 |
+
},
|
35 |
+
{
|
36 |
+
"role": "user",
|
37 |
+
"content": emotion,
|
38 |
+
},
|
39 |
+
]
|
40 |
+
response = model(messages, stop_sequences=["END"])
|
41 |
+
return response.content
|
42 |
|
43 |
|
44 |
@tool
|
45 |
+
def get_postcard_prompt_based_on_color_palette_and_greeting(
|
46 |
+
color_palette: str, greeting: str
|
47 |
+
) -> str:
|
48 |
+
"""A tool that creates the image prompt for post card based on the color palette and greeting.
|
49 |
Args:
|
50 |
+
color_palette: 6 colors in hex format to create the image prompt of.
|
51 |
+
greeting: the greeting to create the image prompt of.
|
52 |
"""
|
53 |
+
model = HfApiModel(
|
54 |
+
max_tokens=2096,
|
55 |
+
temperature=0.5,
|
56 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
57 |
+
custom_role_conversions=None,
|
58 |
+
)
|
59 |
+
|
60 |
+
messages = [
|
61 |
+
{
|
62 |
+
"role": "system",
|
63 |
+
"content": (
|
64 |
+
"ROLE: you are a cute postcard image prompt generator. "
|
65 |
+
"TASK: take the color palette and greeting and create a postcard image prompt which simbolses the greeting. "
|
66 |
+
"Use simple vector shapes, and pastel colors from the color palette. "
|
67 |
+
"OUTPUT: a postcard image prompt. "
|
68 |
+
"CONSTRAINTS: Use only the colors from the color palette. Include the greeting into the image prompt so it would be rendered as a text. "
|
69 |
+
),
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"role": "user",
|
73 |
+
"content": f"Color palette: {color_palette}, Greeting: {greeting}",
|
74 |
+
},
|
75 |
+
]
|
76 |
+
response = model(messages, stop_sequences=["END"])
|
77 |
+
return response.content
|
78 |
|
79 |
|
80 |
final_answer = FinalAnswerTool()
|
|
|
101 |
model=model,
|
102 |
tools=[
|
103 |
final_answer,
|
104 |
+
get_color_palette_based_on_emotion,
|
105 |
+
get_postcard_prompt_based_on_color_palette_and_greeting,
|
|
|
|
|
106 |
image_generation_tool,
|
107 |
], ## add your tools here (don't remove final answer)
|
108 |
max_steps=6,
|