-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.py
141 lines (109 loc) · 4.81 KB
/
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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Make sure that all the following modules are already installed for use.
from flask import Flask
from flask_cors import CORS
from flask_restful import Api, Resource, reqparse
from Models.skin_cancer.mrat_rest import MelanomaRiskAssessmentTool
import joblib
import numpy as np
# ### Creating an instance of the flask app and an API
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
CORS(app)
API = Api(app)
# ### Loading the trained model
BREAST_PROGNOSIS_MODEL = joblib.load('Models/breast-cancer-prognosis-model.pkl')
LUNG_PROGNOSIS_MODEL = joblib.load('Models/lung-cancer-pred-model.pkl')
SKIN_PROGNOSIS_MODEL = MelanomaRiskAssessmentTool()
# ### Creating a class which is responsible for the prognosis of Lung Cancer
class LungCancerPrognosis(Resource):
@staticmethod
def post():
parser = reqparse.RequestParser()
parser.add_argument('Age')
parser.add_argument('Gender')
parser.add_argument('AirPollution')
parser.add_argument('Alcoholuse')
parser.add_argument('DustAllergy')
parser.add_argument('OccuPationalHazards')
parser.add_argument('GeneticRisk')
parser.add_argument('chronicLungDisease')
parser.add_argument('BalancedDiet')
parser.add_argument('Obesity')
parser.add_argument('Smoking')
parser.add_argument('PassiveSmoker')
parser.add_argument('ChestPain')
parser.add_argument('CoughingofBlood')
parser.add_argument('Fatigue')
parser.add_argument('WeightLoss')
parser.add_argument('ShortnessofBreath')
parser.add_argument('Wheezing')
parser.add_argument('SwallowingDifficulty')
parser.add_argument('ClubbingofFingerNails')
parser.add_argument('FrequentCold')
parser.add_argument('DryCough')
parser.add_argument('Snoring')
args = parser.parse_args() # creates dictionary
prognosis_input = np.fromiter(args.values(), dtype=float) # convert input to array
print(prognosis_input)
out = {'Prediction': LUNG_PROGNOSIS_MODEL.predict([prognosis_input])[0]}
print(out)
return out, 200 # returns 200 Status Code if successful with the Output
# ### Creating a class which is responsible for the prognosis of Breast Cancer
class BreastCancerPrognosis(Resource):
@staticmethod
def post():
parser = reqparse.RequestParser()
parser.add_argument('radius_mean')
parser.add_argument('texture_mean')
parser.add_argument('perimeter_mean')
parser.add_argument('compactness_mean')
parser.add_argument('concavity_mean')
parser.add_argument('concave points_mean')
parser.add_argument('fractal_dimension_mean')
parser.add_argument('radius_se')
parser.add_argument('texture_se')
parser.add_argument('perimeter_se')
parser.add_argument('compactness_se')
parser.add_argument('concavity_se')
parser.add_argument('concave points_se')
parser.add_argument('symmetry_se')
parser.add_argument('fractal_dimension_se')
parser.add_argument('compactness_worst')
parser.add_argument('concavity_worst')
parser.add_argument('concave points_worst')
parser.add_argument('symmetry_worst')
parser.add_argument('fractal_dimension_worst')
parser.add_argument('tumor_size')
parser.add_argument('positive_axillary_lymph_node')
args = parser.parse_args() # creates dictionary
prognosis_input = np.fromiter(args.values(), dtype=float) # convert input to array
print(prognosis_input)
out = {'Prediction': BREAST_PROGNOSIS_MODEL.predict([prognosis_input])[0]}
print(out)
return out, 200 # returns 200 Status Code if successful with the Output
# ### Creating a class which is responsible for the prognosis of Breast Cancer
class SkinCancerPrognosis(Resource):
@staticmethod
def post():
parser = reqparse.RequestParser()
parser.add_argument('age')
parser.add_argument('gender')
parser.add_argument('sunburn')
parser.add_argument('complexion')
parser.add_argument('big-moles')
parser.add_argument('small-moles')
parser.add_argument('freckling')
parser.add_argument('damage')
parser.add_argument('tan')
args = parser.parse_args()
out = SKIN_PROGNOSIS_MODEL.getAbsoluteRisk(args)
print(out)
return out, 200 # returns 200 Status Code if successful with the Output
# ### Adding the predict class as a resource to the API
API.add_resource(BreastCancerPrognosis, '/prognosis_breast')
API.add_resource(LungCancerPrognosis, '/prognosis_lung')
API.add_resource(SkinCancerPrognosis, '/prognosis_skin')
# Running the Main Application
if __name__ == "__main__":
app.run(debug=False)
# app.run(port=5000, debug=True)