The app I’m building allows users to either select a document from out database or to upload their own (I’m using st.sidebar.selector and st.upload widgets). If the user changes from widget to the other, I’d like the previous widget to reset. Currently, the old widget stays the same when the other is executed. Can anyone provide guidance on how to reset the old widget when the other is used?
Here’s the code I’m using for the sidebar functionality:
with upload_placeholder.info(" 👈 Select document or upload your own to start chat"):
st.sidebar.header("Select a File or Upload New Document")
with st.sidebar:
sidebar_completed = False
st.session_state.vectore_store = None
# Adding empty line for spacing
st.markdown("")
# Radio button for user confirmation with agreement link
agreement_link = "[User Agreement](https://google.com)"
user_confirmation = st.checkbox(label=f"I confirm that I have read and understood the {agreement_link}.")
if user_confirmation: # User confirmed, allow document selection/upload
# Create a dropdown menu in the sidebar for file selection
file_selected = st.sidebar.selectbox(label="Select a File", options=saved_docs, placeholder='Choose an option', index=None )
select_sidebar_completed, selected_vectore_store = select_document_sidebar(file_selected)
# Widget to upload new document
file_input = st.file_uploader("Upload your PDF file", type="pdf")
upload_sidebar_completed, uploaded_vectore_store = upload_document_sidebar(file_input)
# Determine if a document is selected or uploaded and remove the old document
if select_sidebar_completed:
if "message_container" in st.session_state:
st.session_state.message_container.empty()
message_container = st.empty()
message_container.success('Document loaded! Ready to Chat!', icon="✅")
st.session_state.message_container = message_container
sidebar_completed = select_sidebar_completed
upload_placeholder.empty()
elif upload_sidebar_completed:
if "message_container" in st.session_state:
st.session_state.message_container.empty()
message_container = st.empty()
message_container.success('Document processed successfully! Ready to Chat!', icon="✅")
st.session_state.message_container = message_container
sidebar_completed = upload_sidebar_completed
upload_placeholder.empty()