Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,35 +11,36 @@ 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
|
15 |
Args:
|
16 |
-
query: The search query to
|
17 |
-
generate_visual: Whether to generate
|
18 |
"""
|
19 |
try:
|
20 |
-
# First do
|
21 |
search_tool = DuckDuckGoSearchTool()
|
22 |
-
|
|
|
23 |
|
24 |
-
if not
|
25 |
-
return "No
|
26 |
-
|
27 |
-
# Format the search result
|
28 |
-
result = results[0] # Get first result
|
29 |
-
response = f"Found this information:\n{result['title']}\n{result['snippet']}"
|
30 |
|
31 |
-
#
|
|
|
|
|
|
|
|
|
32 |
if generate_visual:
|
33 |
try:
|
34 |
image_generation_tool(query)
|
35 |
-
response += "\n
|
36 |
-
except Exception as
|
37 |
-
response += "\n
|
38 |
-
|
39 |
return response
|
40 |
|
41 |
except Exception as e:
|
42 |
-
return f"
|
43 |
|
44 |
@tool
|
45 |
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 related images
|
15 |
Args:
|
16 |
+
query: The search query to find information about
|
17 |
+
generate_visual: Whether to generate a visual representation
|
18 |
"""
|
19 |
try:
|
20 |
+
# First do web search
|
21 |
search_tool = DuckDuckGoSearchTool()
|
22 |
+
print(f"Searching for: {query}") # Debug print
|
23 |
+
search_results = search_tool(query)
|
24 |
|
25 |
+
if not search_results:
|
26 |
+
return "No information found for your query."
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Get first result
|
29 |
+
result = search_results[0]
|
30 |
+
response = f"Here's what I found:\n{result['title']}\n{result['snippet']}"
|
31 |
+
|
32 |
+
# Generate image if requested
|
33 |
if generate_visual:
|
34 |
try:
|
35 |
image_generation_tool(query)
|
36 |
+
response += "\n\nI've generated a visual for your query."
|
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"An error occurred while searching: {str(e)}"
|
44 |
|
45 |
@tool
|
46 |
def get_current_time_in_timezone(timezone: str) -> str:
|