Freddolin commited on
Commit
27a9a86
·
verified ·
1 Parent(s): d33cbb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -1
app.py CHANGED
@@ -18,6 +18,46 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -49,13 +89,14 @@ custom_role_conversions=None,
49
 
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_current_time_in_timezone, image_generation_tool], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def generate_meme_text(topic: str, tone: str) -> str:
23
+ """Generates a funny meme caption based on a topic and tone.
24
+ Args:
25
+ topic: What the meme is about (e.g. 'Python', 'Mondays').
26
+ tone: Style of humor (e.g. 'sarcastic', 'dark', 'wholesome').
27
+ """
28
+ topic = topic.strip().capitalize()
29
+ tone = tone.strip().lower()
30
+
31
+ templates = {
32
+ "sarcastic": [
33
+ f"{topic}? Oh sure, because *that* always works.",
34
+ f"When {topic} is your coping mechanism.",
35
+ f"I live, laugh, {topic}... and cry."
36
+ ],
37
+ "dark": [
38
+ f"{topic}: the reason I trust no one.",
39
+ f"Behind every {topic} is a story of despair.",
40
+ f"If {topic} was a person, I’d ghost them."
41
+ ],
42
+ "wholesome": [
43
+ f"{topic} is my happy place 💖",
44
+ f"Start your day with a smile and a little {topic}.",
45
+ f"When in doubt, {topic} it out!"
46
+ ],
47
+ "random": [
48
+ f"{topic}? That escalated quickly.",
49
+ f"One does not simply survive {topic}.",
50
+ f"{topic} – it's a lifestyle choice."
51
+ ]
52
+ }
53
+
54
+ # Choose from tone, fallback to "random"
55
+ selected = templates.get(tone, templates["random"])
56
+
57
+ import random
58
+ return random.choice(selected)
59
+
60
+
61
  @tool
62
  def get_current_time_in_timezone(timezone: str) -> str:
63
  """A tool that fetches the current local time in a specified timezone.
 
89
 
90
  # Import tool from Hub
91
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
92
+ search_tool = DuckDuckGoSearchTool()
93
 
94
  with open("prompts.yaml", 'r') as stream:
95
  prompt_templates = yaml.safe_load(stream)
96
 
97
  agent = CodeAgent(
98
  model=model,
99
+ tools=[final_answer, get_current_time_in_timezone, search_tool, image_generation_tool, generate_meme_text], ## add your tools here (don't remove final answer)
100
  max_steps=6,
101
  verbosity_level=1,
102
  grammar=None,