Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,15 +9,38 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def fetch_top_restaurants(location: str): #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A tool that fetches the yop retraunts in a given location
|
| 15 |
Args:
|
| 16 |
+
location (str): The location to search for restaurants.
|
|
|
|
| 17 |
"""
|
| 18 |
+
return list: A list of dictionaries containing restaurant names and links.
|
| 19 |
+
|
| 20 |
+
# Construct the query for DuckDuckGo
|
| 21 |
+
query = f"top 5 restaurants in {location}"
|
| 22 |
+
url = f"https://duckduckgo.com/html/?q={query}"
|
| 23 |
+
|
| 24 |
+
# Perform the search request
|
| 25 |
+
response = requests.get(url)
|
| 26 |
+
# Parse the response if successful
|
| 27 |
+
if response.status_code == 200:
|
| 28 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 29 |
+
results = []
|
| 30 |
+
for result in soup.find_all('a', class_='result__a', limit=5):
|
| 31 |
+
title = result.get_text()
|
| 32 |
+
link = result['href']
|
| 33 |
+
results.append({'name': title, 'link': link})
|
| 34 |
+
return results
|
| 35 |
+
else:
|
| 36 |
+
return f"Failed to retrieve search results for {location}"
|
| 37 |
|
| 38 |
+
# Example usage - Fetching restaurants for a specific location
|
| 39 |
+
location = "New York"
|
| 40 |
+
top_restaurants = fetch_top_restaurants(location)
|
| 41 |
+
for i, restaurant in enumerate(top_restaurants, start=1):
|
| 42 |
+
print(f"{i}. {restaurant['name']} - {restaurant['link']}")
|
| 43 |
+
```
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 46 |
"""A tool that fetches the current local time in a specified timezone.
|