Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,36 +11,34 @@ from Gradio_UI import GradioUI
|
|
11 |
# Replace this part in app.py
|
12 |
@tool
|
13 |
def my_custom_tool(query: str, generate_visual: bool) -> str:
|
14 |
-
"""A tool that searches for information and optionally generates
|
15 |
Args:
|
16 |
query: The search query to find information about
|
17 |
generate_visual: Whether to generate a visual representation
|
18 |
"""
|
19 |
try:
|
20 |
-
#
|
21 |
search_tool = DuckDuckGoSearchTool()
|
22 |
-
print(f"Searching for: {query}") # Debug print
|
23 |
-
search_results = search_tool(query)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
#
|
33 |
if generate_visual:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
except Exception as img_err:
|
38 |
-
response += f"\n\nNote: Image generation failed: {str(img_err)}"
|
39 |
-
|
40 |
return response
|
41 |
|
42 |
except Exception as e:
|
43 |
-
return f"
|
44 |
|
45 |
@tool
|
46 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
11 |
# Replace this part in app.py
|
12 |
@tool
|
13 |
def my_custom_tool(query: str, generate_visual: bool) -> str:
|
14 |
+
"""A tool that searches for information and optionally generates visuals
|
15 |
Args:
|
16 |
query: The search query to find information about
|
17 |
generate_visual: Whether to generate a visual representation
|
18 |
"""
|
19 |
try:
|
20 |
+
# Initialize search tool
|
21 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
|
22 |
|
23 |
+
# Get results
|
24 |
+
results = search_tool(query)
|
25 |
|
26 |
+
# Format response
|
27 |
+
if not results:
|
28 |
+
return f"No information found for '{query}'"
|
29 |
+
|
30 |
+
result = results[0]
|
31 |
+
response = f"{result['title']}\n{result['snippet']}"
|
32 |
|
33 |
+
# Add visual if requested
|
34 |
if generate_visual:
|
35 |
+
image_generation_tool(query)
|
36 |
+
response += "\n(A visual has been generated)"
|
37 |
+
|
|
|
|
|
|
|
38 |
return response
|
39 |
|
40 |
except Exception as e:
|
41 |
+
return f"Error while searching for '{query}': {str(e)}"
|
42 |
|
43 |
@tool
|
44 |
def get_current_time_in_timezone(timezone: str) -> str:
|