Update app.py
#25
by
UlaMar
- opened
app.py
CHANGED
@@ -7,16 +7,27 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
#
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -51,7 +62,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[final_answer
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# Custom tool to fetch webpage title
|
11 |
@tool
|
12 |
+
def fetch_webpage_title(url: str) -> str:
|
13 |
+
"""A tool that fetches the title of a webpage.
|
14 |
+
|
15 |
Args:
|
16 |
+
url: The URL of the webpage to fetch.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
The title of the webpage.
|
20 |
"""
|
21 |
+
try:
|
22 |
+
response = requests.get(url)
|
23 |
+
response.raise_for_status() # Raise an exception for invalid responses
|
24 |
+
# Extract title from the HTML
|
25 |
+
from bs4 import BeautifulSoup
|
26 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
27 |
+
title = soup.title.string if soup.title else "No title found"
|
28 |
+
return f"The title of the webpage at {url} is: {title}"
|
29 |
+
except Exception as e:
|
30 |
+
return f"Error fetching webpage title: {str(e)}"
|
31 |
|
32 |
@tool
|
33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
62 |
|
63 |
agent = CodeAgent(
|
64 |
model=model,
|
65 |
+
tools=[final_answer, DuckDuckGoSearchTool(), image_generation_tool, fetch_webpage_title],
|
66 |
max_steps=6,
|
67 |
verbosity_level=1,
|
68 |
grammar=None,
|