Spaces:
Sleeping
Sleeping
Commit
·
2adbd31
1
Parent(s):
336dada
add gradio app
Browse files- app.py +56 -0
- logistic_model_pipeline.pkl +3 -0
- requirement.txt +9 -0
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load the saved model
|
| 6 |
+
joblib_file = "logistic_model_pipeline.pkl"
|
| 7 |
+
loaded_pipeline = joblib.load(joblib_file)
|
| 8 |
+
|
| 9 |
+
# Define a function to make predictions
|
| 10 |
+
def predict_heart_disease(age, sex_male, cigs_per_day, tot_chol, sys_bp, glucose):
|
| 11 |
+
# Create a DataFrame for the input
|
| 12 |
+
input_data = pd.DataFrame({
|
| 13 |
+
'age': [age],
|
| 14 |
+
'Sex_male': [sex_male],
|
| 15 |
+
'cigsPerDay': [cigs_per_day],
|
| 16 |
+
'totChol': [tot_chol],
|
| 17 |
+
'sysBP': [sys_bp],
|
| 18 |
+
'glucose': [glucose]
|
| 19 |
+
})
|
| 20 |
+
|
| 21 |
+
# Make prediction using the loaded model
|
| 22 |
+
prob = loaded_pipeline.predict_proba(input_data)[:, 1][0] # Probability of having heart disease
|
| 23 |
+
return f"The probability of having heart disease is: {prob * 100:.2f}%"
|
| 24 |
+
|
| 25 |
+
# Create the Gradio interface
|
| 26 |
+
with gr.Blocks() as interface:
|
| 27 |
+
gr.Markdown("## Heart Disease Risk Prediction")
|
| 28 |
+
gr.Markdown("Enter your details below to check the probability of having heart disease.")
|
| 29 |
+
|
| 30 |
+
# Age input with helper text
|
| 31 |
+
age = gr.Slider(label="Age", minimum=20, maximum=100, value=50, step=1, info="Enter your age (20-100).")
|
| 32 |
+
|
| 33 |
+
# Sex input with helper text
|
| 34 |
+
sex_male = gr.Radio(label="Sex", choices=[1, 0], value=1, info="Select your sex: 1 for Male, 0 for Female.")
|
| 35 |
+
|
| 36 |
+
# Cigarettes per day input with helper text
|
| 37 |
+
cigs_per_day = gr.Slider(label="Cigarettes per Day", minimum=0, maximum=60, value=10, step=1, info="Enter the number of cigarettes you smoke per day (0-60).")
|
| 38 |
+
|
| 39 |
+
# Total cholesterol input with helper text
|
| 40 |
+
tot_chol = gr.Slider(label="Total Cholesterol (mg/dL)", minimum=100, maximum=400, value=200, step=1, info="Enter your total cholesterol level (100-400 mg/dL).")
|
| 41 |
+
|
| 42 |
+
# Systolic blood pressure input with helper text
|
| 43 |
+
sys_bp = gr.Slider(label="Systolic Blood Pressure (mmHg)", minimum=90, maximum=200, value=120, step=1, info="Enter your systolic blood pressure (90-200 mmHg).")
|
| 44 |
+
|
| 45 |
+
# Glucose input with helper text
|
| 46 |
+
glucose = gr.Slider(label="Glucose Level (mg/dL)", minimum=50, maximum=300, value=100, step=1, info="Enter your glucose level (50-300 mg/dL).")
|
| 47 |
+
|
| 48 |
+
# Predict button and output
|
| 49 |
+
predict_btn = gr.Button("Predict")
|
| 50 |
+
output = gr.Textbox(label="Prediction")
|
| 51 |
+
|
| 52 |
+
# Set up the prediction process
|
| 53 |
+
predict_btn.click(predict_heart_disease, inputs=[age, sex_male, cigs_per_day, tot_chol, sys_bp, glucose], outputs=output)
|
| 54 |
+
|
| 55 |
+
# Launch the interface
|
| 56 |
+
interface.launch(share=True)
|
logistic_model_pipeline.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:51eaff70710679311a8f950e382987874caa650264f9d05041a089d0a9852f02
|
| 3 |
+
size 1886
|
requirement.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
numpy
|
| 3 |
+
statsmodels
|
| 4 |
+
scipy
|
| 5 |
+
matplotlib
|
| 6 |
+
scikit-learn
|
| 7 |
+
imbalanced-learn
|
| 8 |
+
gradio
|
| 9 |
+
joblib
|