【问题标题】:Unable to Access Flask App URL within Google Colab getting site not available无法在 Google Colab 中访问 Flask App URL 获取站点不可用
【发布时间】:2021-07-24 14:33:59
【问题描述】:

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

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

For more context please visit my github repo.

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

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)

【问题讨论】:

    标签: flask google-colaboratory pycaret


    【解决方案1】:

    您不能像在您的机器上一样运行烧瓶应用程序。您需要使用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 参数。

    【讨论】:

      猜你喜欢
      • 2018-03-31
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-01-24
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多