File size: 4,487 Bytes
a82c14d
192bc6c
a82c14d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e9925d
 
0d6574e
a82c14d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192bc6c
8cb8f55
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import pickle
import streamlit as st
from streamlit_option_menu import option_menu

# ================== PAGE CONFIG ==================
st.set_page_config(
    page_title="Smart Health AI",
    page_icon="🧠",
    layout="wide",
)

# ================== LOAD MODELS ==================
def load_model(file):
    try:
        return pickle.load(open(file, "rb"))
    except:
        st.error(f"❌ Could not load model: {file}")
        return None

diabetes_model   = load_model("src/models/diabetes_model.sav")
heart_model      = load_model("src/models/heart_model.sav")
parkinson_model  = load_model("src/models/parkinsons_model.sav")

# ================== SIDEBAR MENU ==================
with st.sidebar:
    st.title("🩺 Smart Health AI")
    selected = option_menu(
        "Main Menu",
        ["Diabetes Prediction", "Heart Disease Prediction", "Parkinson's Prediction"],
        icons=["activity", "heart", "person"],
        default_index=0
    )

# ================== INPUT FUNCTIONS ==================

# --------- Diabetes Inputs ---------
def get_diabetes_input():
    col1, col2, col3 = st.columns(3)
    Pregnancies = col1.number_input('Pregnancies', 0)
    Glucose = col2.number_input('Glucose Level', 0.0)
    BloodPressure = col3.number_input('Blood Pressure', 0.0)
    SkinThickness = col1.number_input('Skin Thickness', 0.0)
    Insulin = col2.number_input('Insulin Level', 0.0)
    BMI = col3.number_input('BMI', 0.0)
    DPF = col1.number_input('Diabetes Pedigree Function', 0.0)
    Age = col2.number_input('Age', 0)
    return [Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DPF, Age]


# --------- Heart Inputs ---------
def get_heart_input():
    cols = st.columns(4)
    age      = cols[0].number_input("Age", 0)
    sex      = cols[1].selectbox("Sex", [0,1])
    cp       = cols[2].selectbox("Chest Pain Type (0–3)", [0,1,2,3])
    trestbps = cols[3].number_input("Resting Blood Pressure", 0)

    chol     = cols[0].number_input("Cholesterol", 0)
    fbs      = cols[1].selectbox("Fasting Sugar > 120 mg/dl", [0,1])
    restecg  = cols[2].selectbox("Rest ECG", [0,1,2])
    thalach  = cols[3].number_input("Max Heart Rate", 0)

    exang    = cols[0].selectbox("Exercise Angina", [0,1])
    oldpeak  = cols[1].number_input("ST Depression", 0.0)
    slope    = cols[2].selectbox("Slope", [0,1,2])
    ca       = cols[3].selectbox("Number of Major Vessels (0–4)", [0,1,2,3,4])
    thal     = cols[0].selectbox("Thal", [0,1,2,3])

    return [age, sex, cp, trestbps, chol, fbs, restecg,
            thalach, exang, oldpeak, slope, ca, thal]


# --------- Parkinson Inputs ---------
def get_parkinson_input():
    params = [
        "MDVP:Fo(Hz)", "MDVP:Fhi(Hz)", "MDVP:Flo(Hz)", "MDVP:Jitter(%)",
        "MDVP:Jitter(Abs)", "MDVP:RAP", "MDVP:PPQ", "Jitter:DDP",
        "MDVP:Shimmer", "MDVP:Shimmer(dB)", "Shimmer:APQ3",
        "Shimmer:APQ5", "MDVP:APQ", "Shimmer:DDA", "NHR", "HNR",
        "RPDE", "DFA", "spread1", "spread2", "D2", "PPE"
    ]

    cols = st.columns(3)
    values = []
    for i, p in enumerate(params):
        values.append(cols[i % 3].number_input(p, value=0.0))
    return values


# ================== PREDICT FUNCTION ==================
def predict(model, data):
    return model.predict([data])[0]


# ================== MAIN APP ==================
if selected == "Diabetes Prediction":
    st.header("🩸 Diabetes Prediction")
    data = get_diabetes_input()
    if st.button("Predict"):
        result = predict(diabetes_model, data)
        if result == 1:
            st.error("⚠️ The person is diabetic.")
        else:
            st.success("✅ The person is not diabetic.")

elif selected == "Heart Disease Prediction":
    st.header("❤️ Heart Disease Prediction")
    data = get_heart_input()
    if st.button("Predict Heart Disease"):
        result = predict(heart_model, data)
        if result == 1:
            st.error("⚠️ The patient is at risk of heart disease.")
        else:
            st.success("✅ The heart is healthy.")

elif selected == "Parkinson's Prediction":
    st.header("🧠 Parkinson's Detection")
    data = get_parkinson_input()
    if st.button("Predict Parkinson's"):
        result = predict(parkinson_model, data)
        if result == 1:
            st.error("⚠️ Parkinson's Detected.")
        else:
            st.success("✅ No Parkinson's signs detected.")

st.markdown("---")
st.markdown("Developed by Eng Youssef Samy | AI Smart Health")