import os import random import gradio as gr from selenium import webdriver from selenium_stealth import stealth from selenium.webdriver.chrome.options import Options def main(url): chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument("start-maximized") chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_experimental_option('useAutomationExtension', False) chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) driver = webdriver.Chrome(options=chrome_options) stealth( driver, languages=["en-US", "en"], vendor="Google Inc.", platform="Win32", webgl_vendor="Intel Inc.", renderer="Intel Iris OpenGL Engine", fix_hairline=True ) if("https://" in url.lower() or "http://" in url.lower()): driver.get(url) else: driver.get("http://" + url) page_width = driver.execute_script("return document.body.scrollWidth") page_height = driver.execute_script("return document.body.scrollHeight") driver.set_window_size(page_width, page_height) filename = str(random.randint(111111111, 999999999)) + ".png" file_path = os.path.join(os.path.dirname(__file__), filename) driver.save_screenshot(file_path) return(file_path) iface = gr.Interface(fn=main, inputs=gr.Textbox(label="URL"), outputs=[gr.Image(label="Render")]) iface.launch()