Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,29 +20,19 @@ search_model = HfApiModel(
|
|
| 20 |
|
| 21 |
|
| 22 |
@tool
|
| 23 |
-
def
|
| 24 |
"""Searches the web for top sightseeing locations in a given city.
|
| 25 |
Args:
|
| 26 |
city: Name of the city.
|
| 27 |
count: Number of top sightseeing locations to return.
|
| 28 |
"""
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
response = requests.get(search_url)
|
| 34 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
| 35 |
-
|
| 36 |
-
# This is a placeholder logic. You would need to inspect the actual HTML structure.
|
| 37 |
-
attractions = [tag.text for tag in soup.select('.result-title')][:count]
|
| 38 |
-
|
| 39 |
-
if attractions:
|
| 40 |
-
return f"Top {len(attractions)} sightseeing locations in {city}:\n" + "\n".join(f"{i+1}. {spot}" for i, spot in enumerate(attractions))
|
| 41 |
-
else:
|
| 42 |
-
return f"No sightseeing data found for {city}."
|
| 43 |
-
except Exception as e:
|
| 44 |
-
return f"Error retrieving sightseeing data for {city}: {str(e)}"
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
@tool
|
| 48 |
def my_custom_tool(city:str, season:str)-> str: # it's important to specify the return type
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@tool
|
| 23 |
+
def get_top_sightseeing(city: str, count: int) -> str:
|
| 24 |
"""Searches the web for top sightseeing locations in a given city.
|
| 25 |
Args:
|
| 26 |
city: Name of the city.
|
| 27 |
count: Number of top sightseeing locations to return.
|
| 28 |
"""
|
| 29 |
+
search_tool = DuckDuckGoSearchTool()
|
| 30 |
+
query = f"top {count} sightseeing locations in {city}"
|
| 31 |
+
results = search_tool.run(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
if results:
|
| 34 |
+
return f"Top sightseeing locations in {city}:\n" + "\n".join(f"{i+1}. {r['title']}" for i, r in enumerate(results[:count]))
|
| 35 |
+
else:
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def my_custom_tool(city:str, season:str)-> str: # it's important to specify the return type
|