Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,24 +33,52 @@ 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 |
@tool
|
| 37 |
-
def
|
| 38 |
-
"""
|
| 39 |
Args:
|
| 40 |
-
|
| 41 |
Returns:
|
| 42 |
-
|
| 43 |
"""
|
| 44 |
try:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
final_answer = FinalAnswerTool()
|
| 56 |
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
# @tool
|
| 37 |
+
# def image_generation_tool(prompt: str) -> Image:
|
| 38 |
+
# """A tool that generates images using the FLUX.1-schnell model.
|
| 39 |
+
# Args:
|
| 40 |
+
# prompt: A string containing the image generation prompt.
|
| 41 |
+
# Returns:
|
| 42 |
+
# str: Status message indicating success or error of image generation.
|
| 43 |
+
# """
|
| 44 |
+
# try:
|
| 45 |
+
# tool = Tool.from_space(
|
| 46 |
+
# "black-forest-labs/FLUX.1-schnell",
|
| 47 |
+
# name="image_generator",
|
| 48 |
+
# description="Generate an image from a prompt"
|
| 49 |
+
# )
|
| 50 |
+
# result = tool.generate(prompt)
|
| 51 |
+
# return f"Successfully generated image from prompt: {prompt}"
|
| 52 |
+
# except Exception as e:
|
| 53 |
+
# return f"Error generating image from prompt '{prompt}': {str(e)}"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
@tool
|
| 57 |
+
def get_weather(city: str) -> dict:
|
| 58 |
+
"""Fetches current weather data for a given city using open-meteo API.
|
| 59 |
Args:
|
| 60 |
+
city: Name of the city to get weather for.
|
| 61 |
Returns:
|
| 62 |
+
dict: Weather data including temperature, humidity, etc.
|
| 63 |
"""
|
| 64 |
try:
|
| 65 |
+
# Get coordinates for city using Nominatim
|
| 66 |
+
geolocator = Nominatim(user_agent="weather_tool")
|
| 67 |
+
location = geolocator.geocode(city)
|
| 68 |
+
|
| 69 |
+
if not location:
|
| 70 |
+
raise Exception(f"Could not find coordinates for {city}")
|
| 71 |
+
|
| 72 |
+
# Build open-meteo API URL
|
| 73 |
+
url = f"https://api.open-meteo.com/v1/forecast?latitude={location.latitude}&longitude={location.longitude}¤t=temperature_2m,relative_humidity_2m,precipitation,wind_speed_10m"
|
| 74 |
+
|
| 75 |
+
response = requests.get(url)
|
| 76 |
+
response.raise_for_status()
|
| 77 |
+
|
| 78 |
+
return response.json()['current']
|
| 79 |
except Exception as e:
|
| 80 |
+
raise Exception(f"Error fetching weather data: {str(e)}")
|
| 81 |
+
|
| 82 |
|
| 83 |
final_answer = FinalAnswerTool()
|
| 84 |
|