Spaces:
Running
Running
File size: 20,181 Bytes
8b2d146 b98dc44 f22af82 b98dc44 f22af82 b98dc44 21582cd f22af82 b98dc44 f22af82 b98dc44 4154b8b 3cd46cc 428a5c8 3cd46cc 428a5c8 8e9ec52 3cd46cc 428a5c8 8e9ec52 428a5c8 8e9ec52 428a5c8 8e9ec52 428a5c8 4154b8b 428a5c8 4154b8b b98dc44 2e20ef4 884c56c 2e20ef4 884c56c 2e20ef4 884c56c 2e20ef4 884c56c 2e20ef4 884c56c 2e20ef4 884c56c 2e20ef4 adff81a 2e20ef4 3cd46cc 2e20ef4 4154b8b 3cd46cc 4154b8b 2e20ef4 884c56c 428a5c8 2e20ef4 b14be0c 428a5c8 2e20ef4 b16d98a b98dc44 428a5c8 f22af82 4154b8b 428a5c8 4154b8b 3cd46cc 4154b8b 428a5c8 f22af82 2e20ef4 3cd46cc 428a5c8 3cd46cc 8e9ec52 428a5c8 3cd46cc 4154b8b 2e20ef4 940fa81 2e20ef4 b16d98a 2e20ef4 b14be0c 2e20ef4 b98dc44 fee886c 4154b8b b98dc44 c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 575b62d c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c c8e0eb9 fee886c 2e20ef4 fee886c 21582cd fee886c 21582cd fee886c 21582cd fee886c 21582cd fee886c b98dc44 fee886c 216bae4 fee886c a4ea08a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
import os, re, time, json, datetime, requests, gradio as gr
# โโโโโโโโโโโโโโโโโโโโโ 1. ๊ธฐ๋ณธ ์ค์ โโโโโโโโโโโโโโโโโโโโโ
BEST_FILE, PER_PAGE = "best_games.json", 9
# โโโโโโโโโโโโโโโโโโโโโ 2. BEST ๋ฐ์ดํฐ โโโโโโโโโโโโโโโโโโโโ
def _init_best():
if not os.path.exists(BEST_FILE):
json.dump([], open(BEST_FILE, "w"))
def _load_best():
try:
data = json.load(open(BEST_FILE))
for it in data:
if "ts" not in it:
it["ts"] = int(it.get("timestamp", time.time()))
return data
except Exception as e:
print(f"BEST ๋ฐ์ดํฐ ๋ก๋ ์ค๋ฅ: {e}")
return []
def _save_best(data):
try:
json.dump(data, open(BEST_FILE, "w"))
return True
except Exception as e:
print(f"BEST ๋ฐ์ดํฐ ์ ์ฅ ์ค๋ฅ: {e}")
return False
# โโโโโโโโโโโโโโโโโโโโโ 3. URL ์ถ๊ฐ ๊ธฐ๋ฅ โโโโโโโโโโโโโโโโโโโโโ
def add_url_to_best(title, url):
"""์ฌ์ฉ์๊ฐ ์ ๊ณตํ URL์ BEST ๋ชฉ๋ก์ ์ถ๊ฐํฉ๋๋ค."""
try:
# ํ์ฌ BEST ๋ฐ์ดํฐ ๋ก๋
data = _load_best()
# URL์ด ์ด๋ฏธ ์กด์ฌํ๋์ง ํ์ธ
for item in data:
if item.get("url") == url:
print(f"URL์ด ์ด๋ฏธ ์กด์ฌํฉ๋๋ค: {url}")
return False
# ์ ํญ๋ชฉ ์ถ๊ฐ
new_item = {
"title": title,
"url": url,
"ts": int(time.time()),
"projectId": "", # ์ฌ์ฉ์๊ฐ ์ง์ ์ถ๊ฐํ๋ฏ๋ก projectId ์์
"deploymentId": "" # ์ฌ์ฉ์๊ฐ ์ง์ ์ถ๊ฐํ๋ฏ๋ก deploymentId ์์
}
data.append(new_item)
# ์๊ฐ์์ผ๋ก ์ ๋ ฌ
data = sorted(data, key=lambda x: x["ts"], reverse=True)
# ์ ์ฅ
if _save_best(data):
print(f"URL์ด ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ๋์์ต๋๋ค: {url}")
return True
return False
except Exception as e:
print(f"URL ์ถ๊ฐ ์ค๋ฅ: {str(e)}")
return False
# โโโโโโโโโโโโโโโโโโโโโ 4. ํ์ด์ง๋ค์ด์
โโโโโโโโโโโโโโโโโโโ
def page(lst, pg):
s = (pg-1) * PER_PAGE
e = s + PER_PAGE
total = (len(lst) + PER_PAGE - 1) // PER_PAGE
return lst[s:e], total
# โโโโโโโโโโโโโโโโโโโโโ 5. URL ์ฒ๋ฆฌ ํจ์ โโโโโโโโโโโโโโโโโโโโโ
def process_url_for_iframe(url):
"""URL์ iframe์ ํ์ํ๊ธฐ ์ ํฉํ ํํ๋ก ๋ณํํฉ๋๋ค."""
# ํ๊น
ํ์ด์ค URL ํจํด ๊ฐ์ง
is_huggingface = False
embed_urls = []
# 1. huggingface.co/spaces ํจํด ์ฒ๋ฆฌ
if "huggingface.co/spaces" in url:
is_huggingface = True
# ๊ธฐ๋ณธ URL ์ ๊ทํ
base_url = url.rstrip("/")
try:
# /spaces/ ์ดํ์ ๊ฒฝ๋ก ์ถ์ถ
if "/spaces/" in base_url:
path = base_url.split("/spaces/")[1]
parts = path.split("/")
owner = parts[0]
# name ๋ถ๋ถ ์ถ์ถ
if len(parts) > 1:
name = parts[1]
# ํน์ ๋ฌธ์ ๋ณํ
clean_name = name.replace('.', '-').replace('_', '-').lower()
clean_owner = owner.lower()
# ์ฌ๋ฌ ํฌ๋งท์ URL์ ์๋ํ๊ธฐ ์ํด ๋ชฉ๋ก์ ์ถ๊ฐ
embed_urls.append(f"https://huggingface.co/spaces/{owner}/{name}/embed") # ๊ณต์ embed URL
embed_urls.append(f"https://{clean_owner}-{clean_name}.hf.space") # ์ง์ ๋๋ฉ์ธ ์ ๊ทผ
else:
# owner๋ง ์๋ ๊ฒฝ์ฐ ๊ณต์ URL ์ฌ์ฉ
embed_urls.append(f"https://huggingface.co/spaces/{owner}/embed")
except Exception as e:
print(f"ํ๊น
ํ์ด์ค URL ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {e}")
# ๊ธฐ๋ณธ embed URL ์๋
if not base_url.endswith("/embed"):
embed_urls.append(f"{base_url}/embed")
else:
embed_urls.append(base_url)
# 2. .hf.space ๋๋ฉ์ธ ์ฒ๋ฆฌ
elif ".hf.space" in url:
is_huggingface = True
embed_urls.append(url) # ํ์ฌ URL ๊ทธ๋๋ก ์๋
# 3. ์ผ๋ฐ URL์ ๊ทธ๋๋ก ๋ฐํ
else:
return url, is_huggingface, []
# ์ต์ข
URL๊ณผ ํจ๊ป ์๋ํ ๋์ฒด URL ๋ชฉ๋ก ๋ฐํ
primary_url = embed_urls[0] if embed_urls else url
return primary_url, is_huggingface, embed_urls[1:] if len(embed_urls) > 1 else []
# โโโโโโโโโโโโโโโโโโโโโ 6. HTML ๊ทธ๋ฆฌ๋ โโโโโโโโโโโโโโโโโโโ
def html(cards, pg, total):
if not cards:
return "<div style='text-align:center;padding:70px;color:#555;'>ํ์ํ ๋ฐฐํฌ๊ฐ ์์ต๋๋ค.</div>"
css = r"""
<style>
body {
margin: 0;
padding: 0;
font-family: Poppins, sans-serif;
background: #f0f0f0;
overflow-x: hidden;
overflow-y: auto;
}
.container {
position: relative;
width: 100%;
height: auto;
box-sizing: border-box;
padding: 10px;
padding-bottom: 70px; /* Space for buttons */
overflow-y: auto;
}
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
width: 100%;
margin-bottom: 60px; /* Space for buttons */
}
.card {
background: #fff;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
/* Each card is 50% taller */
height: 300px; /* Base height - will be 50% larger */
}
.hdr {
padding: 8px 12px;
background: rgba(255,255,255,.95);
border-bottom: 1px solid #eee;
flex-shrink: 0;
z-index: 10;
}
.ttl {
margin: 0;
font-size: 0.95rem;
font-weight: 600;
color: #333;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.date {
margin-top: 2px;
font-size: 0.75rem;
color: #777;
}
.frame {
flex: 1;
position: relative;
overflow: hidden;
}
.frame iframe {
position: absolute;
top: 0;
left: 0;
width: 142.857%;
height: 142.857%;
transform: scale(0.7);
transform-origin: top left;
border: 0;
frameborder: 0;
}
/* ํ๊น
ํ์ด์ค iframe ํน๋ณ ์คํ์ผ */
.frame.huggingface iframe {
width: 100% !important;
height: 100% !important;
transform: none !important;
border: none !important;
}
.foot {
padding: 6px 12px;
background: rgba(255,255,255,.95);
text-align: right;
flex-shrink: 0;
border-top: 1px solid #f0f0f0;
z-index: 10;
}
.link {
font-size: 0.8rem;
font-weight: 600;
color: #4a6dd8;
text-decoration: none;
}
/* ๋ฒํผ ์ปจํ
์ด๋ */
.button-area {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
background: #f0f0f0;
box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
z-index: 100;
}
/* ํ์ด์ง ์ ๋ณด */
.page-info {
position: fixed;
bottom: 5px;
left: 0;
right: 0;
text-align: center;
font-size: 0.8rem;
color: #777;
z-index: 101;
}
/* ๋ฏธ๋์ด ์ฟผ๋ฆฌ */
@media (min-width: 1200px) {
.card {
height: 450px; /* 50% taller than 300px */
}
}
@media (min-width: 768px) and (max-width: 1199px) {
.card {
height: 400px; /* Adjusted for medium screens */
}
}
@media (max-width: 767px) {
.grid {
grid-template-columns: 1fr;
}
.card {
height: 350px; /* Adjusted for small screens */
}
}
/* ์ค๋ฅ ๋ฉ์์ง ๊ด๋ จ CSS */
.error-message {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(255, 255, 255, 0.9);
z-index: 20;
padding: 20px;
text-align: center;
}
.error-icon {
font-size: 48px;
margin-bottom: 15px;
}
.error-text {
font-weight: bold;
margin-bottom: 15px;
}
.error-link {
display: inline-block;
padding: 8px 16px;
background-color: #f0f0f7;
border-radius: 4px;
color: #4a6dd8;
font-weight: bold;
text-decoration: none;
transition: background-color 0.2s;
}
.error-link:hover {
background-color: #e0e0f0;
}
</style>"""
js = """
<script>
// ํ๊น
ํ์ด์ค iframe ๋ก๋ฉ ์ค๋ฅ ์ฒ๋ฆฌ
function handleIframeError(iframeId, alternateUrls, originalUrl) {
const iframe = document.getElementById(iframeId);
if (!iframe) return;
// iframe ๋ก๋ ์คํจ ์ฒ๋ฆฌ
iframe.onerror = function() {
tryNextUrl(iframeId, alternateUrls, originalUrl);
};
// onload ์ด๋ฒคํธ์์ ๋ก๋ ์คํจ ํ์ธ
iframe.onload = function() {
try {
// iframe ๋ด์ฉ์ ์ ๊ทผ ์๋ (cross-origin ์ ํ์ผ๋ก ์คํจํ ์ ์์)
const iframeContent = iframe.contentWindow.document;
console.log("iframe loaded successfully: " + iframeId);
} catch (e) {
// cross-origin ์ค๋ฅ๋ ๋ฌด์ (์ ์์ ์ธ ์ํฉ์ผ ์ ์์)
console.log("Cross-origin iframe loaded (expected): " + iframeId);
}
// iframe์ด ์ ๋๋ก ํ์๋๋์ง 10์ด ํ ํ์ธ
setTimeout(function() {
if (iframe.offsetWidth === 0 || iframe.offsetHeight === 0) {
console.log("iframe not visible, trying alternate URL: " + iframeId);
tryNextUrl(iframeId, alternateUrls, originalUrl);
} else {
console.log("iframe appears to be visible: " + iframeId);
}
}, 5000);
};
}
// ๋์ฒด URL ์๋
function tryNextUrl(iframeId, alternateUrls, originalUrl) {
const iframe = document.getElementById(iframeId);
if (!iframe) return;
// ๋์ฒด URL์ด ์์ผ๋ฉด ์๋
if (alternateUrls && alternateUrls.length > 0) {
const nextUrl = alternateUrls.shift();
console.log("Trying alternate URL: " + nextUrl);
iframe.src = nextUrl;
// ๋์ฒด URL๋ก ๋ค์ ์ค๋ฅ ์ฒ๋ฆฌ ์ค์
handleIframeError(iframeId, alternateUrls, originalUrl);
} else {
// ๋ชจ๋ URL ์๋ ์คํจ ์ ์ค๋ฅ ๋ฉ์์ง ํ์
console.log("All URLs failed, showing error for: " + iframeId);
const container = iframe.parentNode;
// ์ค๋ฅ ๋ฉ์์ง ํ์
const errorDiv = document.createElement('div');
errorDiv.className = 'error-message';
errorDiv.innerHTML = `
<div class="error-icon">โ ๏ธ</div>
<p class="error-text">์ฝํ
์ธ ๋ฅผ ๋ก๋ํ ์ ์์ต๋๋ค</p>
<a href="${originalUrl}" target="_blank" class="error-link">
์๋ณธ ํ์ด์ง์์ ์ด๊ธฐ
</a>
`;
// iframe ์จ๊ธฐ๊ณ ์ค๋ฅ ๋ฉ์์ง ํ์
iframe.style.display = 'none';
container.appendChild(errorDiv);
}
}
// ํ์ด์ง ๋ก๋ ์ ๋ชจ๋ ํ๊น
ํ์ด์ค iframe ์ฒ๋ฆฌ
window.addEventListener('load', function() {
const iframes = document.querySelectorAll('.huggingface iframe');
iframes.forEach(function(iframe) {
const id = iframe.id;
const alternateUrlsStr = iframe.getAttribute('data-alternate-urls');
const alternateUrls = alternateUrlsStr ? alternateUrlsStr.split(',').filter(url => url) : [];
const originalUrl = iframe.getAttribute('data-original-url') || iframe.src;
if (id && alternateUrls.length > 0) {
handleIframeError(id, alternateUrls, originalUrl);
}
});
});
</script>
"""
h = css + js + """
<div class="container">
<div class="grid">
"""
for idx, c in enumerate(cards):
date = datetime.datetime.fromtimestamp(int(c["ts"])).strftime("%Y-%m-%d")
# URL ์ฒ๋ฆฌ: ํ๊น
ํ์ด์ค URL์ธ ๊ฒฝ์ฐ ํน๋ณ ์ฒ๋ฆฌ
url = c['url']
iframe_url, is_huggingface, alt_urls = process_url_for_iframe(url)
# ํ๊น
ํ์ด์ค URL์ ํน๋ณ ํด๋์ค ์ถ๊ฐ
frame_class = "frame huggingface" if is_huggingface else "frame"
# ๊ณ ์ ID ์์ฑ
iframe_id = f"iframe-{idx}-{hash(url) % 10000}"
# ๋์ฒด URL์ ๋ฐ์ดํฐ ์์ฑ์ผ๋ก ์ถ๊ฐ
alternate_urls_attr = ""
if alt_urls:
alternate_urls_attr = f'data-alternate-urls="{",".join(alt_urls)}"'
h += f"""
<div class="card">
<div class="hdr"><p class="ttl">{c['title']}</p><p class="date">{date}</p></div>
<div class="{frame_class}">
<iframe
id="{iframe_id}"
src="{iframe_url}"
loading="lazy"
frameborder="0"
width="100%"
height="100%"
allowfullscreen="true"
allow="accelerometer; camera; encrypted-media; gyroscope; geolocation;"
sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"
data-original-url="{url}"
{alternate_urls_attr}>
</iframe>
</div>
<div class="foot"><a class="link" href="{url}" target="_blank">์๋ณธโ</a></div>
</div>"""
h += """
</div>
</div>
"""
# ํ์ด์ง ์ ๋ณด
h += f'<div class="page-info">Page {pg} / {total}</div>'
return h
# โโโโโโโโโโโโโโโโโโโโโ 7. Gradio Blocks UI โโโโโโโโโโโโโโโโโโโโโ
# โโโโโโโโโโโโโโโโโโโโโ 7. Gradio Blocks UI โโโโโโโโโโโโโโโโโโโโโ
def build():
_init_best()
# (1) โโ ํค๋ HTML (๋ณ๊ฒฝ ์์) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
header_html_snippet = """
<style>
.app-header{ text-align:center; margin-bottom:24px; }
.badge-row{
display:inline-flex;
gap:8px;
margin:8px 0;
}
</style>
<div class="app-header">
<h1>๐ฎ Vibe Game Gallery</h1>
<div class="badge-row">
<a href="https://huggingface.co/spaces/openfree/Vibe-Game" target="_blank">
<img src="https://img.shields.io/static/v1?label=huggingface&message=Vibe%20Game%20Craft&color=%23800080&labelColor=%23ffa500&logo=huggingface&logoColor=%23ffff00&style=for-the-badge" alt="HF-Vibe">
</a>
<a href="https://huggingface.co/spaces/openfree/Game-Gallery" target="_blank">
<img src="https://img.shields.io/static/v1?label=huggingface&message=Game%20Gallery&color=%23800080&labelColor=%23ffa500&logo=huggingface&logoColor=%23ffff00&style=for-the-badge" alt="HF-Gallery">
</a>
<a href="https://discord.gg/openfreeai" target="_blank">
<img src="https://img.shields.io/static/v1?label=Discord&message=Openfree%20AI&color=%230000ff&labelColor=%23800080&logo=discord&logoColor=white&style=for-the-badge" alt="Discord">
</a>
</div>
<p>ํ๋กฌํํธ ์
๋ ฅ๋ง์ผ๋ก ์ต์ LLM๋ค๊ณผ Agent๊ฐ ํ์
ํ์ฌ ์น ๊ธฐ๋ฐ ๊ฒ์์ ์์ฑํ๊ณ ๋ฐฐํฌํฉ๋๋ค.</p>
</div>
"""
# (2) โโ ์ ์ญ CSS (ํค๋ sticky + ์คํฌ๋กค ์์ญ ์ฌ์กฐ์ ) โโโโโโโโโ
css_global = """
footer{display:none !important;}
/* ์๋จ ํค๋๋ฅผ ํญ์ ๋ณด์ด๋๋ก ๊ณ ์ */
.app-header{
position:sticky;
top:0;
background:#fff;
z-index:1100;
padding:16px 0 8px;
border-bottom:1px solid #eee;
}
/* ํ๋จ ๊ณ ์ ๋ฒํผ ๋ฐ */
.button-row{
position:fixed !important;
bottom:0 !important;
left:0 !important;
right:0 !important;
height:60px !important;
background:#f0f0f0 !important;
padding:10px !important;
text-align:center !important;
box-shadow:0 -2px 10px rgba(0,0,0,0.05) !important;
margin:0 !important;
z-index:1000 !important;
}
.button-row button{
margin:0 10px !important;
padding:10px 20px !important;
font-size:16px !important;
font-weight:bold !important;
border-radius:50px !important;
}
/* ์นด๋ ๊ทธ๋ฆฌ๋ ์คํฌ๋กค ์์ญ */
#content-area{
overflow-y:auto !important;
height:calc(100vh - 60px - 160px) !important; /* ์ ์ฒด-๋์ด - ํ๋จ๋ฐ - ํค๋ */
box-sizing:border-box;
padding-top:10px;
}
"""
# (3) โโ Gradio Blocks โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Blocks(title="Vibe Game Craft", css=css_global) as demo:
# โ ๊ณ ์ ํค๋
gr.HTML(header_html_snippet)
# โก ๋ณธ๋ฌธ(์นด๋ ๊ทธ๋ฆฌ๋) โ ๊ณ ์ ID ๋ถ์ฌ
out = gr.HTML(elem_id="content-area")
# โข ํ๋จ ํ์ด์ง ๋ค๋น๊ฒ์ด์
๋ฐ
with gr.Row(elem_classes="button-row"):
b_prev = gr.Button("โ ์ด์ ", size="lg")
b_next = gr.Button("๋ค์ โถ", size="lg")
# โโ ์ํ ๋ฐ ํฌํผ โโโโโโโโโโโโโโโโโโโโโโโโโโโ
bp = gr.State(1)
def show_best(p=1):
d, t = page(_load_best(), p)
return html(d, p, t), p
def prev(b):
b = max(1, b-1)
h, _ = show_best(b)
return h, b
def nxt(b):
maxp = (len(_load_best()) + PER_PAGE - 1) // PER_PAGE
b = min(maxp, b+1)
h, _ = show_best(b)
return h, b
# โโ ์ด๋ฒคํธ ๋ฐ์ธ๋ฉ โโโโโโโโโโโโโโโโโโโโโโโโโโ
b_prev.click(prev, inputs=[bp], outputs=[out, bp])
b_next.click(nxt, inputs=[bp], outputs=[out, bp])
# ์ต์ด ๋ก๋
demo.load(show_best, outputs=[out, bp])
return demo
# โโโโโโโโโโโโโโโโโโโโโ 8. ์ฑ ์์ฑ & ์คํ โโโโโโโโโโโโโโโโโโโโโ
app = build() # โ Blocks ์ธ์คํด์ค ์์ฑ
if __name__ == "__main__":
# Spaces๋ ๋ก์ปฌ์์ ์คํ๋ ๋ ์ง์
์
app.launch() # share=True ๋ฑ ์ต์
์ด ํ์ํ๋ฉด ์ฌ๊ธฐ์ ์ง์ |