Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,33 +11,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 11 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 12 |
|
| 13 |
import re
|
| 14 |
-
from smolagents import CodeAgent,
|
| 15 |
-
from smolagents.tools import DuckDuckGoSearchTool
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
@tool
|
| 19 |
-
def visit_webpage(url: str) -> str:
|
| 20 |
-
"""
|
| 21 |
-
Fetches and returns the visible text content of any webpage.
|
| 22 |
-
Use this after a web search to read the full content of a URL.
|
| 23 |
-
|
| 24 |
-
Args:
|
| 25 |
-
url: The full URL to fetch (must start with http:// or https://)
|
| 26 |
-
|
| 27 |
-
Returns:
|
| 28 |
-
The visible text of the page, truncated to 8000 characters.
|
| 29 |
-
"""
|
| 30 |
-
try:
|
| 31 |
-
headers = {"User-Agent": "Mozilla/5.0"}
|
| 32 |
-
resp = requests.get(url, headers=headers, timeout=15)
|
| 33 |
-
resp.raise_for_status()
|
| 34 |
-
clean = re.sub(r"<style[^>]*>.*?</style>", " ", resp.text, flags=re.DOTALL)
|
| 35 |
-
clean = re.sub(r"<script[^>]*>.*?</script>", " ", clean, flags=re.DOTALL)
|
| 36 |
-
clean = re.sub(r"<[^>]+>", " ", clean)
|
| 37 |
-
clean = re.sub(r"\s+", " ", clean).strip()
|
| 38 |
-
return clean[:8000]
|
| 39 |
-
except Exception as e:
|
| 40 |
-
return f"Error fetching {url}: {e}"
|
| 41 |
|
| 42 |
|
| 43 |
@tool
|
|
@@ -128,11 +102,11 @@ class BasicAgent:
|
|
| 128 |
self.agent = CodeAgent(
|
| 129 |
tools=[
|
| 130 |
DuckDuckGoSearchTool(),
|
| 131 |
-
|
| 132 |
download_task_file,
|
| 133 |
calculate,
|
| 134 |
],
|
| 135 |
-
model=
|
| 136 |
max_steps=10,
|
| 137 |
)
|
| 138 |
print("BasicAgent initialized.")
|
|
|
|
| 11 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 12 |
|
| 13 |
import re
|
| 14 |
+
from smolagents import CodeAgent, InferenceClientModel, tool, VisitWebpageTool, DuckDuckGoSearchTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
@tool
|
|
|
|
| 102 |
self.agent = CodeAgent(
|
| 103 |
tools=[
|
| 104 |
DuckDuckGoSearchTool(),
|
| 105 |
+
VisitWebpageTool(),
|
| 106 |
download_task_file,
|
| 107 |
calculate,
|
| 108 |
],
|
| 109 |
+
model=InferenceClientModel(model_id="Qwen/Qwen2.5-72B-Instruct"),
|
| 110 |
max_steps=10,
|
| 111 |
)
|
| 112 |
print("BasicAgent initialized.")
|