Spaces:
Running
Running
Update app.py
Browse filesNow that the code is working, I will add some extra web functionality.
app.py
CHANGED
@@ -8,6 +8,7 @@ from tools.final_answer import FinalAnswerTool
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
import requests
|
10 |
|
|
|
11 |
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
@tool
|
@@ -22,16 +23,38 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
22 |
|
23 |
# Creating an example function to get data from a website of my choice
|
24 |
@tool
|
25 |
-
def webpage_contents_get(url:str)-> str: #it's import to specify the return type
|
26 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
27 |
"""A simple function to grab contents of a webpage
|
28 |
Args:
|
29 |
url: The URL the contents of which the tool will get
|
30 |
"""
|
31 |
-
response = requests.get(url)
|
32 |
-
html_content = response.text
|
33 |
-
return
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
@tool
|
37 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
import requests
|
10 |
|
11 |
+
from bs4 import BeautifulSoup
|
12 |
|
13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
14 |
@tool
|
|
|
23 |
|
24 |
# Creating an example function to get data from a website of my choice
|
25 |
@tool
|
26 |
+
def webpage_contents_get(url:str, headers_in: dict = None)-> str: #it's import to specify the return type
|
27 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
28 |
"""A simple function to grab contents of a webpage
|
29 |
Args:
|
30 |
url: The URL the contents of which the tool will get
|
31 |
"""
|
32 |
+
response = requests.get(url, headers = headers_in)
|
33 |
+
#html_content = response.text
|
34 |
+
return response.content
|
35 |
|
36 |
+
@tool
|
37 |
+
def webpage_header_get(url:str)-> str: #it's import to specify the return type
|
38 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
39 |
+
"""A simple function to grab header of a webpage
|
40 |
+
Args:
|
41 |
+
url: The URL the contents of which the tool will get
|
42 |
+
"""
|
43 |
+
response = requests.get(url)
|
44 |
+
return response.headers
|
45 |
+
@tool
|
46 |
+
def webpage_contents_soup_links(response_content:bytes)->list:
|
47 |
+
'''
|
48 |
+
This function will find all links in the response.content from the webpage_contents_get tool
|
49 |
+
'''
|
50 |
+
soup = BeautifulSoup(response.content, "html.parser")
|
51 |
+
list_ret
|
52 |
+
for link in soup.find_all("a"):
|
53 |
+
ret_t = link.get("href")
|
54 |
+
print(link.get("href"))
|
55 |
+
list_ret.append(link.get("href"))
|
56 |
+
return list_ret
|
57 |
+
|
58 |
|
59 |
@tool
|
60 |
def get_current_time_in_timezone(timezone: str) -> str:
|