Spaces:
Sleeping
Sleeping
Updated the export_chat_history function
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tempfile
|
|
|
|
| 3 |
import os
|
| 4 |
from enhanced_semantic_search import search_cases, chat_with_cases, extract_text_from_pdf, init_database
|
| 5 |
|
|
@@ -83,13 +84,19 @@ def export_chat_history(history):
|
|
| 83 |
|
| 84 |
# Create a formatted document
|
| 85 |
content = "# Legal Assistant Chat Export\n\n"
|
| 86 |
-
content += f"Export Date: {
|
| 87 |
|
| 88 |
for i, (user_msg, bot_response) in enumerate(history, 1):
|
| 89 |
-
content +=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
# Save to temporary file
|
| 92 |
-
temp_file = tempfile.NamedTemporaryFile(
|
|
|
|
|
|
|
| 93 |
temp_file.write(content)
|
| 94 |
temp_file.close()
|
| 95 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tempfile
|
| 3 |
+
import datetime
|
| 4 |
import os
|
| 5 |
from enhanced_semantic_search import search_cases, chat_with_cases, extract_text_from_pdf, init_database
|
| 6 |
|
|
|
|
| 84 |
|
| 85 |
# Create a formatted document
|
| 86 |
content = "# Legal Assistant Chat Export\n\n"
|
| 87 |
+
content += f"Export Date: {datetime.datetime.now().isoformat()}\n\n"
|
| 88 |
|
| 89 |
for i, (user_msg, bot_response) in enumerate(history, 1):
|
| 90 |
+
content += (
|
| 91 |
+
f"## Query {i}\n"
|
| 92 |
+
f"**User:** {user_msg}\n\n"
|
| 93 |
+
f"**Assistant:** {bot_response}\n\n---\n\n"
|
| 94 |
+
)
|
| 95 |
|
| 96 |
# Save to temporary file
|
| 97 |
+
temp_file = tempfile.NamedTemporaryFile(
|
| 98 |
+
mode='w', suffix='.md', delete=False, encoding='utf-8'
|
| 99 |
+
)
|
| 100 |
temp_file.write(content)
|
| 101 |
temp_file.close()
|
| 102 |
|