I want a chat to be in fixed height
Drop files here
or click to upload
import streamlit as st
st.title("Chat with fixed height")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Create a fixed height container for the chat messages
chat_container = st.container(height=400, border=True)
# Display chat messages from history on app rerun
with chat_container:
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 chat_container:
with st.chat_message("user"):
st.markdown(prompt)
# Display assistant response in chat message container
with st.chat_message("assistant"):
response = f"You said: {prompt}"
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?