Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,36 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 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
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
+
def get_weather_in_timezone(timezone: str) -> str:
|
| 12 |
+
"""A tool that fetches the current weather for a location in the specified timezone.
|
|
|
|
| 13 |
Args:
|
| 14 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
| 15 |
"""
|
| 16 |
+
try:
|
| 17 |
+
# Mapping timezone to a city (for demonstration purposes, this can be improved for more accuracy)
|
| 18 |
+
city = timezone.split('/')[-1].replace('_', ' ')
|
| 19 |
+
|
| 20 |
+
# OpenWeatherMap API setup
|
| 21 |
+
api_key = "YOUR_API_KEY" # Replace with your actual API key
|
| 22 |
+
weather_url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
| 23 |
+
|
| 24 |
+
# Fetch weather data
|
| 25 |
+
response = requests.get(weather_url)
|
| 26 |
+
data = response.json()
|
| 27 |
+
|
| 28 |
+
if response.status_code != 200:
|
| 29 |
+
return f"Could not fetch weather for timezone '{timezone}' (city: {city}). Error: {data.get('message', 'Unknown error')}"
|
| 30 |
+
|
| 31 |
+
# Parse weather data
|
| 32 |
+
weather_description = data["weather"][0]["description"].capitalize()
|
| 33 |
+
temperature = data["main"]["temp"]
|
| 34 |
+
humidity = data["main"]["humidity"]
|
| 35 |
+
|
| 36 |
+
return f"The current weather in {city} ({timezone}) is {weather_description} with a temperature of {temperature}°C and humidity of {humidity}%."
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error fetching weather for timezone '{timezone}': {str(e)}"
|
| 39 |
+
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def get_current_time_in_timezone(timezone: str) -> str:
|