Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,38 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
-
|
|
|
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
|
13 |
-
|
14 |
-
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -55,8 +74,8 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
-
max_steps=
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
62 |
planning_interval=None,
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from duckduckgo_search import DDGS
|
8 |
+
import re
|
9 |
from Gradio_UI import GradioUI
|
10 |
+
|
11 |
|
|
|
12 |
@tool
|
13 |
+
def get_top_places(city: str, category: str = "places", n: int = 5, budget: bool = False) -> list:
|
14 |
+
"""
|
15 |
+
Get top places based on city and category using DuckDuckGo search.
|
16 |
+
|
17 |
Args:
|
18 |
+
city: The name of the city to search in.
|
19 |
+
category: The search category ("places", "food", or "museum").
|
20 |
+
n: The number of results to return.
|
21 |
+
budget: If True, modifies the query to focus on budget friendly options.
|
22 |
+
|
23 |
+
Returns:
|
24 |
+
A list of strings, each formatted as "title - URL".
|
25 |
"""
|
26 |
+
valid_categories = ["places", "food", "museum"]
|
27 |
+
if category not in valid_categories:
|
28 |
+
raise ValueError("Invalid category. Choose from: places, food, museum.")
|
29 |
+
|
30 |
+
# Modify the query if budget-friendly options are desired.
|
31 |
+
if budget:
|
32 |
+
query = f"top {n} budget friendly {category} in {city}"
|
33 |
+
else:
|
34 |
+
query = f"top {n} {category} in {city}"
|
35 |
+
|
36 |
+
with DDGS() as ddgs:
|
37 |
+
results = ddgs.text(query, max_results=n)
|
38 |
+
return [f"{result['title']} - {result['href']}" for result in results]
|
39 |
|
40 |
@tool
|
41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
74 |
|
75 |
agent = CodeAgent(
|
76 |
model=model,
|
77 |
+
tools=[final_answer,get_top_places], ## add your tools here (don't remove final answer)
|
78 |
+
max_steps=5,
|
79 |
verbosity_level=1,
|
80 |
grammar=None,
|
81 |
planning_interval=None,
|