It’s me again! I’m trying to load my model in a st.session_state from the landing page and access it in another page (multipage app).
However, it’s telling me that it can’t find the attribute! I’ve changed the code back and forth according to what I’m reading, but nothing works.
Here’s the architecture of my code if it helps!
Home.py
#... import the libraries
## ----------------------------- SETUP PAGE --------------------------------- ##
st.set_page_config(page_title='AISSYR',
page_icon='asset/fav32.png',
layout='wide')
## --------------------------- LOADING MODEL -------------------------------- ##
if 'model' not in st.session_state:
with st.spinner('Loading model...'):
fct.load_model()
This is not necessary to store the model reference in session state, you are just adding memory loads to the server from each user who uses your app and making the code unnecessarily complicated. Calling load_model() directly is enough.
You load it into the cache, but if you don’t set it to a variable, you can’t reuse it in your application?
Here, I load my model as soon as I launch my application, but I don’t use it on the main page (Home.py), but only in my functions file that I call from another page (detection.py). If I assign the model to a variable in Home, I won’t be able to call it in my functions file, hence the need to go through the st.session_state.
If this doesn’t work, isn’t it because of the PyFuncModel format?
My function load_model is in utils/functions, I call it in my Home to download it during the application launch, but I use it via an other function in utils/functions call detect() itself use in pages/detect.py
So actually, I would like to load it in first place during the app launch, but use the model later.
Currently, yes but doesn’t include the load model right now.
for your example, yes that’s not the problem, for the moment I’m loading it into the function for detection. I mainly wanted to find a way to do it upstream, to make inference smoother and have it at application launch and not when the first person makes a prediction.
Really thank you about your ideas anyway, it’s appreciated !
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.