OfirAm commited on
Commit
5e07b61
·
verified ·
1 Parent(s): ae7a494

Implemented generate_popular_image

Browse files
Files changed (1) hide show
  1. app.py +35 -8
app.py CHANGED
@@ -9,14 +9,43 @@ 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:
@@ -47,15 +76,13 @@ custom_role_conversions=None,
47
  )
48
 
49
 
50
- # Import tool from Hub
51
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def generate_popular_image(category:str)-> 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
+ """
15
+ Searches for the most popular {category} using DuckDuckGoSearchTool,
16
+ then generates an image of that item using image_generation_tool.
17
+
18
  Args:
19
+ category (str): The category to search for (e.g., "animal", "car", "fruit").
20
+
21
+ Returns:
22
+ Generated image of the most popular item in the given category.
23
  """
24
+ if not category:
25
+ return "Please provide a category to search for."
26
+
27
+ # Step 1: Search for the most popular item in the category
28
+ search_tool = DuckDuckGoSearchTool()
29
+ query = f"most popular {category} in the world"
30
+ search_results = search_tool.run(query)
31
+
32
+ if not search_results:
33
+ return f"No search results found for the most popular {category}."
34
+
35
+ # Step 2: Extract a relevant item name using regex
36
+ match = re.search(r"\b[A-Z][a-z]+\b", search_results) # Extracts a capitalized word (name)
37
+
38
+ if match:
39
+ item_name = match.group(0)
40
+ else:
41
+ return f"Could not identify a popular {category} from the search results."
42
+
43
+ # Step 3: Generate an image of the identified item
44
+ # Import tool from Hub
45
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
46
+ image_prompt = f"A high-quality, realistic image of a {item_name}."
47
+
48
+ return image_generation_tool(image_prompt) # Return the generated image
49
 
50
  @tool
51
  def get_current_time_in_timezone(timezone: str) -> str:
 
76
  )
77
 
78
 
 
 
79
 
80
  with open("prompts.yaml", 'r') as stream:
81
  prompt_templates = yaml.safe_load(stream)
82
 
83
  agent = CodeAgent(
84
  model=model,
85
+ tools=[final_answer,], ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,