Spaces:
Sleeping
Sleeping
Update src/app.py
Browse filesadded a chat download feature
289 unmodified lines290291292293294295296297298299300301302303304305306307308309310289 unmodified lines# --- CONTROLS AND METRICS ---# The controls are kept outside the chat loop.c1, c2, c3 = st.columns([1, 1, 1])with c1:# Use the global model_choice from the sidebar/tab1 initializationselected_model_name = st.session_state.get('model_choice', 'Granite 4 (IBM)')with c2:use_rag = st.toggle("๐ Enable Knowledge Base", value=False)# The token progress bar will be handled inside the prompt logic based on input length# --- DISPLAY CONVERSATION HISTORY ---for message in st.session_state.messages:with st.chat_message(message["role"]):st.markdown(message["content"])# --- CHAT INPUT HANDLING (Replaces st.text_input and st.button) ---if prompt := st.chat_input("Ask about Naval Systems..."):# 1. Display User Message and save to historyst.session_state.messages.append({"role": "user", "content": prompt})with st.chat_message("user"):289 unmodified lines290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331289 unmodified lines# --- CONTROLS AND METRICS ---# The controls are kept outside the chat loop.c1, c2, c3 = st.columns([2, 1, 1])with c1:# Use the global model_choice from the sidebar/tab1 initializationselected_model_name = st.session_state.get('model_choice', 'Granite 4 (IBM)')st.caption(f"Active Model: **{selected_model_name}**")with c2:use_rag = st.toggle("๐ Enable Knowledge Base", value=False)# The token progress bar will be handled inside the prompt logic based on input lengthwith c3:# --- NEW FEATURE: DOWNLOAD CHAT ---# Convert history to a readable stringchat_log = ""for msg in st.session_state.messages:role = "USER" if msg['role'] == 'user' else "ASSISTANT"chat_log += f"[{role}]: {msg['content']}\n\n"# Only show button if there is history to saveif chat_log:st.download_button(label="๐พ Save Chat",data=chat_log,file_name="mission_log.txt",mime="text/plain",help="Download the current conversation history.")st.divider()# --- DISPLAY CONVERSATION HISTORY ---for message in st.session_state.messages:with st.chat_message(message["role"]):st.markdown(message["content"])# --- CHAT INPUT HANDLING (Replaces st.text_input and st.button) ---if prompt := st.chat_input("Ask a question..."):# 1. Display User Message and save to historyst.session_state.messages.append({"role": "user", "content": prompt})with st.chat_message("user"):
src/app.py+23-2