0

I am deploying my flask python app on heroku but I am getting an application error.
This is my app.py file:

# Importing essential libraries
from flask import Flask, render_template, request
import pickle

# Load the Multinomial Naive Bayes model and CountVectorizer object from disk
filename = 'movie-genre-mnb-model.pkl'
classifier = pickle.load(open(filename, 'rb'))
cv = pickle.load(open('cv-transform.pkl','rb'))

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/predict',methods=['POST'])
def predict():
    if request.method == 'POST':
        message = request.form['message']
        data = [message]
        vect = cv.transform(data).toarray()
        my_prediction = classifier.predict(vect)
        return render_template('after.html', prediction=my_prediction)

if __name__ == '__main__':
    #app.run(host="localhost", port=3000, debug=True)
    #log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))
    app.run(debug=True)

This is Procfile:

web: gunicorn app:app

When I run heroku logs --tail command I get this:

2021-01-09T07:57:17.773012+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=movie-pred-ml.herokuapp.com request_id=df65bbf3-c19c-4410-9efd-ecd3a1748189 fwd="152.57.42.38" dyno= connect= service= status=503 bytes= protocol=https
2021-01-09T07:57:18.216690+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=movie-pred-ml.herokuapp.com request_id=5ef8bf3c-5e50-4304-b0c4-33ffa670443f fwd="152.57.42.38" dyno= connect= service= status=503 bytes= protocol=https

How should I solve this error?

sharuraut7
  • 7
  • 1
  • 6
  • do you have problem to run code or not ? You can always use `logging` to save own information in own log file during running code - maybe this way you will see more information. Maybe problem is not exactly `Flask` but maybe it have problem to read file `.pkl`. Server may runs in different folder then you expect (different `Current Working Dictionary` - see `os.getcwd()`) and files may need `/full/path/to/file.pkl` – furas Jan 09 '21 at 10:09
  • Does this answer your question? [Deploying Flask with Heroku](https://stackoverflow.com/questions/17260338/deploying-flask-with-heroku) – ChrisGPT was on strike Jan 09 '21 at 13:04
  • My app is working when I run it through my local machine. After deploying it on heroku it shows up application error. The answer through the link didn't solve the error. – sharuraut7 Jan 09 '21 at 15:30
  • 1
    You need to provide the port provided by Heroku, see https://stackoverflow.com/a/65625473/9095551 – Beppe C Jan 09 '21 at 15:32
  • Yes, I tried it still didn't solve my error. – sharuraut7 Jan 09 '21 at 16:37

0 Answers0