Spaces:
Sleeping
Sleeping
app.py
Browse files- heart predictor.py +42 -0
heart predictor.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pickle
|
| 4 |
+
from sklearn.preprocessing import normalize
|
| 5 |
+
|
| 6 |
+
model = pickle.load(open("C:/Users/Admin/Downloads/model.pkl", 'rb'))
|
| 7 |
+
|
| 8 |
+
def predict(Age, CigsPerDay, Cholestrol, SysBP, DIaBP, BMI, HeartRate, GlucoseLevel, Gender, BpMedication, PrevalentStroke, Smoker):
|
| 9 |
+
'''
|
| 10 |
+
For making predictions
|
| 11 |
+
'''
|
| 12 |
+
list_to_be_normalised = np.array([Age, CigsPerDay, Cholestrol, SysBP, DIaBP, BMI, HeartRate, GlucoseLevel]).reshape(1, -1)
|
| 13 |
+
normalized = normalize(list_to_be_normalised)
|
| 14 |
+
boolean = [Gender, BpMedication, PrevalentStroke, Smoker]
|
| 15 |
+
final_features = np.append(normalized, boolean).reshape(1, -1)
|
| 16 |
+
prediction = model.predict(final_features)
|
| 17 |
+
|
| 18 |
+
if prediction == 1:
|
| 19 |
+
return "problem"
|
| 20 |
+
else:
|
| 21 |
+
return "healthy"
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.inputs.Number(label="Age (Enter Age)", default=40),
|
| 27 |
+
gr.inputs.Number(label="CigsPerDay (Enter Cigarettes Per Day)", default=10),
|
| 28 |
+
gr.inputs.Number(label="Cholesterol (Enter Cholesterol Level)", default=200),
|
| 29 |
+
gr.inputs.Number(label="SysBP (Enter Systolic Blood Pressure)", default=120),
|
| 30 |
+
gr.inputs.Number(label="DIaBP (Enter Diastolic Blood Pressure)", default=80),
|
| 31 |
+
gr.inputs.Number(label="BMI (Enter Body Mass Index)", default=25),
|
| 32 |
+
gr.inputs.Number(label="HeartRate (Enter Heart Rate)", default=70),
|
| 33 |
+
gr.inputs.Number(label="GlucoseLevel (Enter Glucose Level)", default=100),
|
| 34 |
+
gr.inputs.Checkbox(label="Gender (Select Gender)"),
|
| 35 |
+
gr.inputs.Checkbox(label="BpMedication (Select Blood Pressure Medication)"),
|
| 36 |
+
gr.inputs.Checkbox(label="PrevalentStroke (Select Prevalent Stroke)"),
|
| 37 |
+
gr.inputs.Checkbox(label="Smoker (Select Smoker)"),
|
| 38 |
+
],
|
| 39 |
+
outputs=gr.outputs.Textbox(label="Prediction"),
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
iface.launch()
|