Mayurvora commited on
Commit
55bbd7b
·
1 Parent(s): 9a8c112

Added couple of tools

Browse files
Files changed (1) hide show
  1. app.py +51 -6
app.py CHANGED
@@ -8,15 +8,60 @@ from tools.final_answer import FinalAnswerTool
8
  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_cutom_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:
 
8
  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_cutom_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 generate_custom_image(prompt: str, style: str = "realistic") -> str:
23
+ """A tool that generates a custom image based on a text prompt and style.
 
24
  Args:
25
+ prompt: The text description of the image to generate
26
+ style: The style of the image (e.g., 'realistic', 'cartoon', 'abstract'). Defaults to 'realistic'
27
  """
28
+ try:
29
+ # For this example, we'll use the image_generation_tool that's already imported
30
+ image_url = image_generation_tool(prompt=f"{style} style: {prompt}")
31
+ return f"Generated image URL: {image_url}"
32
+ except Exception as e:
33
+ return f"Error generating image: {str(e)}"
34
+ @tool
35
+ def search_and_summarize(query: str) -> str:
36
+ """A tool that searches DuckDuckGo and summarizes the top result.
37
+ Args:
38
+ query: The search query string
39
+ """
40
+ try:
41
+ # Initialize the DuckDuckGo search tool
42
+ search_tool = DuckDuckGoSearchTool()
43
+
44
+ # Get search results
45
+ results = search_tool(query)
46
+
47
+ if not results:
48
+ return "No search results found."
49
+
50
+ # Get the first (top) result
51
+ top_result = results[0]
52
+
53
+ # Extract title and snippet from the top result
54
+ title = top_result.get('title', 'No title available')
55
+ snippet = top_result.get('snippet', 'No snippet available')
56
+
57
+ # Create a formatted summary
58
+ summary = f"Top Result Summary:\nTitle: {title}\nSummary: {snippet}"
59
+
60
+ return summary
61
+
62
+ except Exception as e:
63
+ return f"Error performing search and summary: {str(e)}"
64
+
65
 
66
  @tool
67
  def get_current_time_in_timezone(timezone: str) -> str: