import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression import pickle import gradio as gr import numpy as np # Load the CSV data data = pd.read_csv('/content/Untitled spreadsheet - Heart desiese data.csv') # Ensure the correct file path # Load the trained model model = pickle.load(open('/content/heart_disease_model.sav', 'rb')) # Prediction function def predict_heart_disease(age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal): input_data = np.array([[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal]]) prediction = model.predict(input_data) if prediction[0] == 1: return "The person has heart disease." else: return "The person does not have heart disease." # Gradio Interface def heart_disease_interface(): with gr.Blocks() as app: gr.Markdown("### Heart Disease Prediction System") age = gr.Number(label="Age") sex = gr.Number(label="Sex") cp = gr.Number(label="Chest Pain Type") trestbps = gr.Number(label="Resting Blood Pressure") chol = gr.Number(label="Serum Cholesterol") fbs = gr.Number(label="Fasting Blood Sugar > 120 mg/dl") restecg = gr.Number(label="Resting ECG Results") thalach = gr.Number(label="Max Heart Rate Achieved") exang = gr.Number(label="Exercise Induced Angina") oldpeak = gr.Number(label="ST Depression by Exercise") slope = gr.Number(label="Slope of Peak Exercise ST Segment") ca = gr.Number(label="Major Vessels Colored by Fluoroscopy") thal = gr.Number(label="Thalassemia Type") submit_btn = gr.Button("Predict") output = gr.Textbox() submit_btn.click( predict_heart_disease, inputs=[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal], outputs=output ) return app # Launch the Gradio Interface heart_disease_interface().launch() # Check the first few rows of the data (optional) print(data.head())