MariaMaraShe commited on
Commit
bc41013
·
verified ·
1 Parent(s): 6a5d3c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import datetime
4
  import requests
5
  import pytz
6
  import yaml
 
7
  from tools.final_answer import FinalAnswerTool
8
  web_search = DuckDuckGoSearchTool()
9
 
@@ -36,6 +37,25 @@ def get_current_time_in_timezone(timezone: str) -> str:
36
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  final_answer = FinalAnswerTool()
40
 
41
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -58,7 +78,7 @@ with open("prompts.yaml", 'r') as stream:
58
 
59
  agent = CodeAgent(
60
  model=model,
61
- tools=[web_search, final_answer], ## add your tools here (don't remove final answer)
62
  max_steps=6,
63
  verbosity_level=1,
64
  grammar=None,
 
4
  import requests
5
  import pytz
6
  import yaml
7
+ from bs4 import BeautifulSoup
8
  from tools.final_answer import FinalAnswerTool
9
  web_search = DuckDuckGoSearchTool()
10
 
 
37
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
38
 
39
 
40
+ @tool
41
+ def visit_webpage(url: str) -> str:
42
+ """Извлекает текстовое содержимое веб-страницы по URL.
43
+
44
+ Args:
45
+ url: Адрес веб-страницы для чтения
46
+ """
47
+ try:
48
+ headers = {
49
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
50
+ }
51
+ response = requests.get(url, headers=headers, timeout=30)
52
+ soup = BeautifulSoup(response.text, 'html.parser')
53
+ for tag in soup(['script', 'style', 'meta', 'link']):
54
+ tag.decompose()
55
+ return soup.get_text(separator='\n', strip=True)
56
+ except Exception as e:
57
+ return f"Error fetching webpage: {str(e)}"
58
+
59
  final_answer = FinalAnswerTool()
60
 
61
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
78
 
79
  agent = CodeAgent(
80
  model=model,
81
+ tools=[web_search, visit_webpage, final_answer], ## add your tools here (don't remove final answer)
82
  max_steps=6,
83
  verbosity_level=1,
84
  grammar=None,