Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,8 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
from typing import List, Dict
|
| 8 |
-
from
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
@@ -36,37 +36,57 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
|
| 39 |
-
|
| 40 |
-
GERMANY_BBOX = (5.8663, 47.2701, 15.0419, 55.0581)
|
| 41 |
|
| 42 |
@tool
|
| 43 |
-
def
|
| 44 |
-
"""
|
|
|
|
|
|
|
| 45 |
Args:
|
| 46 |
-
query:
|
| 47 |
-
city: Optional German city
|
| 48 |
-
limit: Maximum number of
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
"""
|
|
|
|
|
|
|
|
|
|
| 50 |
try:
|
| 51 |
-
|
| 52 |
-
results =
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
return
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
-
return [{"error": f"
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
|
|
@@ -91,7 +111,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 91 |
|
| 92 |
agent = CodeAgent(
|
| 93 |
model=model,
|
| 94 |
-
tools=[final_answer, image_generation_tool,
|
| 95 |
max_steps=6,
|
| 96 |
verbosity_level=1,
|
| 97 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from typing import List, Dict
|
| 8 |
+
from smolagents import DuckDuckGoSearchTool, tool
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
|
| 39 |
+
|
|
|
|
| 40 |
|
| 41 |
@tool
|
| 42 |
+
def search_cafes_in_germany(query: str, city: str = None, limit: int = 10) -> List[Dict]:
|
| 43 |
+
"""
|
| 44 |
+
A refined tool that searches for cafes or restaurants in Germany using DuckDuckGo.
|
| 45 |
+
|
| 46 |
Args:
|
| 47 |
+
query: Search keywords (e.g., 'vegan cafe', 'Indian restaurant').
|
| 48 |
+
city: Optional German city to narrow results (e.g., 'Berlin', 'Cologne').
|
| 49 |
+
limit: Maximum number of results to return (default 10).
|
| 50 |
+
|
| 51 |
+
Returns:
|
| 52 |
+
A list of dictionaries containing structured information about each place, e.g.,
|
| 53 |
+
[
|
| 54 |
+
{
|
| 55 |
+
"name": "Cafe ABC",
|
| 56 |
+
"address": "Some street, Berlin",
|
| 57 |
+
"website": "https://cafeabc.de",
|
| 58 |
+
"phone": "+49 123 456789",
|
| 59 |
+
"rating": 4.5,
|
| 60 |
+
"lat": 52.5200,
|
| 61 |
+
"lon": 13.4050
|
| 62 |
+
},
|
| 63 |
+
...
|
| 64 |
+
]
|
| 65 |
"""
|
| 66 |
+
# Build the final query string
|
| 67 |
+
final_query = f"{query} in {city}" if city else query
|
| 68 |
+
|
| 69 |
try:
|
| 70 |
+
# Use the built-in DuckDuckGoSearchTool from smolagents
|
| 71 |
+
results = DuckDuckGoSearchTool(query=final_query, limit=limit)
|
| 72 |
+
|
| 73 |
+
# Optional: normalize fields for consistency
|
| 74 |
+
normalized = []
|
| 75 |
+
for r in results:
|
| 76 |
+
normalized.append({
|
| 77 |
+
"name": r.get("name"),
|
| 78 |
+
"address": r.get("address"),
|
| 79 |
+
"website": r.get("website"),
|
| 80 |
+
"phone": r.get("phone"),
|
| 81 |
+
"rating": r.get("rating"),
|
| 82 |
+
"lat": r.get("lat"),
|
| 83 |
+
"lon": r.get("lon"),
|
| 84 |
+
})
|
| 85 |
+
return normalized
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
+
return [{"error": f"Search failed: {str(e)}"}]
|
| 89 |
+
|
| 90 |
|
| 91 |
|
| 92 |
|
|
|
|
| 111 |
|
| 112 |
agent = CodeAgent(
|
| 113 |
model=model,
|
| 114 |
+
tools=[final_answer, image_generation_tool, search_cafes_in_germany], ## add your tools here (don't remove final answer)
|
| 115 |
max_steps=6,
|
| 116 |
verbosity_level=1,
|
| 117 |
grammar=None,
|