Spaces:
Sleeping
Sleeping
arxivgpt kim
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
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 |
|
@@ -12,39 +11,31 @@ def take_screenshot(url, capture_type):
|
|
12 |
options.add_argument('--no-sandbox')
|
13 |
options.add_argument('--disable-dev-shm-usage')
|
14 |
|
15 |
-
wd =
|
16 |
-
try:
|
17 |
-
service = Service(ChromeDriverManager().install())
|
18 |
-
wd = webdriver.Chrome(service=service, options=options)
|
19 |
-
wd.get(url)
|
20 |
-
wd.implicitly_wait(10)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
finally:
|
34 |
-
if wd:
|
35 |
-
wd.quit()
|
36 |
|
37 |
return Image.open(BytesIO(screenshot))
|
38 |
|
39 |
iface = gr.Interface(
|
40 |
fn=take_screenshot,
|
41 |
inputs=[
|
42 |
-
gr.
|
43 |
-
gr.
|
44 |
],
|
45 |
-
outputs=gr.Image(type="pil"
|
46 |
title="Website Screenshot",
|
47 |
-
description="Take a screenshot of a website.
|
48 |
)
|
49 |
|
50 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from selenium import webdriver
|
|
|
|
|
3 |
from webdriver_manager.chrome import ChromeDriverManager
|
4 |
+
from selenium.webdriver.chrome.service import Service
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
|
|
|
11 |
options.add_argument('--no-sandbox')
|
12 |
options.add_argument('--disable-dev-shm-usage')
|
13 |
|
14 |
+
wd = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
if capture_type == "전체 페이지":
|
17 |
+
# 전체 페이지 캡처 로직 (예시: JavaScript를 사용하여 페이지 높이 측정)
|
18 |
+
wd.get(url)
|
19 |
+
total_height = wd.execute_script("return document.body.parentNode.scrollHeight")
|
20 |
+
wd.set_window_size(1024, total_height) # 창 크기를 전체 페이지 높이에 맞춤
|
21 |
+
else:
|
22 |
+
wd.set_window_size(1024, 768) # 기본 크기
|
23 |
|
24 |
+
wd.get(url)
|
25 |
+
screenshot = wd.get_screenshot_as_png()
|
26 |
+
wd.quit()
|
|
|
|
|
|
|
27 |
|
28 |
return Image.open(BytesIO(screenshot))
|
29 |
|
30 |
iface = gr.Interface(
|
31 |
fn=take_screenshot,
|
32 |
inputs=[
|
33 |
+
gr.Textbox(label="Website URL", default="https://korating.com"),
|
34 |
+
gr.Radio(choices=["기본 크기", "전체 페이지"], label="캡처 유형 선택")
|
35 |
],
|
36 |
+
outputs=gr.Image(type="pil"),
|
37 |
title="Website Screenshot",
|
38 |
+
description="Take a screenshot of a website."
|
39 |
)
|
40 |
|
41 |
iface.launch()
|