Running time in streamlit

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.

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?

Best,
Randy

Hey @emerys693,

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.cache decorator 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 selectbox, slider and number_input widgets. 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.forms widget 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_button checkout the docs here: Cookbook — Streamlit 0.81.1 documentation

  • Note: I’m not 100% sure what your main_app.py file is but I was looking at the couverture_B0.py file as that seems to be where you import Streamlit and create the title, widgets and main app layout

@randyzwitch here is the link to the GitHub repo, let us know if you see any other tips or tricks they can use to speed up their app!

*Happy Streamlit-ing! *
Marisa

1 Like