Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,26 +16,38 @@ def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
|
|
16 |
search_query: The search query to look up
|
17 |
generate_image: Whether to also generate an image based on the search results
|
18 |
"""
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
@tool
|
41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
16 |
search_query: The search query to look up
|
17 |
generate_image: Whether to also generate an image based on the search results
|
18 |
"""
|
19 |
+
try:
|
20 |
+
# Initialize the search tool
|
21 |
+
search_tool = DuckDuckGoSearchTool()
|
22 |
+
|
23 |
+
# Perform the search and add debug output
|
24 |
+
print(f"Searching for: {search_query}")
|
25 |
+
results = search_tool(search_query)
|
26 |
+
print(f"Got {len(results) if results else 0} results")
|
27 |
+
|
28 |
+
if not results:
|
29 |
+
return "No results found for the query."
|
30 |
+
|
31 |
+
# Get the first result and format it
|
32 |
+
first_result = results[0]
|
33 |
+
summary = f"Latest AI News:\nTitle: {first_result['title']}\nSummary: {first_result['snippet']}"
|
34 |
+
|
35 |
+
# Add image generation if requested
|
36 |
+
if generate_image:
|
37 |
+
try:
|
38 |
+
print("Attempting to generate image...")
|
39 |
+
image_result = image_generation_tool(search_query)
|
40 |
+
summary += f"\n\nGenerated visualization based on the query."
|
41 |
+
except Exception as e:
|
42 |
+
print(f"Image generation failed: {str(e)}")
|
43 |
+
summary += f"\n\nNote: Image generation was requested but failed."
|
44 |
+
|
45 |
+
return summary
|
46 |
+
|
47 |
+
except Exception as e:
|
48 |
+
error_msg = f"Error in my_custom_tool: {str(e)}"
|
49 |
+
print(error_msg) # For debugging
|
50 |
+
return error_msg
|
51 |
|
52 |
@tool
|
53 |
def get_current_time_in_timezone(timezone: str) -> str:
|