Created
December 2, 2018 16:49
-
-
Save hadifar/55acb249210596a286f661a90d6990fc 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
app = Flask(__name__) | |
cors = CORS(app) | |
@app.route("/api/predict", methods=['POST']) | |
def predict(): | |
start = time.time() | |
data = request.data.decode("utf-8") | |
if data == "": | |
params = request.form | |
x_in = json.loads(params['x']) | |
else: | |
params = json.loads(data) | |
x_in = params['x'] | |
# normalize input data! | |
x_in = np.array([[(x_in - 2013) / (2017 - 2013)]]) | |
# Tensorflow part | |
y_out = session.run([y], feed_dict={x: x_in}) | |
# normalize output data! | |
y_out = (float(y_out[0]) * (17500 - 12000)) + 12000 | |
json_data = json.dumps({'y': y_out}) | |
print("Time spent handling the request: %f" % (time.time() - start)) | |
return json_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment