Update app.py
Browse files
app.py
CHANGED
@@ -449,12 +449,9 @@ def load_json_data():
|
|
449 |
}
|
450 |
]
|
451 |
|
452 |
-
|
453 |
def load_session_history(selected_session=None):
|
454 |
try:
|
455 |
-
print("Loading session history...")
|
456 |
json_data = load_json_data()
|
457 |
-
print(f"Loaded {len(json_data)} items")
|
458 |
|
459 |
html_content = """
|
460 |
<style>
|
@@ -469,7 +466,6 @@ def load_session_history(selected_session=None):
|
|
469 |
border: 1px solid #eee;
|
470 |
border-radius: 8px;
|
471 |
padding: 15px;
|
472 |
-
cursor: pointer;
|
473 |
transition: all 0.3s ease;
|
474 |
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
475 |
min-height: 300px;
|
@@ -490,23 +486,13 @@ def load_session_history(selected_session=None):
|
|
490 |
margin-bottom: 8px;
|
491 |
font-size: 16px;
|
492 |
}
|
493 |
-
.card-prompt-container {
|
494 |
-
position: relative;
|
495 |
-
padding-right: 60px;
|
496 |
-
}
|
497 |
.card-prompt {
|
498 |
font-size: 0.9em;
|
499 |
color: #666;
|
500 |
-
|
501 |
-
-webkit-line-clamp: 3;
|
502 |
-
-webkit-box-orient: vertical;
|
503 |
-
overflow: hidden;
|
504 |
}
|
505 |
-
.copy-
|
506 |
-
|
507 |
-
right: 0;
|
508 |
-
top: 0;
|
509 |
-
padding: 4px 8px;
|
510 |
background: #f0f0f0;
|
511 |
border: 1px solid #ddd;
|
512 |
border-radius: 4px;
|
@@ -514,98 +500,68 @@ def load_session_history(selected_session=None):
|
|
514 |
font-size: 0.9em;
|
515 |
transition: all 0.2s ease;
|
516 |
}
|
517 |
-
.copy-
|
518 |
background: #e0e0e0;
|
519 |
}
|
520 |
-
.copy-btn:active {
|
521 |
-
background: #d0d0d0;
|
522 |
-
}
|
523 |
</style>
|
524 |
<div class="prompt-grid">
|
525 |
"""
|
526 |
|
527 |
for item in json_data:
|
528 |
-
|
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
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
</button>
|
542 |
-
</div>
|
543 |
</div>
|
544 |
"""
|
545 |
|
546 |
html_content += """
|
547 |
</div>
|
548 |
<script>
|
549 |
-
|
550 |
-
|
551 |
-
|
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 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
btn.style.color = 'white';
|
579 |
|
580 |
setTimeout(() => {
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
}, 2000);
|
585 |
} catch (err) {
|
586 |
-
|
587 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
588 |
}
|
589 |
-
|
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 |
-
}
|
609 |
}
|
610 |
</script>
|
611 |
"""
|
@@ -614,7 +570,8 @@ def load_session_history(selected_session=None):
|
|
614 |
|
615 |
except Exception as e:
|
616 |
print(f"Error in load_session_history: {str(e)}")
|
617 |
-
return gr.HTML("Error loading templates")
|
|
|
618 |
|
619 |
|
620 |
# νμ€ν 리 μμ΄ν
μ ν μ²λ¦¬ ν¨μ
|
|
|
449 |
}
|
450 |
]
|
451 |
|
|
|
452 |
def load_session_history(selected_session=None):
|
453 |
try:
|
|
|
454 |
json_data = load_json_data()
|
|
|
455 |
|
456 |
html_content = """
|
457 |
<style>
|
|
|
466 |
border: 1px solid #eee;
|
467 |
border-radius: 8px;
|
468 |
padding: 15px;
|
|
|
469 |
transition: all 0.3s ease;
|
470 |
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
471 |
min-height: 300px;
|
|
|
486 |
margin-bottom: 8px;
|
487 |
font-size: 16px;
|
488 |
}
|
|
|
|
|
|
|
|
|
489 |
.card-prompt {
|
490 |
font-size: 0.9em;
|
491 |
color: #666;
|
492 |
+
margin-bottom: 10px;
|
|
|
|
|
|
|
493 |
}
|
494 |
+
.copy-button {
|
495 |
+
padding: 5px 10px;
|
|
|
|
|
|
|
496 |
background: #f0f0f0;
|
497 |
border: 1px solid #ddd;
|
498 |
border-radius: 4px;
|
|
|
500 |
font-size: 0.9em;
|
501 |
transition: all 0.2s ease;
|
502 |
}
|
503 |
+
.copy-button:hover {
|
504 |
background: #e0e0e0;
|
505 |
}
|
|
|
|
|
|
|
506 |
</style>
|
507 |
<div class="prompt-grid">
|
508 |
"""
|
509 |
|
510 |
for item in json_data:
|
511 |
+
prompt_text = html.escape(item.get('prompt', '')).replace('"', '"')
|
|
|
|
|
|
|
|
|
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">{prompt_text}</div>
|
517 |
+
<button class="copy-button" onclick="copyToClipboard(this, '{prompt_text}')">
|
518 |
+
π 볡μ¬
|
519 |
+
</button>
|
|
|
|
|
520 |
</div>
|
521 |
"""
|
522 |
|
523 |
html_content += """
|
524 |
</div>
|
525 |
<script>
|
526 |
+
function copyToClipboard(button, text) {
|
527 |
+
// ν΄λ¦½λ³΄λμ 볡μ¬νλ ν¨μ
|
528 |
+
const copyText = async () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
529 |
try {
|
530 |
+
await navigator.clipboard.writeText(text);
|
531 |
+
button.textContent = 'β 볡μ¬λ¨';
|
532 |
+
button.style.backgroundColor = '#52c41a';
|
533 |
+
button.style.color = 'white';
|
|
|
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 |
+
button.textContent = 'β 볡μ¬λ¨';
|
549 |
+
button.style.backgroundColor = '#52c41a';
|
550 |
+
button.style.color = 'white';
|
551 |
+
|
552 |
+
setTimeout(() => {
|
553 |
+
button.textContent = 'π 볡μ¬';
|
554 |
+
button.style.backgroundColor = '#f0f0f0';
|
555 |
+
button.style.color = 'inherit';
|
556 |
+
}, 2000);
|
557 |
+
} catch (err) {
|
558 |
+
console.error('λ³΅μ¬ μ€ν¨:', err);
|
559 |
+
alert('볡μ¬μ μ€ν¨νμ΅λλ€. μ§μ ν
μ€νΈλ₯Ό μ ννμ¬ λ³΅μ¬ν΄μ£ΌμΈμ.');
|
560 |
+
}
|
561 |
+
document.body.removeChild(textarea);
|
562 |
}
|
563 |
+
};
|
564 |
+
copyText();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
565 |
}
|
566 |
</script>
|
567 |
"""
|
|
|
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 |
|
577 |
# νμ€ν 리 μμ΄ν
μ ν μ²λ¦¬ ν¨μ
|