Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
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",
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
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,
|
103 |
-
frame_class = "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"""
|