Deleting st.status (StatusContainer) after finished Execution

Hello all!

I’m creating a RAG/ChatBot app and, when response is being generated by model, I would like to display a “loading” message, that I want to be deleted after execution.

I’ve achieved an almost desired result by using st.status(), just like this:

def generate_fake_response(question):
    # This function simulates model generating response
    with st.status('Generating response...', expanded=False) as status:
        time.sleep(5)
        fake_answer = 'Response Generated After Model Processing'
        status.update(
            label='Response Generated!', state='complete', expanded=None
        )
        status.empty() # I've tried this to delete StatusContainer but without success
    for word in fake_answer.split():
        yield word + " "
        time.sleep(0.05)


# Reacting to user input (question)
if question := st.chat_input(placeholder='Ex: "Sample Question"', max_chars=2000):
    with st.chat_message(name='assistant', avatar='🕵️‍♂️'):
            result = st.write_stream(generate_fake_response(question))

This is how my app works:

1- Generating Response

2- After Response is Generated, StatusContainer are still visible:

Any ideas on how to delete this container after function execution??

Thank you in advance!

Hi.

Just sharing, I’ve managed to solve using st.empty() in an wrapped way, just like this:

def generate_fake_response(question):
    empty_space = st.empty()
    with empty_space.container():

        with st.status('Generating response...', expanded=False) as status:

            time.sleep(5)
            fake_answer = 'Response Generated After Model Processing'
            status.update(
                label='Response Generated!', state='complete', expanded=None
            )
    empty_space.empty()

    for word in fake_answer.split():
        yield word + " "
        time.sleep(0.05)```
1 Like

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