Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,40 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +76,7 @@ with open("prompts.yaml", 'r') as 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,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import re
|
| 8 |
+
from markdownify import markdownify
|
| 9 |
+
from requests.exceptions import RequestException
|
| 10 |
+
from smolagents import tool
|
| 11 |
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
|
| 14 |
+
|
| 15 |
+
def visit_webpage(url: str) -> str:
|
| 16 |
+
"""Visits a webpage at the given URL and returns its content as a markdown string.
|
| 17 |
+
|
|
|
|
| 18 |
Args:
|
| 19 |
+
url: The URL of the webpage to visit.
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
The content of the webpage converted to Markdown, or an error message if the request fails.
|
| 23 |
"""
|
| 24 |
+
try:
|
| 25 |
+
# Send a GET request to the URL
|
| 26 |
+
response = requests.get(url)
|
| 27 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 28 |
+
|
| 29 |
+
# Convert the HTML content to Markdown
|
| 30 |
+
markdown_content = markdownify(response.text).strip()
|
| 31 |
+
|
| 32 |
+
# Remove multiple line breaks
|
| 33 |
+
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
| 34 |
+
|
| 35 |
+
return markdown_content
|
| 36 |
+
|
| 37 |
+
except RequestException as e:
|
| 38 |
+
return f"Error fetching the webpage: {str(e)}"
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
+
tools=[final_answer, DuckDuckGoSearchTool(), visit_webpage], ## add your tools here (don't remove final answer)
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|