-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (36 loc) · 962 Bytes
/
app.py
File metadata and controls
48 lines (36 loc) · 962 Bytes
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
45
46
47
import pandas as pd
import numpy as np
from flask import Flask, jsonify, request
import sklearn
import pickle as pkl
import json
app = Flask(__name__)
# model path
pkl_path = 'model/neuroChip_AFR_NG_hg38_updatedIDs_callrate_ancestry_umap_linearsvc_ancestry_model.pkl'
# load model
pkl_in = open(pkl_path, 'rb')
pipe_clf = pkl.load(pkl_in)
pkl_in.close()
# prediction function
@app.route('/predict', methods=['POST','GET'])
def predict():
# get instances from json
input = request.json.get('instances')
# predict
prediction = pipe_clf.predict(input)
int_pred = []
# get list of predictions as int
for pred in prediction:
int_pred.append(int(pred))
# create output json
output = {
'predictions':
int_pred
}
return jsonify(output)
# health function
@app.route('/healthz')
def healtz():
return 'OK'
if __name__=='__main__':
app.run(host='0.0.0.0')