我遵循了Create a Python app in Azure App Service on Linux,并使用以下功能上传了我的代码:
@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。
我的代码在https://github.com/mulflar/saturdayAi/blob/master/twitteranalisisdesentimientosnlp.py
答案 0 :(得分:0)
您可以尝试
twitteranalisisdesentimientosnlp.py
重命名为app.py
OR
gunicorn --bind=0.0.0.0 --timeout 600 twitteranalisisdesentimientosnlp:app #The :app corresponds to the name of the flask app inside of the file