-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
30 lines (24 loc) · 791 Bytes
/
app.py
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
import pandas as pd
import dill as pickle
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/predict', methods = ['POST'])
def api_call():
try:
req_json = request.get_json()
input_data = pd.read_json(req_json, orient='records')
except Exception as e:
raise e
clf = 'policy_knn.pk'
if input_data.empty:
return 'zero json'
else:
loaded_model = None
with open('./models/'+clf, 'rb') as f:
loaded_model = pickle.load(f)
policy_pred = pd.DataFrame(loaded_model.predict(input_data))
responses = jsonify(predictions=policy_pred.to_json(orient="records"))
responses.status_code = 200
return responses
if __name__ == '__main__':
app.run(host='0.0.0.0')