Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -113,7 +113,7 @@ def _saliency_figure(sal, p_mean):
|
|
| 113 |
|
| 114 |
# ── Left: 7×7 network heatmap ──────────────────────────────────────────
|
| 115 |
ax = axes[0]
|
| 116 |
-
ax.set_facecolor("#
|
| 117 |
im = ax.imshow(net_sal, cmap="inferno", aspect="auto", interpolation="nearest")
|
| 118 |
ax.set_title("FC Saliency by Brain Network", color="#bbb", fontsize=11, pad=14, fontweight="bold")
|
| 119 |
|
|
@@ -145,7 +145,7 @@ def _saliency_figure(sal, p_mean):
|
|
| 145 |
|
| 146 |
# ── Right: network importance bar chart ────────────────────────────────
|
| 147 |
ax2 = axes[1]
|
| 148 |
-
ax2.set_facecolor("#
|
| 149 |
ax2.tick_params(colors="#555", labelsize=9)
|
| 150 |
|
| 151 |
order = net_imp.argsort()[::-1]
|
|
@@ -173,7 +173,7 @@ def _saliency_figure(sal, p_mean):
|
|
| 173 |
)
|
| 174 |
plt.tight_layout()
|
| 175 |
buf = io.BytesIO()
|
| 176 |
-
plt.savefig(buf, format="png", dpi=140, bbox_inches="tight", facecolor="#
|
| 177 |
plt.close(fig)
|
| 178 |
buf.seek(0)
|
| 179 |
return Image.open(buf).copy()
|
|
@@ -222,54 +222,52 @@ def run_gcn(file_path):
|
|
| 222 |
except Exception:
|
| 223 |
sal_img = None
|
| 224 |
|
| 225 |
-
# ── Verdict
|
| 226 |
if p_mean > 0.6:
|
| 227 |
-
col, label = "#
|
| 228 |
-
grad = "linear-gradient(135deg,#1a0a0b,#2d1015)"
|
| 229 |
detail = f"{consensus}/4 site-blind models agree"
|
| 230 |
elif p_mean < 0.4:
|
| 231 |
-
col, label = "#
|
| 232 |
-
grad = "linear-gradient(135deg,#0a1a0d,#102515)"
|
| 233 |
detail = f"{4-consensus}/4 site-blind models agree"
|
| 234 |
else:
|
| 235 |
-
col, label = "#
|
| 236 |
-
grad = "linear-gradient(135deg,#1a1208,#251c10)"
|
| 237 |
detail = "Clinical review required"
|
| 238 |
|
| 239 |
-
verdict = f"""<div style="background:
|
| 240 |
-
<div style="font-size:0.
|
| 241 |
-
<div style="font-size:
|
| 242 |
-
<div style="display:flex;gap:
|
| 243 |
-
<div><div style="font-size:1.
|
| 244 |
-
<div><div style="font-size:1.
|
| 245 |
-
<div><div style="font-size:
|
| 246 |
</div></div>"""
|
| 247 |
|
| 248 |
-
# ── Ensemble
|
| 249 |
rows = ""
|
| 250 |
for site, p in per_model:
|
| 251 |
lbl = "ASD" if p > 0.5 else "TC"
|
| 252 |
-
clr = "#
|
| 253 |
-
rows += f"""<tr
|
| 254 |
-
<td style="padding:
|
| 255 |
-
<td style="padding:
|
| 256 |
-
<div style="background:{clr};height:
|
| 257 |
-
<td style="padding:
|
| 258 |
-
<td style="padding:
|
| 259 |
-
|
| 260 |
-
ensemble = f"""<div style="background:#
|
| 261 |
-
<div style="font-size:0.
|
| 262 |
<table style="width:100%;border-collapse:collapse">{rows}</table>
|
| 263 |
-
<div style="margin-top:
|
| 264 |
-
|
|
|
|
| 265 |
|
| 266 |
-
# ──
|
| 267 |
if p_mean > 0.6:
|
| 268 |
findings = ["Reduced DMN coherence (mPFC ↔ PCC)",
|
| 269 |
"Atypical salience network lateralization",
|
| 270 |
"Decreased long-range frontotemporal connectivity"]
|
| 271 |
imp = f"ASD-consistent connectivity profile ({conf:.1f}% confidence)."
|
| 272 |
-
cons = f"{consensus}/4 site-blind models agree
|
| 273 |
elif p_mean < 0.4:
|
| 274 |
findings = ["DMN coherence within normal range",
|
| 275 |
"Intact salience network organization",
|
|
@@ -283,16 +281,16 @@ def run_gcn(file_path):
|
|
| 283 |
imp = "Indeterminate. Full evaluation recommended."
|
| 284 |
cons = f"Only {consensus}/4 models agree — specialist input required."
|
| 285 |
|
| 286 |
-
fi = "".join(f"<li style='margin:
|
| 287 |
-
report = f"""<div style="background:#
|
| 288 |
-
<div style="font-size:0.
|
| 289 |
-
<div style="color:#
|
| 290 |
-
<div style="color:#
|
| 291 |
-
<ul style="margin:0 0
|
| 292 |
-
<div style="color:#
|
| 293 |
-
<div style="color:#
|
| 294 |
-
<div style="border-top:1px solid #
|
| 295 |
-
|
| 296 |
|
| 297 |
return verdict, ensemble, report, sal_img
|
| 298 |
|
|
@@ -300,207 +298,177 @@ def run_gcn(file_path):
|
|
| 300 |
# ── Static HTML sections ───────────────────────────────────────────────────
|
| 301 |
|
| 302 |
HEADER = """
|
| 303 |
-
<div style="padding:
|
| 304 |
-
<div style="
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
| 309 |
</div>
|
| 310 |
-
<div style="color:#
|
| 311 |
-
1 in 44 children is diagnosed with ASD
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
then translates raw connectivity patterns into structured clinical language a clinician can act on.
|
| 317 |
</div>
|
| 318 |
-
<div style="display:flex;gap:
|
| 319 |
-
<div style="
|
| 320 |
-
<
|
| 321 |
-
<
|
| 322 |
</div>
|
| 323 |
-
<div style="
|
| 324 |
-
<
|
| 325 |
-
<
|
| 326 |
</div>
|
| 327 |
-
<div style="
|
| 328 |
-
<
|
| 329 |
-
<
|
| 330 |
</div>
|
| 331 |
-
<div style="
|
| 332 |
-
<
|
| 333 |
-
<
|
| 334 |
</div>
|
| 335 |
</div>
|
| 336 |
</div>
|
| 337 |
"""
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
|
|
|
|
|
|
| 347 |
</div>
|
| 348 |
-
<div
|
| 349 |
-
<div style="font-size:
|
| 350 |
-
<div style="color:#
|
| 351 |
</div>
|
| 352 |
-
<div
|
| 353 |
-
<div style="font-size:
|
| 354 |
-
<div style="color:#
|
| 355 |
</div>
|
| 356 |
-
<div
|
| 357 |
-
<div style="font-size:
|
| 358 |
-
<div style="color:#
|
| 359 |
</div>
|
| 360 |
</div>
|
| 361 |
|
| 362 |
-
<img src="data:image/png;base64,{VAL_B64}" style="width:100%;border-radius:
|
| 363 |
-
<img src="data:image/png;base64,{AUC_B64}" style="width:100%;border-radius:
|
| 364 |
-
|
| 365 |
-
<div style="background:#
|
| 366 |
-
<table style="width:100%;border-collapse:collapse;font-size:0.
|
| 367 |
-
<thead><tr
|
| 368 |
-
<th style="padding:
|
| 369 |
-
<th style="padding:
|
| 370 |
-
<th style="padding:
|
| 371 |
-
<th style="padding:
|
| 372 |
-
<th style="padding:
|
| 373 |
-
<th style="padding:
|
| 374 |
</tr></thead>
|
| 375 |
-
<tbody>
|
| 376 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Caltech</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0051456</td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.742</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 377 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Caltech</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0051457</td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.183</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 378 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">CMU</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0050642</td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#f4a261;font-weight:700">INCONCL.</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.521</td><td style="padding:11px 16px;text-align:center;color:#f4a261;font-size:0.8rem">⚠ review</td></tr>
|
| 379 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">CMU</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0050646</td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.312</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 380 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Stanford</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0051160</td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.831</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 381 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Stanford</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0051161</td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.127</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 382 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Trinity</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0050232</td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#f4a261;font-weight:700">INCONCL.</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.487</td><td style="padding:11px 16px;text-align:center;color:#f4a261;font-size:0.8rem">⚠ review</td></tr>
|
| 383 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Trinity</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0050233</td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.241</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 384 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#555">Yale</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0050551</td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#e63946;font-weight:700">ASD</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.689</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 385 |
-
<tr><td style="padding:11px 16px;color:#555">Yale</td><td style="padding:11px 16px;color:#2a2a2a;font-size:0.8rem">0050552</td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center"><span style="color:#2dc653;font-weight:700">TC</span></td><td style="padding:11px 16px;text-align:center;color:#555">0.156</td><td style="padding:11px 16px;text-align:center;color:#2dc653">✓</td></tr>
|
| 386 |
-
</tbody>
|
| 387 |
</table>
|
| 388 |
</div>
|
| 389 |
-
<div style="margin-top:
|
| 390 |
Inconclusive predictions (0.4 < p < 0.6) surface borderline cases for clinical review rather than forcing a wrong label.
|
| 391 |
-
Zero confident misclassifications across
|
| 392 |
</div>
|
| 393 |
</div>
|
| 394 |
"""
|
| 395 |
|
| 396 |
ARCHITECTURE = """
|
| 397 |
-
<div
|
| 398 |
-
<div style="
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
K=16 learnable directions in ROI space.<br>
|
| 405 |
-
<span style="color:#888;font-family:monospace;font-size:0.82rem">M_kl = v_k · FC · v_l</span><br>
|
| 406 |
-
Compresses 19,900 FC features → 152 dims while preserving network structure. Each mode specializes to DMN, salience, FPN.
|
| 407 |
</div>
|
| 408 |
</div>
|
| 409 |
-
<div style="background:#
|
| 410 |
-
<div style="color:#
|
| 411 |
-
<div style="color:#
|
| 412 |
-
Adversarial site deconfounding (Ganin
|
| 413 |
</div>
|
| 414 |
</div>
|
| 415 |
-
<div style="background:#
|
| 416 |
-
<div style="color:#
|
| 417 |
-
<div style="color:#
|
| 418 |
-
4 models × 1 held-out site each.
|
| 419 |
</div>
|
| 420 |
</div>
|
| 421 |
</div>
|
| 422 |
|
| 423 |
-
<div style="background:#
|
| 424 |
-
<
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
<
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
│<br>
|
| 432 |
-
<span style="color:#f4a261">Brain Mode Decomposition</span> K=16<br>
|
| 433 |
-
M_kl = v_k · FC · v_l + std(v_k · bold)<br>
|
| 434 |
-
│ 152 features<br>
|
| 435 |
-
<span style="color:#f4a261">Shared Encoder</span> (MLP, dim=64)<br>
|
| 436 |
-
│<br>
|
| 437 |
-
┌──────┴──────────────────┐<br>
|
| 438 |
-
│ │<br>
|
| 439 |
-
<span style="color:#2dc653">ASD head</span> <span style="color:#1e1e1e">GRL(α) → site head</span><br>
|
| 440 |
-
minimize CE(ASD) <span style="color:#1a1a1a">maximize site confusion</span><br>
|
| 441 |
-
│<br>
|
| 442 |
-
<span style="color:#e63946">p(ASD)</span> + <span style="color:#777">gradient saliency on FC (real-time)</span>
|
| 443 |
-
</div>
|
| 444 |
-
|
| 445 |
-
<div style="background:#0f0f0f;border:1px solid #1e1e1e;border-radius:12px;overflow:hidden">
|
| 446 |
-
<table style="width:100%;border-collapse:collapse;font-size:0.85rem">
|
| 447 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#333;width:180px">Dataset</td><td style="padding:11px 16px;color:#888">ABIDE I — 1,102 subjects, 17 acquisition sites</td></tr>
|
| 448 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#333">Parcellation</td><td style="padding:11px 16px;color:#888">CC200 (Craddock 2012) — 200 functional ROIs</td></tr>
|
| 449 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#333">Architecture</td><td style="padding:11px 16px;color:#888">AdversarialBrainModeNetwork — K=16 modes, hidden_dim=64</td></tr>
|
| 450 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#333">Regularization</td><td style="padding:11px 16px;color:#888">GRL adversarial + orthogonality loss on brain modes</td></tr>
|
| 451 |
-
<tr style="border-bottom:1px solid #111"><td style="padding:11px 16px;color:#333">Validation</td><td style="padding:11px 16px;color:#888">LOSO AUC = <b style="color:#e63946">0.7872</b> across 529 held-out subjects</td></tr>
|
| 452 |
-
<tr><td style="padding:11px 16px;color:#333">Interpretability</td><td style="padding:11px 16px;color:#888">Real-time gradient saliency on 200×200 FC adjacency matrix</td></tr>
|
| 453 |
</table>
|
| 454 |
</div>
|
| 455 |
</div>
|
| 456 |
"""
|
| 457 |
|
| 458 |
AMD = """
|
| 459 |
-
<div
|
| 460 |
-
<div style="
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
<div style="
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
</div>
|
| 467 |
-
<div style="background:#0f0f0f;border:1px solid #1e1e1e;border-radius:12px;padding:24px;flex:1;min-width:120px;text-align:center">
|
| 468 |
-
<div style="font-size:2.4rem;font-weight:900;color:#f4a261;line-height:1">bf16</div>
|
| 469 |
-
<div style="color:#2a2a2a;font-size:0.7rem;margin-top:6px;text-transform:uppercase;letter-spacing:1px">No quantization</div>
|
| 470 |
-
</div>
|
| 471 |
-
<div style="background:#0f0f0f;border:1px solid #1e1e1e;border-radius:12px;padding:24px;flex:1;min-width:120px;text-align:center">
|
| 472 |
-
<div style="font-size:2.4rem;font-weight:900;color:white;line-height:1">7B</div>
|
| 473 |
-
<div style="color:#2a2a2a;font-size:0.7rem;margin-top:6px;text-transform:uppercase;letter-spacing:1px">Qwen2.5 params</div>
|
| 474 |
-
</div>
|
| 475 |
-
<div style="background:#0f0f0f;border:1px solid #1e1e1e;border-radius:12px;padding:24px;flex:1;min-width:120px;text-align:center">
|
| 476 |
-
<div style="font-size:2.4rem;font-weight:900;color:white;line-height:1">2K</div>
|
| 477 |
-
<div style="color:#2a2a2a;font-size:0.7rem;margin-top:6px;text-transform:uppercase;letter-spacing:1px">Domain examples</div>
|
| 478 |
-
</div>
|
| 479 |
-
<div style="background:#0f0f0f;border:1px solid #1e1e1e;border-radius:12px;padding:24px;flex:1;min-width:120px;text-align:center">
|
| 480 |
-
<div style="font-size:2.4rem;font-weight:900;color:white;line-height:1">r=16</div>
|
| 481 |
-
<div style="color:#2a2a2a;font-size:0.7rem;margin-top:6px;text-transform:uppercase;letter-spacing:1px">LoRA rank</div>
|
| 482 |
-
</div>
|
| 483 |
</div>
|
| 484 |
|
| 485 |
-
<div style="background:#
|
| 486 |
-
<table style="width:100%;border-collapse:collapse;font-size:0.
|
| 487 |
-
<tr
|
| 488 |
-
<tr style="border-
|
| 489 |
-
<tr style="border-
|
| 490 |
-
<tr style="border-
|
| 491 |
-
<tr style="border-
|
| 492 |
-
<tr><td style="padding:
|
| 493 |
</table>
|
| 494 |
</div>
|
| 495 |
|
| 496 |
-
<div style="display:
|
| 497 |
-
<div style="background:#
|
| 498 |
-
<div style="color:#
|
| 499 |
-
<div style="color:#
|
| 500 |
</div>
|
| 501 |
-
<div style="background:#
|
| 502 |
-
<div style="color:#
|
| 503 |
-
<div style="color:#
|
| 504 |
</div>
|
| 505 |
</div>
|
| 506 |
</div>
|
|
@@ -509,42 +477,60 @@ AMD = """
|
|
| 509 |
# ── UI ─────────────────────────────────────────────────────────────────────
|
| 510 |
|
| 511 |
css = """
|
| 512 |
-
body { background: #
|
| 513 |
-
.gradio-container { max-width:
|
| 514 |
-
.
|
| 515 |
-
.tab-nav
|
| 516 |
-
.tab-nav button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
footer { display: none !important; }
|
|
|
|
| 518 |
"""
|
| 519 |
|
| 520 |
with gr.Blocks(title="BrainConnect-ASD", css=css, theme=gr.themes.Base()) as demo:
|
| 521 |
gr.HTML(HEADER)
|
| 522 |
|
| 523 |
with gr.Tabs():
|
| 524 |
-
with gr.Tab("
|
| 525 |
-
file_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
verdict_html = gr.HTML()
|
| 527 |
ens_html = gr.HTML()
|
| 528 |
-
gr.HTML("<div style='margin-top:
|
| 529 |
sal_img = gr.Image(label="", type="pil", show_label=False)
|
| 530 |
rep_html = gr.HTML()
|
| 531 |
file_input.change(fn=run_gcn, inputs=file_input,
|
| 532 |
outputs=[verdict_html, ens_html, rep_html, sal_img])
|
| 533 |
-
|
| 534 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
gr.HTML(VALIDATION)
|
| 536 |
|
| 537 |
-
with gr.Tab("
|
| 538 |
gr.HTML(ARCHITECTURE)
|
| 539 |
|
| 540 |
-
with gr.Tab("
|
| 541 |
gr.HTML(AMD)
|
| 542 |
|
| 543 |
gr.HTML("""
|
| 544 |
-
<div style="text-align:center;padding:
|
| 545 |
-
Adversarial Brain-Mode GCN (
|
| 546 |
-
|
| 547 |
-
<a href="https://github.com/Yatsuiii/Brain-Connectivity-GCN" style="color:#222">GitHub</a>
|
| 548 |
</div>""")
|
| 549 |
|
| 550 |
print("Preloading models...")
|
|
|
|
| 113 |
|
| 114 |
# ── Left: 7×7 network heatmap ──────────────────────────────────────────
|
| 115 |
ax = axes[0]
|
| 116 |
+
ax.set_facecolor("#161922")
|
| 117 |
im = ax.imshow(net_sal, cmap="inferno", aspect="auto", interpolation="nearest")
|
| 118 |
ax.set_title("FC Saliency by Brain Network", color="#bbb", fontsize=11, pad=14, fontweight="bold")
|
| 119 |
|
|
|
|
| 145 |
|
| 146 |
# ── Right: network importance bar chart ────────────────────────────────
|
| 147 |
ax2 = axes[1]
|
| 148 |
+
ax2.set_facecolor("#161922")
|
| 149 |
ax2.tick_params(colors="#555", labelsize=9)
|
| 150 |
|
| 151 |
order = net_imp.argsort()[::-1]
|
|
|
|
| 173 |
)
|
| 174 |
plt.tight_layout()
|
| 175 |
buf = io.BytesIO()
|
| 176 |
+
plt.savefig(buf, format="png", dpi=140, bbox_inches="tight", facecolor="#0e1015")
|
| 177 |
plt.close(fig)
|
| 178 |
buf.seek(0)
|
| 179 |
return Image.open(buf).copy()
|
|
|
|
| 222 |
except Exception:
|
| 223 |
sal_img = None
|
| 224 |
|
| 225 |
+
# ── Verdict ──
|
| 226 |
if p_mean > 0.6:
|
| 227 |
+
col, label = "#ef4444", "ASD Indicated"
|
|
|
|
| 228 |
detail = f"{consensus}/4 site-blind models agree"
|
| 229 |
elif p_mean < 0.4:
|
| 230 |
+
col, label = "#22c55e", "Typical Control"
|
|
|
|
| 231 |
detail = f"{4-consensus}/4 site-blind models agree"
|
| 232 |
else:
|
| 233 |
+
col, label = "#f59e0b", "Inconclusive"
|
|
|
|
| 234 |
detail = "Clinical review required"
|
| 235 |
|
| 236 |
+
verdict = f"""<div style="background:#161922;border:1px solid #252a35;border-left:3px solid {col};padding:22px 26px;border-radius:8px;margin-top:14px">
|
| 237 |
+
<div style="font-size:0.65rem;color:#8b95a7;letter-spacing:2px;text-transform:uppercase;margin-bottom:6px;font-weight:500">Classification Result</div>
|
| 238 |
+
<div style="font-size:1.8rem;font-weight:600;color:{col};letter-spacing:-0.5px;line-height:1.1">{label}</div>
|
| 239 |
+
<div style="display:flex;gap:36px;margin-top:18px;flex-wrap:wrap">
|
| 240 |
+
<div><div style="font-size:1.3rem;font-weight:600;color:#f4f4f5;font-variant-numeric:tabular-nums">{conf:.1f}%</div><div style="color:#5e6675;font-size:0.7rem;margin-top:2px">Confidence</div></div>
|
| 241 |
+
<div><div style="font-size:1.3rem;font-weight:600;color:#f4f4f5;font-variant-numeric:tabular-nums">{p_mean:.3f}</div><div style="color:#5e6675;font-size:0.7rem;margin-top:2px">p(ASD)</div></div>
|
| 242 |
+
<div><div style="font-size:0.92rem;color:#cbd5e1;padding-top:8px">{detail}</div><div style="color:#5e6675;font-size:0.7rem;margin-top:2px">Ensemble vote</div></div>
|
| 243 |
</div></div>"""
|
| 244 |
|
| 245 |
+
# ── Ensemble ──
|
| 246 |
rows = ""
|
| 247 |
for site, p in per_model:
|
| 248 |
lbl = "ASD" if p > 0.5 else "TC"
|
| 249 |
+
clr = "#ef4444" if p > 0.5 else "#22c55e"
|
| 250 |
+
rows += f"""<tr>
|
| 251 |
+
<td style="padding:9px 0;color:#cbd5e1;font-weight:500;font-size:0.86rem;width:110px">{site}-blind</td>
|
| 252 |
+
<td style="padding:9px 14px;width:220px"><div style="background:#252a35;border-radius:2px;height:5px;width:200px;overflow:hidden">
|
| 253 |
+
<div style="background:{clr};height:5px;width:{int(p*100)}%"></div></div></td>
|
| 254 |
+
<td style="padding:9px 14px;color:{clr};font-weight:600;font-size:0.85rem;width:50px">{lbl}</td>
|
| 255 |
+
<td style="padding:9px 0;color:#8b95a7;font-size:0.84rem;font-variant-numeric:tabular-nums">p = {p:.3f}</td></tr>"""
|
| 256 |
+
|
| 257 |
+
ensemble = f"""<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 24px;margin-top:10px">
|
| 258 |
+
<div style="font-size:0.65rem;color:#8b95a7;letter-spacing:2px;text-transform:uppercase;margin-bottom:12px;font-weight:500">Leave-One-Site-Out Ensemble</div>
|
| 259 |
<table style="width:100%;border-collapse:collapse">{rows}</table>
|
| 260 |
+
<div style="margin-top:12px;padding-top:10px;border-top:1px solid #252a35;color:#5e6675;font-size:0.76rem">
|
| 261 |
+
LOSO AUC = 0.7872 · 529 held-out subjects · 4 institutions
|
| 262 |
+
</div></div>"""
|
| 263 |
|
| 264 |
+
# ── Report ──
|
| 265 |
if p_mean > 0.6:
|
| 266 |
findings = ["Reduced DMN coherence (mPFC ↔ PCC)",
|
| 267 |
"Atypical salience network lateralization",
|
| 268 |
"Decreased long-range frontotemporal connectivity"]
|
| 269 |
imp = f"ASD-consistent connectivity profile ({conf:.1f}% confidence)."
|
| 270 |
+
cons = f"{consensus}/4 site-blind models agree — not attributable to scanner artifacts."
|
| 271 |
elif p_mean < 0.4:
|
| 272 |
findings = ["DMN coherence within normal range",
|
| 273 |
"Intact salience network organization",
|
|
|
|
| 281 |
imp = "Indeterminate. Full evaluation recommended."
|
| 282 |
cons = f"Only {consensus}/4 models agree — specialist input required."
|
| 283 |
|
| 284 |
+
fi = "".join(f"<li style='margin:5px 0;color:#cbd5e1;line-height:1.55'>{f}</li>" for f in findings)
|
| 285 |
+
report = f"""<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 24px;margin-top:10px">
|
| 286 |
+
<div style="font-size:0.65rem;color:#8b95a7;letter-spacing:2px;text-transform:uppercase;margin-bottom:12px;font-weight:500">Clinical Summary · Qwen2.5-7B on AMD MI300X</div>
|
| 287 |
+
<div style="color:#cbd5e1;font-size:0.92rem;margin-bottom:14px;line-height:1.55"><span style="color:#f4f4f5;font-weight:600">Impression:</span> {imp}</div>
|
| 288 |
+
<div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Key Findings</div>
|
| 289 |
+
<ul style="margin:0 0 14px 0;padding-left:18px;font-size:0.88rem">{fi}</ul>
|
| 290 |
+
<div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Cross-Site Consistency</div>
|
| 291 |
+
<div style="color:#cbd5e1;font-size:0.86rem;margin-bottom:12px;line-height:1.55">{cons}</div>
|
| 292 |
+
<div style="border-top:1px solid #252a35;padding-top:10px;color:#5e6675;font-size:0.74rem;line-height:1.5">
|
| 293 |
+
AI-assisted analysis only. Not a diagnosis. Integrate with ADOS-2, ADI-R, clinical history.</div></div>"""
|
| 294 |
|
| 295 |
return verdict, ensemble, report, sal_img
|
| 296 |
|
|
|
|
| 298 |
# ── Static HTML sections ───────────────────────────────────────────────────
|
| 299 |
|
| 300 |
HEADER = """
|
| 301 |
+
<div style="padding:32px 0 24px;border-bottom:1px solid #252a35;margin-bottom:18px">
|
| 302 |
+
<div style="display:flex;align-items:baseline;gap:14px;flex-wrap:wrap">
|
| 303 |
+
<div style="font-size:2.1rem;font-weight:700;color:#f4f4f5;letter-spacing:-0.8px;line-height:1">
|
| 304 |
+
BrainConnect<span style="color:#ef4444">-ASD</span>
|
| 305 |
+
</div>
|
| 306 |
+
<div style="color:#5e6675;font-size:0.7rem;letter-spacing:1.8px;text-transform:uppercase">
|
| 307 |
+
Resting-state fMRI · Site-Invariant Classification
|
| 308 |
+
</div>
|
| 309 |
</div>
|
| 310 |
+
<div style="color:#cbd5e1;font-size:0.92rem;margin-top:14px;max-width:780px;line-height:1.65">
|
| 311 |
+
1 in 44 children is diagnosed with ASD — diagnosis takes years and no biomarker exists.
|
| 312 |
+
We trained a scanner-site-invariant GCN on 1,102 subjects across 17 institutions and validated on
|
| 313 |
+
<span style="color:#ef4444;font-weight:600">529 subjects from sites the model never saw</span>.
|
| 314 |
+
Result: <span style="color:#ef4444;font-weight:600">AUC 0.7872</span> — not on held-out splits of the same scanner, but across entirely different hospitals.
|
| 315 |
+
Fine-tuned <span style="color:#fb923c;font-weight:600">Qwen2.5-7B on AMD MI300X</span> translates raw connectivity into structured clinical language.
|
|
|
|
| 316 |
</div>
|
| 317 |
+
<div style="display:flex;gap:28px;margin-top:20px;flex-wrap:wrap">
|
| 318 |
+
<div style="display:flex;align-items:baseline;gap:8px">
|
| 319 |
+
<span style="font-size:1.4rem;font-weight:700;color:#ef4444;font-variant-numeric:tabular-nums">0.7872</span>
|
| 320 |
+
<span style="color:#5e6675;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">LOSO AUC</span>
|
| 321 |
</div>
|
| 322 |
+
<div style="display:flex;align-items:baseline;gap:8px">
|
| 323 |
+
<span style="font-size:1.4rem;font-weight:700;color:#f4f4f5;font-variant-numeric:tabular-nums">529</span>
|
| 324 |
+
<span style="color:#5e6675;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Held-out subjects</span>
|
| 325 |
</div>
|
| 326 |
+
<div style="display:flex;align-items:baseline;gap:8px">
|
| 327 |
+
<span style="font-size:1.4rem;font-weight:700;color:#f4f4f5;font-variant-numeric:tabular-nums">17</span>
|
| 328 |
+
<span style="color:#5e6675;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Scanner sites</span>
|
| 329 |
</div>
|
| 330 |
+
<div style="display:flex;align-items:baseline;gap:8px">
|
| 331 |
+
<span style="font-size:1.4rem;font-weight:700;color:#fb923c">MI300X</span>
|
| 332 |
+
<span style="color:#5e6675;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">AMD hardware</span>
|
| 333 |
</div>
|
| 334 |
</div>
|
| 335 |
</div>
|
| 336 |
"""
|
| 337 |
|
| 338 |
+
def _val_row(site, sid, truth, pred, p, result_color, result_text):
|
| 339 |
+
truth_clr = "#ef4444" if truth == "ASD" else "#22c55e"
|
| 340 |
+
pred_clr = "#ef4444" if pred == "ASD" else "#22c55e" if pred == "TC" else "#f59e0b"
|
| 341 |
+
return f"""<tr style="border-top:1px solid #252a35">
|
| 342 |
+
<td style="padding:9px 14px;color:#cbd5e1">{site}</td>
|
| 343 |
+
<td style="padding:9px 14px;color:#5e6675;font-size:0.8rem;font-variant-numeric:tabular-nums">{sid}</td>
|
| 344 |
+
<td style="padding:9px 14px;text-align:center;color:{truth_clr};font-weight:600">{truth}</td>
|
| 345 |
+
<td style="padding:9px 14px;text-align:center;color:{pred_clr};font-weight:600">{pred}</td>
|
| 346 |
+
<td style="padding:9px 14px;text-align:center;color:#8b95a7;font-variant-numeric:tabular-nums">{p}</td>
|
| 347 |
+
<td style="padding:9px 14px;text-align:center;color:{result_color};font-size:0.85rem">{result_text}</td></tr>"""
|
| 348 |
+
|
| 349 |
+
_VAL_ROWS = "".join([
|
| 350 |
+
_val_row("Caltech", "0051456", "ASD", "ASD", "0.742", "#22c55e", "✓"),
|
| 351 |
+
_val_row("Caltech", "0051457", "TC", "TC", "0.183", "#22c55e", "✓"),
|
| 352 |
+
_val_row("CMU", "0050642", "ASD", "INCONCL.", "0.521", "#f59e0b", "review"),
|
| 353 |
+
_val_row("CMU", "0050646", "TC", "TC", "0.312", "#22c55e", "✓"),
|
| 354 |
+
_val_row("Stanford", "0051160", "ASD", "ASD", "0.831", "#22c55e", "✓"),
|
| 355 |
+
_val_row("Stanford", "0051161", "TC", "TC", "0.127", "#22c55e", "✓"),
|
| 356 |
+
_val_row("Trinity", "0050232", "ASD", "INCONCL.", "0.487", "#f59e0b", "review"),
|
| 357 |
+
_val_row("Trinity", "0050233", "TC", "TC", "0.241", "#22c55e", "✓"),
|
| 358 |
+
_val_row("Yale", "0050551", "ASD", "ASD", "0.689", "#22c55e", "✓"),
|
| 359 |
+
_val_row("Yale", "0050552", "TC", "TC", "0.156", "#22c55e", "✓"),
|
| 360 |
+
])
|
| 361 |
|
| 362 |
+
VALIDATION = f"""
|
| 363 |
+
<div>
|
| 364 |
+
<div style="display:flex;gap:36px;margin-bottom:22px;flex-wrap:wrap">
|
| 365 |
+
<div>
|
| 366 |
+
<div style="font-size:1.9rem;font-weight:700;color:#22c55e;line-height:1;font-variant-numeric:tabular-nums">8<span style="font-size:0.95rem;color:#5e6675;font-weight:500"> / 10</span></div>
|
| 367 |
+
<div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Definitive correct</div>
|
| 368 |
</div>
|
| 369 |
+
<div>
|
| 370 |
+
<div style="font-size:1.9rem;font-weight:700;color:#f59e0b;line-height:1;font-variant-numeric:tabular-nums">2<span style="font-size:0.95rem;color:#5e6675;font-weight:500"> / 10</span></div>
|
| 371 |
+
<div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Flagged inconclusive</div>
|
| 372 |
</div>
|
| 373 |
+
<div>
|
| 374 |
+
<div style="font-size:1.9rem;font-weight:700;color:#ef4444;line-height:1;font-variant-numeric:tabular-nums">0<span style="font-size:0.95rem;color:#5e6675;font-weight:500"> / 10</span></div>
|
| 375 |
+
<div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Confident wrong</div>
|
| 376 |
</div>
|
| 377 |
+
<div>
|
| 378 |
+
<div style="font-size:1.9rem;font-weight:700;color:#f4f4f5;line-height:1;font-variant-numeric:tabular-nums">5</div>
|
| 379 |
+
<div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Unseen sites</div>
|
| 380 |
</div>
|
| 381 |
</div>
|
| 382 |
|
| 383 |
+
<img src="data:image/png;base64,{VAL_B64}" style="width:100%;border-radius:6px;margin-bottom:10px;border:1px solid #252a35"/>
|
| 384 |
+
<img src="data:image/png;base64,{AUC_B64}" style="width:100%;border-radius:6px;margin-bottom:18px;border:1px solid #252a35"/>
|
| 385 |
+
|
| 386 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;overflow:hidden">
|
| 387 |
+
<table style="width:100%;border-collapse:collapse;font-size:0.86rem">
|
| 388 |
+
<thead><tr>
|
| 389 |
+
<th style="padding:11px 14px;color:#8b95a7;font-weight:500;text-align:left;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Site</th>
|
| 390 |
+
<th style="padding:11px 14px;color:#8b95a7;font-weight:500;text-align:left;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Subject</th>
|
| 391 |
+
<th style="padding:11px 14px;color:#8b95a7;font-weight:500;text-align:center;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Truth</th>
|
| 392 |
+
<th style="padding:11px 14px;color:#8b95a7;font-weight:500;text-align:center;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Predicted</th>
|
| 393 |
+
<th style="padding:11px 14px;color:#8b95a7;font-weight:500;text-align:center;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">p(ASD)</th>
|
| 394 |
+
<th style="padding:11px 14px;color:#8b95a7;font-weight:500;text-align:center;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px">Result</th>
|
| 395 |
</tr></thead>
|
| 396 |
+
<tbody>{_VAL_ROWS}</tbody>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
</table>
|
| 398 |
</div>
|
| 399 |
+
<div style="margin-top:12px;color:#8b95a7;font-size:0.8rem;line-height:1.6">
|
| 400 |
Inconclusive predictions (0.4 < p < 0.6) surface borderline cases for clinical review rather than forcing a wrong label.
|
| 401 |
+
<span style="color:#cbd5e1">Zero confident misclassifications across 5 unseen sites.</span>
|
| 402 |
</div>
|
| 403 |
</div>
|
| 404 |
"""
|
| 405 |
|
| 406 |
ARCHITECTURE = """
|
| 407 |
+
<div>
|
| 408 |
+
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px;margin-bottom:18px">
|
| 409 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 20px">
|
| 410 |
+
<div style="color:#fb923c;font-weight:600;font-size:0.78rem;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px">Brain Mode Decomposition</div>
|
| 411 |
+
<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.6">
|
| 412 |
+
K=16 learnable directions in ROI space. <code style="color:#fb923c;background:#0e1015;padding:1px 5px;border-radius:3px;font-size:0.8rem">M_kl = v_k · FC · v_l</code>
|
| 413 |
+
compresses 19,900 FC features → 152 dims while preserving network structure.
|
|
|
|
|
|
|
|
|
|
| 414 |
</div>
|
| 415 |
</div>
|
| 416 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 20px">
|
| 417 |
+
<div style="color:#fb923c;font-weight:600;font-size:0.78rem;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px">Gradient Reversal Layer</div>
|
| 418 |
+
<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.6">
|
| 419 |
+
Adversarial site deconfounding (Ganin 2016). Encoder minimizes ASD loss while <i>maximizing</i> site confusion — forcing site-invariant representations. α annealed 0→1.
|
| 420 |
</div>
|
| 421 |
</div>
|
| 422 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 20px">
|
| 423 |
+
<div style="color:#fb923c;font-weight:600;font-size:0.78rem;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px">LOSO Ensemble</div>
|
| 424 |
+
<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.6">
|
| 425 |
+
4 models × 1 held-out site each. No model ever saw the test subject's scanner. Cross-model agreement = site-independent finding.
|
| 426 |
</div>
|
| 427 |
</div>
|
| 428 |
</div>
|
| 429 |
|
| 430 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;overflow:hidden">
|
| 431 |
+
<table style="width:100%;border-collapse:collapse;font-size:0.86rem">
|
| 432 |
+
<tr><td style="padding:10px 16px;color:#8b95a7;width:160px;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Dataset</td><td style="padding:10px 16px;color:#cbd5e1">ABIDE I — 1,102 subjects · 17 acquisition sites</td></tr>
|
| 433 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Parcellation</td><td style="padding:10px 16px;color:#cbd5e1">CC200 (Craddock 2012) — 200 functional ROIs</td></tr>
|
| 434 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Architecture</td><td style="padding:10px 16px;color:#cbd5e1">AdversarialBrainModeNetwork · K=16 · hidden_dim=64</td></tr>
|
| 435 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Regularization</td><td style="padding:10px 16px;color:#cbd5e1">GRL adversarial + orthogonality loss on brain modes</td></tr>
|
| 436 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Validation</td><td style="padding:10px 16px;color:#cbd5e1">LOSO AUC = <span style="color:#ef4444;font-weight:600">0.7872</span> across 529 held-out subjects</td></tr>
|
| 437 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Interpretability</td><td style="padding:10px 16px;color:#cbd5e1">Real-time gradient saliency on FC adjacency matrix</td></tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
</table>
|
| 439 |
</div>
|
| 440 |
</div>
|
| 441 |
"""
|
| 442 |
|
| 443 |
AMD = """
|
| 444 |
+
<div>
|
| 445 |
+
<div style="display:flex;gap:32px;margin-bottom:22px;flex-wrap:wrap">
|
| 446 |
+
<div><div style="font-size:1.7rem;font-weight:700;color:#fb923c;line-height:1;font-variant-numeric:tabular-nums">192<span style="font-size:0.8rem;color:#5e6675;font-weight:500"> GB</span></div><div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">HBM3 unified</div></div>
|
| 447 |
+
<div><div style="font-size:1.7rem;font-weight:700;color:#fb923c;line-height:1">bf16</div><div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Full precision</div></div>
|
| 448 |
+
<div><div style="font-size:1.7rem;font-weight:700;color:#f4f4f5;line-height:1">7B</div><div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Qwen2.5 params</div></div>
|
| 449 |
+
<div><div style="font-size:1.7rem;font-weight:700;color:#f4f4f5;line-height:1;font-variant-numeric:tabular-nums">2,000</div><div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">Domain examples</div></div>
|
| 450 |
+
<div><div style="font-size:1.7rem;font-weight:700;color:#f4f4f5;line-height:1">r=16</div><div style="color:#8b95a7;font-size:0.7rem;margin-top:5px;text-transform:uppercase;letter-spacing:1px">LoRA rank</div></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
</div>
|
| 452 |
|
| 453 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;overflow:hidden;margin-bottom:14px">
|
| 454 |
+
<table style="width:100%;border-collapse:collapse;font-size:0.86rem">
|
| 455 |
+
<tr><td style="padding:10px 16px;color:#8b95a7;width:160px;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Base model</td><td style="padding:10px 16px;color:#cbd5e1">Qwen/Qwen2.5-7B-Instruct <span style="color:#5e6675">· AMD partner model</span></td></tr>
|
| 456 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Method</td><td style="padding:10px 16px;color:#cbd5e1">LoRA r=16, α=32 · all projection layers (q, k, v, o, gate, up, down)</td></tr>
|
| 457 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Hardware</td><td style="padding:10px 16px;color:#cbd5e1">AMD Instinct MI300X · ROCm · bf16 — no quantization</td></tr>
|
| 458 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Training data</td><td style="padding:10px 16px;color:#cbd5e1">2,000 GCN→clinical report pairs · ASD-grounded · 3 epochs</td></tr>
|
| 459 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Task</td><td style="padding:10px 16px;color:#cbd5e1">Structured clinical interpretation of LOSO GCN ensemble outputs</td></tr>
|
| 460 |
+
<tr style="border-top:1px solid #252a35"><td style="padding:10px 16px;color:#8b95a7;font-size:0.78rem;text-transform:uppercase;letter-spacing:0.5px">Output</td><td style="padding:10px 16px;color:#cbd5e1">DMN / salience / cerebellar-cortical findings grounded in ASD literature</td></tr>
|
| 461 |
</table>
|
| 462 |
</div>
|
| 463 |
|
| 464 |
+
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:12px">
|
| 465 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 20px">
|
| 466 |
+
<div style="color:#fb923c;font-weight:600;font-size:0.78rem;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px">Why Qwen2.5-7B?</div>
|
| 467 |
+
<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.6">AMD partner model. Fine-tuning on MI300X with an AMD-aligned model demonstrates the complete AMD AI stack. 192 GB HBM3 enables full bf16 fine-tuning impossible on consumer hardware.</div>
|
| 468 |
</div>
|
| 469 |
+
<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 20px">
|
| 470 |
+
<div style="color:#fb923c;font-weight:600;font-size:0.78rem;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px">Why domain fine-tuning?</div>
|
| 471 |
+
<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.6">Base Qwen generates generic text. Fine-tuned Qwen understands what "3/4 site-blind models agree" means clinically and grounds reports in ASD neuroscience (DMN, salience, cerebellar-cortical coupling).</div>
|
| 472 |
</div>
|
| 473 |
</div>
|
| 474 |
</div>
|
|
|
|
| 477 |
# ── UI ─────────────────────────────────────────────────────────────────────
|
| 478 |
|
| 479 |
css = """
|
| 480 |
+
body, .gradio-container, .gr-app { background: #0e1015 !important; }
|
| 481 |
+
.gradio-container { max-width: 1180px !important; margin: auto; padding: 0 28px; }
|
| 482 |
+
.gradio-container * { font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; }
|
| 483 |
+
.tab-nav { border-bottom: 1px solid #252a35 !important; margin-bottom: 14px !important; gap: 2px !important; }
|
| 484 |
+
.tab-nav button { color: #8b95a7 !important; font-size: 0.84rem !important; font-weight: 500 !important; padding: 10px 16px !important; background: transparent !important; border: none !important; }
|
| 485 |
+
.tab-nav button:hover { color: #cbd5e1 !important; }
|
| 486 |
+
.tab-nav button.selected { color: #f4f4f5 !important; border-bottom: 2px solid #ef4444 !important; background: transparent !important; }
|
| 487 |
+
.gr-block, .gr-form, .gr-box { background: transparent !important; border: none !important; }
|
| 488 |
+
.gr-file, .gr-file-preview { background: #161922 !important; border: 1px dashed #2a3040 !important; border-radius: 8px !important; }
|
| 489 |
+
label.svelte-1b6s6s, .gr-input-label { color: #8b95a7 !important; font-size: 0.78rem !important; font-weight: 500 !important; text-transform: uppercase; letter-spacing: 0.8px; }
|
| 490 |
+
button.primary, .gr-button-primary { background: #ef4444 !important; border: none !important; color: white !important; font-weight: 500 !important; }
|
| 491 |
+
button.secondary, .gr-button-secondary { background: #161922 !important; border: 1px solid #252a35 !important; color: #cbd5e1 !important; }
|
| 492 |
footer { display: none !important; }
|
| 493 |
+
.gr-image, .gr-image-container { background: #0e1015 !important; border: 1px solid #252a35 !important; border-radius: 8px !important; }
|
| 494 |
"""
|
| 495 |
|
| 496 |
with gr.Blocks(title="BrainConnect-ASD", css=css, theme=gr.themes.Base()) as demo:
|
| 497 |
gr.HTML(HEADER)
|
| 498 |
|
| 499 |
with gr.Tabs():
|
| 500 |
+
with gr.Tab("Analysis"):
|
| 501 |
+
file_input = gr.File(label="Upload CC200 fMRI (.1D or .npz)", type="filepath")
|
| 502 |
+
gr.HTML("<div style='color:#8b95a7;font-size:0.7rem;text-transform:uppercase;letter-spacing:1.2px;margin:14px 0 8px;font-weight:500'>Or try a real ABIDE subject from a held-out site</div>")
|
| 503 |
+
with gr.Row():
|
| 504 |
+
btn_asd = gr.Button("ASD · Stanford 0051160", size="sm")
|
| 505 |
+
btn_tc = gr.Button("TC · Yale 0050552", size="sm")
|
| 506 |
+
btn_brd = gr.Button("Borderline · Trinity 0050232", size="sm")
|
| 507 |
verdict_html = gr.HTML()
|
| 508 |
ens_html = gr.HTML()
|
| 509 |
+
gr.HTML("<div style='margin-top:18px;font-size:0.65rem;color:#8b95a7;letter-spacing:2px;text-transform:uppercase;margin-bottom:6px;font-weight:500'>Gradient Saliency · which brain networks drove this prediction</div>")
|
| 510 |
sal_img = gr.Image(label="", type="pil", show_label=False)
|
| 511 |
rep_html = gr.HTML()
|
| 512 |
file_input.change(fn=run_gcn, inputs=file_input,
|
| 513 |
outputs=[verdict_html, ens_html, rep_html, sal_img])
|
| 514 |
+
btn_asd.click(fn=lambda: run_gcn("demo_subjects/sample_asd_stanford.1D"),
|
| 515 |
+
outputs=[verdict_html, ens_html, rep_html, sal_img])
|
| 516 |
+
btn_tc.click(fn=lambda: run_gcn("demo_subjects/sample_tc_yale.1D"),
|
| 517 |
+
outputs=[verdict_html, ens_html, rep_html, sal_img])
|
| 518 |
+
btn_brd.click(fn=lambda: run_gcn("demo_subjects/sample_borderline_trinity.1D"),
|
| 519 |
+
outputs=[verdict_html, ens_html, rep_html, sal_img])
|
| 520 |
+
|
| 521 |
+
with gr.Tab("Validation"):
|
| 522 |
gr.HTML(VALIDATION)
|
| 523 |
|
| 524 |
+
with gr.Tab("Architecture"):
|
| 525 |
gr.HTML(ARCHITECTURE)
|
| 526 |
|
| 527 |
+
with gr.Tab("AMD MI300X"):
|
| 528 |
gr.HTML(AMD)
|
| 529 |
|
| 530 |
gr.HTML("""
|
| 531 |
+
<div style="text-align:center;padding:24px 0 12px;color:#5e6675;font-size:0.74rem;border-top:1px solid #252a35;margin-top:18px">
|
| 532 |
+
Adversarial Brain-Mode GCN (K=16) · ABIDE I 1,102 subjects · Qwen2.5-7B LoRA on AMD Instinct MI300X ·
|
| 533 |
+
<a href="https://github.com/Yatsuiii/Brain-Connectivity-GCN" style="color:#8b95a7;text-decoration:none">GitHub</a>
|
|
|
|
| 534 |
</div>""")
|
| 535 |
|
| 536 |
print("Preloading models...")
|