Pycharl commited on
Commit
b33f59e
·
verified ·
1 Parent(s): 405a8b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -9,14 +9,27 @@ 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 find_website(site:str) -> str:
13
- """A tool that finds websites.
14
  Args:
15
- site: website to find
16
-
17
  """
18
- webpage = requests.get(site)
19
- return f"The webpage {webpage} has been found."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def find_website(site: str) -> str:
13
+ """A tool that fetches a website and returns its text content.
14
  Args:
15
+ site: website URL to fetch (must include https:// or http://)
 
16
  """
17
+ try:
18
+ # Add https:// if not provided
19
+ if not site.startswith(('http://', 'https://')):
20
+ site = 'https://' + site
21
+
22
+ response = requests.get(site, timeout=10)
23
+ response.raise_for_status() # Raises error for bad status codes
24
+
25
+ # Return first 1000 characters of content
26
+ content = response.text[:1000]
27
+ return f"Website {site} fetched successfully!\n\nContent preview:\n{content}..."
28
+
29
+ except requests.exceptions.Timeout:
30
+ return f"Error: Timeout while fetching {site}"
31
+ except requests.exceptions.RequestException as e:
32
+ return f"Error fetching {site}: {str(e)}"
33
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str: