-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
70 lines (55 loc) · 1.66 KB
/
api.py
File metadata and controls
70 lines (55 loc) · 1.66 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import joblib
from flask import Flask
from flask import request
import json
from flask_cors import CORS, cross_origin
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
# loading the models
diabetes_model = joblib.load("diabetes_model.sav")
heart_model = joblib.load("heart_disease_model.sav")
parkinsons_model = joblib.load("parkinsons_model.sav")
@app.route("/api/diabetes", methods=['GET', 'POST'])
@cross_origin()
def diabetes_predict():
data = request.data
data = json.loads(data)
# input parameters
pregenancies = data["pregenancies"]
glucose = data["glucose"]
blood_pressure = data["blood_pressure"]
skin_thickness = data["skin_thickness"]
insulin = data["insulin"]
bmi = data["bmi"]
diabetes_pedigree_function = data["diabetes_pedigree_function"]
age = data["age"]
# getting the prediction from the model
prediction = diabetes_model.predict([[pregenancies, glucose, blood_pressure, skin_thickness, insulin, bmi, diabetes_pedigree_function, age]])
if prediction[0] == 0:
res = "No"
else:
res = "Yes"
return res
@app.route("/api/heart", methods=['GET', 'POST'])
@cross_origin()
def heart_predict():
data = request.data
data = json.loads(data)
# input parameters
res = heart_model.predict()
return res
@app.route("/api/parkinsons", methods=['GET', 'POST'])
@cross_origin()
def parkinsons_predict():
data = request.data
data = json.loads(data)
# input parameters
res = parkinsons_model.predict()
return res
@app.route("/api")
@cross_origin()
def predict():
return "Hello world"
if __name__ == "__main__":
app.run(debug=True)