NavyDevilDoc commited on
Commit
dd05053
·
verified ·
1 Parent(s): cc68cbb

Update src/app.py

Browse files

added chat history download functionality

Files changed (1) hide show
  1. src/app.py +23 -0
src/app.py CHANGED
@@ -210,6 +210,29 @@ tab1, tab2, tab3 = st.tabs(["💬 Chat Playground", "📂 Knowledge & Tools", "
210
  # === TAB 1: CHAT ===
211
  with tab1:
212
  st.header("Discussion & Analysis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  if "messages" not in st.session_state: st.session_state.messages = []
214
 
215
  # RENDER DEBUG OVERLAY (If enabled in Admin)
 
210
  # === TAB 1: CHAT ===
211
  with tab1:
212
  st.header("Discussion & Analysis")
213
+
214
+ # Chat History Downloader
215
+ # Only show the button if there is actually a conversation to save
216
+ if st.session_state.get("messages"):
217
+ # 1. Format the history log
218
+ chat_log = f"# ⚓ Navy AI Toolkit - Chat Log\n"
219
+ chat_log += f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M')}\n"
220
+ chat_log += f"Model: {st.session_state.get('model_selector_radio', 'Unknown')}\n\n"
221
+ chat_log += "---\n\n"
222
+
223
+ for msg in st.session_state.messages:
224
+ role = msg["role"].upper()
225
+ content = msg["content"]
226
+ chat_log += f"**{role}**: {content}\n\n"
227
+
228
+ # 2. Render the Download Button (Right below header)
229
+ st.download_button(
230
+ label="💾 Download Conversation",
231
+ data=chat_log,
232
+ file_name=f"chat_session_{datetime.now().strftime('%Y%m%d_%H%M')}.md",
233
+ mime="text/markdown"
234
+ )
235
+
236
  if "messages" not in st.session_state: st.session_state.messages = []
237
 
238
  # RENDER DEBUG OVERLAY (If enabled in Admin)