arittrabag commited on
Commit
716e241
·
verified ·
1 Parent(s): 71ef4c5

Add 3 Files

Browse files
Files changed (3) hide show
  1. app.py +40 -0
  2. requirements.txt +10 -0
  3. xgboost_cardiovascular_model.pkl +3 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ # Load the saved XGBoost model
7
+ model = joblib.load("xgboost_cardiovascular_model.pkl")
8
+
9
+ # Define feature names (same as training)
10
+ feature_names = ["age", "ap_hi", "ap_lo", "cholesterol", "gluc", "smoke", "alco", "active", "weight"]
11
+
12
+ # Define the prediction function
13
+ def predict_heart_disease(age, systolic_bp, diastolic_bp, cholesterol, glucose, smoking, alcohol, active, weight):
14
+ # Convert inputs into a DataFrame
15
+ input_data = pd.DataFrame([[age, systolic_bp, diastolic_bp, cholesterol, glucose, smoking, alcohol, active, weight]], columns=feature_names)
16
+
17
+ # Make prediction
18
+ prediction = model.predict(input_data)[0]
19
+
20
+ # Return result
21
+ return "High Risk of Cardiovascular Disease" if prediction == 1 else "Low Risk of Cardiovascular Disease"
22
+
23
+ # Define Gradio interface
24
+ inputs = [
25
+ gr.Slider(29, 64, step=1, label="Age (in years)"),
26
+ gr.Slider(90, 180, step=1, label="Systolic Blood Pressure (ap_hi)"),
27
+ gr.Slider(60, 120, step=1, label="Diastolic Blood Pressure (ap_lo)"),
28
+ gr.Radio([1, 2, 3], label="Cholesterol Level (1=Normal, 2=Above Normal, 3=Well Above Normal)"),
29
+ gr.Radio([1, 2, 3], label="Glucose Level (1=Normal, 2=Above Normal, 3=Well Above Normal)"),
30
+ gr.Radio([0, 1], label="Smoking (0=No, 1=Yes)"),
31
+ gr.Radio([0, 1], label="Alcohol Intake (0=No, 1=Yes)"),
32
+ gr.Radio([0, 1], label="Physically Active (0=No, 1=Yes)"),
33
+ gr.Slider(40, 180, step=1, label="Weight (in kg)")
34
+ ]
35
+
36
+ output = gr.Textbox(label="Cardiovascular Disease Risk")
37
+
38
+ gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=output, title="Heart Disease Risk Predictor",
39
+ description="Enter your health details to estimate your cardiovascular disease risk using AI.",
40
+ theme="compact").launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ xgboost
2
+ shap
3
+ gradio
4
+ scikit-learn
5
+ pandas
6
+ numpy
7
+ matplotlib
8
+ seaborn
9
+ joblib
10
+ tensorflow
xgboost_cardiovascular_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72c207d7d17a6751683ee8d9cbca33468525f2f07ccbd9f1f215d2fbbfe6156d
3
+ size 769691