hp1318 commited on
Commit
100fb9f
·
verified ·
1 Parent(s): 4be5ef0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -3,6 +3,7 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
6
  from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
@@ -39,12 +40,14 @@ def get_air_quality(city: str) -> str:
39
  """
40
  try:
41
  search_tool = DuckDuckGoSearchTool()
42
- query = f"current AQI in {city} site:aqicn.org"
43
  results = search_tool.forward(query)
44
 
45
- if results:
46
- top_result = results.split("\n\n")[0] # Get the most relevant result
47
- return f"AQI in {city}: {top_result}"
 
 
48
  return f"No AQI data found for {city}."
49
  except Exception as e:
50
  return f"Error fetching AQI: {e}"
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import re
7
  from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
 
40
  """
41
  try:
42
  search_tool = DuckDuckGoSearchTool()
43
+ query = f"current AQI in {city}"
44
  results = search_tool.forward(query)
45
 
46
+ # Use regex to find numbers likely to be AQI values
47
+ aqi_match = re.search(r"AQI\s*(\d{1,3})", results)
48
+
49
+ if aqi_match:
50
+ return f"AQI in {city}: {aqi_match.group(1)}"
51
  return f"No AQI data found for {city}."
52
  except Exception as e:
53
  return f"Error fetching AQI: {e}"