File size: 1,068 Bytes
c3b7bd1
 
0b0654c
c3b7bd1
 
 
5c6befd
c3b7bd1
 
 
 
 
5c6befd
 
 
 
cabb11a
5c6befd
 
 
 
 
 
 
c3b7bd1
 
 
b7c06b0
 
 
 
 
 
c3b7bd1
 
73d145c
5c6befd
b7c06b0
c3b7bd1
 
5c6befd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from PIL import Image
from io import BytesIO

def take_screenshot(url):
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')

    wd = None
    try:
        wd = webdriver.Chrome(options=options)
        wd.set_window_size(1920, 1080)  # 조정된 윈도우 크기
        wd.get(url)
        wd.implicitly_wait(10)
        screenshot = wd.get_screenshot_as_png()
    except WebDriverException as e:
        return Image.new('RGB', (1, 1))
    finally:
        if wd:
            wd.quit()

    return Image.open(BytesIO(screenshot))

css = """
footer { 
    visibility: hidden; 
}
"""

iface = gr.Interface(
    fn=take_screenshot,
    inputs=gr.inputs.Textbox(label="Website URL", default="https://www.ycombinator.com/"),
    outputs=gr.Image(type="pil", height=540, width=960),  # 조정된 이미지 크기
    css=css
)

iface.launch()