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?

You probably want to cache the model.

Thanks!