broadfield-dev commited on
Commit
bf18344
·
verified ·
1 Parent(s): e2ba8a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -87,7 +87,7 @@ def load_model(model_name):
87
  yield f"Status: Error loading model: {e}", gr.update(interactive=True), None, None
88
 
89
  # --- Playwright Screenshot Function ---
90
- def take_screenshot(url, max_dimension=1024, full_page_capture=True):
91
  if not url.startswith('http://') and not url.startswith('https://'):
92
  url = 'http://' + url
93
  try:
@@ -95,6 +95,7 @@ def take_screenshot(url, max_dimension=1024, full_page_capture=True):
95
  browser = p.chromium.launch(headless=True)
96
  page = browser.new_page()
97
  page.goto(url, wait_until='networkidle')
 
98
  screenshot_path = f"screenshot_{int(time.time())}.png"
99
  page.screenshot(path=screenshot_path, full_page=full_page_capture)
100
  browser.close()
@@ -165,8 +166,10 @@ with gr.Blocks() as demo:
165
 
166
  with gr.Row():
167
  url_input = gr.Textbox(label="Website URL", placeholder="e.g., www.google.com")
168
- screenshot_button = gr.Button("Capture Screenshot")
169
-
 
 
170
  with gr.Row():
171
  image_output = gr.Image(type="numpy", label="Screenshot", scale=1)
172
  with gr.Column(scale=1):
@@ -194,7 +197,7 @@ with gr.Blocks() as demo:
194
 
195
  screenshot_button.click(
196
  fn=update_image,
197
- inputs=[url_input, max_dim_slider, full_page_checkbox],
198
  outputs=image_output
199
  )
200
 
 
87
  yield f"Status: Error loading model: {e}", gr.update(interactive=True), None, None
88
 
89
  # --- Playwright Screenshot Function ---
90
+ def take_screenshot(url, max_dimension=1024, full_page_capture=True, timeout=0):
91
  if not url.startswith('http://') and not url.startswith('https://'):
92
  url = 'http://' + url
93
  try:
 
95
  browser = p.chromium.launch(headless=True)
96
  page = browser.new_page()
97
  page.goto(url, wait_until='networkidle')
98
+ time.sleep(timeout)
99
  screenshot_path = f"screenshot_{int(time.time())}.png"
100
  page.screenshot(path=screenshot_path, full_page=full_page_capture)
101
  browser.close()
 
166
 
167
  with gr.Row():
168
  url_input = gr.Textbox(label="Website URL", placeholder="e.g., www.google.com")
169
+ with gr.Column():
170
+ screenshot_button = gr.Button("Capture Screenshot")
171
+ timeout_slider = gr.Slider(1, 1, 10, step=1, label="Page Load Timeout")
172
+
173
  with gr.Row():
174
  image_output = gr.Image(type="numpy", label="Screenshot", scale=1)
175
  with gr.Column(scale=1):
 
197
 
198
  screenshot_button.click(
199
  fn=update_image,
200
+ inputs=[url_input, max_dim_slider, full_page_checkbox, timeout_slider],
201
  outputs=image_output
202
  )
203