Understanding Streamlit execution process

Hello, everyone.

I am facing a problem with a very simple streamlit app in Python.

For a ML app, I want to ask the user to introduce a text. If the user replies “end”, the app should stop, otherwise the user’s text is lemmatized, and send back to the screen. that’s all. However, the app enters in a inifinite loop when running. It should stop while the user has not yet entered his question, but that is not the case. The code is something like this:

import streamlit as st

import all other necessary libraries (…)

st.write(‘Libraries have been imported’)

#--------------------

Global Variables

#--------------------

(… global variables are defined…)

st.write(‘Global Variables have been defined’)

#-----------------------------------------

Function definitions

#-----------------------------------------
#----------------------------------------------------

clean_txt: Cleans a string, and then lemmatize it.

#----------------------------------------------------
def clean_txt(txt):
# txt: string to clean

(… function code in Python…)

return txt

st.write(‘functions have been defined’)

#---------------------------------------------

The user enter his text

#---------------------------------------------

def tagging():
user_input = st.text_area(“Enter your question here below”, “end”, key = str(counter))
question_txt = clean_txt(user_input)
label_list =
if (question_txt == “end”):
return “end”, False
else:
return question_txt, True

Main program

counter=0
keep_going = True

while (keep_going):
results, keep_going = tagging()
if (results!=“end”):
st.write(results)
counter += 1
if not(keep_going):
st.write(“End of Project”)
st.stop()

maybe my programming logic is not the best, but I found quite confusing how this simple program works. Streamlit doest not stop to wait for users’ input but continues the execution of the remaining code.