我创建了一个 Flask 预测应用程序(在 Google Colab 中),当我尝试运行它时,在 colab 环境中添加所有依赖项后,我得到了 url,但是当我点击它时,它显示无法访问站点。
我有 Procfile、腌制模型和需求文本文件,但由于某种原因它不起作用。另外,我尝试使用 Heroku 部署这个应用程序,它遇到了同样的命运,我得到了应用程序错误。
任何帮助或指导将不胜感激。
from flask import Flask, url_for, redirect, render_template, jsonify
from pycaret.classification import*
import pandas as pd
import numpy as np
import pickle
app = Flask(__name__)
model = load_model('Final RF Model 23JUL2021')
cols = ['AHT','NTT','Sentiment','Complaints','Repeats']
@app.route('/')
def home():
return render_template("home.html")
@app.route('/predict',methods=['POST'])
def predict():
int_features = [x for x in request.form.values()]
final = np.array(int_features)
data_unseen = pd.DataFrame([finak], columns = cols)
prediction = predict_model(model, data=data_unseen, round=0)
prediction = int(prediction.Label[0])
return render_template('home.html',pred='Predicted Maturiy Level is{}'.format(prediction))
@app.route('/predict_api',methods=['POST'])
def predict_api():
data = request.get_json(force=True)
data_unseen = pd.DataFrame([data])
prediction = predict_model(model, data=data_unseen)
output = prediction.Label[0]
return jsonify(output)
if __name__ == '__main__':
app.run(debug=True)