Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -70,7 +70,21 @@ def page(lst, pg):
|
|
70 |
total = (len(lst) + PER_PAGE - 1) // PER_PAGE
|
71 |
return lst[s:e], total
|
72 |
|
73 |
-
# โโโโโโโโโโโโโโโโโโโโโ 5.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
def html(cards, pg, total):
|
75 |
if not cards:
|
76 |
return "<div style='text-align:center;padding:70px;color:#555;'>ํ์ํ ๋ฐฐํฌ๊ฐ ์์ต๋๋ค.</div>"
|
@@ -146,6 +160,12 @@ def html(cards, pg, total):
|
|
146 |
transform-origin: top left;
|
147 |
border: 0;
|
148 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
.foot {
|
150 |
padding: 6px 12px;
|
151 |
background: rgba(255,255,255,.95);
|
@@ -216,12 +236,21 @@ def html(cards, pg, total):
|
|
216 |
|
217 |
for c in cards:
|
218 |
date = datetime.datetime.fromtimestamp(int(c["ts"])).strftime("%Y-%m-%d")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
h += f"""
|
220 |
<div class="card">
|
221 |
<div class="hdr"><p class="ttl">{c['title']}</p><p class="date">{date}</p></div>
|
222 |
-
<div class="
|
223 |
-
allow="accelerometer; camera; encrypted-media; gyroscope;"
|
224 |
-
|
|
|
225 |
</div>"""
|
226 |
|
227 |
h += """
|
@@ -234,7 +263,7 @@ def html(cards, pg, total):
|
|
234 |
|
235 |
return h
|
236 |
|
237 |
-
# โโโโโโโโโโโโโโโโโโโโโ
|
238 |
def build():
|
239 |
_init_best()
|
240 |
with gr.Blocks(title="Vibe Game Craft", css="""
|
|
|
70 |
total = (len(lst) + PER_PAGE - 1) // PER_PAGE
|
71 |
return lst[s:e], total
|
72 |
|
73 |
+
# โโโโโโโโโโโโโโโโโโโโโ 5. URL ์ฒ๋ฆฌ ํจ์ โโโโโโโโโโโโโโโโโโโโโ
|
74 |
+
def process_url_for_iframe(url):
|
75 |
+
"""URL์ iframe์ ํ์ํ๊ธฐ ์ ํฉํ ํํ๋ก ๋ณํํฉ๋๋ค."""
|
76 |
+
# ํ๊น
ํ์ด์ค URL ์ฒ๋ฆฌ
|
77 |
+
if "huggingface.co/spaces" in url:
|
78 |
+
# ์ด๋ฏธ /embed๋ก ๋๋๋์ง ํ์ธ
|
79 |
+
if not url.endswith("/embed"):
|
80 |
+
# URL์์ trailing slash ์ ๊ฑฐ
|
81 |
+
url = url.rstrip("/")
|
82 |
+
# /embed ์ถ๊ฐ
|
83 |
+
url = f"{url}/embed"
|
84 |
+
|
85 |
+
return url
|
86 |
+
|
87 |
+
# โโโโโโโโโโโโโโโโโโโโโ 6. HTML ๊ทธ๋ฆฌ๋ โโโโโโโโโโโโโโโโโโโ
|
88 |
def html(cards, pg, total):
|
89 |
if not cards:
|
90 |
return "<div style='text-align:center;padding:70px;color:#555;'>ํ์ํ ๋ฐฐํฌ๊ฐ ์์ต๋๋ค.</div>"
|
|
|
160 |
transform-origin: top left;
|
161 |
border: 0;
|
162 |
}
|
163 |
+
/* ํ๊น
ํ์ด์ค iframe ํน๋ณ ์คํ์ผ */
|
164 |
+
.frame.huggingface iframe {
|
165 |
+
width: 100%;
|
166 |
+
height: 100%;
|
167 |
+
transform: none;
|
168 |
+
}
|
169 |
.foot {
|
170 |
padding: 6px 12px;
|
171 |
background: rgba(255,255,255,.95);
|
|
|
236 |
|
237 |
for c in cards:
|
238 |
date = datetime.datetime.fromtimestamp(int(c["ts"])).strftime("%Y-%m-%d")
|
239 |
+
|
240 |
+
# URL ์ฒ๋ฆฌ: ํ๊น
ํ์ด์ค URL์ธ ๊ฒฝ์ฐ ํน๋ณ ์ฒ๋ฆฌ
|
241 |
+
url = c['url']
|
242 |
+
iframe_url = process_url_for_iframe(url)
|
243 |
+
|
244 |
+
# ํ๊น
ํ์ด์ค URL์ ํน๋ณ ํด๋์ค ์ถ๊ฐ
|
245 |
+
frame_class = "frame huggingface" if "huggingface.co" in url else "frame"
|
246 |
+
|
247 |
h += f"""
|
248 |
<div class="card">
|
249 |
<div class="hdr"><p class="ttl">{c['title']}</p><p class="date">{date}</p></div>
|
250 |
+
<div class="{frame_class}"><iframe src="{iframe_url}" loading="lazy"
|
251 |
+
allow="accelerometer; camera; encrypted-media; gyroscope; microphone;"
|
252 |
+
sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe></div>
|
253 |
+
<div class="foot"><a class="link" href="{url}" target="_blank">์๋ณธโ</a></div>
|
254 |
</div>"""
|
255 |
|
256 |
h += """
|
|
|
263 |
|
264 |
return h
|
265 |
|
266 |
+
# โโโโโโโโโโโโโโโโโโโโโ 7. Gradio Blocks UI โโโโโโโโโโโโโโโโโโโโโ
|
267 |
def build():
|
268 |
_init_best()
|
269 |
with gr.Blocks(title="Vibe Game Craft", css="""
|