I was wondering if anyone could kindly clarify whether the only way to remove/clear uploaded file(s) is still by hitting the ‘x’ button or if there is an official programmatic way to clear them. The reason I ask is because I have created a streamlit button called
"Reset all" where this button will make the app return to the state of when the program just successfully executed via
streamlit run app.py command.
That’s mean the program is returning to the beginning stage without any user input.
def initialize_session_state(): if "no_file_conversation" not in st.session_state: st.session_state.no_file_conversation = [ SystemMessage(content="I'm a PDF Chatbot. Ask me a question about your documents!") ] if "conversation" not in st.session_state: st.session_state.conversation = None if "chat_history" not in st.session_state: st.session_state.chat_history = None if 'user_input_prompt' not in st.session_state: # This one is specifically use for clearing the user text input after they hit enter st.session_state.user_input_prompt = 'None' if "pdf_docs" not in st.session_state: st.session_state.pdf_docs = None if "is_processed" not in st.session_state: st.session_state.is_processed = None if "is_vectorstore" not in st.session_state: st.session_state.is_vectorstore = False if "extra_class" not in st.session_state: # This is a control variable, use to check the type of user's last conversation, either 'Warning' or 'None' st.session_state.extra_class = None # Reset button part reset = st.sidebar.button('Reset all') if reset: st.session_state.clear() initialize_session_state()
The web app should look like this after clicking the Reset all button.
When I have done with the chatting, I clicked on the Reset all button and it didn’t remove the file I uploaded.
- Streamlit version: 1.23.1
- Python version: 3.10.8
- Using: PipEnv
- OS version: Windows 11 Home
- Browser version: Goole Chrome 114.0.5735.199 (Official Build) (64-bit)