Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,21 +8,27 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
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 fetch_top_restaurants(location: str)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
list: A list of dictionaries containing restaurant names and links.
|
| 19 |
-
|
| 20 |
-
|
| 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')
|
|
@@ -32,7 +38,7 @@ def fetch_top_restaurants(location: str): #it's import to specify the return typ
|
|
| 32 |
link = result['href']
|
| 33 |
results.append({'name': title, 'link': link})
|
| 34 |
return results
|
| 35 |
-
|
| 36 |
return f"Failed to retrieve search results for {location}"
|
| 37 |
|
| 38 |
# Example usage - Fetching restaurants for a specific location
|
|
@@ -40,7 +46,7 @@ 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.
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
python
|
| 12 |
+
import requests
|
| 13 |
+
from bs4 import BeautifulSoup
|
| 14 |
+
|
| 15 |
@tool
|
| 16 |
+
def fetch_top_restaurants(location: str) -> list:
|
| 17 |
+
"""A tool that fetches the top restaurants in a given location.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
location (str): The location to search for restaurants.
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
list: A list of dictionaries containing restaurant names and links.
|
| 24 |
+
"""
|
| 25 |
+
# Construct the query for DuckDuckGo
|
| 26 |
query = f"top 5 restaurants in {location}"
|
| 27 |
url = f"https://duckduckgo.com/html/?q={query}"
|
| 28 |
|
| 29 |
# Perform the search request
|
| 30 |
response = requests.get(url)
|
| 31 |
+
|
| 32 |
# Parse the response if successful
|
| 33 |
if response.status_code == 200:
|
| 34 |
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
|
| 38 |
link = result['href']
|
| 39 |
results.append({'name': title, 'link': link})
|
| 40 |
return results
|
| 41 |
+
else:
|
| 42 |
return f"Failed to retrieve search results for {location}"
|
| 43 |
|
| 44 |
# Example usage - Fetching restaurants for a specific location
|
|
|
|
| 46 |
top_restaurants = fetch_top_restaurants(location)
|
| 47 |
for i, restaurant in enumerate(top_restaurants, start=1):
|
| 48 |
print(f"{i}. {restaurant['name']} - {restaurant['link']}")
|
| 49 |
+
|
| 50 |
@tool
|
| 51 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 52 |
"""A tool that fetches the current local time in a specified timezone.
|