-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhari.py
More file actions
939 lines (772 loc) · 32.7 KB
/
hari.py
File metadata and controls
939 lines (772 loc) · 32.7 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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
import streamlit as st
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import pandas as pd
from streamlit_option_menu import option_menu
import pickle
from PIL import Image
import numpy as np
import plotly.figure_factory as ff
from code.DiseaseModel import DiseaseModel
from code.helper import prepare_symptoms_array
import seaborn as sns
import joblib
import subprocess
import sys
import os
# loading the models
diabetes_model = joblib.load("models/diabetes_model.sav")
heart_model = joblib.load("models/heart_disease_model.sav")
parkinson_model = joblib.load("models/parkinsons_model.sav")
# Load the lung cancer prediction model
lung_cancer_model = joblib.load('models/lung_cancer_model.sav')
# Safety Load for Breast Cancer Model
try:
breast_cancer_model = joblib.load('models/breast_cancer.sav')
except:
breast_cancer_model = None
# Load the pre-trained model
chronic_disease_model = joblib.load('models/chronic_model.sav')
# Load the hepatitis prediction model
hepatitis_model = joblib.load('models/hepititisc_model.sav')
liver_model = joblib.load('models/liver_model.sav')
# Safety Load for Jaundice Model
try:
jaundice_model = joblib.load('models/jaundice_model.sav')
except:
jaundice_model = None
# Load the lung cancer prediction model (Duplicate load kept as in original)
lung_cancer_model = joblib.load('models/lung_cancer_model.sav')
# sidebar
with st.sidebar:
selected = option_menu('Multiple Disease Prediction', [
'Disease Prediction',
'Diabetes Prediction',
'Heart disease Prediction',
'Parkison Prediction',
'Liver prediction',
'Hepatitis prediction',
'Lung Cancer Prediction',
'Chronic Kidney prediction',
'Breast Cancer Prediction',
],
icons=['','activity', 'heart', 'person','person','person','person','bar-chart-fill'],
default_index=0)
st.markdown("---")
st.markdown("### 🤖 AI Assistant")
# Updated Launch Button for Windows CMD
if st.button("Launch AI Chatbot 🚀"):
try:
# Launch Streamlit app in a new CMD window
subprocess.Popen('start cmd /k streamlit run ai.py --server.port 8502', shell=True)
st.success("AI Assistant Launched successfully in a new window!")
except Exception as e:
st.error(f"Failed to open AI Assistant: {e}")
# ==========================================
# multiple disease prediction
if selected == 'Disease Prediction':
# Create disease class and load ML model
disease_model = DiseaseModel()
disease_model.load_xgboost('model/xgboost_model.json')
# Title
st.write('# Disease Prediction using Machine Learning')
symptoms = st.multiselect('What are your symptoms?', options=disease_model.all_symptoms)
X = prepare_symptoms_array(symptoms)
# Trigger XGBoost model
if st.button('Predict'):
# Run the model with the python script
prediction, prob = disease_model.predict(X)
st.write(f'## Disease: {prediction} with {prob*100:.2f}% probability')
tab1, tab2= st.tabs(["Description", "Precautions"])
with tab1:
st.write(disease_model.describe_predicted_disease())
with tab2:
precautions = disease_model.predicted_disease_precautions()
for i in range(4):
st.write(f'{i+1}. {precautions[i]}')
# Diabetes prediction page
if selected == 'Diabetes Prediction': # pagetitle
st.title("Diabetes disease prediction")
image = Image.open('d3.jpg')
st.image(image, caption='diabetes disease prediction')
# columns
# no inputs from the user
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
Pregnancies = st.number_input("Number of Pregnencies")
with col2:
Glucose = st.number_input("Glucose level")
with col3:
BloodPressure = st.number_input("Blood pressure value")
with col1:
SkinThickness = st.number_input("Sckinthickness value")
with col2:
Insulin = st.number_input("Insulin value ")
with col3:
BMI = st.number_input("BMI value")
with col1:
DiabetesPedigreefunction = st.number_input(
"Diabetespedigreefunction value")
with col2:
Age = st.number_input("AGE")
# code for prediction
diabetes_dig = ''
# button
if st.button("Diabetes test result"):
diabetes_prediction=[[]]
diabetes_prediction = diabetes_model.predict(
[[Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreefunction, Age]])
# after the prediction is done if the value in the list at index is 0 is 1 then the person is diabetic
if diabetes_prediction[0] == 1:
diabetes_dig = "we are really sorry to say but it seems like you are Diabetic."
image = Image.open('positive.jpg')
st.image(image, caption='')
else:
diabetes_dig = 'Congratulation,You are not diabetic'
image = Image.open('negative.jpg')
st.image(image, caption='')
st.success(name+' , ' + diabetes_dig)
# Heart prediction page
if selected == 'Heart disease Prediction':
st.title("Heart disease prediction")
image = Image.open('heart2.jpg')
st.image(image, caption='heart failuire')
# age sex cp trestbps chol fbs restecg thalach exang oldpeak slope ca thal target
# columns
# no inputs from the user
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
age = st.number_input("Age")
with col2:
sex=0
display = ("male", "female")
options = list(range(len(display)))
value = st.selectbox("Gender", options, format_func=lambda x: display[x])
if value == "male":
sex = 1
elif value == "female":
sex = 0
with col3:
cp=0
display = ("typical angina","atypical angina","non — anginal pain","asymptotic")
options = list(range(len(display)))
value = st.selectbox("Chest_Pain Type", options, format_func=lambda x: display[x])
if value == "typical angina":
cp = 0
elif value == "atypical angina":
cp = 1
elif value == "non — anginal pain":
cp = 2
elif value == "asymptotic":
cp = 3
with col1:
trestbps = st.number_input("Resting Blood Pressure")
with col2:
chol = st.number_input("Serum Cholestrol")
with col3:
restecg=0
display = ("normal","having ST-T wave abnormality","left ventricular hyperthrophy")
options = list(range(len(display)))
value = st.selectbox("Resting ECG", options, format_func=lambda x: display[x])
if value == "normal":
restecg = 0
elif value == "having ST-T wave abnormality":
restecg = 1
elif value == "left ventricular hyperthrophy":
restecg = 2
with col1:
exang=0
thalach = st.number_input("Max Heart Rate Achieved")
with col2:
oldpeak = st.number_input("ST depression induced by exercise relative to rest")
with col3:
slope=0
display = ("upsloping","flat","downsloping")
options = list(range(len(display)))
value = st.selectbox("Peak exercise ST segment", options, format_func=lambda x: display[x])
if value == "upsloping":
slope = 0
elif value == "flat":
slope = 1
elif value == "downsloping":
slope = 2
with col1:
ca = st.number_input("Number of major vessels (0–3) colored by flourosopy")
with col2:
thal=0
display = ("normal","fixed defect","reversible defect")
options = list(range(len(display)))
value = st.selectbox("thalassemia", options, format_func=lambda x: display[x])
if value == "normal":
thal = 0
elif value == "fixed defect":
thal = 1
elif value == "reversible defect":
thal = 2
with col3:
agree = st.checkbox('Exercise induced angina')
if agree:
exang = 1
else:
exang=0
with col1:
agree1 = st.checkbox('fasting blood sugar > 120mg/dl')
if agree1:
fbs = 1
else:
fbs=0
# code for prediction
heart_dig = ''
# button
if st.button("Heart test result"):
heart_prediction=[[]]
# change the parameters according to the model
# b=np.array(a, dtype=float)
heart_prediction = heart_model.predict([[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal]])
if heart_prediction[0] == 1:
heart_dig = 'we are really sorry to say but it seems like you have Heart Disease.'
image = Image.open('positive.jpg')
st.image(image, caption='')
else:
heart_dig = "Congratulation , You don't have Heart Disease."
image = Image.open('negative.jpg')
st.image(image, caption='')
st.success(name +' , ' + heart_dig)
if selected == 'Parkison Prediction':
st.title("Parkison prediction")
image = Image.open('p1.jpg')
st.image(image, caption='parkinsons disease')
# parameters
# name MDVP:Fo(Hz) MDVP:Fhi(Hz) MDVP:Flo(Hz) MDVP:Jitter(%) MDVP:Jitter(Abs) MDVP:RAP MDVP:PPQ Jitter:DDP MDVP:Shimmer MDVP:Shimmer(dB) Shimmer:APQ3 Shimmer:APQ5 MDVP:APQ Shimmer:DDA NHR HNR status RPDE DFA spread1 spread2 D2 PPE
# change the variables according to the dataset used in the model
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
MDVP = st.number_input("MDVP:Fo(Hz)")
with col2:
MDVPFIZ = st.number_input("MDVP:Fhi(Hz)")
with col3:
MDVPFLO = st.number_input("MDVP:Flo(Hz)")
with col1:
MDVPJITTER = st.number_input("MDVP:Jitter(%)")
with col2:
MDVPJitterAbs = st.number_input("MDVP:Jitter(Abs)")
with col3:
MDVPRAP = st.number_input("MDVP:RAP")
with col2:
MDVPPPQ = st.number_input("MDVP:PPQ ")
with col3:
JitterDDP = st.number_input("Jitter:DDP")
with col1:
MDVPShimmer = st.number_input("MDVP:Shimmer")
with col2:
MDVPShimmer_dB = st.number_input("MDVP:Shimmer(dB)")
with col3:
Shimmer_APQ3 = st.number_input("Shimmer:APQ3")
with col1:
ShimmerAPQ5 = st.number_input("Shimmer:APQ5")
with col2:
MDVP_APQ = st.number_input("MDVP:APQ")
with col3:
ShimmerDDA = st.number_input("Shimmer:DDA")
with col1:
NHR = st.number_input("NHR")
with col2:
HNR = st.number_input("HNR")
with col2:
RPDE = st.number_input("RPDE")
with col3:
DFA = st.number_input("DFA")
with col1:
spread1 = st.number_input("spread1")
with col1:
spread2 = st.number_input("spread2")
with col3:
D2 = st.number_input("D2")
with col1:
PPE = st.number_input("PPE")
# code for prediction
parkinson_dig = ''
# button
if st.button("Parkinson test result"):
parkinson_prediction=[[]]
# change the parameters according to the model
parkinson_prediction = parkinson_model.predict([[MDVP, MDVPFIZ, MDVPFLO, MDVPJITTER, MDVPJitterAbs, MDVPRAP, MDVPPPQ, JitterDDP, MDVPShimmer,MDVPShimmer_dB, Shimmer_APQ3, ShimmerAPQ5, MDVP_APQ, ShimmerDDA, NHR, HNR, RPDE, DFA, spread1, spread2, D2, PPE]])
if parkinson_prediction[0] == 1:
parkinson_dig = 'we are really sorry to say but it seems like you have Parkinson disease'
image = Image.open('positive.jpg')
st.image(image, caption='')
else:
parkinson_dig = "Congratulation , You don't have Parkinson disease"
image = Image.open('negative.jpg')
st.image(image, caption='')
st.success(name+' , ' + parkinson_dig)
# Load the dataset
lung_cancer_data = pd.read_csv('data/lung_cancer.csv')
# Convert 'M' to 0 and 'F' to 1 in the 'GENDER' column
lung_cancer_data['GENDER'] = lung_cancer_data['GENDER'].map({'M': 'Male', 'F': 'Female'})
# Lung Cancer prediction page
if selected == 'Lung Cancer Prediction':
st.title("Lung Cancer Prediction")
image = Image.open('h.png')
st.image(image, caption='Lung Cancer Prediction')
# Columns
# No inputs from the user
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
gender = st.selectbox("Gender:", lung_cancer_data['GENDER'].unique())
with col2:
age = st.number_input("Age")
with col3:
smoking = st.selectbox("Smoking:", ['NO', 'YES'])
with col1:
yellow_fingers = st.selectbox("Yellow Fingers:", ['NO', 'YES'])
with col2:
anxiety = st.selectbox("Anxiety:", ['NO', 'YES'])
with col3:
peer_pressure = st.selectbox("Peer Pressure:", ['NO', 'YES'])
with col1:
chronic_disease = st.selectbox("Chronic Disease:", ['NO', 'YES'])
with col2:
fatigue = st.selectbox("Fatigue:", ['NO', 'YES'])
with col3:
allergy = st.selectbox("Allergy:", ['NO', 'YES'])
with col1:
wheezing = st.selectbox("Wheezing:", ['NO', 'YES'])
with col2:
alcohol_consuming = st.selectbox("Alcohol Consuming:", ['NO', 'YES'])
with col3:
coughing = st.selectbox("Coughing:", ['NO', 'YES'])
with col1:
shortness_of_breath = st.selectbox("Shortness of Breath:", ['NO', 'YES'])
with col2:
swallowing_difficulty = st.selectbox("Swallowing Difficulty:", ['NO', 'YES'])
with col3:
chest_pain = st.selectbox("Chest Pain:", ['NO', 'YES'])
# Code for prediction
cancer_result = ''
# Button
if st.button("Predict Lung Cancer"):
# Create a DataFrame with user inputs
user_data = pd.DataFrame({
'GENDER': [gender],
'AGE': [age],
'SMOKING': [smoking],
'YELLOW_FINGERS': [yellow_fingers],
'ANXIETY': [anxiety],
'PEER_PRESSURE': [peer_pressure],
'CHRONICDISEASE': [chronic_disease],
'FATIGUE': [fatigue],
'ALLERGY': [allergy],
'WHEEZING': [wheezing],
'ALCOHOLCONSUMING': [alcohol_consuming],
'COUGHING': [coughing],
'SHORTNESSOFBREATH': [shortness_of_breath],
'SWALLOWINGDIFFICULTY': [swallowing_difficulty],
'CHESTPAIN': [chest_pain]
})
# Map string values to numeric
user_data.replace({'NO': 1, 'YES': 2}, inplace=True)
# Strip leading and trailing whitespaces from column names
user_data.columns = user_data.columns.str.strip()
# Convert columns to numeric where necessary
numeric_columns = ['AGE', 'FATIGUE', 'ALLERGY', 'ALCOHOLCONSUMING', 'COUGHING', 'SHORTNESSOFBREATH']
user_data[numeric_columns] = user_data[numeric_columns].apply(pd.to_numeric, errors='coerce')
# Perform prediction
cancer_prediction = lung_cancer_model.predict(user_data)
# Display result
if cancer_prediction[0] == 'YES':
cancer_result = "The model predicts that there is a risk of Lung Cancer."
image = Image.open('positive.jpg')
st.image(image, caption='')
else:
cancer_result = "The model predicts no significant risk of Lung Cancer."
image = Image.open('negative.jpg')
st.image(image, caption='')
st.success(name + ', ' + cancer_result)
# Liver prediction page
if selected == 'Liver prediction': # pagetitle
st.title("Liver disease prediction")
image = Image.open('liver.jpg')
st.image(image, caption='Liver disease prediction.')
# columns
# no inputs from the user
# st.write(info.astype(int).info())
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
Sex=0
display = ("male", "female")
options = list(range(len(display)))
value = st.selectbox("Gender", options, format_func=lambda x: display[x])
if value == "male":
Sex = 0
elif value == "female":
Sex = 1
with col2:
age = st.number_input("Entre your age") # 2
with col3:
Total_Bilirubin = st.number_input("Entre your Total_Bilirubin") # 3
with col1:
Direct_Bilirubin = st.number_input("Entre your Direct_Bilirubin")# 4
with col2:
Alkaline_Phosphotase = st.number_input("Entre your Alkaline_Phosphotase") # 5
with col3:
Alamine_Aminotransferase = st.number_input("Entre your Alamine_Aminotransferase") # 6
with col1:
Aspartate_Aminotransferase = st.number_input("Entre your Aspartate_Aminotransferase") # 7
with col2:
Total_Protiens = st.number_input("Entre your Total_Protiens")# 8
with col3:
Albumin = st.number_input("Entre your Albumin") # 9
with col1:
Albumin_and_Globulin_Ratio = st.number_input("Entre your Albumin_and_Globulin_Ratio") # 10
# code for prediction
liver_dig = ''
# button
if st.button("Liver test result"):
liver_prediction=[[]]
liver_prediction = liver_model.predict([[Sex,age,Total_Bilirubin,Direct_Bilirubin,Alkaline_Phosphotase,Alamine_Aminotransferase,Aspartate_Aminotransferase,Total_Protiens,Albumin,Albumin_and_Globulin_Ratio]])
# after the prediction is done if the value in the list at index is 0 is 1 then the person is diabetic
if liver_prediction[0] == 1:
image = Image.open('positive.jpg')
st.image(image, caption='')
liver_dig = "we are really sorry to say but it seems like you have liver disease."
else:
image = Image.open('negative.jpg')
st.image(image, caption='')
liver_dig = "Congratulation , You don't have liver disease."
st.success(name+' , ' + liver_dig)
# Hepatitis prediction page
if selected == 'Hepatitis prediction':
st.title("Hepatitis Prediction")
image = Image.open('h.png')
st.image(image, caption='Hepatitis Prediction')
# Columns
# No inputs from the user
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
age = st.number_input("Enter your age") # 2
with col2:
sex = st.selectbox("Gender", ["Male", "Female"])
sex = 1 if sex == "Male" else 2
with col3:
total_bilirubin = st.number_input("Enter your Total Bilirubin") # 3
with col1:
direct_bilirubin = st.number_input("Enter your Direct Bilirubin") # 4
with col2:
alkaline_phosphatase = st.number_input("Enter your Alkaline Phosphatase") # 5
with col3:
alamine_aminotransferase = st.number_input("Enter your Alamine Aminotransferase") # 6
with col1:
aspartate_aminotransferase = st.number_input("Enter your Aspartate Aminotransferase") # 7
with col2:
total_proteins = st.number_input("Enter your Total Proteins") # 8
with col3:
albumin = st.number_input("Enter your Albumin") # 9
with col1:
albumin_and_globulin_ratio = st.number_input("Enter your Albumin and Globulin Ratio") # 10
with col2:
your_ggt_value = st.number_input("Enter your GGT value") # Add this line
with col3:
your_prot_value = st.number_input("Enter your PROT value") # Add this line
# Code for prediction
hepatitis_result = ''
# Button
if st.button("Predict Hepatitis"):
# Create a DataFrame with user inputs
user_data = pd.DataFrame({
'Age': [age],
'Sex': [sex],
'ALB': [total_bilirubin], # Correct the feature name
'ALP': [direct_bilirubin], # Correct the feature name
'ALT': [alkaline_phosphatase], # Correct the feature name
'AST': [alamine_aminotransferase],
'BIL': [aspartate_aminotransferase], # Correct the feature name
'CHE': [total_proteins], # Correct the feature name
'CHOL': [albumin], # Correct the feature name
'CREA': [albumin_and_globulin_ratio], # Correct the feature name
'GGT': [your_ggt_value], # Replace 'your_ggt_value' with the actual value
'PROT': [your_prot_value] # Replace 'your_prot_value' with the actual value
})
# Perform prediction
hepatitis_prediction = hepatitis_model.predict(user_data)
# Display result
if hepatitis_prediction[0] == 1:
hepatitis_result = "We are really sorry to say but it seems like you have Hepatitis."
image = Image.open('positive.jpg')
st.image(image, caption='')
else:
hepatitis_result = 'Congratulations, you do not have Hepatitis.'
image = Image.open('negative.jpg')
st.image(image, caption='')
st.success(name + ', ' + hepatitis_result)
# jaundice prediction page
if selected == 'Jaundice prediction': # pagetitle
st.title("Jaundice disease prediction")
image = Image.open('j.jpg')
st.image(image, caption='Jaundice disease prediction')
# columns
# no inputs from the user
# st.write(info.astype(int).info())
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
age = st.number_input("Entre your age ") # 2
with col2:
Sex=0
display = ("male", "female")
options = list(range(len(display)))
value = st.selectbox("Gender", options, format_func=lambda x: display[x])
if value == "male":
Sex = 0
elif value == "female":
Sex = 1
with col3:
Total_Bilirubin = st.number_input("Entre your Total_Bilirubin") # 3
with col1:
Direct_Bilirubin = st.number_input("Entre your Direct_Bilirubin")# 4
with col2:
Alkaline_Phosphotase = st.number_input("Entre your Alkaline_Phosphotase") # 5
with col3:
Alamine_Aminotransferase = st.number_input("Entre your Alamine_Aminotransferase") # 6
with col1:
Total_Protiens = st.number_input("Entre your Total_Protiens")# 8
with col2:
Albumin = st.number_input("Entre your Albumin") # 9
# code for prediction
jaundice_dig = ''
# button
if st.button("Jaundice test result"):
if jaundice_model is not None:
jaundice_prediction=[[]]
jaundice_prediction = jaundice_model.predict([[age,Sex,Total_Bilirubin,Direct_Bilirubin,Alkaline_Phosphotase,Alamine_Aminotransferase,Total_Protiens,Albumin]])
# after the prediction is done if the value in the list at index is 0 is 1 then the person is diabetic
if jaundice_prediction[0] == 1:
image = Image.open('positive.jpg')
st.image(image, caption='')
jaundice_dig = "we are really sorry to say but it seems like you have Jaundice."
else:
image = Image.open('negative.jpg')
st.image(image, caption='')
jaundice_dig = "Congratulation , You don't have Jaundice."
st.success(name+' , ' + jaundice_dig)
else:
st.error("Jaundice model file missing in 'models' folder! Please contact your administrator.")
from sklearn.preprocessing import LabelEncoder
import joblib
# Chronic Kidney Disease Prediction Page
if selected == 'Chronic Kidney prediction':
st.title("Chronic Kidney Disease Prediction")
# Add the image for Chronic Kidney Disease prediction if needed
name = st.text_input("Name:")
# Columns
# No inputs from the user
col1, col2, col3 = st.columns(3)
with col1:
age = st.slider("Enter your age", 1, 100, 25) # 2
with col2:
bp = st.slider("Enter your Blood Pressure", 50, 200, 120) # Add your own ranges
with col3:
sg = st.slider("Enter your Specific Gravity", 1.0, 1.05, 1.02) # Add your own ranges
with col1:
al = st.slider("Enter your Albumin", 0, 5, 0) # Add your own ranges
with col2:
su = st.slider("Enter your Sugar", 0, 5, 0) # Add your own ranges
with col3:
rbc = st.selectbox("Red Blood Cells", ["Normal", "Abnormal"])
rbc = 1 if rbc == "Normal" else 0
with col1:
pc = st.selectbox("Pus Cells", ["Normal", "Abnormal"])
pc = 1 if pc == "Normal" else 0
with col2:
pcc = st.selectbox("Pus Cell Clumps", ["Present", "Not Present"])
pcc = 1 if pcc == "Present" else 0
with col3:
ba = st.selectbox("Bacteria", ["Present", "Not Present"])
ba = 1 if ba == "Present" else 0
with col1:
bgr = st.slider("Enter your Blood Glucose Random", 50, 200, 120) # Add your own ranges
with col2:
bu = st.slider("Enter your Blood Urea", 10, 200, 60) # Add your own ranges
with col3:
sc = st.slider("Enter your Serum Creatinine", 0, 10, 3) # Add your own ranges
with col1:
sod = st.slider("Enter your Sodium", 100, 200, 140) # Add your own ranges
with col2:
pot = st.slider("Enter your Potassium", 2, 7, 4) # Add your own ranges
with col3:
hemo = st.slider("Enter your Hemoglobin", 3, 17, 12) # Add your own ranges
with col1:
pcv = st.slider("Enter your Packed Cell Volume", 20, 60, 40) # Add your own ranges
with col2:
wc = st.slider("Enter your White Blood Cell Count", 2000, 20000, 10000) # Add your own ranges
with col3:
rc = st.slider("Enter your Red Blood Cell Count", 2, 8, 4) # Add your own ranges
with col1:
htn = st.selectbox("Hypertension", ["Yes", "No"])
htn = 1 if htn == "Yes" else 0
with col2:
dm = st.selectbox("Diabetes Mellitus", ["Yes", "No"])
dm = 1 if dm == "Yes" else 0
with col3:
cad = st.selectbox("Coronary Artery Disease", ["Yes", "No"])
cad = 1 if cad == "Yes" else 0
with col1:
appet = st.selectbox("Appetite", ["Good", "Poor"])
appet = 1 if appet == "Good" else 0
with col2:
pe = st.selectbox("Pedal Edema", ["Yes", "No"])
pe = 1 if pe == "Yes" else 0
with col3:
ane = st.selectbox("Anemia", ["Yes", "No"])
ane = 1 if ane == "Yes" else 0
# Code for prediction
kidney_result = ''
# Button
if st.button("Predict Chronic Kidney Disease"):
# Create a DataFrame with user inputs
user_input = pd.DataFrame({
'age': [age],
'bp': [bp],
'sg': [sg],
'al': [al],
'su': [su],
'rbc': [rbc],
'pc': [pc],
'pcc': [pcc],
'ba': [ba],
'bgr': [bgr],
'bu': [bu],
'sc': [sc],
'sod': [sod],
'pot': [pot],
'hemo': [hemo],
'pcv': [pcv],
'wc': [wc],
'rc': [rc],
'htn': [htn],
'dm': [dm],
'cad': [cad],
'appet': [appet],
'pe': [pe],
'ane': [ane]
})
# Perform prediction
kidney_prediction = chronic_disease_model.predict(user_input)
# Display result
if kidney_prediction[0] == 1:
image = Image.open('positive.jpg')
st.image(image, caption='')
kidney_prediction_dig = "we are really sorry to say but it seems like you have kidney disease."
else:
image = Image.open('negative.jpg')
st.image(image, caption='')
kidney_prediction_dig = "Congratulation , You don't have kidney disease."
st.success(name+' , ' + kidney_prediction_dig)
# Breast Cancer Prediction Page
if selected == 'Breast Cancer Prediction':
st.title("Breast Cancer Prediction")
name = st.text_input("Name:")
# Columns
# No inputs from the user
col1, col2, col3 = st.columns(3)
with col1:
radius_mean = st.slider("Enter your Radius Mean", 6.0, 30.0, 15.0)
texture_mean = st.slider("Enter your Texture Mean", 9.0, 40.0, 20.0)
perimeter_mean = st.slider("Enter your Perimeter Mean", 43.0, 190.0, 90.0)
with col2:
area_mean = st.slider("Enter your Area Mean", 143.0, 2501.0, 750.0)
smoothness_mean = st.slider("Enter your Smoothness Mean", 0.05, 0.25, 0.1)
compactness_mean = st.slider("Enter your Compactness Mean", 0.02, 0.3, 0.15)
with col3:
concavity_mean = st.slider("Enter your Concavity Mean", 0.0, 0.5, 0.2)
concave_points_mean = st.slider("Enter your Concave Points Mean", 0.0, 0.2, 0.1)
symmetry_mean = st.slider("Enter your Symmetry Mean", 0.1, 1.0, 0.5)
with col1:
fractal_dimension_mean = st.slider("Enter your Fractal Dimension Mean", 0.01, 0.1, 0.05)
radius_se = st.slider("Enter your Radius SE", 0.1, 3.0, 1.0)
texture_se = st.slider("Enter your Texture SE", 0.2, 2.0, 1.0)
with col2:
perimeter_se = st.slider("Enter your Perimeter SE", 1.0, 30.0, 10.0)
area_se = st.slider("Enter your Area SE", 6.0, 500.0, 150.0)
smoothness_se = st.slider("Enter your Smoothness SE", 0.001, 0.03, 0.01)
with col3:
compactness_se = st.slider("Enter your Compactness SE", 0.002, 0.2, 0.1)
concavity_se = st.slider("Enter your Concavity SE", 0.0, 0.05, 0.02)
concave_points_se = st.slider("Enter your Concave Points SE", 0.0, 0.03, 0.01)
with col1:
symmetry_se = st.slider("Enter your Symmetry SE", 0.1, 1.0, 0.5)
fractal_dimension_se = st.slider("Enter your Fractal Dimension SE", 0.01, 0.1, 0.05)
with col2:
radius_worst = st.slider("Enter your Radius Worst", 7.0, 40.0, 20.0)
texture_worst = st.slider("Enter your Texture Worst", 12.0, 50.0, 25.0)
perimeter_worst = st.slider("Enter your Perimeter Worst", 50.0, 250.0, 120.0)
with col3:
area_worst = st.slider("Enter your Area Worst", 185.0, 4250.0, 1500.0)
smoothness_worst = st.slider("Enter your Smoothness Worst", 0.07, 0.3, 0.15)
compactness_worst = st.slider("Enter your Compactness Worst", 0.03, 0.6, 0.3)
with col1:
concavity_worst = st.slider("Enter your Concavity Worst", 0.0, 0.8, 0.4)
concave_points_worst = st.slider("Enter your Concave Points Worst", 0.0, 0.2, 0.1)
symmetry_worst = st.slider("Enter your Symmetry Worst", 0.1, 1.0, 0.5)
with col2:
fractal_dimension_worst = st.slider("Enter your Fractal Dimension Worst", 0.01, 0.2, 0.1)
# Code for prediction
breast_cancer_result = ''
# Button
if st.button("Predict Breast Cancer"):
if breast_cancer_model is not None:
# Create a DataFrame with user inputs
user_input = pd.DataFrame({
'radius_mean': [radius_mean],
'texture_mean': [texture_mean],
'perimeter_mean': [perimeter_mean],
'area_mean': [area_mean],
'smoothness_mean': [smoothness_mean],
'compactness_mean': [compactness_mean],
'concavity_mean': [concavity_mean],
'concave points_mean': [concave_points_mean], # Update this line
'symmetry_mean': [symmetry_mean],
'fractal_dimension_mean': [fractal_dimension_mean],
'radius_se': [radius_se],
'texture_se': [texture_se],
'perimeter_se': [perimeter_se],
'area_se': [area_se],
'smoothness_se': [smoothness_se],
'compactness_se': [compactness_se],
'concavity_se': [concavity_se],
'concave points_se': [concave_points_se], # Update this line
'symmetry_se': [symmetry_se],
'fractal_dimension_se': [fractal_dimension_se],
'radius_worst': [radius_worst],
'texture_worst': [texture_worst],
'perimeter_worst': [perimeter_worst],
'area_worst': [area_worst],
'smoothness_worst': [smoothness_worst],
'compactness_worst': [compactness_worst],
'concavity_worst': [concavity_worst],
'concave points_worst': [concave_points_worst], # Update this line
'symmetry_worst': [symmetry_worst],
'fractal_dimension_worst': [fractal_dimension_worst],
})
# Perform prediction
breast_cancer_prediction = breast_cancer_model.predict(user_input)
# Display result
if breast_cancer_prediction[0] == 1:
image = Image.open('positive.jpg')
st.image(image, caption='')
breast_cancer_result = "The model predicts that you have Breast Cancer."
else:
image = Image.open('negative.jpg')
st.image(image, caption='')
breast_cancer_result = "The model predicts that you don't have Breast Cancer."
st.success(breast_cancer_result)
else:
st.error("Breast Cancer model file missing in 'models' folder!")