Spaces:
Sleeping
Sleeping
criticalDanger
commited on
Commit
•
163b90f
1
Parent(s):
799baa3
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
# Load the trained model
|
6 |
+
with open('heart_disease_model.pkl', 'rb') as file:
|
7 |
+
model = pickle.load(file)
|
8 |
+
|
9 |
+
# Define the prediction function
|
10 |
+
def predict_heart_disease(male, age, currentSmoker, cigsPerDay, BPMeds, prevalentStroke, prevalentHyp, diabetes, BMI):
|
11 |
+
male = 1 if male == 'Male' else 0
|
12 |
+
currentSmoker = 1 if currentSmoker == "Yes" else 0
|
13 |
+
BPMeds = 1 if BPMeds == "Yes" else 0
|
14 |
+
prevalentStroke = 1 if prevalentStroke == "Yes" else 0
|
15 |
+
prevalentHyp = 1 if prevalentHyp == "Yes" else 0
|
16 |
+
diabetes = 1 if diabetes == "Yes" else 0
|
17 |
+
input_data = np.array([[male, age, currentSmoker, cigsPerDay, BPMeds, prevalentStroke, prevalentHyp, diabetes, BMI]])
|
18 |
+
prediction = model.predict(input_data)
|
19 |
+
return 'Heart Disease' if prediction[0] == 1 else 'No Heart Disease'
|
20 |
+
|
21 |
+
# Define the input components
|
22 |
+
inputs = [
|
23 |
+
gr.Radio(choices=["Male", "Female"], label="Sex"),
|
24 |
+
gr.Number(label="Age")
|
25 |
+
gr.Text(label="Do you smoke? (Yes/No)")
|
26 |
+
gr.Number(label="Number of ciggerates a day")
|
27 |
+
gr.Text(label="Do you take BP medicines?")
|
28 |
+
gr.text(label="Have you hade strokes previously?")
|
29 |
+
gr.text(label="Have you hade High BP previously?")
|
30 |
+
gr.text(label="Do you have Diabetes?")
|
31 |
+
gr.Number(value=float, label="BMI")
|
32 |
+
|
33 |
+
]
|
34 |
+
|
35 |
+
# Define the output component
|
36 |
+
outputs = gr.Textbox(label="Prediction")
|
37 |
+
|
38 |
+
# Create and launch the Gradio interface
|
39 |
+
gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=outputs).launch()
|