NatalieCheong commited on
Commit
5667f25
·
verified ·
1 Parent(s): d6a6fb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -10,35 +10,35 @@ from Gradio_UI import GradioUI
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
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:
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  # Replace this part in app.py
12
  @tool
13
+ def my_custom_tool(search_topic: str, max_results: int) -> str:
14
+ """A tool that performs a web search and returns formatted results
15
  Args:
16
+ search_topic: The topic to search for
17
+ max_results: Number of results to return (1-3)
18
  """
19
  try:
 
20
  search_tool = DuckDuckGoSearchTool()
21
+ results = search_tool(search_topic)
22
 
 
 
 
 
23
  if not results:
24
+ return f"No information found about '{search_topic}'"
25
 
26
+ # Limit number of results
27
+ max_results = min(max(1, max_results), 3)
28
+ results = results[:max_results]
29
 
30
+ # Format response like the time zone example
31
+ formatted_results = []
32
+ for result in results:
33
+ formatted_results.append(
34
+ f"Title: {result['title']}\n"
35
+ f"Summary: {result['snippet']}"
36
+ )
37
 
38
+ return "\n\n".join(formatted_results)
39
 
40
  except Exception as e:
41
+ return f"Error searching for '{search_topic}': {str(e)}"
42
 
43
  @tool
44
  def get_current_time_in_timezone(timezone: str) -> str: