Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,37 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
search_tool = DuckDuckGoSearchTool()
|
|
@@ -56,7 +87,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer,search_tool,image_generation_tool], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def get_weather(city: str) -> str:
|
| 38 |
+
"""Fetches current weather information for a given city.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
city: The name of the city (e.g., 'London', 'New York', 'Tokyo')
|
| 42 |
+
"""
|
| 43 |
+
try:
|
| 44 |
+
# Clean the city name
|
| 45 |
+
city = city.strip()
|
| 46 |
+
if not city:
|
| 47 |
+
return "Error: City name cannot be empty"
|
| 48 |
+
|
| 49 |
+
url = f"https://wttr.in/{city}?format=%C+%t+Wind:+%w+Humidity:+%h"
|
| 50 |
+
response = requests.get(url, timeout=5)
|
| 51 |
+
|
| 52 |
+
if response.status_code == 200:
|
| 53 |
+
weather_info = response.text.strip()
|
| 54 |
+
|
| 55 |
+
# Check if the response indicates an error
|
| 56 |
+
if "Unknown location" in weather_info or len(weather_info) < 5:
|
| 57 |
+
return f"Could not find weather data for '{city}'. Please check the spelling."
|
| 58 |
+
|
| 59 |
+
return f"Weather in {city}: {weather_info}"
|
| 60 |
+
else:
|
| 61 |
+
return f"Could not fetch weather for '{city}'. Please check the city name."
|
| 62 |
+
except requests.exceptions.Timeout:
|
| 63 |
+
return f"Request timed out while fetching weather for '{city}'. Please try again."
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"Error fetching weather: {str(e)}"
|
| 66 |
+
|
| 67 |
|
| 68 |
final_answer = FinalAnswerTool()
|
| 69 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
| 87 |
|
| 88 |
agent = CodeAgent(
|
| 89 |
model=model,
|
| 90 |
+
tools=[final_answer,search_tool,image_generation_tool,get_weather ], ## add your tools here (don't remove final answer)
|
| 91 |
max_steps=6,
|
| 92 |
verbosity_level=1,
|
| 93 |
grammar=None,
|