How to enable scroll for streamlit_chat keeping input box at same position

I am building a chatbot by using chatgpt3.5 and streamlit app.
I am able to put Input text (text_input) at bottom of screen. But as text queries grows my input text area also goes down.

Frontend code for streamlit_chat st-chat/stChat.tsx at main · AI-Yash/st-chat · GitHub

Here is the code:

import openai
import streamlit as st
from streamlit_chat import message


def generate_response(prompt):
    return message

st.title("ChatGPT3.5 BOT")

if 'generated' not in st.session_state:
    st.session_state['generated'] = []
if 'past' not in st.session_state:
    st.session_state['past'] = []

def inputchange():

        "inputs": {
            "past_user_inputs": st.session_state.past,
            "generated_responses": st.session_state.generated,
            "text": st.session_state.input,

    # append user_input and output to state

# If responses have been generated by the model
if st.session_state['generated']:
    # Reverse iteration through the list
    for i in range(len(st.session_state['generated']) - 1, -1, -1):
        # message from streamlit_chat
        # message(st.session_state['past'][::-1][i], is_user=True, key=str(i) + '_user', )
        message(st.session_state['past'][::-1][i], is_user=True, key=str(i) + '_user', )
        message(st.session_state['generated'][::-1][i], key=str(i),avatar_style="adventurer",seed=123,)

user_input = st.text_input("Input Message: ", "", key="input", on_change=inputchange)

How to add scroll for messages just like ChatGPT3.5 does the messages can be scrolled up instead of scrolling the whole page.

Secondly, If I type same message in user_input then it doesn’t take this into account.

1 Like

Haven’t personally found a good way to keep a container size fixed. This is why in my application, I kept the user text message box on top, and render the chat messages below (starting from most recent).

Also, seems a bit excessive for you to keep user messages and AI responses in separate lists. You can simply have a list of dictionaries (each with “message” and “is_user” fields).


Have you got a solution for this scrolling issue. Even for me, I need to scroll manually