Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,36 @@ 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 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -29,7 +51,8 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 29 |
tz = pytz.timezone(timezone)
|
| 30 |
# Get current time in that timezone
|
| 31 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 32 |
-
return f"The current local time in {timezone} is:
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_weather(city: str, country_code: str = "US") -> str:
|
| 13 |
+
"""Fetches current weather information for a given city and country.
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
city: The name of the city (e.g., 'New York').
|
| 17 |
+
country_code: The 2-letter country code (default is 'US').
|
| 18 |
"""
|
| 19 |
+
try:
|
| 20 |
+
api_key = Weatherapi # Replace with your actual API key
|
| 21 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city},{country_code}&appid={api_key}&units=metric"
|
| 22 |
+
|
| 23 |
+
response = requests.get(url)
|
| 24 |
+
data = response.json()
|
| 25 |
+
|
| 26 |
+
if response.status_code != 200:
|
| 27 |
+
return f"Failed to fetch weather: {data.get('message', 'Unknown error')}"
|
| 28 |
+
|
| 29 |
+
weather_description = data["weather"][0]["description"]
|
| 30 |
+
temperature = data["main"]["temp"]
|
| 31 |
+
feels_like = data["main"]["feels_like"]
|
| 32 |
+
humidity = data["main"]["humidity"]
|
| 33 |
+
|
| 34 |
+
return (
|
| 35 |
+
f"Current weather in {city}, {country_code}:\n"
|
| 36 |
+
f"- Description: {weather_description}\n"
|
| 37 |
+
f"- Temperature: {temperature}°C (feels like {feels_like}°C)\n"
|
| 38 |
+
f"- Humidity: {humidity}%"
|
| 39 |
+
)
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"An error occurred: {str(e)}"
|
| 42 |
|
| 43 |
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 51 |
tz = pytz.timezone(timezone)
|
| 52 |
# Get current time in that timezone
|
| 53 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 54 |
+
return f"The current local time in {timezone} is:
|
| 55 |
+
{local_time}"
|
| 56 |
except Exception as e:
|
| 57 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 58 |
|