Last active
April 10, 2019 14:02
-
-
Save tldrafael/4d4d3747c1d785b4daf6b3aea7f09fe0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Generic example | |
# | |
from flask import Flask, json, request, Response | |
import helpers | |
app = Flask(__name__) | |
@app.route('/predict', methods = ['POST']) | |
def api_predict(): | |
if request.headers['Content-Type'] == 'application/json': | |
errors_message = helpers.validate_request_payload(request.json) | |
if len(errors_message) > 0: | |
return Response(json.dumps(errors_message), | |
status=422, | |
mimetype='application/json') | |
inputs_normalized = helpers.normalize_predictors_values(request.json, norm_params) | |
prediction = model.predict(inputs_normalized) | |
prediction_response = json.dumps({'y': int(prediction)}) | |
return Response(prediction_response, | |
status=200, | |
mimetype='application/json') | |
else: | |
return "415 Unsupported Media Type" | |
if __name__ == '__main__': | |
app.run() | |
# | |
# Curl requests | |
# | |
# curl -X POST -H "Content-Type: application/json" -d '{"audio_path":"data/00009900115260465871771878070.wav"}' localhost:5000/predict | |
# | |
# with environment variable | |
# curl -X POST -H "Content-Type: application/json" -d '{"audio_path":"'"${audiopath}"'"}' localhost:5000/predict | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment