0

我创建了一个 Flask 预测应用程序(在 Google Colab 中),当我尝试运行它时,在 colab 环境中添加所有依赖项后,我得到了 url,但是当我点击它时,它显示无法访问站点。

我有 Procfile、腌制模型和需求文本文件,但由于某种原因它不起作用。另外,我尝试使用 Heroku 部署这个应用程序,它遇到了同样的命运,我得到了应用程序错误。

有关更多上下文,请访问我的 github 存储库。

任何帮助或指导将不胜感激。

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

1 回答 1

0

您不能像在您的机器上一样运行烧瓶应用程序。你需要使用flask-ngrok.

!pip install flask-ngrok

from flask_ngrok import run_with_ngrok
[...]
app = Flask(__name__)
run_with_ngrok(app)
[...]
app.run()

您不能在 ngrok 中使用 debug=True 参数。

于 2021-07-24T15:13:00.323 回答