Object of type 'bytes' is not JSON serializable

I run the same code on a jupyter notebook, it works fine.
but when I run it on a script with streamlit i keep getting “Object of type bytes is not JSON serializable”. this is the script codes

def lime_explain(x_train, x_val, y_train, feat, model, i):

    ml_model = pickle.load(open(model, 'rb'))

    explainer = lime.lime_tabular.LimeTabularExplainer(x_train.values, feature_names =   
  feat, class_names = ['True', 'False'], mode='classification', training_labels=x_train.colu 

   predict_fn = lambda x: ml_model.predict_proba(x).astype(float)

    exp = explainer.explain_instance(x_val.values[i], predict_fn, num_features = 5)

and this is the jupyter code with the output by the left.

Please what could be the problem? thanks in advance

Could you post the code the surrounds this in terms of calling this function? It’s not really clear where Streamlit would need to serialize the data at all, since this function only writes to disk.

can i send a link to github code instead?

from explain.py line 115 defines the function
from app.py line 148 and 149 calls the lime function

None of that seems Streamlit related, and it shouldn’t do anything on the Streamlit side (it appears you’re just writing to an html file). I wonder if the backtrace is getting confused on the line numbers somehow.