Is there a way to only rerun a part of the code whenever a widget changes?

Hi,

I understand that streamlit reruns the entire code whenever some element is clicked or interacted. However I have a setup where a pretrained model loads up at the beginning of the code which I do not want the code to rerun every time I input some text or click on a button, since it takes a couple of seconds and is redundant.
is there a way to only rerun a portion of the code on change or on click?

1 Like

You probably want to cache the model.

1 Like

Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.