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.
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.
My demo show a generated image from model. If run st.experimental_rerun()
to get button clickable as you said, this image will disappear immediately. How to solve that?
Save the image into session state and then retrieve it from session state after the rerun.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.