hp1318 commited on
Commit
73cb380
·
verified ·
1 Parent(s): 52003fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -29,7 +29,7 @@ def get_weather(city: str) -> str:
29
  # Tool to fetch AQI (Air Quality Index) - No API Key Needed (Uses waqi.info with a demo token)
30
  @tool
31
  def get_air_quality(city: str) -> str:
32
- """Fetches air quality index (AQI) for a specified city using waqi.info.
33
 
34
  Args:
35
  city: The name of the city for which AQI information is needed.
@@ -38,11 +38,14 @@ def get_air_quality(city: str) -> str:
38
  str: The AQI value along with air quality status.
39
  """
40
  try:
41
- url = f"https://api.waqi.info/feed/{city}/?token=demo" # Demo token (no key needed)
42
- response = requests.get(url).json()
43
- if 'data' in response and 'aqi' in response['data']:
44
- return f"Air Quality in {city}: AQI {response['data']['aqi']}"
45
- return "AQI data unavailable."
 
 
 
46
  except Exception as e:
47
  return f"Error fetching AQI: {e}"
48
 
 
29
  # Tool to fetch AQI (Air Quality Index) - No API Key Needed (Uses waqi.info with a demo token)
30
  @tool
31
  def get_air_quality(city: str) -> str:
32
+ """Finds the air quality index (AQI) for a city using DuckDuckGo search.
33
 
34
  Args:
35
  city: The name of the city for which AQI information is needed.
 
38
  str: The AQI value along with air quality status.
39
  """
40
  try:
41
+ search_tool = DuckDuckGoSearchTool()
42
+ query = f"current air quality index AQI in {city}"
43
+ results = search_tool.forward(query)
44
+
45
+ if results:
46
+ top_result = results.split("\n\n")[0] # Get the first search result
47
+ return f"Air Quality in {city}:\n{top_result}"
48
+ return "No AQI data found."
49
  except Exception as e:
50
  return f"Error fetching AQI: {e}"
51