Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,32 @@ 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 my_custom_tool(
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
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 |
+
def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
|
13 |
+
"""A tool that combines web search and optional image generation
|
|
|
14 |
Args:
|
15 |
+
search_query: The search query to look up
|
16 |
+
generate_image: Whether to also generate an image based on the search results
|
17 |
"""
|
18 |
+
# First, search using DuckDuckGo
|
19 |
+
search_tool = DuckDuckGoSearchTool()
|
20 |
+
results = search_tool(search_query)
|
21 |
+
|
22 |
+
if not results:
|
23 |
+
return "No results found for the query."
|
24 |
+
|
25 |
+
# Get the first result
|
26 |
+
first_result = results[0]
|
27 |
+
summary = f"Found: {first_result['title']}\nSummary: {first_result['snippet']}"
|
28 |
+
|
29 |
+
# If image generation is requested, also generate an image
|
30 |
+
if generate_image:
|
31 |
+
try:
|
32 |
+
image_result = image_generation_tool(search_query)
|
33 |
+
summary += f"\n\nGenerated visualization based on the query."
|
34 |
+
except Exception as e:
|
35 |
+
summary += f"\n\nImage generation failed: {str(e)}"
|
36 |
+
|
37 |
+
return summary
|
38 |
|
39 |
@tool
|
40 |
def get_current_time_in_timezone(timezone: str) -> str:
|