Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from selenium import webdriver
|
|
| 3 |
from selenium.common.exceptions import WebDriverException
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
|
|
|
| 6 |
|
| 7 |
def take_screenshot(url):
|
| 8 |
options = webdriver.ChromeOptions()
|
|
@@ -15,6 +16,7 @@ def take_screenshot(url):
|
|
| 15 |
wd.set_window_size(1080, 720) # Adjust the window size here
|
| 16 |
wd.get(url)
|
| 17 |
wd.implicitly_wait(10)
|
|
|
|
| 18 |
screenshot = wd.get_screenshot_as_png()
|
| 19 |
except WebDriverException as e:
|
| 20 |
return Image.new('RGB', (1, 1))
|
|
@@ -27,9 +29,9 @@ def take_screenshot(url):
|
|
| 27 |
iface = gr.Interface(
|
| 28 |
fn=take_screenshot,
|
| 29 |
inputs=gr.Textbox(label="Website URL", value="https://github.com/aiclubiitropar"),
|
| 30 |
-
outputs=gr.Image(type="pil", label="Screenshot", height=360, width=540),
|
| 31 |
title="Website Screenshot",
|
| 32 |
description="Take a screenshot of a website."
|
| 33 |
)
|
| 34 |
|
| 35 |
-
iface.launch()
|
|
|
|
| 3 |
from selenium.common.exceptions import WebDriverException
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
| 6 |
+
import time # <-- import time
|
| 7 |
|
| 8 |
def take_screenshot(url):
|
| 9 |
options = webdriver.ChromeOptions()
|
|
|
|
| 16 |
wd.set_window_size(1080, 720) # Adjust the window size here
|
| 17 |
wd.get(url)
|
| 18 |
wd.implicitly_wait(10)
|
| 19 |
+
time.sleep(2) # <-- Add delay before screenshot
|
| 20 |
screenshot = wd.get_screenshot_as_png()
|
| 21 |
except WebDriverException as e:
|
| 22 |
return Image.new('RGB', (1, 1))
|
|
|
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=take_screenshot,
|
| 31 |
inputs=gr.Textbox(label="Website URL", value="https://github.com/aiclubiitropar"),
|
| 32 |
+
outputs=gr.Image(type="pil", label="Screenshot", height=360, width=540),
|
| 33 |
title="Website Screenshot",
|
| 34 |
description="Take a screenshot of a website."
|
| 35 |
)
|
| 36 |
|
| 37 |
+
iface.launch()
|