Spaces:
Sleeping
Sleeping
Generalise the function and make some args optional
Browse files
app.py
CHANGED
|
@@ -11,28 +11,40 @@ from Gradio_UI import GradioUI
|
|
| 11 |
search_tool = DuckDuckGoSearchTool()
|
| 12 |
|
| 13 |
@tool
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
Args:
|
| 18 |
location: A string representing the location area to search for open restaurants.
|
| 19 |
-
cuisine:
|
| 20 |
-
rating:
|
| 21 |
-
timezone:
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
local_time = datetime.datetime.now(tz).strftime("%H:%M")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if not search_results:
|
| 33 |
-
return f"❌ No
|
| 34 |
|
| 35 |
-
return f"🍽️ Open
|
| 36 |
[result["title"] + " - " + result["url"] for result in search_results[:5]]
|
| 37 |
)
|
| 38 |
|
|
|
|
| 11 |
search_tool = DuckDuckGoSearchTool()
|
| 12 |
|
| 13 |
@tool
|
| 14 |
+
def find_restaurants_by_location(location: str,
|
| 15 |
+
cuisine: str = None,
|
| 16 |
+
rating: float = None,
|
| 17 |
+
timezone: str = None
|
| 18 |
+
)-> str:
|
| 19 |
+
"""A tool that searches for restaurants according to location, cuisine, rating and local time.
|
| 20 |
Args:
|
| 21 |
location: A string representing the location area to search for open restaurants.
|
| 22 |
+
cuisine: An optional string representing the cuisine type (e.g. Asian, Indian, Italian, breakfast, lunch, etc.)
|
| 23 |
+
rating: An optional float representing the average customer rating of the restaurant from Google, TripAdvisor, or Yelp.
|
| 24 |
+
timezone: An optional string representing a valid timezone (e.g., 'America/New_York').
|
| 25 |
"""
|
| 26 |
try:
|
| 27 |
+
# If no timezone is provided, default to UTC
|
| 28 |
+
if timezone:
|
| 29 |
+
tz = pytz.timezone(timezone)
|
| 30 |
+
else:
|
| 31 |
+
tz = pytz.utc # Default timezone
|
| 32 |
local_time = datetime.datetime.now(tz).strftime("%H:%M")
|
| 33 |
|
| 34 |
+
# Build query dynamically based on provided inputs
|
| 35 |
+
query_parts = [f"restaurants open now in {location}"]
|
| 36 |
+
if cuisine:
|
| 37 |
+
query_parts.append(f"serving {cuisine} cuisine")
|
| 38 |
+
if rating:
|
| 39 |
+
query_parts.append(f"with a rating of {rating} or higher")
|
| 40 |
+
|
| 41 |
+
query = " ".join(query_parts) # Construct final query
|
| 42 |
+
search_results = search_tool(query)
|
| 43 |
|
| 44 |
if not search_results:
|
| 45 |
+
return f"❌ No matching restaurants found in {location} at {local_time}."
|
| 46 |
|
| 47 |
+
return f"🍽️ Open restaurants in {location} at {local_time}:\n\n" + "\n".join(
|
| 48 |
[result["title"] + " - " + result["url"] for result in search_results[:5]]
|
| 49 |
)
|
| 50 |
|