arxivgpt kim commited on
Commit
cabb11a
·
verified ·
1 Parent(s): a5b6e16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
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 = None
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
- if capture_type == "전체 페이지":
23
- # 전체 페이지 높이와 너비를 가져옵니다.
24
- total_width = wd.execute_script("return document.body.offsetWidth")
25
- total_height = wd.execute_script("return document.body.parentNode.scrollHeight")
26
- wd.set_window_size(total_width, total_height) # 윈도우 크기를 전체 페이지 크기로 조정합니다.
27
- else:
28
- wd.set_window_size(1024, 768) # 기본 크기
29
 
30
- screenshot = wd.get_screenshot_as_png()
31
- except WebDriverException as e:
32
- return Image.new('RGB', (1, 1))
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.inputs.Textbox(label="Website URL", default="https://korating.com"),
43
- gr.inputs.Radio(choices=["기본 크기", "전체 페이지"], label="캡처 유형 선택")
44
  ],
45
- outputs=gr.Image(type="pil", tool="editor"),
46
  title="Website Screenshot",
47
- description="Take a screenshot of a website. Choose '전체 페이지' to capture the full page.",
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()