NavyDevilDoc commited on
Commit
7e43b15
·
verified ·
1 Parent(s): 8ba0387

Update src/app.py

Browse files

added a chat download feature

Files changed (1) hide show
  1. src/app.py +23 -2
src/app.py CHANGED
@@ -290,21 +290,42 @@ with tab2:
290
 
291
  # --- CONTROLS AND METRICS ---
292
  # The controls are kept outside the chat loop.
293
- c1, c2, c3 = st.columns([1, 1, 1])
294
  with c1:
295
  # Use the global model_choice from the sidebar/tab1 initialization
296
  selected_model_name = st.session_state.get('model_choice', 'Granite 4 (IBM)')
 
297
  with c2:
298
  use_rag = st.toggle("🔌 Enable Knowledge Base", value=False)
299
  # The token progress bar will be handled inside the prompt logic based on input length
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  # --- DISPLAY CONVERSATION HISTORY ---
302
  for message in st.session_state.messages:
303
  with st.chat_message(message["role"]):
304
  st.markdown(message["content"])
305
 
306
  # --- CHAT INPUT HANDLING (Replaces st.text_input and st.button) ---
307
- if prompt := st.chat_input("Ask about Naval Systems..."):
308
  # 1. Display User Message and save to history
309
  st.session_state.messages.append({"role": "user", "content": prompt})
310
  with st.chat_message("user"):
 
290
 
291
  # --- CONTROLS AND METRICS ---
292
  # The controls are kept outside the chat loop.
293
+ c1, c2, c3 = st.columns([2, 1, 1])
294
  with c1:
295
  # Use the global model_choice from the sidebar/tab1 initialization
296
  selected_model_name = st.session_state.get('model_choice', 'Granite 4 (IBM)')
297
+ st.caption(f"Active Model: **{selected_model_name}**")
298
  with c2:
299
  use_rag = st.toggle("🔌 Enable Knowledge Base", value=False)
300
  # The token progress bar will be handled inside the prompt logic based on input length
301
 
302
+ with c3:
303
+ # --- NEW FEATURE: DOWNLOAD CHAT ---
304
+ # Convert history to a readable string
305
+ chat_log = ""
306
+ for msg in st.session_state.messages:
307
+ role = "USER" if msg['role'] == 'user' else "ASSISTANT"
308
+ chat_log += f"[{role}]: {msg['content']}\n\n"
309
+
310
+ # Only show button if there is history to save
311
+ if chat_log:
312
+ st.download_button(
313
+ label="💾 Save Chat",
314
+ data=chat_log,
315
+ file_name="mission_log.txt",
316
+ mime="text/plain",
317
+ help="Download the current conversation history."
318
+ )
319
+
320
+ st.divider()
321
+
322
  # --- DISPLAY CONVERSATION HISTORY ---
323
  for message in st.session_state.messages:
324
  with st.chat_message(message["role"]):
325
  st.markdown(message["content"])
326
 
327
  # --- CHAT INPUT HANDLING (Replaces st.text_input and st.button) ---
328
+ if prompt := st.chat_input("Ask a question..."):
329
  # 1. Display User Message and save to history
330
  st.session_state.messages.append({"role": "user", "content": prompt})
331
  with st.chat_message("user"):