Azie88 commited on
Commit
1e430e2
·
verified ·
1 Parent(s): e45608f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -26
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
 
2
  import datetime
3
  import requests
4
  import pytz
@@ -8,20 +9,26 @@ from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
 
13
 
14
  @tool
15
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
16
- #Keep this format for the description / args / args description but feel free to modify the tool
17
- """A tool that does nothing yet
18
  Args:
19
- arg1: the first argument
20
- arg2: the second argument
21
  """
22
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
23
 
24
-
25
 
26
  @tool
27
  def travel_recommendations_for_city(city: str) -> str:
@@ -30,7 +37,7 @@ def travel_recommendations_for_city(city: str) -> str:
30
  city: A string representing a specific city (e.g., 'Nairobi/Johannesburg').
31
  """
32
  search = DuckDuckGoSearchTool()
33
- results = search(f"Top 5 things to do in {city}")
34
  if not results:
35
  return f"Couldn't find any recommendations for {city}."
36
  recommendations = "\n".join([f"- {r['body']}" for r in results[:5]])
@@ -38,32 +45,20 @@ def travel_recommendations_for_city(city: str) -> str:
38
 
39
 
40
 
41
- @tool
42
- def get_current_time_in_timezone(timezone: str) -> str:
43
- """A tool that fetches the current local time in a specified timezone.
44
- Args:
45
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
46
- """
47
- try:
48
- # Create timezone object
49
- tz = pytz.timezone(timezone)
50
- # Get current time in that timezone
51
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
52
- return f"The current local time in {timezone} is: {local_time}"
53
- except Exception as e:
54
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
55
-
56
 
57
  # Import tool from Hub
58
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
59
 
60
  @tool
61
- def generate_travel_brochure_image(description: str) -> Image.Image:
62
  """A tool that generates a travel brochure image based on a description.
63
  Args:
64
  description: A string representing text to be converted into a brochure.
65
  """
66
- return image_generation_tool(description)
 
 
 
67
 
68
 
69
 
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
+ from smolagents.agent_types import AgentImage
3
  import datetime
4
  import requests
5
  import pytz
 
9
 
10
  from Gradio_UI import GradioUI
11
 
12
+
13
 
14
 
15
  @tool
16
+ def get_current_time_in_timezone(timezone: str) -> str:
17
+ """A tool that fetches the current local time in a specified timezone.
 
18
  Args:
19
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
20
  """
21
+ try:
22
+ # Create timezone object
23
+ tz = pytz.timezone(timezone)
24
+ # Get current time in that timezone
25
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
26
+ return f"The current local time in {timezone} is: {local_time}"
27
+ except Exception as e:
28
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
29
+
30
+
31
 
 
32
 
33
  @tool
34
  def travel_recommendations_for_city(city: str) -> str:
 
37
  city: A string representing a specific city (e.g., 'Nairobi/Johannesburg').
38
  """
39
  search = DuckDuckGoSearchTool()
40
+ results = search(f"Top things to do in {city}")
41
  if not results:
42
  return f"Couldn't find any recommendations for {city}."
43
  recommendations = "\n".join([f"- {r['body']}" for r in results[:5]])
 
45
 
46
 
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  # Import tool from Hub
50
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
51
 
52
  @tool
53
+ def generate_travel_brochure_image(description: str) -> AgentImage:
54
  """A tool that generates a travel brochure image based on a description.
55
  Args:
56
  description: A string representing text to be converted into a brochure.
57
  """
58
+ image = image_generation_tool(description)
59
+ if isinstance(image, Image.Image):
60
+ return AgentImage(image)
61
+ raise ValueError("Image generation failed or returned invalid data.")
62
 
63
 
64