Azie88 commited on
Commit
6dce7e4
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -8,6 +8,8 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
11
  @tool
12
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
@@ -18,6 +20,23 @@ 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.
@@ -34,6 +53,19 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -47,21 +79,23 @@ custom_role_conversions=None,
47
  )
48
 
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], ## add your tools here (don't remove final answer)
 
 
 
 
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
62
  planning_interval=None,
63
- name=None,
64
- description=None,
65
  prompt_templates=prompt_templates
66
  )
67
 
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+
12
+
13
  @tool
14
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
15
  #Keep this format for the description / args / args description but feel free to modify the tool
 
20
  """
21
  return "What magic will you build ?"
22
 
23
+
24
+
25
+ @tool
26
+ def travel_recommendations_for_city(city: str) -> str:
27
+ """A tool that provides tourist recommendations for a given city.
28
+ Args:
29
+ city: A string representing a specific city (e.g., 'Nairobi/Johannesburg').
30
+ """
31
+ search = DuckDuckGoSearchTool()
32
+ results = search(f"Top 5 things to do in {city}")
33
+ if not results:
34
+ return f"Couldn't find any recommendations for {city}."
35
+ recommendations = "\n".join([f"- {r['body']}" for r in results[:5]])
36
+ return f"Here are some things to do in {city}:\n{recommendations}"
37
+
38
+
39
+
40
  @tool
41
  def get_current_time_in_timezone(timezone: str) -> str:
42
  """A tool that fetches the current local time in a specified timezone.
 
53
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
54
 
55
 
56
+ # Import tool from Hub
57
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
58
+
59
+ @tool
60
+ def generate_travel_brochure_image(description: str) -> str:
61
+ """A tool that generates a travel brochure image based on a description.
62
+ Args:
63
+ description: A string representing text to be converted into a brochure.
64
+ """
65
+ return image_generation_tool(description)
66
+
67
+
68
+
69
  final_answer = FinalAnswerTool()
70
 
71
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
79
  )
80
 
81
 
 
 
 
82
  with open("prompts.yaml", 'r') as stream:
83
  prompt_templates = yaml.safe_load(stream)
84
 
85
  agent = CodeAgent(
86
  model=model,
87
+ tools=[
88
+ final_answer,
89
+ get_current_time_in_timezone,
90
+ travel_recommendations_for_city,
91
+ generate_travel_brochure_image
92
+ ], ## add your tools here (don't remove final answer)
93
  max_steps=6,
94
  verbosity_level=1,
95
  grammar=None,
96
  planning_interval=None,
97
+ name="Travel Brochure Agent",
98
+ description="Provides local time, travel tips, and generates a brochure image.",
99
  prompt_templates=prompt_templates
100
  )
101