ginipick commited on
Commit
3cd46cc
ยท
verified ยท
1 Parent(s): 4154b8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -15
app.py CHANGED
@@ -73,16 +73,19 @@ def page(lst, pg):
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):
@@ -159,12 +162,14 @@ def html(cards, pg, total):
159
  transform: scale(0.7);
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;
@@ -239,17 +244,26 @@ def html(cards, pg, total):
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
 
 
73
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 5. URL ์ฒ˜๋ฆฌ ํ•จ์ˆ˜ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
74
  def process_url_for_iframe(url):
75
  """URL์„ iframe์— ํ‘œ์‹œํ•˜๊ธฐ ์ ํ•ฉํ•œ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค."""
76
+ # ํ—ˆ๊น…ํŽ˜์ด์Šค URL ํŒจํ„ด ๊ฐ์ง€
77
+ is_huggingface = False
78
+
79
+ # .hf.space ๋„๋ฉ”์ธ ๋˜๋Š” huggingface.co ํŒจํ„ด ํ™•์ธ
80
+ if ".hf.space" in url or "huggingface.co" in url:
81
+ is_huggingface = True
82
+
83
+ # huggingface.co/spaces ํŒจํ„ด์— /embed ์ถ”๊ฐ€ (์ด๋ฏธ ์—†๋Š” ๊ฒฝ์šฐ)
84
+ if "huggingface.co/spaces" in url and not url.endswith("/embed"):
85
  url = url.rstrip("/")
 
86
  url = f"{url}/embed"
87
 
88
+ return url, is_huggingface
89
 
90
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 6. HTML ๊ทธ๋ฆฌ๋“œ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
91
  def html(cards, pg, total):
 
162
  transform: scale(0.7);
163
  transform-origin: top left;
164
  border: 0;
165
+ frameborder: 0;
166
  }
167
  /* ํ—ˆ๊น…ํŽ˜์ด์Šค iframe ํŠน๋ณ„ ์Šคํƒ€์ผ */
168
  .frame.huggingface iframe {
169
+ width: 100% !important;
170
+ height: 100% !important;
171
+ transform: none !important;
172
+ border: none !important;
173
  }
174
  .foot {
175
  padding: 6px 12px;
 
244
 
245
  # URL ์ฒ˜๋ฆฌ: ํ—ˆ๊น…ํŽ˜์ด์Šค URL์ธ ๊ฒฝ์šฐ ํŠน๋ณ„ ์ฒ˜๋ฆฌ
246
  url = c['url']
247
+ iframe_url, is_huggingface = process_url_for_iframe(url)
248
 
249
  # ํ—ˆ๊น…ํŽ˜์ด์Šค URL์— ํŠน๋ณ„ ํด๋ž˜์Šค ์ถ”๊ฐ€
250
+ frame_class = "frame huggingface" if is_huggingface else "frame"
251
 
252
  h += f"""
253
  <div class="card">
254
  <div class="hdr"><p class="ttl">{c['title']}</p><p class="date">{date}</p></div>
255
+ <div class="{frame_class}">
256
+ <iframe
257
+ src="{iframe_url}"
258
+ loading="lazy"
259
+ frameborder="0"
260
+ width="100%"
261
+ height="100%"
262
+ allowfullscreen="true"
263
+ allow="accelerometer; camera; encrypted-media; gyroscope; microphone;"
264
+ sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads">
265
+ </iframe>
266
+ </div>
267
  <div class="foot"><a class="link" href="{url}" target="_blank">์›๋ณธโ†—</a></div>
268
  </div>"""
269