Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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:
|