forked from cwallaceh/sklearn_flask_docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (35 loc) · 1009 Bytes
/
app.py
File metadata and controls
51 lines (35 loc) · 1009 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
48
49
50
51
# Local imports
import datetime
# Third part imports
from flask import request
import pandas as pd
from ms import app
from ms.functions import get_model_response
model_name = "Breast Cancer Wisconsin (Diagnostic)"
model_file = 'model_binary.dat.gz'
version = "v1.0.0"
@app.route('/info', methods=['GET'])
def info():
"""Return model information, version, how to call"""
result = {}
result["name"] = model_name
result["version"] = version
return result
@app.route('/health', methods=['GET'])
def health():
"""Return service health"""
return 'ok'
@app.route('/predict', methods=['POST'])
def predict():
feature_dict = request.get_json()
if not feature_dict:
return {
'error': 'Body is empty.'
}, 500
try:
response = get_model_response(feature_dict)
except ValueError as e:
return {'error': str(e).split('\n')[-1].strip()}, 500
return response, 200
if __name__ == '__main__':
app.run(host='0.0.0.0')