Upload trained models from github to streamlit

I’m trying to upload trained models saved on github using pickle / joblib, but I’m not able to do it on streamlit cloud

Hi @TowardsInnovationLab

This is certainly possible to use serialized/trained models (pickle/joblib) with Streamlit Community Cloud.

Here’s an app and the corresponding repo deployed on Streamlit Community Cloud that I made. It loads a pre-trained ML model (pickle) from the GitHub repo via the pickle library.

First, import pickle

import pickle

Next, the model is loaded:

model = pickle.load(open('data/oversampling_PubChem_RandomForestClassifier.pkl', 'rb'))

And finally the model is used to make predictions via:


Thanks @dataprofessor you’re right, my mistake was in building the serialized file.
This solution works for me:

save the model to disk

with open(‘LR_classifier.pkl’, ‘wb’) as pickle_out:
serialized_classifier = pickle.dumps(LR_classifier)

loading in the model to predict on the data

with open(‘./data/LR_classifier.pkl’, ‘rb’) as pickle_in:
LR_classifier = pickle.load(pickle_in)

1 Like

You’re welcome, Glad to hear that it works now!

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