Should I load my model pkl object every time when I predict?

I am predicting the data in real time , when I hit the url it should predict but I should not load my model again and again . Can someone help to optimize the code ? Can I load globally or how can I persist my model object session while prediction ?

@app.route("/predict",methods = ['GET'])
def predictData():
    try:
        message = request.args.get('message', default = '')
        message = message.translate(str.maketrans(string.punctuation, ' '*len(string.punctuation)))

        text_clf_nb_fit = joblib.load('UpdatedAmtAlertClassifierModel.pkl')

        result = text_clf_nb_fit.predict([message])  

Thanks in advance .

Topic pickle python

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.