Remove chat logs and conversation history sections from UI
Browse files- Removed unnecessary Chat Logs accordion section
- Removed Konuşma Geçmişi (JSON) accordion section
- Cleaned up redundant functions (get_chat_logs, download_chat_logs, etc.)
- Kept API endpoints for dashboard functionality
- Simplified UI to focus only on chatbot interaction
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
app.py
CHANGED
@@ -1135,168 +1135,6 @@ 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 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():
|
1179 |
-
refresh_json_btn = gr.Button("🔄 Yenile", scale=1)
|
1180 |
-
download_json_btn = gr.Button("💾 JSON İndir", scale=1)
|
1181 |
-
view_dashboard_btn = gr.Button("📈 Dashboard'u Aç", scale=1)
|
1182 |
-
|
1183 |
-
json_display = gr.JSON(label="Konuşmalar", elem_id="json_viewer")
|
1184 |
-
download_file = gr.File(label="İndir", visible=False)
|
1185 |
-
|
1186 |
-
def get_conversations_json():
|
1187 |
-
from conversation_tracker import load_conversations
|
1188 |
-
convs = load_conversations()
|
1189 |
-
# Also save to file for download
|
1190 |
-
import json as json_module
|
1191 |
-
with open("temp_conversations.json", "w", encoding="utf-8") as f:
|
1192 |
-
json_module.dump(convs, f, ensure_ascii=False, indent=2)
|
1193 |
-
return convs
|
1194 |
-
|
1195 |
-
def download_conversations():
|
1196 |
-
get_conversations_json() # Ensure file is updated
|
1197 |
-
return gr.update(visible=True, value="temp_conversations.json")
|
1198 |
-
|
1199 |
-
def open_dashboard():
|
1200 |
-
return gr.HTML("""
|
1201 |
-
<div style='padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 10px; color: white;'>
|
1202 |
-
<h3>📊 Dashboard Kullanım Talimatları</h3>
|
1203 |
-
<ol style='margin: 15px 0;'>
|
1204 |
-
<li>Yukarıdaki "💾 JSON İndir" butonuna tıkla</li>
|
1205 |
-
<li>conversations.json dosyasını indir</li>
|
1206 |
-
<li>bf_dashboard_json.html dosyasını aç</li>
|
1207 |
-
<li>İndirdiğin JSON dosyasını dashboard'a yükle</li>
|
1208 |
-
</ol>
|
1209 |
-
<p style='margin-top: 15px; font-size: 14px;'>
|
1210 |
-
Dashboard HTML dosyasını almak için:<br>
|
1211 |
-
<a href='https://github.com/yourusername/bf-dashboard' target='_blank' style='color: white; text-decoration: underline;'>
|
1212 |
-
GitHub'dan indir
|
1213 |
-
</a>
|
1214 |
-
</p>
|
1215 |
-
</div>
|
1216 |
-
""")
|
1217 |
-
|
1218 |
-
refresh_json_btn.click(get_conversations_json, outputs=json_display)
|
1219 |
-
download_json_btn.click(download_conversations, outputs=download_file)
|
1220 |
-
view_dashboard_btn.click(open_dashboard, outputs=json_display)
|
1221 |
-
|
1222 |
-
# Auto-load on start
|
1223 |
-
demo.load(get_conversations_json, outputs=json_display)
|
1224 |
-
|
1225 |
-
# Define function for JSON HTML before using it
|
1226 |
-
def create_json_html():
|
1227 |
-
"""Create HTML with embedded JSON data"""
|
1228 |
-
from conversation_tracker import load_conversations
|
1229 |
-
import json
|
1230 |
-
conversations = load_conversations()
|
1231 |
-
json_str = json.dumps(conversations, ensure_ascii=False)
|
1232 |
-
return f'''
|
1233 |
-
<div id="json-data" style="display:none;">
|
1234 |
-
<script type="application/json" id="conversations-json">
|
1235 |
-
{json_str}
|
1236 |
-
</script>
|
1237 |
-
</div>
|
1238 |
-
'''
|
1239 |
-
|
1240 |
-
# Add HTML component with embedded JSON for external access
|
1241 |
-
with gr.Row(visible=False):
|
1242 |
-
# Create an HTML element that contains the JSON data
|
1243 |
-
json_html = gr.HTML(
|
1244 |
-
value=create_json_html(), # Call directly, not as lambda
|
1245 |
-
visible=False,
|
1246 |
-
elem_id="json_data_container"
|
1247 |
-
)
|
1248 |
-
|
1249 |
-
# Update JSON HTML on page load
|
1250 |
-
demo.load(create_json_html, outputs=json_html)
|
1251 |
-
|
1252 |
-
# API endpoints for dashboard
|
1253 |
-
def get_all_conversations():
|
1254 |
-
"""API endpoint to get all conversations"""
|
1255 |
-
from conversation_tracker import load_conversations
|
1256 |
-
conversations = load_conversations()
|
1257 |
-
|
1258 |
-
# Format for dashboard
|
1259 |
-
formatted = {}
|
1260 |
-
for conv in conversations:
|
1261 |
-
session_id = f"session_{conv['timestamp'].replace(':', '').replace('-', '').replace('T', '_')[:15]}"
|
1262 |
-
|
1263 |
-
if session_id not in formatted:
|
1264 |
-
formatted[session_id] = {
|
1265 |
-
"customer": "Kullanıcı",
|
1266 |
-
"phone": session_id,
|
1267 |
-
"messages": []
|
1268 |
-
}
|
1269 |
-
|
1270 |
-
formatted[session_id]["messages"].append({
|
1271 |
-
"type": "received",
|
1272 |
-
"text": conv["user"],
|
1273 |
-
"time": conv["timestamp"]
|
1274 |
-
})
|
1275 |
-
|
1276 |
-
formatted[session_id]["messages"].append({
|
1277 |
-
"type": "sent",
|
1278 |
-
"text": conv["bot"],
|
1279 |
-
"time": conv["timestamp"]
|
1280 |
-
})
|
1281 |
-
|
1282 |
-
return formatted
|
1283 |
-
|
1284 |
-
def get_conversation_stats():
|
1285 |
-
"""Get conversation statistics"""
|
1286 |
-
from conversation_tracker import load_conversations
|
1287 |
-
from datetime import datetime
|
1288 |
-
|
1289 |
-
conversations = load_conversations()
|
1290 |
-
today = datetime.now().date()
|
1291 |
-
today_count = sum(1 for conv in conversations
|
1292 |
-
if datetime.fromisoformat(conv["timestamp"]).date() == today)
|
1293 |
-
|
1294 |
-
return {
|
1295 |
-
"total": len(conversations),
|
1296 |
-
"today": today_count,
|
1297 |
-
"active": len(set(conv.get("session_id", i) for i, conv in enumerate(conversations)))
|
1298 |
-
}
|
1299 |
-
|
1300 |
# API will be handled separately in production
|
1301 |
|
1302 |
# Add FastAPI endpoints for CORS-enabled API access
|
@@ -1337,10 +1175,12 @@ async def get_latest_conversations():
|
|
1337 |
except Exception as e:
|
1338 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
1339 |
|
|
|
|
|
1340 |
# Mount FastAPI to Gradio
|
1341 |
demo = gr.mount_gradio_app(api, demo, path="/")
|
1342 |
|
1343 |
if __name__ == "__main__":
|
1344 |
import uvicorn
|
1345 |
# Run with uvicorn for FastAPI support
|
1346 |
-
uvicorn.run(api, host="0.0.0.0", port=7860)
|
|
|
1135 |
|
1136 |
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
1137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1138 |
# API will be handled separately in production
|
1139 |
|
1140 |
# Add FastAPI endpoints for CORS-enabled API access
|
|
|
1175 |
except Exception as e:
|
1176 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
1177 |
|
1178 |
+
|
1179 |
+
|
1180 |
# Mount FastAPI to Gradio
|
1181 |
demo = gr.mount_gradio_app(api, demo, path="/")
|
1182 |
|
1183 |
if __name__ == "__main__":
|
1184 |
import uvicorn
|
1185 |
# Run with uvicorn for FastAPI support
|
1186 |
+
uvicorn.run(api, host="0.0.0.0", port=7860)
|