Clear st.file_uploader without using st.form

In my script upon uploading a file a series of dataframes are being generated. After they are created the script creates two buttons REJECT and APPROVE which either delete the dataframes or send the to Google Cloud Services. The problem I am having is that I would like to revert to a clear page with the uploader once the function of REJECT or APPROVE buttons is complete. Unfortunately on click the desired upload / deletion takes place, but then the entire set of dataframes reloads again, which takes forever. Is there a way not to reload the entire page on click, or to remove the uploaded file on click so that no dataframe would be generated? I have tried st.form but it requires a Submit button, tha tI don’t need nor want, I tried st.container in combination with st.empty which cleared the page from the dataframes but only after reloading them again. I am runnig out of ideas. Also wasn’t very successful with the st.session_state to achieve the desired effect. I also tried to create a list and to place the uploaded file inside, and clear it on click (see example code below), but nothing works. Any ideas?

if uploaded_file is not None:
    if ifcEntity_dataframes:  
        col1, col2 = st.columns(2)  
        with col1:
            if st.button("REJECT"):
                delete_from_bucket(blob_name)
                delete_pickles(bucket_name)
                uploaded_file = []
                st.write("SUCCESS!")
            st.write("If you are not satisifed with the content of the IFC file and wish not to merge it with the warehouse database, click REJECT. This will remove all temporary data you have created, including DataFrames and IFC files.")

        with col2:
            if st.button("APPROVE"):
                move_file_between_buckets(processing_bucket, ifc_bucket, blob_name)
                for entity, generated_df in ifcEntity_dataframes.items():
                    pickle_data = io.BytesIO()
                    generated_df.to_pickle(pickle_data)
                    pickle_data.seek(0)
                    save_pickle_to_bucket(pickle_data, f"wh_{entity}.pickle")
                    uploaded_file = []
                    st.write("SUCCESS!")
            st.write("If you have checked the content of the dataframes and are confident that the data meets the requirements click APPROVE. Your data will be merged with the main dataframe.")

Hey @PeterPetersen , I found this solution that might work for you Are there any ways to clear file uploader values without using streamlit form

Thanks! This solves the uploader problem, that’s great.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.