openfree commited on
Commit
2464c1f
โ€ข
1 Parent(s): 0d75f36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -13,6 +13,9 @@ from datetime import datetime
13
  import gradio as gr
14
  from typing import Tuple
15
  import time
 
 
 
16
 
17
  # ์Šคํฌ๋ฆฐ์ƒท ์บ์‹œ ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ •
18
  CACHE_DIR = Path("screenshot_cache")
@@ -21,7 +24,18 @@ CACHE_DIR.mkdir(exist_ok=True)
21
 
22
  # ์ „์—ญ ๋ณ€์ˆ˜๋กœ ์Šคํฌ๋ฆฐ์ƒท ์บ์‹œ ์„ ์–ธ
23
  SCREENSHOT_CACHE = {}
 
24
 
 
 
 
 
 
 
 
 
 
 
25
  def take_screenshot(url):
26
  """์›น์‚ฌ์ดํŠธ ์Šคํฌ๋ฆฐ์ƒท ์ดฌ์˜ ํ•จ์ˆ˜ (๋กœ๋”ฉ ๋Œ€๊ธฐ ์‹œ๊ฐ„ ์ถ”๊ฐ€)"""
27
  if url in SCREENSHOT_CACHE:
 
13
  import gradio as gr
14
  from typing import Tuple
15
  import time
16
+ # ์ƒ๋‹จ์— Path import ์ถ”๊ฐ€
17
+ from pathlib import Path
18
+
19
 
20
  # ์Šคํฌ๋ฆฐ์ƒท ์บ์‹œ ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ •
21
  CACHE_DIR = Path("screenshot_cache")
 
24
 
25
  # ์ „์—ญ ๋ณ€์ˆ˜๋กœ ์Šคํฌ๋ฆฐ์ƒท ์บ์‹œ ์„ ์–ธ
26
  SCREENSHOT_CACHE = {}
27
+ # get_cached_screenshot ํ•จ์ˆ˜ ์ถ”๊ฐ€
28
 
29
+ def get_cached_screenshot(url: str) -> str:
30
+ """์บ์‹œ๋œ ์Šคํฌ๋ฆฐ์ƒท ๊ฐ€์ ธ์˜ค๊ธฐ ๋˜๋Š” ์ƒˆ๋กœ ์ƒ์„ฑ"""
31
+ cache_file = CACHE_DIR / f"{base64.b64encode(url.encode()).decode()}.png"
32
+
33
+ if cache_file.exists():
34
+ with open(cache_file, "rb") as f:
35
+ return base64.b64encode(f.read()).decode()
36
+
37
+ return take_screenshot(url)
38
+
39
  def take_screenshot(url):
40
  """์›น์‚ฌ์ดํŠธ ์Šคํฌ๋ฆฐ์ƒท ์ดฌ์˜ ํ•จ์ˆ˜ (๋กœ๋”ฉ ๋Œ€๊ธฐ ์‹œ๊ฐ„ ์ถ”๊ฐ€)"""
41
  if url in SCREENSHOT_CACHE: