Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,15 +10,27 @@ from Gradio_UI import GradioUI
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def crypto_duck(addr: str) -> str:
|
| 13 |
-
"""Search DuckDuckGo for information about a cryptocurrency address and return the top result.
|
| 14 |
-
Args:
|
| 15 |
-
addr: A string representing a valid cryptocurrency address.
|
| 16 |
-
"""
|
| 17 |
try:
|
| 18 |
ddg = DuckDuckGoSearchTool(max_results=1)
|
| 19 |
query = f'cryptocurrency address "{addr}"'
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"Search error: {str(e)}"
|
| 24 |
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def crypto_duck(addr: str) -> str:
|
| 13 |
+
"""Search DuckDuckGo for information about a cryptocurrency address and return the top result."""
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
ddg = DuckDuckGoSearchTool(max_results=1)
|
| 16 |
query = f'cryptocurrency address "{addr}"'
|
| 17 |
+
# Some versions expose .run; others are callable. Try .run first:
|
| 18 |
+
if hasattr(ddg, "run"):
|
| 19 |
+
res = ddg.run(query=query)
|
| 20 |
+
else:
|
| 21 |
+
res = ddg(query)
|
| 22 |
+
# res may already be a string; if it’s a list of dicts, format the first
|
| 23 |
+
if isinstance(res, list) and res:
|
| 24 |
+
top = res[0]
|
| 25 |
+
title = top.get("title", "")
|
| 26 |
+
href = top.get("href") or top.get("link", "")
|
| 27 |
+
snippet = top.get("body") or top.get("snippet", "")
|
| 28 |
+
return f"{title}\n{snippet}\n{href}".strip()
|
| 29 |
+
if isinstance(res, str):
|
| 30 |
+
if res.startswith("## Search Results"):
|
| 31 |
+
res = res.split("\n\n", 1)[-1]
|
| 32 |
+
return res or "No results found."
|
| 33 |
+
return "No results found."
|
| 34 |
except Exception as e:
|
| 35 |
return f"Search error: {str(e)}"
|
| 36 |
|