Progress is not displayed after disabling CORS and XSRF_PROTECTION

Good morning,
I have a problem with the display of progress and its text when I go through session_state to decide on the display. The goal of my code is not to display all the blocks, I would like to deactivate the display of d 'a previous part before moving on to the next part hence the use of multiple session state.
Unfortunately, when going through if st.session_state.displayProgress, sometimes the progress bar and the text are not displayed while the code is executed, this happens when deactivating the CORS and XSRF_PROTECTION protocols (I have to to disable them in my deployment environment).
when both protocols are activated, I don’t have this problem
The application is tested locally, I already had the same problem using the app contained with Docker and with the app deployed by deactivating CORS and XSRF_PROTECTION.

I don’t understand the link between the display and these two protocols, but if anyone has an idea to help me find a solution I’m interested. THANKS

import streamlit as st

def init_sessions():
    if "initializedPage" not in st.session_state:
        st.session_state.initializedPage = True

    if "displayProgress" not in st.session_state:
        st.session_state.displayProgress = False

    if "filesUploadedNumber" not in st.session_state:
        st.session_state.filesUploadedNumber = None

    if "displayRerunButton" not in st.session_state:
        st.session_state.displayRerunButton = False

    if "displayProgressEnd" not in st.session_state:
        st.session_state.displayProgressEnd = False

    if "nextStepButton" not in st.session_state:
        st.session_state.nextStepButton = False

    if "displayProgress2" not in st.session_state:
        st.session_state.displayProgress2 = False

    if "displayProgressEnd2" not in st.session_state:
        st.session_state.displayProgressEnd2 = False

def display_end_progress(imagesNumber: int):
    status_text = st.empty()
    _ = st.progress(1.)
    status_text.text(f"Detecting and computing colors values: Image {imagesNumber} of {imagesNumber} treated (100% treated)")

init_sessions()


if st.session_state.initializedPage:
    uploadedFiles = st.file_uploader("Choose a file", accept_multiple_files=True)
    submitted = st.button("Start Process")

    if len(uploadedFiles) == 0:
        if submitted:
            st.error("No files loaded, please upload files")
    else:
        if submitted:
            st.session_state.filesUploadedNumber = 50#len(uploadedFiles)
            st.session_state.initializedPage = False
            st.session_state.displayProgress = True
            st.session_state.displayRerunButton = True
            st.rerun()

if st.session_state.displayProgress:
    
    status_text = st.empty()
    status_text.text(f"Detecting ........")
    progressbar = st.progress(0.)
    for idx in range (st.session_state.filesUploadedNumber):
        import time
        time.sleep(0.1)
        value = (idx + 1.) / st.session_state.filesUploadedNumber
        status_text.text(f'... {idx + 1} of {st.session_state.filesUploadedNumber}')
        progressbar.progress(value)
    st.session_state.displayProgress = False
    st.session_state.displayProgressEnd = True
    st.rerun()

if st.session_state.displayProgressEnd:
    display_end_progress(st.session_state.filesUploadedNumber)
    st.session_state.nextStepButton = True

if st.session_state.nextStepButton:
    if st.button("next"):
        st.session_state.displayProgress2 = True
        st.session_state.nextStepButton = False
        st.rerun()

if st.session_state.displayProgress2:
    status_text = st.empty()
    status_text.text(f"Detecting ........")
    progressbar = st.progress(0.)
    for idx in range (st.session_state.filesUploadedNumber):
        import time
        time.sleep(0.1)
        value = (idx + 1.) / st.session_state.filesUploadedNumber
        status_text.text(f'... {idx + 1} of {st.session_state.filesUploadedNumber}')
        progressbar.progress(value)
    st.session_state.displayProgress2 = False
    st.session_state.displayProgressEnd2 = True
    st.rerun()


if st.session_state.displayProgressEnd2:
    display_end_progress(st.session_state.filesUploadedNumber)

if st.session_state.displayRerunButton:
    if st.button("Rerun"):
        st.session_state.clear()
        st.session_state.initializedPage = True
        st.session_state.displayProgress = False
        st.session_state.displayProgress = False
        st.session_state.filesUploadedNumber = None
        st.session_state.displayRerunButton = False
        st.session_state.nextStepButton = False
        st.session_state.displayProgress2 = False
        st.session_state.displayProgressEnd2 = False
        st.rerun()

using:

Streamlit version 1.30.0 and python 3.9.18

streamlit run source.py --server.enableCORS=false --server.enableXsrfProtection=false

1 Like