Incorrect execution order within a form?

I have a streamlit app within Snowflake that takes in data from an input table and displays 1 row at a time within a form. When I click the submit button, it’s supposed to take that displayed data from that particular row and write it to an output table in Snowflake. The issue I’m getting is that when I click the submit button, rather than writing the current displayed data, it refreshes with a new row and writes that data to the output table instead so the submit button is lagging behind. I’ve tried putting the if submit_button outside of the form as. well but it doesn’t seem to work.

Here’s a really simplified version of my code:

import streamlit as st
from snowflake.snowpark.context import get_active_session
import pandas as pd

session = get_active_session()

with st.form('prediction_form'):
    predictions_query = """
    select p.*
    from tableA p 
    left join tableB l on l.partid=p.part_id and l.pred_number=p.pred_number
    where l.partid is null and l.pred_number is null
    order by random()
    limit 1
    predictions_df = session.sql(predictions_query).to_pandas()
    row = predictions_df.iloc[0] if not predictions_df.empty else None

    if row is not None:
        st.write(f"##### Prediction:")
        st.write(f"laborid: {row['LABORID']}")
        # Add radio buttons
        label_options = ['Accept', 'Reject', 'Skip', 'Correct']
        selected_label ="Select Label:", label_options, key='label_radio')
    # Form submission button
    submit_button = st.form_submit_button('Submit')

    if submit_button:
        session.sql(f"""INSERT INTO output_table 
        VALUES ('{predictions_df['LABORID'][0]}')"""
        st.success('Success!', icon="✅")