Hello to you!,
I am an user of streamlit however although inserting @ st.cache commands to my code, the running time is always extremely long which is a disadvantage for my presentations because although people are captivated by the tool , the running time which is not instantaneous on heavier projects discourages more than one.
So I would like to know if it is possible to just run a specific part of the code on which we have made modifications (for example when changing some parameters on the side board) without running all the code as is the case now.
Thank you for your reply.
Hello to you!,
Hi @emerys693, welcome to the Streamlit forum!
Without seeing the code, using st.cache is the expected way to handle these things. Essentially, the programmer is declaring which steps need to be constantly re-calculated vs. can remain static. Are there steps in your app that can’t be cached and take a long time?
To answer your questions (as continued from the email you sent me), I have a few suggestions for your code:
You load in about 30 or so trained and pickled ML’s, I imagine that these take a lot of time to do. The best thing for these, since you wouldn’t expect to change their training, is to put them in a function and use the
@st.cachedecorator on them.
Do you always need to load all the ML’s in? It seems there are a variety of pre-trained models that work for different machine learning types. Maybe when the user makes selections on the different widgets, you can load just the relevant ML’s for that case (ie. only load the regression models when someone selects regression)
You have a bunch of
number_inputwidgets. This can slow things down as you have them coded because by changing any of those widgets the script re-runs. That can easily be solved by our new
st.formswidget that will be able to group these together so the user can set all of the widgets and have the script only run once when they click the
st.form_submit_buttoncheckout the docs here: Cookbook — Streamlit 0.81.1 documentation
Note: I’m not 100% sure what your
main_app.pyfile is but I was looking at the
couverture_B0.pyfile as that seems to be where you import Streamlit and create the title, widgets and main app layout
*Happy Streamlit-ing! *