NatalieCheong commited on
Commit
78ff159
·
verified ·
1 Parent(s): 051005a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
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 performs web search and optionally generates images.
15
  Args:
16
- query: The search query to look up information about
17
- generate_visual: Whether to generate an image for the query
18
  """
19
  try:
20
- # First do the web search
21
  search_tool = DuckDuckGoSearchTool()
22
- results = search_tool(query)
 
23
 
24
- if not results:
25
- return "No results found for your query."
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
- # If image generation was requested
 
 
 
 
32
  if generate_visual:
33
  try:
34
  image_generation_tool(query)
35
- response += "\n(An image has been generated for your query)"
36
- except Exception as e:
37
- response += "\n(Image generation failed)"
38
-
39
  return response
40
 
41
  except Exception as e:
42
- return f"Error occurred: {str(e)}"
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: