Update app.py
Browse files
app.py
CHANGED
|
@@ -45,6 +45,30 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 45 |
# return text[:5000] # limit size
|
| 46 |
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# --- Basic Agent Definition ---
|
| 49 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 50 |
class BasicAgent:
|
|
@@ -90,11 +114,11 @@ class BasicAgent:
|
|
| 90 |
'post_messages': 'Write:\n\n<code>\nfinal_answer(result)\n</code>\n\nWhere result is:\n- a string\n- or a number\n- NEVER a list or array\n'}}
|
| 91 |
|
| 92 |
self.web_search = DuckDuckGoSearchTool()
|
| 93 |
-
|
| 94 |
|
| 95 |
self.agent = CodeAgent(
|
| 96 |
model=self.model,
|
| 97 |
-
tools=[self.web_search,],
|
| 98 |
max_steps=5,
|
| 99 |
verbosity_level=1,
|
| 100 |
additional_authorized_imports=["json", "pandas", "wiki", 'random', 'time', 'itertools', 'statistics', 'queue', 'math', 'collections', 'datetime', 'unicodedata', 're', 'stat'],
|
|
|
|
| 45 |
# return text[:5000] # limit size
|
| 46 |
|
| 47 |
|
| 48 |
+
@tool
|
| 49 |
+
def visit_webpage(url: str) -> str:
|
| 50 |
+
"""
|
| 51 |
+
Fetch and read the content of a webpage.
|
| 52 |
+
Args:
|
| 53 |
+
url: URL of the webpage
|
| 54 |
+
Returns:
|
| 55 |
+
Extracted readable text (truncated)
|
| 56 |
+
"""
|
| 57 |
+
headers = {
|
| 58 |
+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
response = requests.get(url, headers=headers, timeout=10)
|
| 62 |
+
response.raise_for_status()
|
| 63 |
+
|
| 64 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 65 |
+
|
| 66 |
+
paragraphs = [p.get_text() for p in soup.find_all("p")]
|
| 67 |
+
text = "\n".join(paragraphs)
|
| 68 |
+
|
| 69 |
+
return text[:5000]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
# --- Basic Agent Definition ---
|
| 73 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 74 |
class BasicAgent:
|
|
|
|
| 114 |
'post_messages': 'Write:\n\n<code>\nfinal_answer(result)\n</code>\n\nWhere result is:\n- a string\n- or a number\n- NEVER a list or array\n'}}
|
| 115 |
|
| 116 |
self.web_search = DuckDuckGoSearchTool()
|
| 117 |
+
# self.visit_webpage = VisitWebpageTool()
|
| 118 |
|
| 119 |
self.agent = CodeAgent(
|
| 120 |
model=self.model,
|
| 121 |
+
tools=[self.web_search, visit_webpage,],
|
| 122 |
max_steps=5,
|
| 123 |
verbosity_level=1,
|
| 124 |
additional_authorized_imports=["json", "pandas", "wiki", 'random', 'time', 'itertools', 'statistics', 'queue', 'math', 'collections', 'datetime', 'unicodedata', 're', 'stat'],
|