-
Notifications
You must be signed in to change notification settings - Fork 0
/
symptoms.py
410 lines (374 loc) · 18.5 KB
/
symptoms.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
import numpy as np
import pandas as pd
import streamlit as st
from streamlit_option_menu import option_menu
from streamlit.components.v1 import html
import cv2
psymptom=[]
st.set_page_config(page_title="Multiple Disease Prediction System", page_icon=":stethoscope:",layout="wide")
# function to obtain user symptoms
def get_symptoms1():
options = sorted(l1)
symptom1 = st.selectbox('What are you experiencing',options,key="1")
symptom2 = st.selectbox('What are you experiencing',options,key="2")
symptom3 = st.selectbox('What are you experiencing',options,key="3")
symptom4 = st.selectbox('What are you experiencing',options,key="4")
symptom5 = st.selectbox('What are you experiencing',options,key="5")
symptoms = [symptom1,symptom2,symptom3,symptom4,symptom5]
answer = st.radio("Would you like to enter more symptoms?",("Yes","No"),index = 1)
if answer == "Yes":
symptom = st.text_input("Enter number of symptms:",1)
for i in range(int(symptom)):
symptomn = st.selectbox('What are you experiencing',options,key=i+6)
symptoms.append(symptomn)
if answer == "No":
symptoms = symptoms[:5]
return symptoms
#-----------------------------------------------------------functions to deploy machine learning models and incorporation into Streamlit framework----------
def DecisionTree():
from sklearn import tree
z = tree.DecisionTreeClassifier()
z = z.fit(X,y)
from sklearn.metrics import accuracy_score
y_pred=z.predict(X_test)
print(accuracy_score(y_test, y_pred))
print(accuracy_score(y_test, y_pred,normalize=False))
for i in range(0,len(symptom)):
value = symptom[i]
psymptom.append(value)
for k in range(0,len(l1)):
for c in psymptom:
if(c==l1[k]):
l2[k]=1
inputtest = [l2]
predict = z.predict(inputtest)
predicted=predict[0]
h='no'
for a in range(0,len(disease)):
if(predicted == a):
h='yes'
break
if (h=='yes'):
result=disease[a]
organ = result
return organ
else:
result="You seem to be healthy. Take Care!"
organ = result
return organ
def randomforest():
from sklearn.ensemble import RandomForestClassifier
clf4 = RandomForestClassifier()
clf4 = clf4.fit(X,np.ravel(y))
# calculating accuracy
from sklearn.metrics import accuracy_score
y_pred=clf4.predict(X_test)
print(accuracy_score(y_test, y_pred))
print(accuracy_score(y_test, y_pred,normalize=False))
for i in range(0,len(symptom)):
value = symptom[i]
psymptom.append(value)
for k in range(0,len(l1)):
for z in psymptom:
if(z==l1[k]):
l2[k]=1
inputtest = [l2]
predict = clf4.predict(inputtest)
predicted=predict[0]
h='no'
for a in range(0,len(disease)):
if(predicted == a):
h='yes'
break
if (h=='yes'):
result=disease[a]
organ = result
return organ
else:
result="You seem to be healthy. Take Care!"
organ = result
return organ
def NB():
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
gnb=gnb.fit(X,np.ravel(y))
from sklearn.metrics import accuracy_score
y_pred=gnb.predict(X_test)
print(accuracy_score(y_test, y_pred))
print(accuracy_score(y_test, y_pred,normalize=False))
for i in range(0,len(symptom)):
value = symptom[i]
psymptom.append(value)
for k in range(0,len(l1)):
for z in psymptom:
if(z==l1[k]):
l2[k]=1
inputtest = [l2]
predict = gnb.predict(inputtest)
predicted=predict[0]
h='no'
for a in range(0,len(disease)):
if(predicted == a):
h='yes'
break
if (h=='yes'):
result=disease[a]
organ = result
return organ
else:
result="You seem to be healthy. Take Care!"
organ = result
return organ
# ----------------------------------------------------------end of function block---------------------------------------------------------------------------
# list of symptoms
l1=['None','itching', 'skin_rash', 'nodal_skin_eruptions', 'continuous_sneezing', 'shivering', 'chills', 'joint_pain', 'acidity', 'ulcers_on_tongue', 'muscle_wasting', 'burning_micturition', 'spotting_ urination', 'fatigue', 'weight_gain', 'anxiety', 'cold_hands_and_feets', 'mood_swings', 'weight_loss',
'restlessness', 'lethargy', 'patches_in_throat', 'irregular_sugar_level', 'cough', 'high_fever', 'sunken_eyes', 'breathlessness', 'sweating', 'dehydration', 'indigestion', 'headache', 'yellowish_skin',
'dark_urine', 'nausea', 'loss_of_appetite', 'pain_behind_the_eyes', 'back_pain', 'constipation', 'abdominal_pain', 'diarrhoea', 'mild_fever', 'yellow_urine', 'yellowing_of_eyes', 'acute_liver_failure','vomiting',
'fluid_overload', 'swelling_of_stomach', 'swelled_lymph_nodes', 'malaise', 'blurred_and_distorted_vision', 'phlegm', 'throat_irritation', 'redness_of_eyes', 'sinus_pressure', 'runny_nose', 'congestion', 'chest_pain', 'weakness_in_limbs', 'fast_heart_rate', 'pain_during_bowel_movements', 'pain_in_anal_region', 'bloody_stool', 'irritation_in_anus', 'neck_pain', 'dizziness', 'cramps', 'bruising', 'obesity', 'swollen_legs', 'swollen_blood_vessels', 'puffy_face_and_eyes', 'enlarged_thyroid', 'brittle_nails', 'swollen_extremeties', 'excessive_hunger', 'extra_marital_contacts', 'drying_and_tingling_lips', 'slurred_speech', 'knee_pain', 'hip_joint_pain', 'muscle_weakness', 'stiff_neck', 'swelling_joints', 'movement_stiffness', 'spinning_movements', 'loss_of_balance', 'unsteadiness', 'weakness_of_one_body_side', 'loss_of_smell', 'bladder_discomfort', 'foul_smell_of urine', 'continuous_feel_of_urine', 'passage_of_gases', 'internal_itching', 'toxic_look_(typhos)', 'depression', 'irritability', 'muscle_pain', 'altered_sensorium', 'red_spots_over_body', 'belly_pain', 'abnormal_menstruation', 'dischromic _patches', 'watering_from_eyes', 'increased_appetite', 'polyuria', 'family_history', 'mucoid_sputum', 'rusty_sputum', 'lack_of_concentration', 'visual_disturbances', 'receiving_blood_transfusion', 'receiving_unsterile_injections', 'coma', 'stomach_bleeding', 'distention_of_abdomen', 'history_of_alcohol_consumption', 'fluid_overload', 'blood_in_sputum', 'prominent_veins_on_calf', 'palpitations', 'painful_walking', 'pus_filled_pimples', 'blackheads', 'scurring', 'skin_peeling', 'silver_like_dusting', 'small_dents_in_nails', 'inflammatory_nails', 'blister', 'red_sore_around_nose', 'yellow_crust_ooze']
# disease list
disease=['Fungal infection','Allergy','GERD','Chronic cholestasis','Drug Reaction',
'Peptic ulcer diseae','AIDS','Diabetes','Gastroenteritis','Bronchial Asthma','Hypertension',
' Migraine','Cervical spondylosis',
'Paralysis (brain hemorrhage)','Jaundice','Malaria','Chicken pox','Dengue','Typhoid','hepatitis A',
'Hepatitis B','Hepatitis C','Hepatitis D','Hepatitis E','Alcoholic hepatitis','Tuberculosis',
'Common Cold','Pneumonia','Dimorphic hemmorhoids(piles)',
'Heartattack','Varicoseveins','Hypothyroidism','Hyperthyroidism','Hypoglycemia','Osteoarthristis',
'Arthritis','(vertigo) Paroymsal Positional Vertigo','Acne','Urinary tract infection','Psoriasis',
'Impetigo']
l2=[]
for i in range(0,len(l1)):
l2.append(0)
df=pd.read_csv('Prototype.csv')
df.replace({'prognosis':{'Fungal infection':0,'Allergy':1,'GERD':2,'Chronic cholestasis':3,'Drug Reaction':4,
'Peptic ulcer diseae':5,'AIDS':6,'Diabetes ':7,'Gastroenteritis':8,'Bronchial Asthma':9,'Hypertension ':10,
'Migraine':11,'Cervical spondylosis':12,
'Paralysis (brain hemorrhage)':13,'Jaundice':14,'Malaria':15,'Chicken pox':16,'Dengue':17,'Typhoid':18,'hepatitis A':19,
'Hepatitis B':20,'Hepatitis C':21,'Hepatitis D':22,'Hepatitis E':23,'Alcoholic hepatitis':24,'Tuberculosis':25,
'Common Cold':26,'Pneumonia':27,'Dimorphic hemmorhoids(piles)':28,'Heart attack':29,'Varicose veins':30,'Hypothyroidism':31,
'Hyperthyroidism':32,'Hypoglycemia':33,'Osteoarthristis':34,'Arthritis':35,
'(vertigo) Paroymsal Positional Vertigo':36,'Acne':37,'Urinary tract infection':38,'Psoriasis':39,
'Impetigo':40}},inplace=True)
X= df[l1]
y = df[["prognosis"]]
np.ravel(y)
tr=pd.read_csv('Prototype-1.csv')
tr.replace({'prognosis':{'Fungal infection':0,'Allergy':1,'GERD':2,'Chronic cholestasis':3,'Drug Reaction':4,
'Peptic ulcer diseae':5,'AIDS':6,'Diabetes ':7,'Gastroenteritis':8,'Bronchial Asthma':9,'Hypertension ':10,
'Migraine':11,'Cervical spondylosis':12,
'Paralysis (brain hemorrhage)':13,'Jaundice':14,'Malaria':15,'Chicken pox':16,'Dengue':17,'Typhoid':18,'hepatitis A':19,
'Hepatitis B':20,'Hepatitis C':21,'Hepatitis D':22,'Hepatitis E':23,'Alcoholic hepatitis':24,'Tuberculosis':25,
'Common Cold':26,'Pneumonia':27,'Dimorphic hemmorhoids(piles)':28,'Heart attack':29,'Varicose veins':30,'Hypothyroidism':31,
'Hyperthyroidism':32,'Hypoglycemia':33,'Osteoarthristis':34,'Arthritis':35,
'(vertigo) Paroymsal Positional Vertigo':36,'Acne':37,'Urinary tract infection':38,'Psoriasis':39,
'Impetigo':40}},inplace=True)
X_test= tr[l1]
y_test = tr[["prognosis"]]
np.ravel(y_test)
result=""
state = st.session_state
#---------------------------------------------------------------------------CSS Code-------------------------------------------------------------------
#---styling for buttons---"
st.markdown("""
<style>
.stButton button {
border-radius: 50px;
background-color: #00CED1;
color: white;
font-weight: bold;
padding: 10px 20px;
border: none;
box-shadow: 0px 5px 10px #6495ED;
display: flex;
align-items: center;
}
.stButton button:hover {
background-color: #4169E1;
box-shadow: 0px 3px 6px #4169E1;
}
.stButton button i {
margin-right: 10px;
}
</style>
""", unsafe_allow_html=True)
#---styling for the hr---"
hr = """
<style>
.circle {
width: 15px;
height: 15px;
border-radius: 50%;
display: inline-block;
margin: 0 10px;
}
#circle-1 {
background-color: #FF0000;
}
#circle-2 {
background-color: #808080;
}
#circle-3 {
background-color:#008000;
}
.circle-container {
display: flex;
align-items: center;
justify-content: center;
margin-top: 50px;
}
</style>
<div class="circle-container">
<div class="circle" id="circle-1"></div>
<div class="circle" id="circle-2"></div>
<div class="circle" id="circle-3"></div>
</div>
"""
# CSS style for the expanders
style = """
.streamlit-expander {
border-radius: 10px;
border: 1px solid #f0f0f0;
padding: 10px;
margin-bottom: 10px;
}
.streamlit-expanderHeader {
border-radius: 10px 10px 0px 0px;
background-color: #E6E6FA;
padding: 10px;
}
.streamlit-expanderContent {
border-radius: 0px 0px 10px 10px;
border-top: none;
margin-top: -10px;
margin-bottom: 10px;
padding: 10px;
}
"""
#------------------------------------------------------------------streamlit framework design-----------------------------------------------------------
with st.sidebar:
selected=option_menu('Menu Options',
['Home','Check your Symptoms','View Diagnosis'],
icons=['person-circle','file-earmark-medical-fill'],
default_index=0)
image = cv2.imread('image1.png')
st.sidebar.image(image, caption="", use_column_width=True)
#-------------------------------------------------------------------------------------------------------------------------------------------------------
if selected=='Home':
#st.write("<h1>MULTIPLE DISEASE PREDICTION SYSTEM</h1>", unsafe_allow_html=True)
st.write("<div style='text-align:left; font-size:50px;'>MULTIPLE DISEASE PREDICTION SYSTEM</div>", unsafe_allow_html=True)
st.info("Welcome to the Multiple Disease Prediction System! Our web-application provides you the oppurtunity to gain an understanding of your symptoms.\n Harness the potential of machine learning algorithms to avoid health issues!!!")
st.write(hr ,unsafe_allow_html=True,)
st.markdown("<br>", unsafe_allow_html=True)
st.header("USAGE")
st.write("<div style='text-align:left; color:blue; font-size:20px;'>Using our web-app has 4 key steps. Expand each step to view.</div>", unsafe_allow_html=True)
st.write("\n")
steps = {
"STEP 1.": "SYMPTOMS SPECIFICATION \n\n <span style='color: red; font-style: italic'> Specify your symptoms using the symptoms select box.",
"STEP 2.": "OBTAIN RESULT \n\n <span style='color: red; font-style: italic'> Activate each result to understand your symptoms.",
"STEP 3.": "IDENTIFY POTENTIALLY INFECTED ORGAN \n\n <span style='color: red; font-style: italic'> View the diagnosis to understand which organ could be potentially affected",
"STEP 4.": "<span style='color: red; font-style: italic'> If the diagnosis suggests you may have a particular condition, follow up with your doctor. If your symptoms are severe or you have other concerns, seek medical attention immediately."
}
st.write(f"<style>{style}</style>", unsafe_allow_html=True)
for step_title, step_content in steps.items():
with st.expander(step_title):
st.write(step_content,unsafe_allow_html=True)
st.write(hr ,unsafe_allow_html=True)
st.markdown("<br>", unsafe_allow_html=True)
st.header("ACCESS ANYWHERE!")
st.write("<div style='text-align:left; color:blue; font-size:20px;'>Access our web-app anywhere, anytime for better health-care & management!!!.</div>", unsafe_allow_html=True)
image1 = cv2.imread('image3.jpeg')
st.markdown("<br>", unsafe_allow_html=True)
st.image(image1, width=800,use_column_width=True)
#----------------------------------------------------------------------------------------------------------------------------------------------------------
if selected=='Check your Symptoms':
st.title("Symptoms Checker")
OPTIONS = sorted(l1)
symptom = get_symptoms1()
for value in symptom:
if value =='None':
continue
else:
psymptom.append(value)
print(psymptom)
if len(psymptom) < 1:
st.warning(' No symptoms have been selcted. To proceed, please select accordingly')
if len(psymptom)<3:
st.warning("Please enter at least 3 symptoms.")
elif len(set(psymptom)) != len(psymptom):
st.warning("Duplicate symptoms selected!!! Please select accordingly.")
else:
if st.button('RESULT 1 : DT'):
value=DecisionTree()
st.success(value)
state.input_data = value
if st.button('RESULT 2 : RF'):
value1 = randomforest()
st.success(value1)
if st.button('RESULT 3 : NB'):
value2 = NB()
st.success(value2)
#------------------------------------------------------------------------------------------------------------------------------------------------------------
if selected=='View Diagnosis':
if 'input_data' not in st.session_state:
st.warning('It looks like you have not checked your symptoms yet. Please check your symptoms in order to view the diagnosis.')
else:
org = state.input_data
st.info("Based on the symptoms you have entered, you might be experiencing:")
st.success(org)
organs = {
'Common Cold': (1700, 0, 350, 350),
'Heartattack': (1300, 1400, 350, 350),
'Hypertension': (1300, 1400, 350, 350),
'Pneumonia': (900, 900, 1100, 1100),
'Tuberculosis':(900, 900, 1100, 1100),
'Hypothyroidism':(1300, 700, 200, 200),
'Hyperthyroidism':(1300, 700, 200, 200),
'Diabetes':(900, 1900, 500, 500),
'Malaria':(900, 1900, 500, 500),
'Bronchial Asthma':(900, 1900, 1100, 1100),
'Jaundice':(900, 1900, 500, 500),
'Gastroenteritis':(1100,2700,500,500),
'hepatitis A':(800, 1900, 900, 300),
'Peptic ulcer diseae':(1600,2150,200,100),
'Chronic cholestasis':(800, 1900, 900, 300),
'Alcoholic hepatitis':(800, 1900, 900, 300),
'Hepatitis B':(800, 1900, 900, 300),
'Hepatitis C':(800, 1900, 900, 300),
'Hepatitis D':(800,1900,900,300),
'Hepatitis E':(800,1900,900,300),
'Dengue':(850,1900,811,396),
'GERD':(1500,2000,318,314),
'Typhoid':(1100,2700,500,500)
}
toporgan = {
'Paralysis (brain hemorrhage)':(200,100,75,75),
'Migraine':(100,100,50,50),
'Cervical spondylosis':(200,300,100,100),
'(vertigo) Paroymsal Positional Vertigo':(180,170,60,77),
'Hypoglycemia':(200,100,75,75)
}
bottomorgan = {
'Varicoseveins':(400,750,752,990),
'Arthritis':(400,1000,834,228),
'Osteoarthristis':(400,1000,219,354),
'Urinary tract infection':(670,300,219,254),
'Dimorphic hemmorhoids(piles)':(670,300,219,254)
}
#org = st.text_input('Enter obtained result to view diagnosis') provision for manual user entry
if st.button('View Diagnosis'):
if org in organs:
x,y,w,h= organs[org]
img = cv2.imread('image21.jpg')
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0),8)
st.image(img, caption='Human Body with Infected Organ Highlighted',use_column_width=True)
elif org in toporgan:
x,y,w,h= toporgan[org]
img = cv2.imread('image31.jpg')
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0),8)
st.image(img, caption='Human Body with Infected Organ Highlighted',use_column_width=True)
elif org in bottomorgan:
x,y,w,h= bottomorgan[org]
img = cv2.imread('image41.jpg')
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0),8)
st.image(img, caption='Human Body with Infected Organ Highlighted',use_column_width=True)
else:
st.write('Diagnosis not available')