hp1318 commited on
Commit
ea43098
·
verified ·
1 Parent(s): 916de5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -37
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 AQI (Air Quality Index) - No API Key Needed (Uses waqi.info with a demo token)
31
  @tool
32
- def get_air_quality(city: str) -> str:
33
- """Finds the air quality index (AQI) for a city using DuckDuckGo search.
34
-
35
  Args:
36
- city: The name of the city for which AQI information is needed.
37
 
38
  Returns:
39
- str: The AQI value along with air quality status.
40
  """
41
  try:
42
- # Step 1: Search for the city on AQI.in to find the correct country path
43
- search_url = f"https://www.aqi.in/search?query={city.replace(' ', '+')}"
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 match:
69
- aqi_value = match.group(1)
70
- return f"Air Quality in {city}: AQI {aqi_value} ({city_url})"
71
 
72
- return f"No AQI data found for {city}."
73
-
74
  except Exception as e:
75
- return f"Error fetching AQI: {e}"
 
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