Update app.py
Browse files
app.py
CHANGED
@@ -508,13 +508,14 @@ def load_session_history(selected_session=None):
|
|
508 |
"""
|
509 |
|
510 |
for item in json_data:
|
511 |
-
|
|
|
512 |
html_content += f"""
|
513 |
<div class="prompt-card">
|
514 |
<img src="{item.get('image_url', '')}" class="card-image" alt="{html.escape(item.get('name', ''))}">
|
515 |
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
516 |
-
<div class="card-prompt">{
|
517 |
-
<button class="copy-button"
|
518 |
๐ ๋ณต์ฌ
|
519 |
</button>
|
520 |
</div>
|
@@ -523,46 +524,47 @@ def load_session_history(selected_session=None):
|
|
523 |
html_content += """
|
524 |
</div>
|
525 |
<script>
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
|
535 |
-
setTimeout(() => {
|
536 |
-
button.textContent = '๐ ๋ณต์ฌ';
|
537 |
-
button.style.backgroundColor = '#f0f0f0';
|
538 |
-
button.style.color = 'inherit';
|
539 |
-
}, 2000);
|
540 |
-
} catch (err) {
|
541 |
-
// fallback
|
542 |
-
const textarea = document.createElement('textarea');
|
543 |
-
textarea.value = text;
|
544 |
-
document.body.appendChild(textarea);
|
545 |
-
textarea.select();
|
546 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
document.execCommand('copy');
|
548 |
-
|
549 |
-
button.style.backgroundColor = '#52c41a';
|
550 |
-
button.style.color = 'white';
|
551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
552 |
setTimeout(() => {
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
}, 2000);
|
|
|
557 |
} catch (err) {
|
558 |
console.error('๋ณต์ฌ ์คํจ:', err);
|
559 |
alert('๋ณต์ฌ์ ์คํจํ์ต๋๋ค. ์ง์ ํ
์คํธ๋ฅผ ์ ํํ์ฌ ๋ณต์ฌํด์ฃผ์ธ์.');
|
560 |
}
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
copyText();
|
565 |
-
}
|
566 |
</script>
|
567 |
"""
|
568 |
|
@@ -570,7 +572,7 @@ def load_session_history(selected_session=None):
|
|
570 |
|
571 |
except Exception as e:
|
572 |
print(f"Error in load_session_history: {str(e)}")
|
573 |
-
return gr.HTML("Error loading templates")
|
574 |
|
575 |
|
576 |
|
|
|
508 |
"""
|
509 |
|
510 |
for item in json_data:
|
511 |
+
# JSON์ผ๋ก ์ง๋ ฌํํ์ฌ JavaScript ๋ฌธ์์ด๋ก ์์ ํ๊ฒ ๋ณํ
|
512 |
+
prompt_json = json.dumps(item.get('prompt', ''))
|
513 |
html_content += f"""
|
514 |
<div class="prompt-card">
|
515 |
<img src="{item.get('image_url', '')}" class="card-image" alt="{html.escape(item.get('name', ''))}">
|
516 |
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
517 |
+
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
518 |
+
<button class="copy-button" data-prompt={prompt_json}>
|
519 |
๐ ๋ณต์ฌ
|
520 |
</button>
|
521 |
</div>
|
|
|
524 |
html_content += """
|
525 |
</div>
|
526 |
<script>
|
527 |
+
// ๋ชจ๋ ๋ณต์ฌ ๋ฒํผ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ถ๊ฐ
|
528 |
+
document.addEventListener('DOMContentLoaded', function() {
|
529 |
+
document.querySelectorAll('.copy-button').forEach(button => {
|
530 |
+
button.addEventListener('click', async function(e) {
|
531 |
+
e.preventDefault();
|
532 |
+
e.stopPropagation();
|
533 |
+
|
534 |
+
const promptText = this.dataset.prompt;
|
535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
try {
|
537 |
+
// ํ
์คํธ ์์ญ ์์ฑ ๋ฐ ์ค์
|
538 |
+
const textarea = document.createElement('textarea');
|
539 |
+
textarea.value = promptText;
|
540 |
+
textarea.style.position = 'fixed';
|
541 |
+
textarea.style.left = '-9999px';
|
542 |
+
document.body.appendChild(textarea);
|
543 |
+
textarea.select();
|
544 |
+
|
545 |
+
// ๋ณต์ฌ ์๋
|
546 |
document.execCommand('copy');
|
547 |
+
document.body.removeChild(textarea);
|
|
|
|
|
548 |
|
549 |
+
// ๋ฒํผ ์ํ ์
๋ฐ์ดํธ
|
550 |
+
this.textContent = 'โ ๋ณต์ฌ๋จ';
|
551 |
+
this.style.backgroundColor = '#52c41a';
|
552 |
+
this.style.color = 'white';
|
553 |
+
|
554 |
+
// 2์ด ํ ์๋ ์ํ๋ก ๋ณต๊ตฌ
|
555 |
setTimeout(() => {
|
556 |
+
this.textContent = '๐ ๋ณต์ฌ';
|
557 |
+
this.style.backgroundColor = '#f0f0f0';
|
558 |
+
this.style.color = 'inherit';
|
559 |
}, 2000);
|
560 |
+
|
561 |
} catch (err) {
|
562 |
console.error('๋ณต์ฌ ์คํจ:', err);
|
563 |
alert('๋ณต์ฌ์ ์คํจํ์ต๋๋ค. ์ง์ ํ
์คํธ๋ฅผ ์ ํํ์ฌ ๋ณต์ฌํด์ฃผ์ธ์.');
|
564 |
}
|
565 |
+
});
|
566 |
+
});
|
567 |
+
});
|
|
|
|
|
568 |
</script>
|
569 |
"""
|
570 |
|
|
|
572 |
|
573 |
except Exception as e:
|
574 |
print(f"Error in load_session_history: {str(e)}")
|
575 |
+
return gr.HTML("Error loading templates")
|
576 |
|
577 |
|
578 |
|