Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,57 @@ 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
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 capture_website_screenshot(url: str, full_page: bool = False) -> str:
|
13 |
+
"""Captures a screenshot of a specified webpage.
|
|
|
14 |
Args:
|
15 |
+
url: The URL of the website to screenshot
|
16 |
+
full_page: Whether to capture the entire page or just the viewport
|
17 |
"""
|
18 |
+
import os
|
19 |
+
import tempfile
|
20 |
+
from selenium import webdriver
|
21 |
+
from selenium.webdriver.chrome.options import Options
|
22 |
+
from datetime import datetime
|
23 |
+
|
24 |
+
try:
|
25 |
+
# Create a temporary file path for the screenshot
|
26 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
27 |
+
temp_dir = tempfile.gettempdir()
|
28 |
+
screenshot_path = os.path.join(temp_dir, f"screenshot_{timestamp}.png")
|
29 |
+
|
30 |
+
# Configure Chrome options
|
31 |
+
chrome_options = Options()
|
32 |
+
chrome_options.add_argument("--headless") # Run in headless mode
|
33 |
+
chrome_options.add_argument("--disable-gpu")
|
34 |
+
chrome_options.add_argument("--no-sandbox")
|
35 |
+
chrome_options.add_argument("--disable-dev-shm-usage")
|
36 |
+
chrome_options.add_argument("--window-size=1920,1080")
|
37 |
+
|
38 |
+
# Initialize the WebDriver
|
39 |
+
driver = webdriver.Chrome(options=chrome_options)
|
40 |
+
|
41 |
+
# Navigate to the URL
|
42 |
+
driver.get(url)
|
43 |
+
|
44 |
+
# Wait for page to load (you might need to adjust this)
|
45 |
+
driver.implicitly_wait(5)
|
46 |
+
|
47 |
+
if full_page:
|
48 |
+
# Get the total height of the page
|
49 |
+
total_height = driver.execute_script("return document.body.scrollHeight")
|
50 |
+
# Set the window size to capture everything
|
51 |
+
driver.set_window_size(1920, total_height)
|
52 |
+
|
53 |
+
# Take the screenshot
|
54 |
+
driver.save_screenshot(screenshot_path)
|
55 |
+
|
56 |
+
# Close the browser
|
57 |
+
driver.quit()
|
58 |
+
|
59 |
+
return f"Screenshot captured successfully and saved to: {screenshot_path}"
|
60 |
+
|
61 |
+
except Exception as e:
|
62 |
+
return f"Error capturing screenshot: {str(e)}"
|
63 |
|
64 |
@tool
|
65 |
def get_current_time_in_timezone(timezone: str) -> str:
|