Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 12 |
|
| 13 |
|
| 14 |
@tool
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
"""A tool that does nothing yet
|
| 18 |
Args:
|
| 19 |
-
|
| 20 |
-
arg2: the second argument
|
| 21 |
"""
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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) ->
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
|