File size: 3,863 Bytes
ab19217
 
 
 
 
 
 
 
 
 
f082102
 
 
ab19217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df591a9
 
ab19217
 
df591a9
 
ab19217
 
df591a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab19217
 
4a45805
ab19217
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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score 
from sklearn.linear_model import LogisticRegression
import warnings 
warnings.filterwarnings('ignore')
import joblib
import gradio as gr


loaded_model = joblib.load('heart.pkl')



def heart_disease(age,	sex,	cp,	trestbps,	chol,	fbs,	restecg,	thalach,	exang,	oldpeak,	slope,	ca,thal):
#turning the arguments into a numpy array  

  x = np.array([age,	sex,	cp,	trestbps,	chol,	fbs,	restecg,	thalach,	exang,	oldpeak,	slope,	ca,thal])

  prediction = loaded_model.predict(x.reshape(1, -1))

  if(prediction[0]==0):
    return("The person does not have any heart diseases")
  else:
    return('The person has a heart disease')

outputs = gr.outputs.Textbox()

# Define some example inputs for the interface
examples = [
    [59, 1, 1, 140, 221, 0, 1, 164, 1, 0.0, 2, 0, 2],
    [45, 0, 2, 125, 212, 1, 0, 168, 0, 1.6, 1, 0, 3],
    [72, 1, 3, 160, 114, 0, 0, 115, 0, 1.1, 2, 0, 7],
]

app = gr.Interface(fn=heart_disease,  inputs=[
        gr.inputs.Number(label="Age"), 
        gr.inputs.Radio(choices=[("Male", 1), ("Female", 0)], label="Sex"), 
        gr.inputs.Radio(choices=[
            ("Typical Angina", 0), 
            ("Atypical Angina", 1), 
            ("Non-Anginal Pain", 2), 
            ("Asymptomatic", 3)
        ], label="Chest Pain Type"), 
        gr.inputs.Number(label="Resting Blood Pressure (mm Hg)"), 
        gr.inputs.Number(label="Serum Cholesterol Level (mg/dL)"), 
        gr.inputs.Radio(choices=[("Fasting Blood Sugar > 120 mg/dL", 1), ("Fasting Blood Sugar <= 120 mg/dL", 0)], label="Fasting Blood Sugar Level"), 
        gr.inputs.Radio(choices=[
            ("Normal", 0), 
            ("ST-T Wave Abnormality", 1), 
            ("Probable or Definite Left Ventricular Hypertrophy", 2)
        ], label="Resting Electrocardiographic Results"), 
        gr.inputs.Number(label="Maximum Heart Rate Achieved"), 
        gr.inputs.Radio(choices=[("Exercise-Induced Angina", 1), ("No Exercise-Induced Angina", 0)], label="Exercise-Induced Angina"), 
        gr.inputs.Number(label="ST Depression Induced by Exercise Relative to Rest"), 
        gr.inputs.Radio(choices=[("Upsloping", 0), ("Flat", 1), ("Downsloping", 2)], label="Slope of the Peak Exercise ST Segment"), 
        gr.inputs.Number(label="Number of Major Vessels (0-3) Colored by Fluoroscopy"), 
        gr.inputs.Radio(choices=[
            ("Normal", 3), 
            ("Fixed Defect", 6), 
            ("Reversible Defect", 7)
        ], label="Thalassemia")
    ],  outputs=outputs, examples=examples,title="Heart Disease Prediction",description=''' 
    #This model predicts the presence of heart disease based on various input parameters. Please enter the values for the following inputs:

##Description about the inputs. age: The age of the patient in years.
sex: The patient's gender (1 = male, 0 = female).
cp: Chest pain type (0 = typical angina, 1 = atypical angina, 2 = non-anginal pain, 3 = asymptomatic).
trestbps: Resting blood pressure (in mm Hg) on admission to the hospital.
chol: Serum cholesterol level (in mg/dL).
fbs: Fasting blood sugar level (> 120 mg/dL = 1, <= 120 mg/dL = 0).
restecg: Resting electrocardiographic results (0 = normal, 1 = having ST-T wave abnormality, 2 = showing probable or definite left ventricular hypertrophy).
thalach: Maximum heart rate achieved.
exang: Exercise-induced angina (1 = yes, 0 = no).
oldpeak: ST depression induced by exercise relative to rest.
slope: The slope of the peak exercise ST segment (0 = upsloping, 1 = flat, 2 = downsloping).
ca: Number of major vessels (0-3) colored by fluoroscopy.
thal: A blood disorder called thalassemia (3 = normal, 6 = fixed defect, 7 = reversible defect). ''')


app.launch()