Spaces:
Paused
Paused
arxivgpt kim commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from selenium import webdriver
|
| 3 |
from selenium.common.exceptions import WebDriverException
|
| 4 |
-
from selenium.webdriver.chrome.service import Service
|
| 5 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
| 6 |
from PIL import Image
|
| 7 |
from io import BytesIO
|
| 8 |
|
| 9 |
-
def take_screenshot(url
|
| 10 |
options = webdriver.ChromeOptions()
|
| 11 |
options.add_argument('--headless')
|
| 12 |
options.add_argument('--no-sandbox')
|
| 13 |
options.add_argument('--disable-dev-shm-usage')
|
| 14 |
|
| 15 |
-
wd =
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
wd.get(url)
|
| 19 |
-
wd.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
screenshot = wd.get_screenshot_as_png()
|
| 27 |
-
wd.quit()
|
| 28 |
|
| 29 |
return Image.open(BytesIO(screenshot))
|
| 30 |
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=take_screenshot,
|
| 33 |
-
inputs=
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
outputs=gr.Image(type="pil"),
|
| 38 |
-
title="Website Screenshot Tool",
|
| 39 |
-
description="Take a screenshot of a website. Choose between default size or full page."
|
| 40 |
)
|
| 41 |
|
| 42 |
-
iface.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 |
+
wd = None
|
| 14 |
+
try:
|
| 15 |
+
wd = webdriver.Chrome(options=options)
|
| 16 |
+
wd.set_window_size(1920, 1080) # 조정된 윈도우 크기
|
| 17 |
wd.get(url)
|
| 18 |
+
wd.implicitly_wait(10)
|
| 19 |
+
screenshot = wd.get_screenshot_as_png()
|
| 20 |
+
except WebDriverException as e:
|
| 21 |
+
return Image.new('RGB', (1, 1))
|
| 22 |
+
finally:
|
| 23 |
+
if wd:
|
| 24 |
+
wd.quit()
|
|
|
|
|
|
|
| 25 |
|
| 26 |
return Image.open(BytesIO(screenshot))
|
| 27 |
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=take_screenshot,
|
| 30 |
+
inputs=gr.inputs.Textbox(label="Website URL", default="https://korating.com"),
|
| 31 |
+
outputs=gr.Image(type="pil", height=540, width=960), # 조정된 이미지 크기
|
| 32 |
+
title="Website Screenshot",
|
| 33 |
+
description="Take a screenshot of a website.",
|
|
|
|
|
|
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
+
iface.launch()
|