When I open my web app, the model starts retraining, which significantly increases the loading time. To optimize this process, I want to explore ways to pretrain the model in advance, save it, and then load the trained model when the app is launched. This approach would allow the web app to quickly provide predictions based on user input without the need for retraining, thereby improving the overall efficiency and user experience.
Can you directly load the trained model for inference, maybe by pushing it to github with your code?
If not, check cache_resource
to train it once, and then use the trained model for all users: st.cache_resource - Streamlit Docs