Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import joblib | |
| import pandas as pd | |
| from huggingface_hub import hf_hub_download | |
| # 1. Download your model from your repo | |
| model_path = hf_hub_download(repo_id="Aaravkumar/heart-disease-prediction", filename="heart_disease_model.joblib") | |
| model = joblib.load(model_path) | |
| # 2. Define the prediction function | |
| def predict(age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal): | |
| # Create a dataframe matching your training columns | |
| input_data = pd.DataFrame([[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal]], | |
| columns=['Age', 'Sex', 'Chest pain type', 'BP', 'Cholesterol', 'FBS over 120', | |
| 'EKG results', 'Max HR', 'Exercise angina', 'ST depression', | |
| 'Slope of ST', 'Number of vessels fluro', 'Thallium']) | |
| prediction = model.predict(input_data)[0] | |
| probability = model.predict_proba(input_data)[0][1] | |
| result = "❤️ Heart Disease Detected" if prediction == 1 else "✅ No Heart Disease Detected" | |
| return f"{result} (Confidence: {probability:.2%})" | |
| # 3. Create a beautiful UI | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=[ | |
| gr.Slider(20, 90, value=50, label="Age"), | |
| gr.Radio([0, 1], label="Sex (1=M, 0=F)"), | |
| gr.Slider(1, 4, step=1, label="Chest Pain Type"), | |
| gr.Number(label="Resting BP (trestbps)"), | |
| gr.Number(label="Cholesterol"), | |
| gr.Radio([0, 1], label="Fasting Blood Sugar > 120 (1=True)"), | |
| gr.Slider(0, 2, step=1, label="Resting EKG"), | |
| gr.Number(label="Max Heart Rate"), | |
| gr.Radio([0, 1], label="Exercise Induced Angina"), | |
| gr.Number(label="ST Depression (oldpeak)"), | |
| gr.Slider(1, 3, step=1, label="Slope of ST"), | |
| gr.Slider(0, 3, step=1, label="Major Vessels (ca)"), | |
| gr.Slider(1, 3, step=1, label="Thallium") | |
| ], | |
| outputs="text", | |
| title="Heart Disease Risk Analyzer", | |
| description="Enter patient vitals to predict cardiac risk using Aarav's Random Forest Model." | |
| ) | |
| demo.launch() |