路径中的Python Azure应用404

路径中的Python Azure应用404,python,azure,flask,Python,Azure,Flask,我遵循这一点,上传了带有以下功能的代码: @app.route('/predict_json', methods=['POST']) def add_message(): content = request.json tweets = pd.DataFrame(content) tweets["polarity"] = pipeline.predict(tweets.Tweet) return tweets.to_json() @app.route('

我遵循这一点,上传了带有以下功能的代码:

@app.route('/predict_json', methods=['POST'])
def add_message():
    content = request.json

    tweets = pd.DataFrame(content)
    tweets["polarity"] = pipeline.predict(tweets.Tweet)   

    return tweets.to_json()

@app.route('/predict')
def predict():
    # Retrieve query parameters related to this request.
    content = request.args.get('content')    

    d = {'tweet': [content]}
    df = pd.DataFrame(data=d)

    # Use the model to predict the class
    label_index = pipeline.predict(df.tweet)
    # Retrieve the iris name that is associated with the predicted class
    label = MODEL_LABELS[label_index[0]]
    label_int = MODEL_INT[label_index[0]]
    # Create and send a response to the API caller
    return jsonify(status='complete',tweet=content, polarity=label_int, polarity_text=label)
在本地,它们工作得很好。但部署时我得到了404

我的代码在这里

你能试试吗

  • 将TwitterAnalysisSentimientOSNLP.py重命名为app.py

  • 由于主应用程序文件不是app.py或application.py,因此需要指定启动时运行的命令(有关更多信息,请参阅)。在这种情况下,它将是:

哪条路线给了你404,你也能发布错误吗?两条路线都是完整路径,我昨晚在自己的应用服务中运行了你的代码,我注意到应用没有及时启动。我认为这是因为它试图在启动时执行所有应用程序逻辑。将逻辑封装在函数中,然后将其作为新的
/startup
路由的一部分调用,这可能是一个好主意。或者将逻辑放入一个函数中,然后添加
@app.before\u first\u request
decorator,这样每当flask应用程序收到其第一个请求时,它就会运行。我不知道您使用的库有多好,但通常情况下,长时间运行的作业,即
/predict
/predict\u json
会将结果放入数据库,然后使用另一个路径(例如
/view\u predictions
gunicorn --bind=0.0.0.0 --timeout 600 twitteranalisisdesentimientosnlp:app #The :app corresponds to the name of the flask app inside of the file