Problem uploading personal model

Hi,

I am having trouble with uploading a model. I am using st.file_uploader as such.

uploaded_model = st.file_uploader('And/Or upload your classification model (.sav)', type='sav')

I would then call my function load_model:

def load_model(model):
    f = io.open(model)
    loaded_model = pickle.load(f)
    return loaded_model

I would get this error:
`
TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO

Traceback:

  File "/anaconda3/lib/python3.7/site-packages/streamlit/ScriptRunner.py", line 324, in _run_script
    exec(code, module.__dict__)
  File "/Users/vinhnguyen/Documents/Amruta/ML-Explainability-Front-End/Explain_ai_classification.py", line 289, in <module>
    main()
  File "/Users/vinhnguyen/Documents/Amruta/ML-Explainability-Front-End/Explain_ai_classification.py", line 95, in main
    model = load_model(uploaded_model)
  File "/Users/vinhnguyen/Documents/Amruta/ML-Explainability-Front-End/Explain_ai_classification.py", line 198, in load_model
    f = io.open(model)

`

1 Like

Bumping this post.

BytesIO is already a stream-like object. Have you tried just passing it directly to pickel.load?

def load_model(model):
    loaded_model = pickle.load(model)
    return loaded_model