Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,22 +8,22 @@ from Gradio_UI import GradioUI
|
|
| 8 |
@tool
|
| 9 |
def get_snowfall_forecast(city: str, date: str) -> str:
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
city (str): The name of the city
|
| 15 |
-
date (str): The date in YYYY-MM-DD format
|
| 16 |
|
| 17 |
Returns:
|
| 18 |
-
str: A message
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
-
#
|
| 22 |
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1&format=json"
|
| 23 |
geo_response = requests.get(geo_url).json()
|
| 24 |
|
| 25 |
if "results" not in geo_response or not geo_response["results"]:
|
| 26 |
-
return f"Error:
|
| 27 |
|
| 28 |
latitude = geo_response["results"][0]["latitude"]
|
| 29 |
longitude = geo_response["results"][0]["longitude"]
|
|
@@ -39,7 +39,7 @@ def get_snowfall_forecast(city: str, date: str) -> str:
|
|
| 39 |
return f"No snowfall data available for {city} on {date}."
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
-
return f"Error
|
| 43 |
|
| 44 |
# ✅ Load the Final Answer Tool
|
| 45 |
final_answer = FinalAnswerTool()
|
|
@@ -54,7 +54,7 @@ model = HfApiModel(
|
|
| 54 |
# ✅ Create the AI Agent with Tools
|
| 55 |
agent = CodeAgent(
|
| 56 |
model=model,
|
| 57 |
-
tools=[final_answer, get_snowfall_forecast], #
|
| 58 |
max_steps=6,
|
| 59 |
verbosity_level=1,
|
| 60 |
)
|
|
|
|
| 8 |
@tool
|
| 9 |
def get_snowfall_forecast(city: str, date: str) -> str:
|
| 10 |
"""
|
| 11 |
+
Retrieve the expected snowfall for a given city on a specific date.
|
| 12 |
|
| 13 |
+
Parameters:
|
| 14 |
+
city (str): The name of the city for which snowfall forecast is required.
|
| 15 |
+
date (str): The date in YYYY-MM-DD format to check the snowfall forecast.
|
| 16 |
|
| 17 |
Returns:
|
| 18 |
+
str: A message stating the expected snowfall in centimeters or an error if data is unavailable.
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
+
# Get latitude and longitude of the city
|
| 22 |
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1&format=json"
|
| 23 |
geo_response = requests.get(geo_url).json()
|
| 24 |
|
| 25 |
if "results" not in geo_response or not geo_response["results"]:
|
| 26 |
+
return f"Error: Could not determine location for '{city}'."
|
| 27 |
|
| 28 |
latitude = geo_response["results"][0]["latitude"]
|
| 29 |
longitude = geo_response["results"][0]["longitude"]
|
|
|
|
| 39 |
return f"No snowfall data available for {city} on {date}."
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
return f"Error retrieving snowfall forecast: {str(e)}"
|
| 43 |
|
| 44 |
# ✅ Load the Final Answer Tool
|
| 45 |
final_answer = FinalAnswerTool()
|
|
|
|
| 54 |
# ✅ Create the AI Agent with Tools
|
| 55 |
agent = CodeAgent(
|
| 56 |
model=model,
|
| 57 |
+
tools=[final_answer, get_snowfall_forecast], # Added the snowfall forecast tool
|
| 58 |
max_steps=6,
|
| 59 |
verbosity_level=1,
|
| 60 |
)
|