Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,16 +12,15 @@ def get_weather(city: str) -> str:
|
|
| 12 |
Args:
|
| 13 |
city: A string representing a city (e.g., 'Paris','Roma')
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
url = f"http://api.weatherapi.com/v1/current.json?key=65b5427878074cd4bba163957250503&q={city}&aqi=no"
|
| 17 |
|
| 18 |
try:
|
| 19 |
-
response = requests.get(url)
|
| 20 |
-
response.raise_for_status()
|
| 21 |
|
| 22 |
weather_data = response.json()
|
| 23 |
|
| 24 |
-
# Format the weather data in a more readable way
|
| 25 |
location = weather_data['location']
|
| 26 |
current = weather_data['current']
|
| 27 |
|
|
@@ -44,7 +43,7 @@ def get_weather(city: str) -> str:
|
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
-
|
| 48 |
return f"""Weather in {result['location']['name']}, {result['location']['country']}:
|
| 49 |
- Temperature: {result['current']['temp_c']}°C ({result['current']['temp_f']}°F)
|
| 50 |
- Feels like: {result['current']['feelslike_c']}°C
|
|
@@ -57,22 +56,6 @@ def get_weather(city: str) -> str:
|
|
| 57 |
except requests.exceptions.RequestException as e:
|
| 58 |
return f"Error fetching weather data: {str(e)}"
|
| 59 |
|
| 60 |
-
@tool
|
| 61 |
-
def get_weather_image(city: str, weather_description: str) -> str:
|
| 62 |
-
"""A tool that generates an image of the weather in a city.
|
| 63 |
-
Args:
|
| 64 |
-
city: A string representing a city (e.g., 'Paris','Roma')
|
| 65 |
-
weather_description: A string describing the current weather conditions
|
| 66 |
-
"""
|
| 67 |
-
try:
|
| 68 |
-
# Create a descriptive prompt for the image generation
|
| 69 |
-
time_of_day = "daytime" # This could be improved by checking actual local time
|
| 70 |
-
prompt = f"A photorealistic view of {city} during {time_of_day} with {weather_description} weather conditions. Beautiful high-quality image showing the current weather."
|
| 71 |
-
|
| 72 |
-
# Return the prompt that will be used with the image generation tool
|
| 73 |
-
return prompt
|
| 74 |
-
except Exception as e:
|
| 75 |
-
return f"Error preparing weather image prompt: {str(e)}"
|
| 76 |
|
| 77 |
@tool
|
| 78 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -111,7 +94,6 @@ agent = CodeAgent(
|
|
| 111 |
model=model,
|
| 112 |
tools=[
|
| 113 |
get_weather,
|
| 114 |
-
get_weather_image,
|
| 115 |
get_current_time_in_timezone,
|
| 116 |
image_generation_tool,
|
| 117 |
final_answer
|
|
|
|
| 12 |
Args:
|
| 13 |
city: A string representing a city (e.g., 'Paris','Roma')
|
| 14 |
"""
|
| 15 |
+
|
| 16 |
url = f"http://api.weatherapi.com/v1/current.json?key=65b5427878074cd4bba163957250503&q={city}&aqi=no"
|
| 17 |
|
| 18 |
try:
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
response.raise_for_status()
|
| 21 |
|
| 22 |
weather_data = response.json()
|
| 23 |
|
|
|
|
| 24 |
location = weather_data['location']
|
| 25 |
current = weather_data['current']
|
| 26 |
|
|
|
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
+
|
| 47 |
return f"""Weather in {result['location']['name']}, {result['location']['country']}:
|
| 48 |
- Temperature: {result['current']['temp_c']}°C ({result['current']['temp_f']}°F)
|
| 49 |
- Feels like: {result['current']['feelslike_c']}°C
|
|
|
|
| 56 |
except requests.exceptions.RequestException as e:
|
| 57 |
return f"Error fetching weather data: {str(e)}"
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
@tool
|
| 61 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 94 |
model=model,
|
| 95 |
tools=[
|
| 96 |
get_weather,
|
|
|
|
| 97 |
get_current_time_in_timezone,
|
| 98 |
image_generation_tool,
|
| 99 |
final_answer
|