arenukvern commited on
Commit
2d84b2a
·
1 Parent(s): 8fd5ca8

feat: postcard generator

Browse files
Files changed (1) hide show
  1. app.py +60 -25
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 get_design_specs_for_year(
18
- year: str,
19
- ) -> str: # it's import to specify the return type
20
- """A tool that
21
  Args:
22
- year: the year of the design specs
23
  """
24
- return search_tool(f"What is the relevant design specs for {year}?")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  @tool
28
- def get_current_time_in_timezone(timezone: str) -> str:
29
- """A tool that fetches the current local time in a specified timezone.
 
 
30
  Args:
31
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
32
  """
33
- try:
34
- # Create timezone object
35
- tz = pytz.timezone(timezone)
36
- # Get current time in that timezone
37
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
38
- return f"The current local time in {timezone} is: {local_time}"
39
- except Exception as e:
40
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  final_answer = FinalAnswerTool()
@@ -64,10 +101,8 @@ agent = CodeAgent(
64
  model=model,
65
  tools=[
66
  final_answer,
67
- get_current_time_in_timezone,
68
- search_tool,
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,