norsu commited on
Commit
c736fe6
1 Parent(s): ff9ffd2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +118 -0
  2. heart1.pkl +3 -0
app.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import joblib as jb
4
+ import pandas as pd
5
+
6
+
7
+ pipe = jb.load('heart1.pkl')
8
+
9
+
10
+
11
+
12
+
13
+
14
+ def predict(age, sex, cp, trtbps, chol, fbs, restecg, thalachh, exng, oldpeak, slp, caa, thall):
15
+ if sex=="Male":
16
+ sex=1
17
+ else:
18
+ sex=0
19
+
20
+ if cp=="Typical Angina":
21
+ cp=0
22
+ elif cp=="Typical Angina":
23
+ cp=1
24
+ elif cp=="Atypical Angina":
25
+ cp=2
26
+ elif cp=="Non-Anginal pain":
27
+ cp=3
28
+ elif cp=="Asymptomatic":
29
+ cp=4
30
+ else:
31
+ cp=0
32
+
33
+ if fbs>120:
34
+ fbs=1
35
+ else:
36
+ fbs=0
37
+
38
+ if restecg=="Normal":
39
+ restecg=0
40
+ elif restecg=="ST-T wave abnormality":
41
+ restecg=1
42
+ elif restecg=="Definite left Ventricular hypertrophy":
43
+ restecg=2
44
+ else:
45
+ restecg=0
46
+
47
+ if slp=="Unsloping":
48
+ slp=0
49
+ elif restecg=="flat":
50
+ slp=1
51
+ elif restecg=="Downsloping":
52
+ slp=2
53
+ else:
54
+ slp=0
55
+
56
+ if exng=="Yes":
57
+ exng=1
58
+ else:
59
+ exng=0
60
+
61
+ if thall=="Null":
62
+ thall=0
63
+ elif thall=="Fixed defect":
64
+ thall=1
65
+ elif cp=="Normal":
66
+ thall=2
67
+ elif cp=="Reversable defect":
68
+ thall=3
69
+ else:
70
+ thall=0
71
+
72
+
73
+ x = pd.DataFrame([[age, sex, cp, trtbps, chol, fbs, restecg, thalachh, exng, oldpeak, slp, caa, thall]])
74
+ x.columns = ["age", "sex", "cp", "trtbps", "chol", "fbs", "restecg", "thalachh", "exng", "oldpeak", "slp", "caa", "thall"]
75
+ prediction = pipe.predict(x)
76
+
77
+ ans = prediction[0]
78
+
79
+ if ans>=1:
80
+ ans = 100
81
+ elif ans<=0:
82
+ ans = 0
83
+ else:
84
+ ans = ans*100
85
+
86
+ if ans>50:
87
+ final = str(int(ans)) + "%" +"\n>50% Diameter narrowing.\nMore chance of heart disease."
88
+ else:
89
+ final = str(int(ans)) + "%" + "\n< 50% Diameter narrowing.\nLess chance of heart disease."
90
+
91
+
92
+ return final
93
+
94
+
95
+
96
+ app = gr.Interface(title="Heart Attack Predictor",fn=predict,
97
+ inputs=[
98
+ gr.inputs.Number(label='Age'),
99
+ gr.inputs.Radio(["Male","Female"],label='Sex'),
100
+ gr.inputs.Radio(["Typical Angina","Atypical Angina","Non-Anginal pain","Asymptomatic"],label='Chest Pain'),
101
+ gr.inputs.Number(label='Resting blood pressure (in mm Hg)'),
102
+ gr.inputs.Number(label='Cholestoral in mg/dl '),
103
+ gr.inputs.Number(label='Fasting blood sugar'),
104
+ gr.inputs.Radio(["Normal","ST-T wave abnormality","Definite left Ventricular hypertrophy"],label='Resting Rlectrocardiographic Results'),
105
+ gr.inputs.Number(label='Maximum Heartrate achieved'),
106
+ gr.inputs.Radio(["Yes","No"],label='Exercise induced Angina'),
107
+ gr.inputs.Number(label='ST depression induced by exercise'),
108
+ gr.inputs.Radio(["Unsloping","flat","Downsloping"],label='Slope of the peak exercise ST segment'),
109
+ gr.inputs.Slider(minimum=0,maximum=3,step=1,label='Number of major vessels'),
110
+ gr.inputs.Radio(["Null","Fixed defect","Normal","Reversable defect"],label='Thalassemia'),
111
+ ],
112
+ outputs=gr.outputs.Textbox(label="Prediction")
113
+ )
114
+
115
+
116
+
117
+ app.launch()
118
+
heart1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ea135ed7e84201ee0622c35a012a0757d2d291a33f0a751910db244c702c57e
3
+ size 3367