Hi. I am building a basic chat interface with streamlit, using the st.chat_input() and st.chat_message() widgets. I would like to place some extra content beneath the chat_input() box, but it seems any content is sent to the top of the page.
Here is the code I am using:
for message in st.session_state["messages"][1:]:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("Type your message..."):
st.session_state["messages"].append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)
with st.spinner("Thinking..."):
full_response, total_tokens, prompt_tokens, completion_tokens = generate_response(prompt)
st.chat_message("assistant").write(full_response)
st.session_state["messages"].append({"role": "assistant", "content": full_response})
st.markdown("Some content") # this appears above the chat_input() element.
Even if I wrap this code in a container, any content ends up inside the container. Does anyone know how to fix this?
It may be possible to tinker with the CSS and adjust the layout and position of the container. The trick is to figure out the name of the CSS element then define this and the desired property.
One easy way to get something similar now (as of streamlit 1.31) is to put st.chat_input inside of a container, and then it gets placed inline, rather than at the bottom of the screen.
If you still want it at the bottom, and this example doesn’t work, it will probably take some work to inspect the code and see what classes are now used with st.chat_input.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.