✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Dash unable to read pickle file after deploying on heroku

Hi All,

I have deployed a dash app on Heroku for prediction of car price. But after deployment it is unable to reflect the predicted price.

Below are the example on local

this is on heroku

.

I am using pickle file for the prediction. Below is the code to create an app

import dash
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
from loaded_model import loadmodel
from layout import layout
import pandas as pd
import numpy as np


app = dash.Dash(__name__,external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
app.layout = layout()

@app.callback(Output('priceindicator', 'children'),
              [Input('old_price_range', 'value'),
               Input('new_price_range', 'value'),
               Input('years', 'value'),
               Input('distance_covered', 'value'),
               Input('rating', 'value'),
               Input('condition', 'value'),
               Input('Mileage', 'value'),
               Input('Speed', 'value'),
               Input('Hp', 'value')])
def predict_price(value1,value2,value3,value4,value5,value6,value7,value8,value9):
    model = loadmodel('finalized_model.pkl')
    X_single_point = pd.DataFrame(data = np.array([[value1,value2,value3,value4,int(value5),int(value6),value7,value8,value9]]),
                              columns = ['on road old', 'on road now', 'years', 'km ', 'rating', 'condition', 'economy', 'top speed', 'hp']               
                              )
    predicted_price = model.predict(X_single_point)
    return  'Price : {}'.format(int(round(predicted_price[0])))

if __name__ == "__main__":
    app.run_server()

below to code read pickle file

import pickle

def loadmodel(filename):
    loaded_model = pickle.load(open(filename, 'rb'))
    return loaded_model
    

Please help me if I miss some steps

Have you uploaded the file to Heroku?

Hi Emil,

Yes, I have uploaded the pickle file and I confirmed it. Also when I downloaded the code from Heroku and ran it locally, it work correctly. I am unable to understand why it is not working on Heroku.