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.