Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from selenium import webdriver
|
| 3 |
-
from selenium.
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
driver.get(url)
|
| 13 |
-
|
| 14 |
-
# Wait until all processes are complete
|
| 15 |
-
wait = WebDriverWait(driver, 10) # Maximum wait time in seconds
|
| 16 |
-
wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
|
| 17 |
-
|
| 18 |
-
# Extract the page title
|
| 19 |
-
title = driver.title
|
| 20 |
-
|
| 21 |
-
# Close the browser
|
| 22 |
-
driver.quit()
|
| 23 |
-
|
| 24 |
-
return title
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
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()
|
| 9 |
+
options.add_argument('--headless')
|
| 10 |
+
options.add_argument('--no-sandbox')
|
| 11 |
+
options.add_argument('--disable-dev-shm-usage')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
try:
|
| 14 |
+
wd = webdriver.Chrome(options=options)
|
| 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))
|
| 21 |
+
finally:
|
| 22 |
+
if wd:
|
| 23 |
+
wd.quit()
|
| 24 |
+
|
| 25 |
+
return Image.open(BytesIO(screenshot))
|
| 26 |
+
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
+
fn=take_screenshot,
|
| 29 |
+
inputs=gr.inputs.Textbox(label="Website URL", default="https://kargaranamir.github.io"),
|
| 30 |
+
outputs=gr.Image(type="pil", height=360, width=540), # Adjust the image size here
|
| 31 |
+
title="Website Screenshot",
|
| 32 |
+
description="Take a screenshot of a website.",
|
| 33 |
)
|
| 34 |
|
| 35 |
+
iface.launch()
|
|
|