Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -445,18 +445,56 @@ def load_json_data():
|
|
| 445 |
# ์ ์ญ ๋ณ์๋ก ํ
ํ๋ฆฟ ๋ฐ์ดํฐ ์บ์
|
| 446 |
TEMPLATE_CACHE = None
|
| 447 |
|
| 448 |
-
def load_session_history(
|
| 449 |
global TEMPLATE_CACHE
|
| 450 |
|
| 451 |
try:
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
html_content = """
|
| 459 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
.prompt-grid {
|
| 461 |
display: grid;
|
| 462 |
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
@@ -501,18 +539,35 @@ def load_session_history(selected_session=None):
|
|
| 501 |
padding: 8px;
|
| 502 |
border-radius: 4px;
|
| 503 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
</style>
|
| 505 |
-
<div class="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
"""
|
| 507 |
|
| 508 |
-
|
|
|
|
| 509 |
html_content += f"""
|
| 510 |
-
<div class="
|
| 511 |
-
<
|
| 512 |
-
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
| 513 |
-
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
| 514 |
-
</div>
|
| 515 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
|
| 517 |
html_content += """
|
| 518 |
<script>
|
|
@@ -525,12 +580,32 @@ def load_session_history(selected_session=None):
|
|
| 525 |
document.querySelector('.session-drawer .close-btn').click();
|
| 526 |
}
|
| 527 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
</script>
|
| 529 |
-
</div>
|
| 530 |
"""
|
| 531 |
|
| 532 |
-
|
| 533 |
-
return TEMPLATE_CACHE
|
| 534 |
|
| 535 |
except Exception as e:
|
| 536 |
print(f"Error in load_session_history: {str(e)}")
|
|
@@ -686,16 +761,16 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
| 686 |
outputs=[history_drawer]
|
| 687 |
)
|
| 688 |
|
| 689 |
-
|
| 690 |
-
|
| 691 |
# ์ธ์
๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์์
|
| 692 |
sessionBtn.click(
|
| 693 |
fn=lambda: (gr.update(open=True), load_session_history()),
|
| 694 |
inputs=[],
|
| 695 |
outputs=[session_drawer, session_history],
|
| 696 |
-
queue=False
|
| 697 |
)
|
| 698 |
|
|
|
|
|
|
|
| 699 |
# ์ธ์
๋๋ก์ด ๋ซ๊ธฐ ์ด๋ฒคํธ ์์
|
| 700 |
session_drawer.close(
|
| 701 |
lambda: (gr.update(open=False), gr.HTML("")),
|
|
|
|
| 445 |
# ์ ์ญ ๋ณ์๋ก ํ
ํ๋ฆฟ ๋ฐ์ดํฐ ์บ์
|
| 446 |
TEMPLATE_CACHE = None
|
| 447 |
|
| 448 |
+
def load_session_history(template_type="best"):
|
| 449 |
global TEMPLATE_CACHE
|
| 450 |
|
| 451 |
try:
|
| 452 |
+
json_data = load_json_data()
|
| 453 |
+
|
| 454 |
+
# ๋ฐ์ดํฐ๋ฅผ ์ธ ์น์
์ผ๋ก ๋๋๊ธฐ
|
| 455 |
+
templates = {
|
| 456 |
+
"best": json_data[:12], # ๋ฒ ์คํธ ํ
ํ๋ฆฟ
|
| 457 |
+
"trending": json_data[12:24], # ํธ๋ ๋ฉ ํ
ํ๋ฆฟ
|
| 458 |
+
"new": json_data[24:36] # NEW ํ
ํ๋ฆฟ
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
titles = {
|
| 462 |
+
"best": "๐ ๋ฒ ์คํธ ํ
ํ๋ฆฟ",
|
| 463 |
+
"trending": "๐ฅ ํธ๋ ๋ฉ ํ
ํ๋ฆฟ",
|
| 464 |
+
"new": "โจ NEW ํ
ํ๋ฆฟ"
|
| 465 |
+
}
|
| 466 |
|
| 467 |
html_content = """
|
| 468 |
<style>
|
| 469 |
+
.template-nav {
|
| 470 |
+
display: flex;
|
| 471 |
+
gap: 10px;
|
| 472 |
+
margin: 20px;
|
| 473 |
+
position: sticky;
|
| 474 |
+
top: 0;
|
| 475 |
+
background: white;
|
| 476 |
+
z-index: 100;
|
| 477 |
+
padding: 10px 0;
|
| 478 |
+
border-bottom: 1px solid #eee;
|
| 479 |
+
}
|
| 480 |
+
.template-btn {
|
| 481 |
+
padding: 8px 16px;
|
| 482 |
+
border: 1px solid #1890ff;
|
| 483 |
+
border-radius: 4px;
|
| 484 |
+
cursor: pointer;
|
| 485 |
+
background: white;
|
| 486 |
+
color: #1890ff;
|
| 487 |
+
font-weight: bold;
|
| 488 |
+
transition: all 0.3s;
|
| 489 |
+
}
|
| 490 |
+
.template-btn:hover {
|
| 491 |
+
background: #1890ff;
|
| 492 |
+
color: white;
|
| 493 |
+
}
|
| 494 |
+
.template-btn.active {
|
| 495 |
+
background: #1890ff;
|
| 496 |
+
color: white;
|
| 497 |
+
}
|
| 498 |
.prompt-grid {
|
| 499 |
display: grid;
|
| 500 |
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
|
|
| 539 |
padding: 8px;
|
| 540 |
border-radius: 4px;
|
| 541 |
}
|
| 542 |
+
.template-section {
|
| 543 |
+
display: none;
|
| 544 |
+
}
|
| 545 |
+
.template-section.active {
|
| 546 |
+
display: block;
|
| 547 |
+
}
|
| 548 |
</style>
|
| 549 |
+
<div class="template-nav">
|
| 550 |
+
<button class="template-btn" onclick="showTemplate('best')">๐ ๋ฒ ์คํธ</button>
|
| 551 |
+
<button class="template-btn" onclick="showTemplate('trending')">๐ฅ ํธ๋ ๋ฉ</button>
|
| 552 |
+
<button class="template-btn" onclick="showTemplate('new')">โจ NEW</button>
|
| 553 |
+
</div>
|
| 554 |
"""
|
| 555 |
|
| 556 |
+
# ๊ฐ ์น์
์ ํ
ํ๋ฆฟ ์์ฑ
|
| 557 |
+
for section, items in templates.items():
|
| 558 |
html_content += f"""
|
| 559 |
+
<div class="template-section" id="{section}-templates">
|
| 560 |
+
<div class="prompt-grid">
|
|
|
|
|
|
|
|
|
|
| 561 |
"""
|
| 562 |
+
for item in items:
|
| 563 |
+
html_content += f"""
|
| 564 |
+
<div class="prompt-card" onclick="copyToInput(this)" data-prompt="{html.escape(item.get('prompt', ''))}">
|
| 565 |
+
<img src="{item.get('image_url', '')}" class="card-image" loading="lazy" alt="{html.escape(item.get('name', ''))}">
|
| 566 |
+
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
| 567 |
+
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
| 568 |
+
</div>
|
| 569 |
+
"""
|
| 570 |
+
html_content += "</div></div>"
|
| 571 |
|
| 572 |
html_content += """
|
| 573 |
<script>
|
|
|
|
| 580 |
document.querySelector('.session-drawer .close-btn').click();
|
| 581 |
}
|
| 582 |
}
|
| 583 |
+
|
| 584 |
+
function showTemplate(type) {
|
| 585 |
+
// ๋ชจ๋ ์น์
์จ๊ธฐ๊ธฐ
|
| 586 |
+
document.querySelectorAll('.template-section').forEach(section => {
|
| 587 |
+
section.style.display = 'none';
|
| 588 |
+
});
|
| 589 |
+
// ๋ชจ๋ ๋ฒํผ ๋นํ์ฑํ
|
| 590 |
+
document.querySelectorAll('.template-btn').forEach(btn => {
|
| 591 |
+
btn.classList.remove('active');
|
| 592 |
+
});
|
| 593 |
+
|
| 594 |
+
// ์ ํ๋ ์น์
๋ณด์ด๊ธฐ
|
| 595 |
+
document.getElementById(type + '-templates').style.display = 'block';
|
| 596 |
+
// ์ ํ๋ ๋ฒํผ ํ์ฑํ
|
| 597 |
+
event.target.classList.add('active');
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
// ์ด๊ธฐ ๋ก๋์ ๋ฒ ์คํธ ํ
ํ๋ฆฟ ํ์
|
| 601 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 602 |
+
showTemplate('best');
|
| 603 |
+
document.querySelector('.template-btn').classList.add('active');
|
| 604 |
+
});
|
| 605 |
</script>
|
|
|
|
| 606 |
"""
|
| 607 |
|
| 608 |
+
return gr.HTML(value=html_content)
|
|
|
|
| 609 |
|
| 610 |
except Exception as e:
|
| 611 |
print(f"Error in load_session_history: {str(e)}")
|
|
|
|
| 761 |
outputs=[history_drawer]
|
| 762 |
)
|
| 763 |
|
|
|
|
|
|
|
| 764 |
# ์ธ์
๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์์
|
| 765 |
sessionBtn.click(
|
| 766 |
fn=lambda: (gr.update(open=True), load_session_history()),
|
| 767 |
inputs=[],
|
| 768 |
outputs=[session_drawer, session_history],
|
| 769 |
+
queue=False
|
| 770 |
)
|
| 771 |
|
| 772 |
+
|
| 773 |
+
|
| 774 |
# ์ธ์
๋๋ก์ด ๋ซ๊ธฐ ์ด๋ฒคํธ ์์
|
| 775 |
session_drawer.close(
|
| 776 |
lambda: (gr.update(open=False), gr.HTML("")),
|