avatarAndyCheung0211

Summary

Streamlit 1.26.0 introduces the st.status feature to enhance user experience by displaying the progress and status of long-running processes in Streamlit applications.

Abstract

The latest release of Streamlit, version 1.26.0, introduces a significant new feature called st.status. This feature is designed to provide users with real-time feedback on the status of their Streamlit app, including intermediate and final outputs of long-running processes. It helps users understand the progress of data loading or computations happening behind the scenes, and it can also display error messages if a step in the process fails. To use st.status, users must have Streamlit version 1.26.0 or higher installed. The feature can be demonstrated in a demo app provided by Streamlit, and it integrates well with st.chat_message for conversational apps that require API calls or data loading. The Streamlit documentation provides tutorials and resources for developers to implement these new features effectively.

Opinions

  • The author believes that the st.status feature adds significant value to Streamlit applications by improving transparency during long loading processes.
  • The integration of st.status with st.chat_message is highlighted as particularly useful for conversational apps, suggesting that the author sees this as a key use case.
  • By providing a demo app and detailed documentation, the author conveys a commitment to user education and ease of adoption for the new features.
  • The mention of error display capabilities indicates the author's recognition of the importance of error handling in user experience.
  • The reference to previous Streamlit releases and their features suggests that the author views the evolution of Streamlit as a series of meaningful enhancements to the platform.

Streamlit 1.26.0 brings Status to show process of your app

Photo by Mike van den Bos on Unsplash

What’s new in streamlit 1.26.0?

st.status is added to show status of your streamlit app, providing extra info to let user know what is running behind the scenes.

Other new features can be found in https://discuss.streamlit.io/t/version-1-26-0/50056

Why show status?

Status is for displaying intermediate and final output of a long loading process, this can help user to understand the running progress and details of loading.

status can also display error tell user which step raise error

How to use Status?

First of all, you need streamilt version 1.26.0 or above to use st.status upgrade your streamlit if needed.

pip install --upgrade streamlit

streamlit --version

See Status in action

you can play around with Streamlit’s demo app here or use my code below to see st.status different use cases.

# basic count down using status, collpase after count down

import streamlit as st
import time

st.title('Streamlit new function Status')

st.write('hello world')

with st.status("counting down", expanded=True) as status:
    for i in range(10, 0, -1):
        st.write(f"{i}...")
        time.sleep(1)
    status.update(label="Time is up", state="complete", expanded=False)

st.button('Rerun')

Use Status with chat message

st.status works great with st.chat_message when a chat message needs to wait for API calls or data loading st.status is useful.

the code is based on Streamlit documentation and I added Status with sleep 1 second.

import streamlit as st
import random
import time

st.title("Simple chat")

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Accept user input
if prompt := st.chat_input("What is up?"):
    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})
    # Display user message in chat message container
    with st.chat_message("user"):
        st.markdown(prompt)

    # Display assistant response in chat message container
    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        full_response = ""
        assistant_response = random.choice(
            [
                "Hello there! How can I assist you today?",
                "Hi, human! Is there anything I can help you with?",
                "Do you need help?",
            ]
        )
        # this part is new 
        with st.status("Thinking...") as status:
            time.sleep(1)
            # Simulate stream of response with milliseconds delay
            for chunk in assistant_response.split():
                full_response += chunk + " "
                time.sleep(0.05)
                # Add a blinking cursor to simulate typing
                message_placeholder.markdown(full_response + "▌")
            message_placeholder.markdown(full_response)
            status.update(label="Done", state="complete", expanded=False)

    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": full_response})

Useful Documents

Other Streamlit articles

Thank You! Until next time~ 👋

Streamlit
Python
Chatbots
Streamlit App Deployment
Recommended from ReadMedium