arxivgpt kim commited on
Commit
5c6befd
·
verified ·
1 Parent(s): 1991b2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
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, capture_type):
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 = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
16
-
17
- if capture_type == "전체 페이지":
 
18
  wd.get(url)
19
- wd.set_window_size(1920, 1080) # 임시로 큰 값을 설정합니다. 실제 높이는 아래에서 계산됩니다.
20
- total_height = wd.execute_script("return document.body.scrollHeight")
21
- wd.set_window_size(1920, total_height) # 페이지 전체 높이로 창 크기 조정
22
- else:
23
- wd.set_window_size(1920, 1080) # 기본 크기
24
-
25
- wd.get(url)
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
- gr.Textbox(label="Website URL", placeholder="https://korating.com"),
35
- gr.Radio(choices=["기본 크기", "전체 페이지"], label="캡처 유형 선택", default="기본 크기")
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()