Created
January 23, 2019 17:46
-
-
Save prakhar21/de5032d154afc3d3009809bea8c84c39 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
from flask import Flask, jsonify, request | |
import numpy as np | |
import pickle | |
app = Flask(__name__) | |
model_filepath = 'best_model.pickle' | |
def load_model(): | |
return pickle.load(open(model_filepath, 'rb')) | |
model = load_model() | |
@app.route('/predict', methods=['POST']) | |
def predict(): | |
data = request.get_json().get('data') | |
prediction = model.predict(data) | |
return jsonify({'output': prediction}) | |
@app.route('/shutdown', methods=['POST']) | |
def shutdown(): | |
func = request.environ.get('werkzeug.server.shutdown') | |
if func is None: | |
raise RuntimeError('Not running with the Werkzeug Server') | |
func() | |
return jsonify({'output': 'Server shutting down.'}) | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0', port=5555) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment