|
from selenium import webdriver |
|
from selenium.webdriver.chrome.service import Service |
|
from webdriver_manager.chrome import ChromeDriverManager |
|
import gradio as gr |
|
|
|
def capture_webpage_screenshot(url): |
|
save_path = "screenshot.png" |
|
|
|
service = Service(ChromeDriverManager().install()) |
|
options = webdriver.ChromeOptions() |
|
|
|
options.add_argument('--headless') |
|
options.add_argument('--disable-gpu') |
|
options.add_argument('window-size=1200x600') |
|
|
|
|
|
driver = webdriver.Chrome(service=service, options=options) |
|
|
|
|
|
driver.get(url) |
|
|
|
|
|
driver.save_screenshot(save_path) |
|
|
|
|
|
driver.quit() |
|
return save_path |
|
|
|
|
|
with gr.Blocks() as demo: |
|
txt = gr.Textbox() |
|
|
|
btn = gr.Button() |
|
img = gr.Image() |
|
btn.click(capture_webpage_screenshot, [txt], [img]) |
|
|
|
|
|
demo.launch() |