GrizzGrizz commited on
Commit
661b349
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -7
app.py CHANGED
@@ -7,16 +7,59 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
+ def summarize_webpage(url: str, max_length: int = 300) -> str:
12
+ """A tool that fetches a webpage and provides a concise summary of its content.
13
+
14
  Args:
15
+ url: The URL of the webpage to summarize
16
+ max_length: Maximum length of the summary in characters
17
  """
18
+ try:
19
+ import requests
20
+ from bs4 import BeautifulSoup
21
+ import re
22
+
23
+ # Fetch the webpage
24
+ headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
25
+ response = requests.get(url, headers=headers, timeout=10)
26
+ response.raise_for_status()
27
+
28
+ # Parse HTML content
29
+ soup = BeautifulSoup(response.content, 'html.parser')
30
+
31
+ # Remove script and style elements
32
+ for script in soup(["script", "style", "header", "footer", "nav"]):
33
+ script.extract()
34
+
35
+ # Get text and clean it
36
+ text = soup.get_text()
37
+ lines = (line.strip() for line in text.splitlines())
38
+ chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
39
+ text = '\n'.join(chunk for chunk in chunks if chunk)
40
+
41
+ # Remove excessive newlines and whitespace
42
+ text = re.sub(r'\n+', '\n', text)
43
+ text = re.sub(r'\s+', ' ', text)
44
+
45
+ # Truncate to avoid overwhelming the model
46
+ text = text[:10000] if len(text) > 10000 else text
47
+
48
+ # Get title
49
+ title = soup.title.string if soup.title else "Unknown Title"
50
+
51
+ # For the summarization, we'll use our agent's model directly
52
+ # Note: This assumes the agent will handle the summarization part
53
+
54
+ return {
55
+ "title": title,
56
+ "url": url,
57
+ "content": text,
58
+ "summary_request": f"Please summarize the above webpage content in no more than {max_length} characters."
59
+ }
60
+
61
+ except Exception as e:
62
+ return f"Error fetching or processing webpage: {str(e)}"
63
 
64
  @tool
65
  def get_current_time_in_timezone(timezone: str) -> str: