openfree commited on
Commit
7caf443
ยท
verified ยท
1 Parent(s): 83e6b57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os, json, time, datetime, requests, gradio as gr
2
 
3
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 1. ๊ธฐ๋ณธ ์„ค์ • โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
4
  BEST_FILE, PER_PAGE = "best_games.json", 9 # โถ ํŽ˜์ด์ง€๋‹น 9๊ฐœ ์œ ์ง€
@@ -41,11 +41,24 @@ def page(lst, pg):
41
  return lst[s:e], total
42
 
43
  def process_url_for_iframe(url):
44
- # Hugging Face Spaces embed ์šฐ์„ 
 
 
 
 
45
  if "huggingface.co/spaces" in url:
46
  owner, name = url.rstrip("/").split("/spaces/")[1].split("/")[:2]
47
- return f"https://huggingface.co/spaces/{owner}/{name}/embed", True, []
48
- return url, False, []
 
 
 
 
 
 
 
 
 
49
 
50
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 6. HTML ๊ทธ๋ฆฌ๋“œ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
51
  def html(cards, pg, total):
@@ -61,14 +74,12 @@ def html(cards, pg, total):
61
  background-attachment:fixed;
62
  overflow-x:hidden;overflow-y:auto;
63
  }
64
-
65
  .container{width:100%;padding:10px 10px 70px;box-sizing:border-box;}
66
  .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;width:100%;}
67
  .card{
68
  background:#fff;border-radius:10px;overflow:hidden;box-shadow:0 4px 10px rgba(0,0,0,0.08);
69
  height:420px;display:flex;flex-direction:column;position:relative;
70
  }
71
-
72
  /* ๊ฒŒ์ž„ ํ™”๋ฉด ์ถ•์†Œ */
73
  .frame{flex:1;position:relative;overflow:hidden;}
74
  .frame iframe{
@@ -76,13 +87,21 @@ def html(cards, pg, total):
76
  width:166.667%;height:166.667%;
77
  transform:scale(0.6);transform-origin:top left;border:0;
78
  }
79
- .frame.huggingface iframe{width:100%!important;height:100%!important;transform:none!important;border:none!important;}
80
-
 
 
 
 
 
 
 
 
 
81
  /* ํ•˜๋‹จ ๋ฐ”๋กœ๊ฐ€๊ธฐ */
82
  .foot{height:34px;display:flex;align-items:center;justify-content:center;background:#fafafa;border-top:1px solid #eee;}
83
  .foot a{font-size:0.85rem;font-weight:600;color:#4a6dd8;text-decoration:none;}
84
  .foot a:hover{text-decoration:underline;}
85
-
86
  /* ๋ฐ˜์‘ํ˜• ๋†’์ด */
87
  @media(min-width:1200px){.card{height:560px;}}
88
  @media(max-width:767px){
@@ -99,8 +118,8 @@ def html(cards, pg, total):
99
 
100
  h = css + js + '<div class="container"><div class="grid">'
101
  for idx, url in enumerate(cards):
102
- iframe_url, is_huggingface, alt_urls = process_url_for_iframe(url)
103
- frame_class = "frame huggingface" if is_huggingface else "frame"
104
  iframe_id = f"iframe-{idx}-{hash(url)%10000}"
105
  alt_attr = f'data-alternate-urls="{",".join(alt_urls)}"' if alt_urls else ""
106
  h += f"""
 
1
+ import os, json, time, datetime, requests, gradio as gr, re
2
 
3
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 1. ๊ธฐ๋ณธ ์„ค์ • โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
4
  BEST_FILE, PER_PAGE = "best_games.json", 9 # โถ ํŽ˜์ด์ง€๋‹น 9๊ฐœ ์œ ์ง€
 
41
  return lst[s:e], total
42
 
43
  def process_url_for_iframe(url):
44
+ """
45
+ ๋ฐ˜ํ™˜: (iframe_url, extra_class, alternate_urls)
46
+ extra_class : '' | 'huggingface' | 'hfspace'
47
+ """
48
+ # Hugging Face Spaces embed (Gradio/Streamlit)
49
  if "huggingface.co/spaces" in url:
50
  owner, name = url.rstrip("/").split("/spaces/")[1].split("/")[:2]
51
+ return f"https://huggingface.co/spaces/{owner}/{name}/embed", "huggingface", []
52
+
53
+ # *.hf.space (์ •์ /static Space ํฌํ•จ)
54
+ m = re.match(r"https?://([^/]+)\.hf\.space(/.*)?", url)
55
+ if m:
56
+ sub, rest = m.groups()
57
+ static_url = f"https://{sub}.static.hf.space{rest or ''}"
58
+ # alt_urls ์— ์›๋ณธ ์ €์žฅ(์‹คํŒจ ์‹œ ์žฌ์‹œ๋„ ๊ฐ€๋Šฅ)
59
+ return static_url, "hfspace", [url]
60
+
61
+ return url, "", []
62
 
63
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 6. HTML ๊ทธ๋ฆฌ๋“œ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
64
  def html(cards, pg, total):
 
74
  background-attachment:fixed;
75
  overflow-x:hidden;overflow-y:auto;
76
  }
 
77
  .container{width:100%;padding:10px 10px 70px;box-sizing:border-box;}
78
  .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;width:100%;}
79
  .card{
80
  background:#fff;border-radius:10px;overflow:hidden;box-shadow:0 4px 10px rgba(0,0,0,0.08);
81
  height:420px;display:flex;flex-direction:column;position:relative;
82
  }
 
83
  /* ๊ฒŒ์ž„ ํ™”๋ฉด ์ถ•์†Œ */
84
  .frame{flex:1;position:relative;overflow:hidden;}
85
  .frame iframe{
 
87
  width:166.667%;height:166.667%;
88
  transform:scale(0.6);transform-origin:top left;border:0;
89
  }
90
+ /* Gradio/Streamlit Embed์šฉ */
91
+ .frame.huggingface iframe{
92
+ width:100%!important;height:100%!important;
93
+ transform:none!important;border:none!important;
94
+ }
95
+ /* hf.space ์ „์ฒด ํŽ˜์ด์ง€์šฉ - ํ•œ ๋ฒˆ ๋” ์ถ•์†Œ */
96
+ .frame.hfspace iframe{
97
+ width:200%;height:200%;
98
+ transform:scale(0.5);
99
+ transform-origin:top left;border:0;
100
+ }
101
  /* ํ•˜๋‹จ ๋ฐ”๋กœ๊ฐ€๊ธฐ */
102
  .foot{height:34px;display:flex;align-items:center;justify-content:center;background:#fafafa;border-top:1px solid #eee;}
103
  .foot a{font-size:0.85rem;font-weight:600;color:#4a6dd8;text-decoration:none;}
104
  .foot a:hover{text-decoration:underline;}
 
105
  /* ๋ฐ˜์‘ํ˜• ๋†’์ด */
106
  @media(min-width:1200px){.card{height:560px;}}
107
  @media(max-width:767px){
 
118
 
119
  h = css + js + '<div class="container"><div class="grid">'
120
  for idx, url in enumerate(cards):
121
+ iframe_url, extra_cls, alt_urls = process_url_for_iframe(url)
122
+ frame_class = f"frame {extra_cls}".strip()
123
  iframe_id = f"iframe-{idx}-{hash(url)%10000}"
124
  alt_attr = f'data-alternate-urls="{",".join(alt_urls)}"' if alt_urls else ""
125
  h += f"""