NatalieCheong commited on
Commit
4d2bad8
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -9,14 +9,32 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
13
+ """A tool that combines web search and optional image generation
 
14
  Args:
15
+ search_query: The search query to look up
16
+ generate_image: Whether to also generate an image based on the search results
17
  """
18
+ # First, search using DuckDuckGo
19
+ search_tool = DuckDuckGoSearchTool()
20
+ results = search_tool(search_query)
21
+
22
+ if not results:
23
+ return "No results found for the query."
24
+
25
+ # Get the first result
26
+ first_result = results[0]
27
+ summary = f"Found: {first_result['title']}\nSummary: {first_result['snippet']}"
28
+
29
+ # If image generation is requested, also generate an image
30
+ if generate_image:
31
+ try:
32
+ image_result = image_generation_tool(search_query)
33
+ summary += f"\n\nGenerated visualization based on the query."
34
+ except Exception as e:
35
+ summary += f"\n\nImage generation failed: {str(e)}"
36
+
37
+ return summary
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str: