Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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}
|
43 |
results = search_tool.forward(query)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
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}"
|