pip install gradio selenium webdriver-manager import gradio as gr from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager import os from time import sleep def take_screenshot(url): # Set up Chrome options chrome_options = Options() chrome_options.add_argument("--headless") # Run in headless mode chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") # Set up Chrome WebDriver service = Service(ChromeDriverManager().install()) driver = webdriver.Chrome(service=service, options=chrome_options) # Open the URL and take screenshot try: driver.get(url) sleep(2) # Wait for page to fully load screenshot_path = "screenshot.png" driver.save_screenshot(screenshot_path) driver.quit() return screenshot_path except Exception as e: driver.quit() return str(e) # Define the Gradio interface with gr.Blocks() as demo: gr.Markdown("## Website Screenshot Tool") url_input = gr.Textbox(label="Enter Website URL", placeholder="e.g., https://example.com") screenshot_output = gr.Image(label="Screenshot") capture_button = gr.Button("Capture Screenshot") capture_button.click(take_screenshot, inputs=url_input, outputs=screenshot_output) # Launch the interface if __name__ == "__main__": demo.launch()