Hide button during inference time

Hi,

I am developing an application, which infer an AI model when RUN button is pressed. How can i disable/hide this RUN button while model is running.

Here’s a toy example:

import streamlit as st
import time

def run():
    st.session_state.run = True

def clear():
    st.session_state.result = None

def expensive_process():
    with st.spinner('Inference running...'):
        time.sleep(5)
    st.session_state.run = False
    st.session_state.result = 'Done!'

if 'run' not in st.session_state:
    st.session_state.run = False
    st.session_state.result = None

st.button('Run inference', on_click=run, disabled=st.session_state.run)

if st.session_state.run:
    expensive_process()
    # Include rerun if you want the Run Inference button to be clickable as soon
    # as the inference is done.
    # st.experimental_rerun()

if st.session_state.result is not None:
    st.write(st.session_state.result)
    st.button('Clear', on_click=clear)

I created a feature request for a method to simplify this common scenario. Feel free to vote on it here or check out the linked, related feature requests.