在heroku上部署我的flask python应用程序时如何解决应用程序错误?

时间:2021-01-09 08:01:37

标签: python flask heroku deployment

我正在 heroku 上部署我的 Flask python 应用程序,但出现应用程序错误。
这是我的 app.py 文件:

# 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)

这是Procfile:

web: gunicorn app:app

当我运行 heroku logs --tail 命令时,我得到了这个:

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

我应该如何解决这个错误?

0 个答案:

没有答案