User interaction to mark predictions as correct or not

Hi

I recently moved some of my NLP workflow to Streamlit and came across a use case. Currently I have a model that makes predictions on some text and I wanted to use Streamlit to easily show it to my users and ask them if the predictions were correct or not. I have a interface like below in Streamlit currently

In this the user can click on each checkbox to let me know if the prediction for corresponding paragraph in document is correct or not. I was wondering how might I do some form of callback in Streamlit ? Currently the way I do it is using Flask where same thing is shown but every time a user clicks on a checkbox, it do a Ajax call to backend which save the info to database.

In Streamlit, I can only get the value of each checkbox but not the info that it has changed from last time. I would only want to write to the database the value of checkbox that was clicked.

One way I found on the forum is to have a single update once the user has selected all the checkboxes and click some update all button. I was wondering if there was a way where I can do it anytime a checkbox is clicked.

for para in doc.paragraphs:
        st.write(
                    " ".join(
                        [
                            generate_valid_word(token, mentions)
                            for sentence in para.sentences
                            for token, mentions in sentence.annotated_tokens
                        ]
                    ),
                    unsafe_allow_html=True,
                )
                checked = st.checkbox(label="Has Relation ?", key=f"{doc.document_id}-{para.paragraph_id}")

                # Write to database checked value but only if it updated.

I also had a second question: Do widgets persist in memory ? For example, for each paragraph in my document , I have a single checkbox (there could be unto 50 checkboxes per document).
But if the user switches to a different document (I have a dropbox in sidebar for that), do the previous checkboxes remain in the memory ?

Push!

I am working on something similar and wonder if there were any solutions on your side @Sarthak_Jain or from the streamlit team.