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 predict_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],dtype=float) 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=predict_heart_disease, inputs=[ gr.inputs.Number(label="Age"), gr.inputs.Number(label="Sex (0 for Female, 1 for Male)"), gr.inputs.Number(label="Chest Pain Type (0 for Typical Angina, 1 for Atypical Angina, 2 for Non-Anginal Pain, 3 for Asymptomatic)"), gr.inputs.Number(label="Resting Blood Pressure (mm Hg)"), gr.inputs.Number(label="Serum Cholesterol Level (mg/dL)"), gr.inputs.Number(label="Fasting Blood Sugar Level (0 for <= 120 mg/dL, 1 for > 120 mg/dL)"), gr.inputs.Number(label="Resting Electrocardiographic Results (0 for Normal, 1 for ST-T Wave Abnormality, 2 for Probable or Definite Left Ventricular Hypertrophy)"), gr.inputs.Number(label="Maximum Heart Rate Achieved"), gr.inputs.Number(label="Exercise-Induced Angina (0 for No, 1 for Yes)"), gr.inputs.Number(label="ST Depression Induced by Exercise Relative to Rest"), gr.inputs.Number(label="Slope of the Peak Exercise ST Segment (0 for Upsloping, 1 for Flat, 2 for Downsloping)"), gr.inputs.Number(label="Number of Major Vessels (0-3) Colored by Fluoroscopy"), gr.inputs.Number(label="Thalassemia (3 for Normal, 6 for Fixed Defect, 7 for Reversible Defect)") ], outputs=outputs, examples=examples,examples_output = [predict_heart_disease(*example) for example in 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()