Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,40 @@ 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 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: type of gift that the shop sells
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
from smolagents import tool
|
| 13 |
+
from duckduckgo_search import DDGS
|
| 14 |
+
|
| 15 |
+
@tool
|
| 16 |
+
def my_custom_tool(location: str) -> str:
|
| 17 |
+
"""Searches the web for 5 local gift shops in a given area and returns a table
|
| 18 |
+
with store names, addresses, and contact information.
|
| 19 |
+
|
| 20 |
Args:
|
| 21 |
+
location: The location where the shops should be searched.
|
|
|
|
| 22 |
"""
|
| 23 |
+
query = f"gift shops in {location} address phone"
|
| 24 |
+
|
| 25 |
+
rows = []
|
| 26 |
+
with DDGS() as ddgs:
|
| 27 |
+
results = ddgs.text(query, max_results=10)
|
| 28 |
+
for r in results:
|
| 29 |
+
title = r.get("title", "Unknown")
|
| 30 |
+
snippet = r.get("body", "No details found")
|
| 31 |
+
link = r.get("href", "")
|
| 32 |
+
|
| 33 |
+
rows.append((title, snippet, link))
|
| 34 |
+
if len(rows) == 5:
|
| 35 |
+
break
|
| 36 |
+
|
| 37 |
+
if not rows:
|
| 38 |
+
return f"No gift shops found for {location}."
|
| 39 |
+
|
| 40 |
+
table = "| Store | Details | Source |\n"
|
| 41 |
+
table += "|---|---|---|\n"
|
| 42 |
+
for name, details, source in rows:
|
| 43 |
+
table += f"| {name} | {details} | {source} |\n"
|
| 44 |
+
|
| 45 |
+
return table
|
| 46 |
|
| 47 |
@tool
|
| 48 |
def get_current_time_in_timezone(timezone: str) -> str:
|