Not found my file .pkl with joblib.load

Hello,

I try to deploy my web app with a prediction using data from a fil X.pkl. My script and this file working correctly in local host, prediction iss working too. But in streamlit cloud, it’s not possible to load my file .pkl !! I have always the same error :
" Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.

2023-09-26 21:00:11.881 Uncaught app exception

Traceback (most recent call last):

File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 565, in _run_script

exec(code, module.__dict__)

File “/mount/src/scoring_model/notebook/Streamlit/pages/1_Analyse_.py”, line 96, in

X, X_test = load_data()

File “/mount/src/scoring_model/notebook/Streamlit/pages/1_Analyse_.py”, line 91, in load_data

X = joblib.load('../X.pkl')

File “/home/adminuser/venv/lib/python3.9/site-packages/joblib/numpy_pickle.py”, line 650, in load

with open(filename, 'rb') as f:

FileNotFoundError: [Errno 2] No such file or directory: ‘…/X.pkl’ "

my repo here

The file that load X.pkl is in notebook → streamlit → pages → 1_Analyse.py.

The function in this script to load pkl files is :
def load_data():
X = joblib.load(‘…/X.pkl’)
X_test = joblib.load(‘…/X_test.pkl’)

return X, X_test

Have you an idea how to fixe it please ?

Thank you :slight_smile:

1 Like

Salut Dalila, iirc applications in Community Cloud are started from the root of your repo, not from Scoring_Model/notebook/Streamlit where your script is stored. Paths need to be set relative to the root, this is why you don’t get an error looking up best_model.pkl, because there is a file with the same name at root, but X.pkl cannot be found.

Hope that helps

2 Likes

yeahhh ! thank you so much @edsaac !! I found the solution and it’s working :star_struck:

1 Like

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