memex-in commited on
Commit
b4578fb
Β·
verified Β·
1 Parent(s): c941300

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import gradio as gr
3
+ from playwright.sync_api import sync_playwright
4
+ from PIL import Image
5
+ import io
6
+
7
+ # Install Playwright browsers
8
+ subprocess.run(["playwright", "install"], check=True)
9
+
10
+ # Initialize Playwright
11
+ p = sync_playwright().start()
12
+ browser = p.chromium.launch()
13
+ page = browser.new_page(viewport={"width": 1024, "height": 768})
14
+ page.goto("https://example.com")
15
+
16
+ def click_on_browser(evt: gr.SelectData):
17
+ x, y = evt.index
18
+ page.mouse.click(x, y)
19
+ screenshot = page.screenshot()
20
+ return Image.open(io.BytesIO(screenshot))
21
+
22
+ def get_screenshot():
23
+ screenshot = page.screenshot()
24
+ return Image.open(io.BytesIO(screenshot))
25
+
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("### Simple Interactive Browser (Gradio)")
28
+ img = gr.Image(value=get_screenshot, interactive=True, label="Click the browser").style(full_width=True)
29
+ img.select(click_on_browser, None, img)
30
+
31
+ demo.launch()