首页 > 解决方案 > 应用程序中的错误:/predict [POST] 上的异常

问题描述

在 gcloud 上运行我的应用程序时,我在浏览器上遇到以下错误消息:
内部服务器错误服务器遇到内部错误,无法完成您的请求。服务器过载或应用程序出错。

在查看日志文件时,它显示:
应用程序中的错误:/predict [POST] 上的异常

我的代码如下:


@app.route('/predict', methods=['POST'])
def predict(): 
    if request.method == 'POST':
        BizUnit = request.form.get('BizUnit')
        Region = request.form.get('Region')
        Category = request.form.get('Category')
        sel = (BizUnit, Region, Category)
        dict = {'COO': 0, 'Finance': 1, 'HR': 2, 'AMER': 0, 'APAC': 1,
                'EMEA': 2, 'Resources': 0, 'Facility': 1, 'Services': 2}
        sel_num = ([dict[sel[0]], dict[sel[1]], dict[sel[2]]])
    final_features = [np.array(sel_num)]
    prediction = model.predict(final_features)

    output = round(prediction[0], 2)

    return render_template('index.html', prediction_text=
                           'Spends should be $ {}'.format(output))

如果有人能提出一些解决这个问题的建议,将不胜感激。谢谢

标签: pythonpostflaskserver-error

解决方案


推荐阅读