DenverJones commited on
Commit
ea8c721
·
verified ·
1 Parent(s): 69b2570

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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
- Fetch the expected snowfall in a given city on a specific date.
12
 
13
- Args:
14
- city (str): The name of the city to get the snowfall forecast for. Example: "Denver".
15
- date (str): The date in YYYY-MM-DD format for which the snowfall forecast is needed.
16
 
17
  Returns:
18
- str: A message with the expected snowfall in centimeters or an error message if data is unavailable.
19
  """
20
  try:
21
- # Geocode the city to get latitude & longitude
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: Unable to find location for '{city}'."
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 fetching snowfall forecast: {str(e)}"
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], # Snowfall Forecast Tool Added
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
  )