Anupam202224 commited on
Commit
5335199
1 Parent(s): 210654a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py CHANGED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import gradio as gr
3
+ import numpy as np
4
+
5
+ # Load the trained model
6
+ model = pickle.load(open('/content/heart_disease_model.sav', 'rb'))
7
+
8
+ # Prediction function
9
+ def predict_heart_disease(age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal):
10
+ input_data = np.array([[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal]])
11
+ prediction = model.predict(input_data)
12
+
13
+ if prediction[0] == 1:
14
+ return "The person has heart disease."
15
+ else:
16
+ return "The person does not have heart disease."
17
+
18
+ # Gradio Interface
19
+ def heart_disease_interface():
20
+ with gr.Blocks() as app:
21
+ gr.Markdown("### Heart Disease Prediction System")
22
+ age = gr.Number(label="Age")
23
+ sex = gr.Number(label="Sex")
24
+ cp = gr.Number(label="Chest Pain Type")
25
+ trestbps = gr.Number(label="Resting Blood Pressure")
26
+ chol = gr.Number(label="Serum Cholesterol")
27
+ fbs = gr.Number(label="Fasting Blood Sugar > 120 mg/dl")
28
+ restecg = gr.Number(label="Resting ECG Results")
29
+ thalach = gr.Number(label="Max Heart Rate Achieved")
30
+ exang = gr.Number(label="Exercise Induced Angina")
31
+ oldpeak = gr.Number(label="ST Depression by Exercise")
32
+ slope = gr.Number(label="Slope of Peak Exercise ST Segment")
33
+ ca = gr.Number(label="Major Vessels Colored by Fluoroscopy")
34
+ thal = gr.Number(label="Thalassemia Type")
35
+ submit_btn = gr.Button("Predict")
36
+ output = gr.Textbox()
37
+ submit_btn.click(
38
+ predict_heart_disease,
39
+ inputs=[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal],
40
+ outputs=output
41
+ )
42
+ return app
43
+
44
+ # Launch the Gradio Interface
45
+ heart_disease_interface().launch()