Sandiago21 commited on
Commit
eee9f17
·
verified ·
1 Parent(s): 7ca5376

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -12,7 +12,7 @@ import yaml
12
  # from tools.final_answer import FinalAnswerTool
13
  from PIL import Image
14
  from io import BytesIO
15
- from smolagents.tools import BaseTool
16
  import requests
17
  from bs4 import BeautifulSoup
18
 
@@ -20,29 +20,29 @@ from bs4 import BeautifulSoup
20
  # --- Constants ---
21
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
22
 
23
- class VisitWebpageTool(BaseTool):
24
- name = "visit_webpage"
25
- description = "Fetch and read the content of a webpage"
26
- inputs = {"url": {"type": "string"}}
27
- output_type = "string"
28
-
29
- def __call__(self, url: str):
30
- # response = requests.get(url)
31
- # soup = BeautifulSoup(response.text, "html.parser")
32
- # return soup.get_text()[:5000] # truncate for safety
33
-
34
- headers = {
35
- "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"
36
- }
37
- response = requests.get(url, headers=headers, timeout=10)
38
- response.raise_for_status()
39
- soup = BeautifulSoup(response.text, "html.parser")
40
-
41
- # Extract only readable text
42
- paragraphs = [p.get_text() for p in soup.find_all("p")]
43
- text = "\n".join(paragraphs)
44
-
45
- return text[:5000] # limit size
46
 
47
 
48
  # --- Basic Agent Definition ---
 
12
  # from tools.final_answer import FinalAnswerTool
13
  from PIL import Image
14
  from io import BytesIO
15
+ # from smolagents.tools import BaseTool
16
  import requests
17
  from bs4 import BeautifulSoup
18
 
 
20
  # --- Constants ---
21
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
22
 
23
+ # class VisitWebpageTool(BaseTool):
24
+ # name = "visit_webpage"
25
+ # description = "Fetch and read the content of a webpage"
26
+ # inputs = {"url": {"type": "string"}}
27
+ # output_type = "string"
28
+
29
+ # def __call__(self, url: str):
30
+ # # response = requests.get(url)
31
+ # # soup = BeautifulSoup(response.text, "html.parser")
32
+ # # return soup.get_text()[:5000] # truncate for safety
33
+
34
+ # headers = {
35
+ # "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"
36
+ # }
37
+ # response = requests.get(url, headers=headers, timeout=10)
38
+ # response.raise_for_status()
39
+ # soup = BeautifulSoup(response.text, "html.parser")
40
+
41
+ # # Extract only readable text
42
+ # paragraphs = [p.get_text() for p in soup.find_all("p")]
43
+ # text = "\n".join(paragraphs)
44
+
45
+ # return text[:5000] # limit size
46
 
47
 
48
  # --- Basic Agent Definition ---