Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,14 +16,25 @@ def get_city_weather(city:str)-> str: #it's import to specify the return type
|
|
| 16 |
Args:
|
| 17 |
city: A string representing a valid city (e.g., 'Chicago')
|
| 18 |
"""
|
| 19 |
-
weather_API = os.getenv(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
data = response.json()
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
@tool
|
| 29 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 16 |
Args:
|
| 17 |
city: A string representing a valid city (e.g., 'Chicago')
|
| 18 |
"""
|
| 19 |
+
weather_API = os.getenv("weather_API") # Ensure this is set
|
| 20 |
+
if not weather_API:
|
| 21 |
+
return "Error: Weather API key is missing."
|
| 22 |
+
|
| 23 |
+
api_url = f"https://api.weatherapi.com/v1/current.json?key={weather_API}&q={city}&aqi=no"
|
| 24 |
+
try:
|
| 25 |
+
response = requests.get(api_url)
|
| 26 |
+
response.raise_for_status() # Raise an error for non-200 responses
|
| 27 |
data = response.json()
|
| 28 |
+
|
| 29 |
+
if "current" in data:
|
| 30 |
+
temp = data["current"]["temp_c"]
|
| 31 |
+
condition = data["current"]["condition"]["text"]
|
| 32 |
+
return f"The temperature in {city} is {temp}°C with {condition}."
|
| 33 |
+
else:
|
| 34 |
+
return "Error: Weather data not available."
|
| 35 |
+
|
| 36 |
+
except requests.exceptions.RequestException as e:
|
| 37 |
+
return f"Error: Unable to fetch weather data. {e}"
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|