Files changed (3) hide show
  1. README.md +4 -77
  2. app.py +4 -240
  3. requirements.txt +0 -4
README.md CHANGED
@@ -1,85 +1,12 @@
1
  ---
2
- title: Alzheimer's Disease Risk Predictor
3
- emoji: 🧠
4
- colorFrom: purple
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.2.0
8
  app_file: app.py
9
  pinned: false
10
- license: mit
11
  ---
12
 
13
- # 🧠 Alzheimer's Disease Risk Predictor
14
-
15
- An AI-powered tool for assessing Alzheimer's disease risk using biomarkers, clinical markers, and cognitive assessment data.
16
-
17
- ## 📋 Features
18
-
19
- This application predicts the probability of three cognitive states:
20
- - **AD (Alzheimer's Disease)** - High probability of Alzheimer's Disease
21
- - **MCI (Mild Cognitive Impairment)** - Moderate cognitive decline
22
- - **CN (Cognitively Normal)** - Normal cognitive function
23
-
24
- ## 🔬 Input Parameters
25
-
26
- ### Diagnostic Criteria (1)
27
- | Parameter | Values | Description |
28
- |-----------|--------|-------------|
29
- | DXMDES | 1, -9 | MCI Criteria Met (1 = Yes, -9 = Missing) |
30
-
31
- ### Biomarkers (8)
32
- | Parameter | Unit | Description |
33
- |-----------|------|-------------|
34
- | Aβ40 | pg/mL | Amyloid-beta 40 concentration |
35
- | Aβ42 | pg/mL | Amyloid-beta 42 concentration |
36
- | pTau181 | pg/mL | Phosphorylated Tau 181 |
37
- | pTau217 | pg/mL | Phosphorylated Tau 217 |
38
- | npTau217 | pg/mL | Non-phosphorylated Tau 217 |
39
- | GFAP | pg/mL | Glial Fibrillary Acidic Protein |
40
- | NfL | pg/mL | Neurofilament Light Chain |
41
- | Aβ Ratio | - | Amyloid-beta 42/40 ratio |
42
-
43
- ### Clinical Markers (5)
44
- | Parameter | Unit | Description |
45
- |-----------|------|-------------|
46
- | MMSE Score | 0-30 | Mini-Mental State Examination |
47
- | DHA | μg/mL | Docosahexaenoic Acid |
48
- | Formic Acid | μM | Formic Acid concentration |
49
- | Lactoferrin | ng/mL | Lactoferrin level |
50
- | NTP | μM | Nucleotide Triphosphate |
51
-
52
- ### Cognitive Assessment - DXMPTR (6)
53
- | Assessment | Description |
54
- |------------|-------------|
55
- | DXMPTR1 | Subjective memory complaint |
56
- | DXMPTR2 | Informant memory complaint |
57
- | DXMPTR3 | Change in general cognitive function |
58
- | DXMPTR4 | Change in activities of daily living |
59
- | DXMPTR5 | Objective memory impairment for age/education |
60
- | DXMPTR6 | Not demented by clinical criteria |
61
-
62
- Each DXMPTR assessment accepts: **Yes** (1), **Maybe** (0.5), or **No** (0)
63
-
64
- ## 📊 Output
65
-
66
- The model provides:
67
- 1. **Probability percentages** for each category (AD, MCI, CN)
68
- 2. **Highest risk assessment** with the most likely category highlighted
69
- 3. **Clinical interpretation** with recommendations
70
-
71
- ## 🚀 Usage
72
-
73
- 1. Set DXMDES diagnostic criteria
74
- 2. Enter all biomarker values
75
- 3. Enter clinical marker measurements
76
- 4. Complete the cognitive assessment questionnaire
77
- 5. Click "Analyze Risk" to get the prediction
78
-
79
- ## ⚠️ Disclaimer
80
-
81
- This tool is for **educational and research purposes only**. It should not be used as a substitute for professional medical diagnosis. Always consult qualified healthcare professionals for medical advice and diagnosis.
82
-
83
- ## 📄 License
84
-
85
- MIT License
 
1
  ---
2
+ title: Alzheimers ML
3
+ emoji: 👀
4
+ colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.2.0
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,243 +1,7 @@
1
  import gradio as gr
2
- import pickle
3
- import numpy as np
4
 
5
- # Load the model and label encoder
6
- with open("model.pkl", "rb") as f:
7
- model = pickle.load(f)
8
 
9
- with open("label_encoder.pkl", "rb") as f:
10
- label_encoder = pickle.load(f)
11
-
12
- # DXMPTR mapping: Yes=1, Maybe=0.5, No=0
13
- DXMPTR_MAP = {"Yes": 1, "Maybe": 0.5, "No": 0}
14
-
15
- def predict(
16
- # DXMDES
17
- dxmdes,
18
- # Biomarkers (8)
19
- ab40, ab42, ptau181, ptau217, nptau217, gfap, nfl, ab_ratio,
20
- # Clinical Markers (5)
21
- mmse_score, dha, formic_acid, lactoferrin, ntp,
22
- # Cognitive Assessment - DXMPTR (6)
23
- dxmptr1, dxmptr2, dxmptr3, dxmptr4, dxmptr5, dxmptr6
24
- ):
25
- """
26
- Predict Alzheimer's disease risk based on biomarkers, clinical markers, and cognitive assessment.
27
- Total: 19 raw inputs + 7 engineered features = 26 features
28
- """
29
- # Convert DXMPTR values
30
- dxmptr1_val = DXMPTR_MAP[dxmptr1]
31
- dxmptr2_val = DXMPTR_MAP[dxmptr2]
32
- dxmptr3_val = DXMPTR_MAP[dxmptr3]
33
- dxmptr4_val = DXMPTR_MAP[dxmptr4]
34
- dxmptr5_val = DXMPTR_MAP[dxmptr5]
35
- dxmptr6_val = DXMPTR_MAP[dxmptr6]
36
-
37
- # ========================================================================
38
- # FEATURE ENGINEERING (same as training notebook)
39
- # ========================================================================
40
-
41
- # 1. pTau217/Aβ42 ratio
42
- ptau217_ab42_ratio = ptau217 / (ab42 + 1e-10)
43
-
44
- # 2. pTau181/Aβ42 ratio
45
- ptau181_ab42_ratio = ptau181 / (ab42 + 1e-10)
46
-
47
- # 3. NfL/GFAP ratio (neurodegeneration vs neuroinflammation)
48
- nfl_gfap_ratio = nfl / (gfap + 1e-10)
49
-
50
- # 4. Composite biomarker burden score
51
- biomarker_burden = ptau217 + gfap + nfl - (ab42 * 0.01)
52
-
53
- # 5. DXMPTR aggregations
54
- dxmptr_values = [dxmptr1_val, dxmptr2_val, dxmptr3_val, dxmptr4_val, dxmptr5_val, dxmptr6_val]
55
- dxmptr_mean = np.mean(dxmptr_values)
56
- dxmptr_std = np.std(dxmptr_values)
57
-
58
- # Create feature array with all 26 features
59
- # Order MUST match FEATURE_COLUMNS from training notebook:
60
- # ['DXMDES', 'DXMPTR1-6', 'Abeta40', 'Abeta42', 'Abeta_ratio', 'GFAP', 'NfL',
61
- # 'npTau217', 'pTau181', 'pTau217', 'DHA', 'FORMICACID', 'LACTOFERRIN', 'MMSE', 'NTP']
62
- # + 6 engineered features
63
-
64
- # DXMDES value (from user input)
65
- dxmdes_val = dxmdes
66
-
67
- features = np.array([[
68
- # Raw features (20) - exact order from FEATURE_COLUMNS
69
- dxmdes_val,
70
- dxmptr1_val, dxmptr2_val, dxmptr3_val, dxmptr4_val, dxmptr5_val, dxmptr6_val,
71
- ab40, ab42, ab_ratio,
72
- gfap, nfl,
73
- nptau217, ptau181, ptau217,
74
- dha, formic_acid, lactoferrin, mmse_score, ntp,
75
- # Engineered features (6)
76
- ptau217_ab42_ratio,
77
- ptau181_ab42_ratio,
78
- nfl_gfap_ratio,
79
- biomarker_burden,
80
- dxmptr_mean,
81
- dxmptr_std
82
- ]])
83
-
84
- # Get probability predictions
85
- probabilities = model.predict_proba(features)[0]
86
-
87
- # Get class names from label encoder
88
- class_names = label_encoder.classes_
89
-
90
- # Create probability dictionary
91
- prob_dict = {}
92
- for i, class_name in enumerate(class_names):
93
- prob_dict[class_name] = probabilities[i] * 100
94
-
95
- # Find highest risk
96
- highest_risk_idx = np.argmax(probabilities)
97
- highest_risk_class = class_names[highest_risk_idx]
98
- highest_risk_prob = probabilities[highest_risk_idx] * 100
99
-
100
- # Format result strings
101
- prob_results = ""
102
- for class_name in ["AD", "MCI", "CN"]:
103
- if class_name in prob_dict:
104
- prob_results += f"**{class_name}**: {prob_dict[class_name]:.2f}%\n\n"
105
-
106
- # Final verdict with styling
107
- final_result = f"## 🎯 Highest Risk: **{highest_risk_class}** ({highest_risk_prob:.2f}%)"
108
-
109
- # Risk interpretation
110
- risk_interpretation = ""
111
- if highest_risk_class == "AD":
112
- risk_interpretation = "⚠️ **Alzheimer's Disease (AD)** - High probability of Alzheimer's Disease. Please consult a neurologist for further evaluation."
113
- elif highest_risk_class == "MCI":
114
- risk_interpretation = "⚡ **Mild Cognitive Impairment (MCI)** - Moderate cognitive decline detected. Regular monitoring and lifestyle modifications recommended."
115
- else:
116
- risk_interpretation = "✅ **Cognitively Normal (CN)** - No significant cognitive impairment detected. Continue with healthy lifestyle practices."
117
-
118
- return prob_results, final_result, risk_interpretation
119
-
120
- # Create the Gradio interface
121
- with gr.Blocks(title="Alzheimer's Disease Risk Predictor") as demo:
122
- gr.Markdown(
123
- """
124
- # 🧠 Alzheimer's Disease Risk Predictor
125
- AI-powered assessment using biomarkers, clinical markers, and cognitive evaluation
126
- """
127
- )
128
-
129
- with gr.Row():
130
- with gr.Column(scale=1):
131
- gr.Markdown("### 🧬 Biomarkers")
132
- with gr.Row():
133
- ab40 = gr.Number(label="Aβ40 (pg/mL)", value=0.12, info="Amyloid-beta 40 concentration")
134
- ab42 = gr.Number(label="Aβ42 (pg/mL)", value=0.154, info="Amyloid-beta 42 concentration")
135
- with gr.Row():
136
- ptau181 = gr.Number(label="pTau181 (pg/mL)", value=0.65, info="Phosphorylated Tau 181")
137
- ptau217 = gr.Number(label="pTau217 (pg/mL)", value=1.78, info="Phosphorylated Tau 217")
138
- with gr.Row():
139
- nptau217 = gr.Number(label="npTau217 (pg/mL)", value=0.42, info="Non-phosphorylated Tau 217")
140
- gfap = gr.Number(label="GFAP (pg/mL)", value=0.79, info="Glial Fibrillary Acidic Protein")
141
- with gr.Row():
142
- nfl = gr.Number(label="NfL (pg/mL)", value=1.84, info="Neurofilament Light Chain")
143
- ab_ratio = gr.Number(label="Aβ Ratio (Aβ42/Aβ40)", value=0.44, info="Amyloid-beta 42/40 ratio")
144
-
145
- gr.Markdown("### 🏥 Clinical Markers")
146
- with gr.Row():
147
- mmse_score = gr.Number(label="MMSE Score", value=20, minimum=0, maximum=30, info="Mini-Mental State Examination (0-30)")
148
- dha = gr.Number(label="DHA (μg/mL)", value=35633.35, info="Docosahexaenoic Acid")
149
- with gr.Row():
150
- formic_acid = gr.Number(label="Formic Acid (μM)", value=489.7, info="Formic Acid concentration")
151
- lactoferrin = gr.Number(label="Lactoferrin (ng/mL)", value=7099.47, info="Lactoferrin level")
152
- ntp = gr.Number(label="NTP (μM)", value=2.39, info="Nucleotide Triphosphate")
153
-
154
- with gr.Column(scale=1):
155
- gr.Markdown("### 📋 Diagnostic Criteria")
156
- dxmdes = gr.Radio(
157
- choices=[1, -9],
158
- value=1,
159
- label="DXMDES: MCI Criteria Met",
160
- info="1 = Yes (criteria met), -9 = Missing/Unknown"
161
- )
162
-
163
- gr.Markdown("### 📋 Cognitive Assessment (DXMPTR)")
164
-
165
- dxmptr1 = gr.Radio(
166
- choices=["Yes", "Maybe", "No"],
167
- value="Yes",
168
- label="DXMPTR1: Subjective memory complaint",
169
- info="Patient reports memory issues"
170
- )
171
- dxmptr2 = gr.Radio(
172
- choices=["Yes", "Maybe", "No"],
173
- value="Yes",
174
- label="DXMPTR2: Informant memory complaint",
175
- info="Family/caregiver reports memory issues"
176
- )
177
- dxmptr3 = gr.Radio(
178
- choices=["Yes", "Maybe", "No"],
179
- value="Yes",
180
- label="DXMPTR3: Change in general cognitive function",
181
- info="Observable cognitive changes"
182
- )
183
- dxmptr4 = gr.Radio(
184
- choices=["Yes", "Maybe", "No"],
185
- value="Yes",
186
- label="DXMPTR4: Change in activities of daily living",
187
- info="Impact on daily activities"
188
- )
189
- dxmptr5 = gr.Radio(
190
- choices=["Yes", "Maybe", "No"],
191
- value="Yes",
192
- label="DXMPTR5: Objective memory impairment",
193
- info="For age/education adjusted"
194
- )
195
- dxmptr6 = gr.Radio(
196
- choices=["Yes", "Maybe", "No"],
197
- value="Yes",
198
- label="DXMPTR6: Not demented by clinical criteria",
199
- info="Clinical dementia criteria not met"
200
- )
201
-
202
- gr.Markdown("---")
203
-
204
- predict_btn = gr.Button("🔍 Analyze Risk", variant="primary", size="lg")
205
-
206
- gr.Markdown("### 📊 Results")
207
-
208
- with gr.Row():
209
- with gr.Column():
210
- prob_output = gr.Markdown(label="Probability Distribution")
211
- with gr.Column():
212
- final_output = gr.Markdown(label="Final Assessment")
213
-
214
- interpretation_output = gr.Markdown(label="Clinical Interpretation")
215
-
216
- predict_btn.click(
217
- fn=predict,
218
- inputs=[
219
- dxmdes,
220
- ab40, ab42, ptau181, ptau217, nptau217, gfap, nfl, ab_ratio,
221
- mmse_score, dha, formic_acid, lactoferrin, ntp,
222
- dxmptr1, dxmptr2, dxmptr3, dxmptr4, dxmptr5, dxmptr6
223
- ],
224
- outputs=[prob_output, final_output, interpretation_output]
225
- )
226
-
227
- gr.Markdown(
228
- """
229
- ---
230
- ### ℹ️ About This Tool
231
-
232
- This AI-powered tool analyzes multiple biomarkers and clinical indicators to assess Alzheimer's disease risk:
233
-
234
- - **AD (Alzheimer's Disease)**: Indicates high probability of Alzheimer's Disease
235
- - **MCI (Mild Cognitive Impairment)**: Indicates moderate cognitive decline
236
- - **CN (Cognitively Normal)**: Indicates normal cognitive function
237
-
238
- > ⚠️ **Disclaimer**: This tool is for educational and research purposes only. It should not be used as a substitute for professional medical diagnosis. Always consult qualified healthcare professionals for medical advice.
239
- """
240
- )
241
-
242
- if __name__ == "__main__":
243
- demo.launch(css=".gradio-container { max-width: 1000px !important; margin: auto !important; }")
 
1
  import gradio as gr
 
 
2
 
3
+ def greet(name):
4
+ return "Hello " + name + "!!"
 
5
 
6
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt DELETED
@@ -1,4 +0,0 @@
1
- gradio>=4.0.0
2
- numpy
3
- scikit-learn
4
- lightgbm