Multiline text in chat_message interface

Hey @Preetham_Manjunatha,

To keep the original chunks, you could still split on the spaces but preserve them:

import streamlit as st
import time
import re

with st.chat_message("assistant"):
                message_placeholder = st.empty()
                assistant_response = "Hey there, I am Line 1 of text!  \nHey there, I am Line 2 of text."

                # Simulate stream of response with milliseconds delay
                full_response = ""
                for chunk in re.split(r'(\s+)', assistant_response):
                    full_response += chunk + " "
                    time.sleep(0.01)

                    # Add a blinking cursor to simulate typing
                    message_placeholder.markdown(full_response + "▌")
2 Likes