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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
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 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:
 
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: