-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (34 loc) · 1.27 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pickle
import pandas as pd
from flask import Flask, request, Response
from classes.cardio_catch_diseases import Cardio_Catch_Diseases
import os
# loading model trained from pickle file
with open('models/lgbm_model_tuned.pkl', 'rb') as file:
model = pickle.load(file)
# initializing API
app = Flask(__name__)
@app.route('/predict', methods=['POST'])
def disease_predict():
test_json = request.get_json()
if test_json:
# Unique Example
if isinstance(test_json, dict):
test_raw = pd.DataFrame(test_json, index=[0])
# multiple Example
else: # multiple Example
test_raw = pd.DataFrame(test_json, columns=test_json[0].keys())
# instantiating CDD class
pipeline = Cardio_Catch_Diseases()
# manipulating features
test_raw_features = pipeline.features_engineering(test_raw)
# rescaling features to predict
test_raw_prepared = pipeline.data_preparation(test_raw_features)
# predicting
df_response = pipeline.get_predict(model, test_raw_prepared)
return df_response
else:
return Response("{}", status=200, mimetype='application/json')
if __name__ == '__main__':
port = os.environ.get('PORT', 5000)
app.run(host='0.0.0.0', port=port)