Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,46 +10,34 @@ from Gradio_UI import GradioUI
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
# Replace this part in app.py
|
12 |
@tool
|
13 |
-
def my_custom_tool(
|
14 |
-
"""A tool that
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
try:
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
search_tool = DuckDuckGoSearchTool()
|
25 |
-
print("Successfully created DuckDuckGoSearchTool")
|
26 |
-
except Exception as search_tool_error:
|
27 |
-
return f"Failed to create search tool: {str(search_tool_error)}"
|
28 |
-
|
29 |
-
# Then try to perform the search
|
30 |
-
print(f"Attempting search for: {search_query}")
|
31 |
-
try:
|
32 |
-
results = search_tool(search_query)
|
33 |
-
print(f"Search completed with {len(results) if results else 0} results")
|
34 |
-
except Exception as search_error:
|
35 |
-
return f"Failed to perform search: {str(search_error)}"
|
36 |
-
|
37 |
-
# Process the results
|
38 |
if not results:
|
39 |
-
return "
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
f"
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
print("Successfully created result text")
|
49 |
-
return result_text
|
50 |
-
|
51 |
except Exception as e:
|
52 |
-
return f"
|
53 |
|
54 |
|
55 |
@tool
|
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
# Replace this part in app.py
|
12 |
@tool
|
13 |
+
def my_custom_tool(topic: str, include_links: bool = False) -> str:
|
14 |
+
"""A tool that fetches comprehensive information about any topic using DuckDuckGo search
|
15 |
Args:
|
16 |
+
topic: The topic to search for information about
|
17 |
+
include_links: Whether to include source links in the response (default: False)
|
18 |
"""
|
19 |
try:
|
20 |
+
print(f"Searching for information about: {topic}")
|
21 |
+
search_tool = DuckDuckGoSearchTool()
|
22 |
+
results = search_tool(topic)
|
23 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
if not results:
|
25 |
+
return f"No information found about {topic}"
|
26 |
+
|
27 |
+
# Get the top 3 results for more comprehensive information
|
28 |
+
summary = f"Here's what I found about {topic}:\n\n"
|
29 |
+
|
30 |
+
for i, result in enumerate(results[:3], 1):
|
31 |
+
summary += f"{i}. {result['title']}\n"
|
32 |
+
summary += f"{result['snippet']}\n"
|
33 |
+
if include_links:
|
34 |
+
summary += f"Source: {result['link']}\n"
|
35 |
+
summary += "\n"
|
36 |
+
|
37 |
+
return summary.strip()
|
38 |
|
|
|
|
|
|
|
39 |
except Exception as e:
|
40 |
+
return f"Error while searching: {str(e)}"
|
41 |
|
42 |
|
43 |
@tool
|