ginipick commited on
Commit
4154b8b
ยท
verified ยท
1 Parent(s): 884c56c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
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. HTML ๊ทธ๋ฆฌ๋“œ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="frame"><iframe src="{c['url']}" loading="lazy"
223
- allow="accelerometer; camera; encrypted-media; gyroscope;"></iframe></div>
224
- <div class="foot"><a class="link" href="{c['url']}" target="_blank">์›๋ณธโ†—</a></div>
 
225
  </div>"""
226
 
227
  h += """
@@ -234,7 +263,7 @@ def html(cards, pg, total):
234
 
235
  return h
236
 
237
- # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 6. Gradio Blocks UI โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
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="""