St.chat_input does not work every time in streamlit cloud (but does locally)

Please help me solve this problem:

  1. deployed app
    Github repo : GitHub - djordjethai/NeoChatbot
  2. No error shown, only stop working in this code:

The script runs completely without errors on localhost, but when deployed on Streamlit cloud - it sometimes (it seems to be completely random) runs briefly, then stops and doesn’t give any kind of output, nor is there anything in the Streamlit logs.
After troubleshooting, I came to a conclusion that the prompt itself gets lost in the server side communication, because at one point it just becomes None (in the same run of the script, no user interaction in-between).

The question is generated the usual way; the following code isn’t directly dependent on e.g. some st.button or similar, it will run every time if a thread is entered:

if prompt := st.chat_input(placeholder="Enter the question"):
    if st.session_state.thread_id is not None:
        client.beta.threads.messages.create(thread_id=st.session_state.thread_id, role="user", content=prompt)

        run = client.beta.threads.runs.create(thread_id=st.session_state.thread_id,, 
        st.warning("No chat was selected.")

Later parts of the code can’t be reached because a run can’t be used without an actual message.
The runs without an output aren’t related to some specific user actions or questions - they also aren’t periodical.

  1. Streamlit 1.29.0 and Python 3.11

Thank you.

Hi @djordjethai

Have you initialized if st.session_state.thread_id?

I have, but not used it after :slight_smile:

if chosen_chat.strip() not in [“”, “Select…”] and st.sidebar.button(label=“Select Chat”, key=“selectchat2”):
thread = client.beta.threads.retrieve(thread_id=threads_dict.get(chosen_chat))
st.session_state.thread_id =

So, I will try replacing thread_id=st.session_state.thread_id here:
run_status = client.beta.threads.runs.retrieve(,

Hi @dataprofessor,
Unfortunately, this has not solved the problem of randomly disappearing questions. But I tried the same code on Azure App Services (in streamlit of course), and I have tested it extensively. It worked every time.

It seems that perhaps streamlit server is a bit busy, so if there is a way to handle this issue in the code, it will be useful. If not, we will try this cloud option later.

Best regard


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