-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflask_server.py
More file actions
44 lines (34 loc) · 1.07 KB
/
Copy pathflask_server.py
File metadata and controls
44 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# %%
import flask
import pandas as pd
import tensorflow as tf
import keras
from keras.models import load_model
# %%
# instantiate flask
app = flask.Flask(__name__)
# we need to redefine our metric function in order
# to use it when loading the model
def auc(y_true, y_pred):
auc = tf.metrics.auc(y_true, y_pred)[1]
keras.backend.get_session().run(tf.local_variables_initializer())
return auc
# load the model, and pass in the custom metric function
# global graph
# graph = tf.get_default_graph()
# model = load_model('./simple_training.h5', custom_objects={'auc': auc})
model = load_model('./simple_training.h5')
# define a predict function as an endpoint
@app.route("/predict", methods=["POST"])
def predict():
data = {"success": False}
params = flask.request.json
if (params == None):
raise KeyError()
# if parameters are found, return a prediction
if (params != None):
return params
# return a response in json format
return flask.jsonify(data)
# start the flask app, allow remote connections
app.run(host='0.0.0.0')