TheDawoud commited on
Commit
c96ee12
·
1 Parent(s): 8290b4f

- Hopefully this fixes it

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -6,20 +6,27 @@ import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import numpy as np
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 get_animal_image(animal_name: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
  """A tool that gets a random animal image from the internet and returns an image as numpy array
15
  Args:
16
  animal_name: the animal name
17
  """
 
 
 
 
 
 
 
 
18
  #get the image from the internet
19
- image_url = f"https://www.google.com/search?q={animal_name}&tbm=isch"
20
- #download the image
21
- response = requests.get(image_url)
22
- #return the image as base64 string
23
  return np.array(response.content)
24
 
25
  @tool
 
6
  from tools.final_answer import FinalAnswerTool
7
  import numpy as np
8
  from Gradio_UI import GradioUI
9
+ from bs4 import BeautifulSoup
10
+ import random
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def get_animal_image(animal_name:str)-> np.ndarray: #it's import to specify the return type
14
  #Keep this format for the description / args / args description but feel free to modify the tool
15
  """A tool that gets a random animal image from the internet and returns an image as numpy array
16
  Args:
17
  animal_name: the animal name
18
  """
19
+ # search for the animal name on the internet in images search
20
+ search_url = f"https://www.google.com/search?q={animal_name}&tbm=isch"
21
+ #get the image from the internet
22
+ response = requests.get(search_url)
23
+ #parse the html
24
+ soup = BeautifulSoup(response.text, 'html.parser')
25
+ # select a random image from the search results
26
+ image_url = random.choice(soup.find_all('img'))['src']
27
  #get the image from the internet
28
+ response = requests.get(image_url)
29
+ #return the image as numpy array
 
 
30
  return np.array(response.content)
31
 
32
  @tool