Previous Message Remains When Using Popover for Chat Message Content

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.

  1. Enter first message
  2. 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.

Hi @miix

I tried to reproduce the code and did not notice the ghosting message that you had encountered. I did notice a lag of 10 seconds before a response is displayed.

Have you tried another browser or computer to see if this is still the case?

See: Chatbot message appears twice - #7 by asehmi

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