Bring User_Input textbox at bottom of page

Summary

How to bring chat box at bottom of page , right now it was coming down only when I type something in chatbot

Steps to reproduce

Code snippet:

%%writefile app.py
import openai
import streamlit as st
from streamlit_chat import message

model = "gpt-3.5-turbo"
openai.api_key = "secreat_key"
# Setting page title and header
st.set_page_config(page_title="MYBOT", page_icon=":robot_face:")
st.markdown("<h1 style='text-align: center;'>MYBOT- a totally harmless chatbot 😬</h1>", unsafe_allow_html=True)

# Initialise session state variables
if 'generated' not in st.session_state:
    st.session_state['generated'] = []
if 'past' not in st.session_state:
    st.session_state['past'] = []
if 'messages' not in st.session_state:
    st.session_state['messages'] = [
        {"role": "system", "content": "You are a helpful assistant."}
    ]
# generate a response
def generate_response(prompt):
    st.session_state['messages'].append({"role": "user", "content": prompt})

    completion = openai.ChatCompletion.create(
        model=model,
        messages=st.session_state['messages']
    )
    response = completion.choices[0].message.content
    st.session_state['messages'].append({"role": "assistant", "content": response})
    return response
# container for chat history
response_container = st.container()
# container for text box
container = st.container()


with container:
    with st.form(key='my_form', clear_on_submit=True):
        user_input = st.text_area("You:", key='input', height=100)
        submit_button = st.form_submit_button(label='Send')
        
    if submit_button and user_input:
        output= generate_response(user_input)
        st.session_state['past'].append(user_input)
        st.session_state['generated'].append(output)

if st.session_state['generated']:
    with response_container:
        for i in range(len(st.session_state['generated'])):
            message(st.session_state["past"][i], is_user=True, key=str(i) + '_user')
            message(st.session_state["generated"][i], key=str(i))

Hey @Nitish,

Just to clarify, are you hoping to have the chatbot pinned to the bottom of the page?

1 Like

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