Last active
July 14, 2019 17:34
-
-
Save canhtran/23cfc3389fba30ec56b78b12c33acf23 to your computer and use it in GitHub Desktop.
data-devops-medium blog
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
import pickle | |
import numpy as np | |
from flask import ( | |
Flask, | |
jsonify, | |
request | |
) | |
app = Flask(__name__) | |
with open('model.pkl', 'rb') as handle: | |
app.model = pickle.load(handle) | |
@app.route('/heartbeat', methods=['GET']) | |
def heartbeat(): | |
return 'ok' | |
@app.route('/predict', methods=['POST']) | |
def predict(): | |
payload = request.get_json() | |
np_array = np.expand_dims(list(payload.values()), 0) | |
pred = app.model.predict(np_array) | |
if pred is None: | |
return jsonify({'error': 'Model cannot predict with input'}) | |
else: | |
return jsonify(result=pred[0].item()) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment