Spaces:
Sleeping
Sleeping
Update app.py
Browse fileschanged the custom tool to weather
app.py
CHANGED
|
@@ -7,16 +7,41 @@ 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 |
+
|
| 11 |
+
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
+
def get_weather(city: str) -> str:
|
| 15 |
+
"""Fetches the current weather for a given city using the OpenWeatherMap API.
|
|
|
|
| 16 |
Args:
|
| 17 |
+
city: Name of the city (e.g., 'Paris', 'New York').
|
|
|
|
| 18 |
"""
|
| 19 |
+
api_key = "a7c858f6bddb71d42c105ea61c497407" # Replace with your real API key
|
| 20 |
+
base_url = "https://api.openweathermap.org/data/2.5/weather"
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
params = {
|
| 24 |
+
"q": city,
|
| 25 |
+
"appid": api_key,
|
| 26 |
+
"units": "metric" # Use 'imperial' for Fahrenheit
|
| 27 |
+
}
|
| 28 |
+
response = requests.get(base_url, params=params)
|
| 29 |
+
data = response.json()
|
| 30 |
+
|
| 31 |
+
if response.status_code != 200:
|
| 32 |
+
return f"Error: {data.get('message', 'Failed to fetch weather data')}"
|
| 33 |
+
|
| 34 |
+
weather = data["weather"][0]["description"]
|
| 35 |
+
temp = data["main"]["temp"]
|
| 36 |
+
feels_like = data["main"]["feels_like"]
|
| 37 |
+
humidity = data["main"]["humidity"]
|
| 38 |
+
|
| 39 |
+
return (f"Weather in {city}:\n"
|
| 40 |
+
f"- Condition: {weather}\n"
|
| 41 |
+
f"- Temperature: {temp}°C (Feels like {feels_like}°C)\n"
|
| 42 |
+
f"- Humidity: {humidity}%")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"An error occurred while fetching weather: {str(e)}"
|
| 45 |
|
| 46 |
@tool
|
| 47 |
def get_current_time_in_timezone(timezone: str) -> str:
|