Spaces:
Sleeping
Sleeping
hackerbyhobby
commited on
testing
Browse files- README.md +6 -4
- app.py +73 -0
- feature_names.json +1 -0
- optimized_heart_failure_model.pkl +3 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
---
|
2 |
title: Heartfailure
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Heartfailure
|
3 |
+
emoji: 🦀
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.6.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: Model Predicting Heart Failure
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import pandas as pd
|
4 |
+
import json
|
5 |
+
|
6 |
+
# Load the trained model
|
7 |
+
model = joblib.load("optimized_heart_failure_model.pkl")
|
8 |
+
|
9 |
+
# Load feature names used during training
|
10 |
+
with open("feature_names.json", "r") as f:
|
11 |
+
feature_names = json.load(f)
|
12 |
+
|
13 |
+
# Define the prediction function
|
14 |
+
def predict_heart_failure(age_category, alcohol_drinkers, chest_scan, covid_positive, physical_health_days, mental_health_days, sleep_hours, bmi):
|
15 |
+
# Initialize all features to 0
|
16 |
+
input_data = {feature: 0 for feature in feature_names}
|
17 |
+
|
18 |
+
# Handle Age Category
|
19 |
+
input_data[f"AgeCategory_{age_category}"] = 1 # Set the selected age category to 1
|
20 |
+
|
21 |
+
# Handle categorical inputs
|
22 |
+
input_data[f"AlcoholDrinkers_{alcohol_drinkers}"] = 1 # Alcohol Drinkers
|
23 |
+
input_data[f"ChestScan_{chest_scan}"] = 1 # Chest Scan
|
24 |
+
input_data[f"CovidPos_{covid_positive}"] = 1 # Covid Positive
|
25 |
+
|
26 |
+
# Handle numeric inputs
|
27 |
+
input_data["PhysicalHealthDays"] = physical_health_days
|
28 |
+
input_data["MentalHealthDays"] = mental_health_days
|
29 |
+
input_data["SleepHours"] = sleep_hours
|
30 |
+
input_data["BMI"] = bmi
|
31 |
+
|
32 |
+
# Create a DataFrame with the required feature names
|
33 |
+
input_df = pd.DataFrame([input_data])
|
34 |
+
|
35 |
+
# Ensure all required features are present
|
36 |
+
for feature in feature_names:
|
37 |
+
if feature not in input_df.columns:
|
38 |
+
input_df[feature] = 0 # Fill missing features with default value (e.g., 0)
|
39 |
+
|
40 |
+
# Ensure no extra features are included
|
41 |
+
input_df = input_df[feature_names]
|
42 |
+
|
43 |
+
# Make a prediction
|
44 |
+
prediction = model.predict(input_df)[0]
|
45 |
+
return "High likelihood of heart failure" if prediction == 1 else "Low likelihood of heart failure"
|
46 |
+
|
47 |
+
# Define Gradio inputs
|
48 |
+
gradio_inputs = [
|
49 |
+
gr.Radio(
|
50 |
+
["18-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75-79", "80 or older"],
|
51 |
+
label="Age Category"
|
52 |
+
),
|
53 |
+
gr.Radio(["Yes", "No"], label="Alcohol Drinkers"),
|
54 |
+
gr.Radio(["Yes", "No"], label="Chest Scan"),
|
55 |
+
gr.Radio(["Yes", "No"], label="COVID Positive"),
|
56 |
+
gr.Slider(0, 30, step=1, label="Physical Health Days"),
|
57 |
+
gr.Slider(0, 30, step=1, label="Mental Health Days"),
|
58 |
+
gr.Slider(0, 12, step=0.5, label="Sleep Hours"),
|
59 |
+
gr.Slider(10, 50, step=0.1, label="BMI")
|
60 |
+
]
|
61 |
+
|
62 |
+
# Set up the Gradio interface
|
63 |
+
interface = gr.Interface(
|
64 |
+
fn=predict_heart_failure,
|
65 |
+
inputs=gradio_inputs,
|
66 |
+
outputs="text",
|
67 |
+
title="Heart Failure Risk Prediction",
|
68 |
+
description="This app predicts the likelihood of heart failure based on health and lifestyle inputs."
|
69 |
+
)
|
70 |
+
|
71 |
+
# Launch the app
|
72 |
+
if __name__ == "__main__":
|
73 |
+
interface.launch()
|
feature_names.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
["PhysicalHealthDays", "MentalHealthDays", "SleepHours", "HeightInMeters", "WeightInKilograms", "BMI", "State_Alaska", "State_Arizona", "State_Arkansas", "State_California", "State_Colorado", "State_Connecticut", "State_Delaware", "State_District of Columbia", "State_Florida", "State_Georgia", "State_Guam", "State_Hawaii", "State_Idaho", "State_Illinois", "State_Indiana", "State_Iowa", "State_Kansas", "State_Kentucky", "State_Louisiana", "State_Maine", "State_Maryland", "State_Massachusetts", "State_Michigan", "State_Minnesota", "State_Mississippi", "State_Missouri", "State_Montana", "State_Nebraska", "State_Nevada", "State_New Hampshire", "State_New Jersey", "State_New Mexico", "State_New York", "State_North Carolina", "State_North Dakota", "State_Ohio", "State_Oklahoma", "State_Oregon", "State_Pennsylvania", "State_Puerto Rico", "State_Rhode Island", "State_South Carolina", "State_South Dakota", "State_Tennessee", "State_Texas", "State_Utah", "State_Vermont", "State_Virgin Islands", "State_Virginia", "State_Washington", "State_West Virginia", "State_Wisconsin", "State_Wyoming", "Sex_Male", "GeneralHealth_Fair", "GeneralHealth_Good", "GeneralHealth_Poor", "GeneralHealth_Very good", "LastCheckupTime_Within past 2 years (1 year but less than 2 years ago)", "LastCheckupTime_Within past 5 years (2 years but less than 5 years ago)", "LastCheckupTime_Within past year (anytime less than 12 months ago)", "PhysicalActivities_Yes", "RemovedTeeth_6 or more, but not all", "RemovedTeeth_All", "RemovedTeeth_None of them", "HadStroke_Yes", "HadAsthma_Yes", "HadSkinCancer_Yes", "HadCOPD_Yes", "HadDepressiveDisorder_Yes", "HadKidneyDisease_Yes", "HadArthritis_Yes", "HadDiabetes_No, pre-diabetes or borderline diabetes", "HadDiabetes_Yes", "HadDiabetes_Yes, but only during pregnancy (female)", "DeafOrHardOfHearing_Yes", "BlindOrVisionDifficulty_Yes", "DifficultyConcentrating_Yes", "DifficultyWalking_Yes", "DifficultyDressingBathing_Yes", "DifficultyErrands_Yes", "SmokerStatus_Current smoker - now smokes some days", "SmokerStatus_Former smoker", "SmokerStatus_Never smoked", "ECigaretteUsage_Not at all (right now)", "ECigaretteUsage_Use them every day", "ECigaretteUsage_Use them some days", "ChestScan_Yes", "RaceEthnicityCategory_Hispanic", "RaceEthnicityCategory_Multiracial, Non-Hispanic", "RaceEthnicityCategory_Other race only, Non-Hispanic", "RaceEthnicityCategory_White only, Non-Hispanic", "AgeCategory_Age 25 to 29", "AgeCategory_Age 30 to 34", "AgeCategory_Age 35 to 39", "AgeCategory_Age 40 to 44", "AgeCategory_Age 45 to 49", "AgeCategory_Age 50 to 54", "AgeCategory_Age 55 to 59", "AgeCategory_Age 60 to 64", "AgeCategory_Age 65 to 69", "AgeCategory_Age 70 to 74", "AgeCategory_Age 75 to 79", "AgeCategory_Age 80 or older", "AlcoholDrinkers_Yes", "HIVTesting_Yes", "FluVaxLast12_Yes", "PneumoVaxEver_Yes", "TetanusLast10Tdap_Yes, received Tdap", "TetanusLast10Tdap_Yes, received tetanus shot but not sure what type", "TetanusLast10Tdap_Yes, received tetanus shot, but not Tdap", "HighRiskLastYear_Yes", "CovidPos_Tested positive using home test without a health professional", "CovidPos_Yes"]
|
optimized_heart_failure_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b38947d94cf77ec9b86bc963fcb91cb396c025cecfa499e7f576addf67b411a1
|
3 |
+
size 665007513
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
joblib
|
4 |
+
scikit-learn
|