Update app.py
Browse files
app.py
CHANGED
@@ -402,9 +402,8 @@ def update_session_list():
|
|
402 |
def load_session_history(selected_session):
|
403 |
try:
|
404 |
if not selected_session:
|
405 |
-
return gr.
|
406 |
|
407 |
-
# ์ธ์
ID ์ถ์ถ
|
408 |
session_id = selected_session.split(" (")[0] if " (" in selected_session else selected_session
|
409 |
|
410 |
conn = sqlite3.connect('chat_history.db')
|
@@ -418,7 +417,6 @@ def load_session_history(selected_session):
|
|
418 |
history = c.fetchall()
|
419 |
conn.close()
|
420 |
|
421 |
-
# ํ๋กฌํํธ ์นด๋์ฉ HTML ์์ฑ
|
422 |
cards_html = """
|
423 |
<style>
|
424 |
.prompt-grid {
|
@@ -445,43 +443,55 @@ def load_session_history(selected_session):
|
|
445 |
color: #666;
|
446 |
margin-top: 10px;
|
447 |
}
|
|
|
|
|
|
|
448 |
</style>
|
449 |
<div class="prompt-grid">
|
450 |
"""
|
451 |
|
|
|
|
|
|
|
|
|
452 |
for i, (prompt, response, timestamp) in enumerate(history):
|
453 |
-
# ํ๋กฌํํธ ํ
์คํธ๋ฅผ ์ ์ ํ ๊ธธ์ด๋ก ์๋ฅด๊ธฐ
|
454 |
short_prompt = prompt[:100] + "..." if len(prompt) > 100 else prompt
|
455 |
formatted_time = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f').strftime('%Y-%m-%d %H:%M')
|
456 |
|
|
|
|
|
|
|
457 |
cards_html += f"""
|
458 |
-
<div class="prompt-card" onclick="
|
459 |
<div>{short_prompt}</div>
|
460 |
<div class="timestamp">{formatted_time}</div>
|
461 |
</div>
|
462 |
"""
|
463 |
-
|
464 |
cards_html += "</div>"
|
465 |
|
466 |
-
# JavaScript ํจ์
|
467 |
-
cards_html += """
|
468 |
<script>
|
469 |
-
|
470 |
-
|
471 |
-
document.getElementById('code-display').innerHTML = `<pre><code>${responses[index]}</code></pre>`;
|
472 |
-
}
|
473 |
-
</script>
|
474 |
-
""" % json.dumps([response for _, response, _ in history])
|
475 |
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
"""
|
486 |
|
487 |
return gr.HTML(value=cards_html)
|
|
|
402 |
def load_session_history(selected_session):
|
403 |
try:
|
404 |
if not selected_session:
|
405 |
+
return gr.HTML("")
|
406 |
|
|
|
407 |
session_id = selected_session.split(" (")[0] if " (" in selected_session else selected_session
|
408 |
|
409 |
conn = sqlite3.connect('chat_history.db')
|
|
|
417 |
history = c.fetchall()
|
418 |
conn.close()
|
419 |
|
|
|
420 |
cards_html = """
|
421 |
<style>
|
422 |
.prompt-grid {
|
|
|
443 |
color: #666;
|
444 |
margin-top: 10px;
|
445 |
}
|
446 |
+
#code-display {
|
447 |
+
display: none;
|
448 |
+
}
|
449 |
</style>
|
450 |
<div class="prompt-grid">
|
451 |
"""
|
452 |
|
453 |
+
# ์๋ต ๋ฐ์ดํฐ๋ฅผ JavaScript ๋ฐฐ์ด๋ก ์ค๋น
|
454 |
+
responses_data = []
|
455 |
+
prompts_data = []
|
456 |
+
|
457 |
for i, (prompt, response, timestamp) in enumerate(history):
|
|
|
458 |
short_prompt = prompt[:100] + "..." if len(prompt) > 100 else prompt
|
459 |
formatted_time = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f').strftime('%Y-%m-%d %H:%M')
|
460 |
|
461 |
+
responses_data.append(response)
|
462 |
+
prompts_data.append(prompt)
|
463 |
+
|
464 |
cards_html += f"""
|
465 |
+
<div class="prompt-card" onclick="executeHistoryItem({i})">
|
466 |
<div>{short_prompt}</div>
|
467 |
<div class="timestamp">{formatted_time}</div>
|
468 |
</div>
|
469 |
"""
|
470 |
+
|
471 |
cards_html += "</div>"
|
472 |
|
473 |
+
# JavaScript ํจ์ ์์
|
474 |
+
cards_html += f"""
|
475 |
<script>
|
476 |
+
const responses = {json.dumps(responses_data)};
|
477 |
+
const prompts = {json.dumps(prompts_data)};
|
|
|
|
|
|
|
|
|
478 |
|
479 |
+
function executeHistoryItem(index) {{
|
480 |
+
// ์
๋ ฅ ํ๋์ ํ๋กฌํํธ ์ค์
|
481 |
+
document.querySelector('textarea').value = prompts[index];
|
482 |
+
|
483 |
+
// ์ฝ๋ ์คํ
|
484 |
+
const code = responses[index];
|
485 |
+
const encodedHtml = btoa(code);
|
486 |
+
const dataUri = `data:text/html;charset=utf-8;base64,${{encodedHtml}}`;
|
487 |
+
|
488 |
+
// iframe ์
๋ฐ์ดํธ
|
489 |
+
document.querySelector('.html_content iframe').src = dataUri;
|
490 |
+
|
491 |
+
// ์ธ์
๋๋ก์ด ๋ซ๊ธฐ
|
492 |
+
document.querySelector('.session-drawer').style.display = 'none';
|
493 |
+
}}
|
494 |
+
</script>
|
495 |
"""
|
496 |
|
497 |
return gr.HTML(value=cards_html)
|