Spaces:
Sleeping
Sleeping
adding weather tool
Browse files
app.py
CHANGED
|
@@ -33,7 +33,38 @@ 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 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 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, country_code: str) -> str:
|
| 38 |
+
"""A tool that fetches current weather information for a specified city.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
city: Name of the city (e.g., 'Paris')
|
| 42 |
+
country_code: Two-letter country code (e.g., 'FR')
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
str: Weather information including temperature and conditions
|
| 46 |
+
"""
|
| 47 |
+
API_KEY = "YOUR_API_KEY" # Replace with your OpenWeatherMap API key
|
| 48 |
+
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
| 49 |
+
|
| 50 |
+
try:
|
| 51 |
+
# Construct API URL
|
| 52 |
+
url = f"{base_url}?q={city},{country_code}&appid={API_KEY}&units=metric"
|
| 53 |
+
|
| 54 |
+
# Make API request
|
| 55 |
+
response = requests.get(url)
|
| 56 |
+
response.raise_for_status()
|
| 57 |
+
|
| 58 |
+
# Parse response
|
| 59 |
+
weather_data = response.json()
|
| 60 |
+
temperature = weather_data['main']['temp']
|
| 61 |
+
conditions = weather_data['weather'][0]['description']
|
| 62 |
+
|
| 63 |
+
return f"Current weather in {city}: {temperature}°C, {conditions}"
|
| 64 |
+
|
| 65 |
+
except requests.exceptions.RequestException as e:
|
| 66 |
+
return f"Error fetching weather data: {str(e)}"
|
| 67 |
+
|
| 68 |
final_answer = FinalAnswerTool()
|
| 69 |
|
| 70 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|