Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -527,15 +527,16 @@ def load_session_history(selected_session=None):
|
|
| 527 |
for item in json_data:
|
| 528 |
name = html.escape(item.get('name', ''))
|
| 529 |
image_url = item.get('image_url', '')
|
| 530 |
-
|
|
|
|
| 531 |
|
| 532 |
html_content += f"""
|
| 533 |
-
<div class="prompt-card"
|
| 534 |
<img src="{image_url}" class="card-image" alt="{name}">
|
| 535 |
<div class="card-name">{name}</div>
|
| 536 |
<div class="card-prompt-container">
|
| 537 |
-
<div class="card-prompt">{prompt}</div>
|
| 538 |
-
<button class="copy-btn" onclick="copyPrompt(
|
| 539 |
๐ ๋ณต์ฌ
|
| 540 |
</button>
|
| 541 |
</div>
|
|
@@ -545,33 +546,63 @@ def load_session_history(selected_session=None):
|
|
| 545 |
html_content += """
|
| 546 |
</div>
|
| 547 |
<script>
|
| 548 |
-
function copyPrompt(
|
| 549 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
btn.textContent = 'โ ๋ณต์ฌ๋จ';
|
|
|
|
|
|
|
|
|
|
| 551 |
setTimeout(() => {
|
| 552 |
btn.textContent = '๐ ๋ณต์ฌ';
|
|
|
|
|
|
|
| 553 |
}, 2000);
|
| 554 |
-
})
|
| 555 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
}
|
| 557 |
|
| 558 |
function handleCardClick(card) {
|
| 559 |
-
console.log('Card clicked');
|
| 560 |
const prompt = card.getAttribute('data-prompt');
|
| 561 |
const textarea = document.querySelector('textarea');
|
| 562 |
if (textarea) {
|
| 563 |
-
console.log('Setting prompt:', prompt);
|
| 564 |
textarea.value = prompt;
|
| 565 |
|
| 566 |
const sendButton = document.querySelector('button:contains("Send")');
|
| 567 |
if (sendButton) {
|
| 568 |
-
console.log('Clicking Send button');
|
| 569 |
sendButton.click();
|
| 570 |
}
|
| 571 |
|
| 572 |
const drawer = document.querySelector('.session-drawer');
|
| 573 |
if (drawer) {
|
| 574 |
-
console.log('Closing drawer');
|
| 575 |
drawer.style.display = 'none';
|
| 576 |
}
|
| 577 |
}
|
|
@@ -585,6 +616,7 @@ def load_session_history(selected_session=None):
|
|
| 585 |
print(f"Error in load_session_history: {str(e)}")
|
| 586 |
return gr.HTML("Error loading templates")
|
| 587 |
|
|
|
|
| 588 |
# ํ์คํ ๋ฆฌ ์์ดํ
์ ํ ์ฒ๋ฆฌ ํจ์
|
| 589 |
def handle_history_selection(evt: gr.SelectData):
|
| 590 |
try:
|
|
|
|
| 527 |
for item in json_data:
|
| 528 |
name = html.escape(item.get('name', ''))
|
| 529 |
image_url = item.get('image_url', '')
|
| 530 |
+
# ํ๋กฌํํธ์์ ํน์ ๋ฌธ์ ์ฒ๋ฆฌ๋ฅผ ์ํด JSON.stringify ์ฌ์ฉ
|
| 531 |
+
prompt = json.dumps(item.get('prompt', ''))
|
| 532 |
|
| 533 |
html_content += f"""
|
| 534 |
+
<div class="prompt-card">
|
| 535 |
<img src="{image_url}" class="card-image" alt="{name}">
|
| 536 |
<div class="card-name">{name}</div>
|
| 537 |
<div class="card-prompt-container">
|
| 538 |
+
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
| 539 |
+
<button class="copy-btn" onclick="copyPrompt(event, {prompt})" title="ํ๋กฌํํธ ๋ณต์ฌ">
|
| 540 |
๐ ๋ณต์ฌ
|
| 541 |
</button>
|
| 542 |
</div>
|
|
|
|
| 546 |
html_content += """
|
| 547 |
</div>
|
| 548 |
<script>
|
| 549 |
+
async function copyPrompt(event, prompt) {
|
| 550 |
+
event.preventDefault();
|
| 551 |
+
event.stopPropagation();
|
| 552 |
+
|
| 553 |
+
try {
|
| 554 |
+
await navigator.clipboard.writeText(prompt);
|
| 555 |
+
const btn = event.target;
|
| 556 |
btn.textContent = 'โ ๋ณต์ฌ๋จ';
|
| 557 |
+
btn.style.backgroundColor = '#52c41a';
|
| 558 |
+
btn.style.color = 'white';
|
| 559 |
+
|
| 560 |
setTimeout(() => {
|
| 561 |
btn.textContent = '๐ ๋ณต์ฌ';
|
| 562 |
+
btn.style.backgroundColor = '#f0f0f0';
|
| 563 |
+
btn.style.color = 'inherit';
|
| 564 |
}, 2000);
|
| 565 |
+
} catch (err) {
|
| 566 |
+
// ํด๋ฆฝ๋ณด๋ API๊ฐ ์คํจํ ๊ฒฝ์ฐ ๋์ฒด ๋ฐฉ๋ฒ ์ฌ์ฉ
|
| 567 |
+
const textarea = document.createElement('textarea');
|
| 568 |
+
textarea.value = prompt;
|
| 569 |
+
textarea.style.position = 'fixed';
|
| 570 |
+
textarea.style.opacity = '0';
|
| 571 |
+
document.body.appendChild(textarea);
|
| 572 |
+
textarea.select();
|
| 573 |
+
try {
|
| 574 |
+
document.execCommand('copy');
|
| 575 |
+
const btn = event.target;
|
| 576 |
+
btn.textContent = 'โ ๋ณต์ฌ๋จ';
|
| 577 |
+
btn.style.backgroundColor = '#52c41a';
|
| 578 |
+
btn.style.color = 'white';
|
| 579 |
+
|
| 580 |
+
setTimeout(() => {
|
| 581 |
+
btn.textContent = '๐ ๋ณต์ฌ';
|
| 582 |
+
btn.style.backgroundColor = '#f0f0f0';
|
| 583 |
+
btn.style.color = 'inherit';
|
| 584 |
+
}, 2000);
|
| 585 |
+
} catch (err) {
|
| 586 |
+
console.error('๋ณต์ฌ ์คํจ:', err);
|
| 587 |
+
alert('๋ณต์ฌ์ ์คํจํ์ต๋๋ค. ์ง์ ํ
์คํธ๋ฅผ ์ ํํ์ฌ ๋ณต์ฌํด์ฃผ์ธ์.');
|
| 588 |
+
}
|
| 589 |
+
document.body.removeChild(textarea);
|
| 590 |
+
}
|
| 591 |
}
|
| 592 |
|
| 593 |
function handleCardClick(card) {
|
|
|
|
| 594 |
const prompt = card.getAttribute('data-prompt');
|
| 595 |
const textarea = document.querySelector('textarea');
|
| 596 |
if (textarea) {
|
|
|
|
| 597 |
textarea.value = prompt;
|
| 598 |
|
| 599 |
const sendButton = document.querySelector('button:contains("Send")');
|
| 600 |
if (sendButton) {
|
|
|
|
| 601 |
sendButton.click();
|
| 602 |
}
|
| 603 |
|
| 604 |
const drawer = document.querySelector('.session-drawer');
|
| 605 |
if (drawer) {
|
|
|
|
| 606 |
drawer.style.display = 'none';
|
| 607 |
}
|
| 608 |
}
|
|
|
|
| 616 |
print(f"Error in load_session_history: {str(e)}")
|
| 617 |
return gr.HTML("Error loading templates")
|
| 618 |
|
| 619 |
+
|
| 620 |
# ํ์คํ ๋ฆฌ ์์ดํ
์ ํ ์ฒ๋ฆฌ ํจ์
|
| 621 |
def handle_history_selection(evt: gr.SelectData):
|
| 622 |
try:
|