Text_input is not being cleared out/reset

 def submit():
        record_timing()  # Record time before submitting message
        st.session_state.something = st.session_state.widget
        st.session_state.widget = ''

    if "messages" not in st.session_state:
        st.session_state.messages = [{"role": "assistant", "content": "How may I help you today?"}]

    if user_prompt := st.text_input("Your message here", on_change=submit, key="text_input"):  # Assign unique key
        st.session_state.messages.append({"role": "user", "content": user_prompt})
        with st.chat_message("user"):

    if st.session_state.messages[-1]["role"] != "assistant":
        with st.chat_message("assistant"):
            with st.spinner("Thinking..."):
                response = model(user_prompt, max_length, temp)
                placeholder = st.empty()
                full_response = ''
                for item in response:
                    full_response += item
        message = {"role": "assistant", "content": full_response}

here even after user submits the query, the text_input is not being cleared out
as u can see below,

1 Like

Could you show the code that calls submit?

1 Like


 user_prompt := st.text_input("Your message here", **on_change=submit,** key="text_input")

i thought this would do the task

1 Like

Is this thread the same as this? If so delete this thread and focus on that thread instead.

1 Like

is it ok of i delete that thread?

1 Like

What is the reason?

1 Like

Since I have changed the code
so now I have this error currently which I want to solve

Could you post a minimal sample code that can reproduce the issue? Or a link of the code from github.

It is difficult to solve that without seeing other codes.

the above is the github link for the streamit app, it is also hosed on cloud.

Also there is a need to add the api token before proceeding, so the steps for that would be:

Getting a Hugging Face token


found the solution.
I used st.chat_input which clears the input textbox on entering.

st.chat_input("enter your query")

instead of using
st.text_input("Your message here", on_change=submit, key="text_input")

1 Like

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