Add chat_logs.txt viewer to Space UI
Browse files- Added Chat Logs accordion section with viewer and download
- Shows content of chat_logs.txt file if exists
- Download button for chat_logs.txt
- Separate from JSON conversation tracking system
Now both logging systems are accessible:
- chat_logs.txt: Simple text logging
- conversations.json: Structured JSON with dashboard
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -1135,6 +1135,44 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı", head=storag
|
|
| 1135 |
|
| 1136 |
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
| 1137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1138 |
# Add conversation viewer
|
| 1139 |
with gr.Accordion("📊 Konuşma Geçmişi (JSON)", open=False):
|
| 1140 |
with gr.Row():
|
|
|
|
| 1135 |
|
| 1136 |
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
| 1137 |
|
| 1138 |
+
# Add chat logs viewer
|
| 1139 |
+
with gr.Accordion("📄 Chat Logs (Text)", open=False):
|
| 1140 |
+
with gr.Row():
|
| 1141 |
+
refresh_logs_btn = gr.Button("🔄 Yenile", scale=1)
|
| 1142 |
+
download_logs_btn = gr.Button("💾 Logları İndir", scale=1)
|
| 1143 |
+
|
| 1144 |
+
logs_display = gr.Textbox(
|
| 1145 |
+
label="Chat Logs",
|
| 1146 |
+
lines=10,
|
| 1147 |
+
max_lines=20,
|
| 1148 |
+
interactive=False
|
| 1149 |
+
)
|
| 1150 |
+
|
| 1151 |
+
logs_file = gr.File(visible=False)
|
| 1152 |
+
|
| 1153 |
+
def get_chat_logs():
|
| 1154 |
+
"""Get chat logs content"""
|
| 1155 |
+
try:
|
| 1156 |
+
if os.path.exists(LOG_FILE):
|
| 1157 |
+
with open(LOG_FILE, 'r', encoding='utf-8') as f:
|
| 1158 |
+
return f.read()
|
| 1159 |
+
return "Henüz log kaydı yok."
|
| 1160 |
+
except Exception as e:
|
| 1161 |
+
return f"Log okuma hatası: {e}"
|
| 1162 |
+
|
| 1163 |
+
def download_chat_logs():
|
| 1164 |
+
"""Download chat logs file"""
|
| 1165 |
+
if os.path.exists(LOG_FILE):
|
| 1166 |
+
return LOG_FILE
|
| 1167 |
+
# Create empty file if doesn't exist
|
| 1168 |
+
with open(LOG_FILE, 'w') as f:
|
| 1169 |
+
f.write("Chat Logs\n")
|
| 1170 |
+
return LOG_FILE
|
| 1171 |
+
|
| 1172 |
+
refresh_logs_btn.click(get_chat_logs, outputs=logs_display)
|
| 1173 |
+
download_logs_btn.click(download_chat_logs, outputs=logs_file)
|
| 1174 |
+
demo.load(get_chat_logs, outputs=logs_display)
|
| 1175 |
+
|
| 1176 |
# Add conversation viewer
|
| 1177 |
with gr.Accordion("📊 Konuşma Geçmişi (JSON)", open=False):
|
| 1178 |
with gr.Row():
|