Update app.py
Browse files
app.py
CHANGED
@@ -446,7 +446,7 @@ def load_json_data():
|
|
446 |
}
|
447 |
]
|
448 |
|
449 |
-
#
|
450 |
template_html_cache = None
|
451 |
|
452 |
def load_session_history(selected_session=None):
|
@@ -521,7 +521,7 @@ def load_session_history(selected_session=None):
|
|
521 |
|
522 |
for item in json_data:
|
523 |
html_content += f"""
|
524 |
-
<div class="prompt-card" onclick="
|
525 |
<img src="{item.get('image_url', '')}" class="card-image" loading="lazy" alt="{html.escape(item.get('name', ''))}">
|
526 |
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
527 |
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
@@ -530,12 +530,14 @@ def load_session_history(selected_session=None):
|
|
530 |
|
531 |
html_content += """
|
532 |
<script>
|
533 |
-
function
|
534 |
-
const prompt = card.getAttribute('data-prompt');
|
535 |
const textarea = document.querySelector('.ant-input-textarea-large textarea');
|
536 |
if (textarea) {
|
537 |
textarea.value = prompt;
|
538 |
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
|
|
|
|
|
539 |
}
|
540 |
}
|
541 |
</script>
|
@@ -551,6 +553,8 @@ def load_session_history(selected_session=None):
|
|
551 |
print(f"Error in load_session_history: {str(e)}")
|
552 |
return gr.HTML("Error loading templates")
|
553 |
|
|
|
|
|
554 |
# Demo ์ธ์คํด์ค ์์ฑ
|
555 |
demo_instance = Demo()
|
556 |
|
@@ -701,25 +705,14 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
701 |
)
|
702 |
|
703 |
|
|
|
|
|
704 |
# ์ธ์
๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์์
|
705 |
sessionBtn.click(
|
706 |
fn=lambda: (gr.update(open=True), load_session_history()),
|
707 |
inputs=[],
|
708 |
-
outputs=[session_drawer, session_history]
|
709 |
-
_js="""
|
710 |
-
() => {
|
711 |
-
document.body.style.cursor = 'wait';
|
712 |
-
const drawer = document.querySelector('.session-drawer');
|
713 |
-
if (drawer) drawer.style.opacity = '0';
|
714 |
-
setTimeout(() => {
|
715 |
-
if (drawer) drawer.style.opacity = '1';
|
716 |
-
document.body.style.cursor = 'default';
|
717 |
-
}, 100);
|
718 |
-
}
|
719 |
-
"""
|
720 |
)
|
721 |
-
|
722 |
-
|
723 |
# ์ธ์
๋๋ก์ด ๋ซ๊ธฐ ์ด๋ฒคํธ ์์
|
724 |
session_drawer.close(
|
725 |
lambda: (gr.update(open=False), gr.HTML("")),
|
|
|
446 |
}
|
447 |
]
|
448 |
|
449 |
+
# ํ
ํ๋ฆฟ HTML ์บ์ ์ ์ฅ
|
450 |
template_html_cache = None
|
451 |
|
452 |
def load_session_history(selected_session=None):
|
|
|
521 |
|
522 |
for item in json_data:
|
523 |
html_content += f"""
|
524 |
+
<div class="prompt-card" onclick="copyToInput('{html.escape(item.get('prompt', ''))}')">
|
525 |
<img src="{item.get('image_url', '')}" class="card-image" loading="lazy" alt="{html.escape(item.get('name', ''))}">
|
526 |
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
527 |
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
|
|
530 |
|
531 |
html_content += """
|
532 |
<script>
|
533 |
+
function copyToInput(prompt) {
|
|
|
534 |
const textarea = document.querySelector('.ant-input-textarea-large textarea');
|
535 |
if (textarea) {
|
536 |
textarea.value = prompt;
|
537 |
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
538 |
+
// ๋๋ก์ด ๋ซ๊ธฐ
|
539 |
+
const closeBtn = document.querySelector('.session-drawer .close-btn');
|
540 |
+
if (closeBtn) closeBtn.click();
|
541 |
}
|
542 |
}
|
543 |
</script>
|
|
|
553 |
print(f"Error in load_session_history: {str(e)}")
|
554 |
return gr.HTML("Error loading templates")
|
555 |
|
556 |
+
|
557 |
+
|
558 |
# Demo ์ธ์คํด์ค ์์ฑ
|
559 |
demo_instance = Demo()
|
560 |
|
|
|
705 |
)
|
706 |
|
707 |
|
708 |
+
|
709 |
+
|
710 |
# ์ธ์
๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์์
|
711 |
sessionBtn.click(
|
712 |
fn=lambda: (gr.update(open=True), load_session_history()),
|
713 |
inputs=[],
|
714 |
+
outputs=[session_drawer, session_history]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
715 |
)
|
|
|
|
|
716 |
# ์ธ์
๋๋ก์ด ๋ซ๊ธฐ ์ด๋ฒคํธ ์์
|
717 |
session_drawer.close(
|
718 |
lambda: (gr.update(open=False), gr.HTML("")),
|