I’m running my app locally.
In my problem, I use a popover for the chat message content. When I enter the next message, the previous message remains like a caption, as shown in the screenshot below.
- Enter first message
- Enter next Message
There is an issue where the popover from the previous message remains like a caption while the chatbot’s response is streaming after the first message.
Below is a simplified version of my code. I used time.sleep(10)
to represent the streaming.
import streamlit as st
import time
st.title("Echo Bot")
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("What is up?"):
st.chat_message("user").markdown(prompt)
st.session_state.messages.append({"role": "user", "content": prompt})
response = f"Echo: {prompt}"
with st.chat_message("assistant"):
time.sleep(10)
container = st.container()
with container:
with st.popover(response):
st.write(response)
st.markdown(response)
st.session_state.messages.append({"role": "assistant", "content": response})
Streamlit : ^1.35.0
Python : ^3.11
Additionally, after entering the next message, the popover from the previous message does not need to be kept in the history, so I did not use session_state
for it.