Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,52 +27,30 @@ def get_weather(city: str) -> str:
|
|
27 |
except Exception as e:
|
28 |
return f"Error fetching weather: {e}"
|
29 |
|
30 |
-
# Tool to fetch
|
31 |
@tool
|
32 |
-
def
|
33 |
-
"""Finds the
|
34 |
-
|
35 |
Args:
|
36 |
-
city: The name of the city
|
37 |
|
38 |
Returns:
|
39 |
-
str:
|
40 |
"""
|
41 |
try:
|
42 |
-
|
43 |
-
|
44 |
-
search_response = requests.get(search_url)
|
45 |
-
|
46 |
-
if search_response.status_code != 200:
|
47 |
-
return f"Failed to fetch AQI data for {city}. Status Code: {search_response.status_code}"
|
48 |
-
|
49 |
-
# Step 2: Extract the correct city URL from search results
|
50 |
-
import re
|
51 |
-
match = re.search(r'href="(/dashboard/[^"]+)"', search_response.text)
|
52 |
-
|
53 |
-
if not match:
|
54 |
-
return f"No AQI data found for {city}."
|
55 |
-
|
56 |
-
city_url_path = match.group(1)
|
57 |
-
city_url = f"https://www.aqi.in{city_url_path}"
|
58 |
-
|
59 |
-
# Step 3: Fetch AQI details from the city's AQI page
|
60 |
-
city_response = requests.get(city_url)
|
61 |
-
|
62 |
-
if city_response.status_code != 200:
|
63 |
-
return f"Failed to fetch AQI data for {city}. Status Code: {city_response.status_code}"
|
64 |
-
|
65 |
-
# Step 4: Extract AQI value using regex
|
66 |
-
match = re.search(r"AQI is (\d+)", city_response.text)
|
67 |
|
68 |
-
if
|
69 |
-
|
70 |
-
return f"
|
71 |
|
72 |
-
return f"No
|
73 |
-
|
74 |
except Exception as e:
|
75 |
-
return f"Error fetching
|
|
|
76 |
|
77 |
# Tool to get local time
|
78 |
@tool
|
|
|
27 |
except Exception as e:
|
28 |
return f"Error fetching weather: {e}"
|
29 |
|
30 |
+
# Tool to fetch top 5 tourist attractions in a city
|
31 |
@tool
|
32 |
+
def get_top_tourist_attractions(city: str) -> str:
|
33 |
+
"""Finds the top 5 must-visit places in a specified city using DuckDuckGo search.
|
34 |
+
|
35 |
Args:
|
36 |
+
city: The name of the city where attractions are being searched.
|
37 |
|
38 |
Returns:
|
39 |
+
str: A list of the top 5 tourist attractions (names only).
|
40 |
"""
|
41 |
try:
|
42 |
+
search_tool = DuckDuckGoSearchTool()
|
43 |
+
results = search_tool.forward(f"Top tourist attractions in {city}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
if results:
|
46 |
+
top_places = '\n'.join([f"{i+1}. {r['title']}" for i, r in enumerate(results[:5])])
|
47 |
+
return f"Top 5 Tourist Attractions in {city}:\n{top_places}"
|
48 |
|
49 |
+
return f"No tourist attractions found for {city}."
|
50 |
+
|
51 |
except Exception as e:
|
52 |
+
return f"Error fetching tourist attractions: {e}"
|
53 |
+
|
54 |
|
55 |
# Tool to get local time
|
56 |
@tool
|