Nested if statements break session store

I’m having an issue with nested buttons in if statements. Editing the session store in the first if, before the second, works fine, but as soon as I put it under the second if it doesn’t work at all. Is there a way to edit the session store in that second block. This is the code that doesn’t work:

def show():
    st.title('My App')

    user_input = st.text_area('Prompt (required)', value=st.session_state.prompt, key=1)
    update_input(user_input)

def update_prompt(input, input2):
    st.session_state.prompt = input+input2

if st.button('Generate Text'):
    generated_text = get_text(st.session_state.input)
    st.text_area('Output', value=st.session_state.input + generated_text)
    if st.button('Use in next run'):
        update_prompt(st.session_state.input, generated_text)
        show()

Moving the update_prompt() function up one level works fine, but I only want it to execute if that second button is pressed.
The goal is to create a button that can use the previous output as the input for the next run. Thanks!