Spaces:
Runtime error
Runtime error
import subprocess | |
import gradio as gr | |
from playwright.sync_api import sync_playwright | |
from PIL import Image | |
import io | |
# Install Playwright browsers | |
subprocess.run(["playwright", "install"], check=True) | |
# Initialize Playwright | |
p = sync_playwright().start() | |
browser = p.chromium.launch() | |
page = browser.new_page(viewport={"width": 1024, "height": 768}) | |
page.goto("https://example.com") | |
def click_on_browser(evt: gr.SelectData): | |
x, y = evt.index | |
page.mouse.click(x, y) | |
screenshot = page.screenshot() | |
return Image.open(io.BytesIO(screenshot)) | |
def get_screenshot(): | |
screenshot = page.screenshot() | |
return Image.open(io.BytesIO(screenshot)) | |
with gr.Blocks() as demo: | |
gr.Markdown("### Simple Interactive Browser (Gradio)") | |
img = gr.Image(value=get_screenshot, interactive=True, label="Click the browser").style(full_width=True) | |
img.select(click_on_browser, None, img) | |
demo.launch() | |