Hi I am running my streamlit app locally. I want to build a survey where users can edit a pre-generated text. I have this within an st.form because otherwise I cannot easily resample the pre-generated text from a SQL database.
My problem is that when the user edits the text, I cannot access the edited text. It always stores the original pre-generated text. Here my code:
with st.form(key = "form_editing", clear_on_submit=True):
with pool.connect() as db_conn:
query = text("SELECT * FROM df_prompts ORDER BY RAND() LIMIT 1")
result = db_conn.execute(query)
sample_row = result.fetchone()
st.subheader("Prompt")
prompt_id = sample_row["prompt_id"]
st.write("{} [Source]({})".format(sample_row["question"],sample_row["dataset_source"]))
st.subheader("Edit pre-generated answer")
answer_edited = st.text_area("Answer:", value = sample_row["answer"], key = "text_area", max_chars = 1000, help = "You can write your own response to your liking.")
if st.form_submit_button("Submit and View Next"):
insert_editing(
sample_row["question_id"], # question_id
sample_row["prompt_id"], # prompt_id
answer_edited
)
I already tried accessing the updated text via the key in session_state, but nothing worked so far.
Would very much appreciate your help