Upload app.py with huggingface_hub
Browse files16 unmodified lines17181920212266 unmodified lines8990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132127 unmodified lines26026126226326426516 unmodified lines_MAX_WINDOWS = 30_FC_THRESHOLD = 0.2_CKPTS = {"NYU": Path("checkpoints/nyu.ckpt"),"USM": Path("checkpoints/usm.ckpt"),66 unmodified linesimport matplotlib.pyplot as pltfrom PIL import Imagethresh = np.percentile(sal, 95)sal_top = np.where(sal >= thresh, sal, 0.0)roi_imp = sal.sum(1)top20 = roi_imp.argsort()[-20:][::-1]color = "#e63946" if p_mean > 0.6 else "#2dc653" if p_mean < 0.4 else "#f4a261"fig, axes = plt.subplots(1, 2, figsize=(14, 5))fig.patch.set_facecolor("#0d0d0d")ax = axes[0]ax.set_facecolor("#111"); ax.tick_params(colors="#555", labelsize=8)for sp in ax.spines.values(): sp.set_color("#222")im = ax.imshow(sal_top, cmap="inferno", aspect="auto", interpolation="nearest")ax.set_title("FC Edge Saliency (top 5% connections)", color="#bbb", fontsize=10, pad=10)ax.set_xlabel("ROI index", color="#555", fontsize=9)ax.set_ylabel("ROI index", color="#555", fontsize=9)cb = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)cb.ax.yaxis.set_tick_params(color="#444", labelsize=7)plt.setp(cb.ax.yaxis.get_ticklabels(), color="#555")ax2 = axes[1]ax2.set_facecolor("#111"); ax2.tick_params(colors="#555", labelsize=8)ax2.barh(range(20), roi_imp[top20], color=color, alpha=0.8, edgecolor="none")ax2.set_yticks(range(20))ax2.set_yticklabels([f"ROI {i:03d}" for i in top20], fontsize=8, color="#aaa")ax2.set_xlabel("Cumulative gradient magnitude", color="#555", fontsize=9)ax2.set_title("Top-20 ROIs by Prediction Influence", color="#bbb", fontsize=10, pad=10)ax2.invert_yaxis()for sp in ["top", "right"]: ax2.spines[sp].set_visible(False)for sp in ["bottom", "left"]: ax2.spines[sp].set_color("#222")fig.suptitle(f"Gradient Saliency · p(ASD)={p_mean:.3f} · {len(_models)}-model LOSO ensemble",color="#555", fontsize=9, y=1.01,)plt.tight_layout()buf = io.BytesIO()plt.savefig(buf, format="png", dpi=130, bbox_inches="tight", facecolor="#0d0d0d")plt.close(fig)buf.seek(0)return Image.open(buf).copy()127 unmodified lines<div style="color:#333;font-size:0.72rem;letter-spacing:4px;text-transform:uppercase;margin-top:10px">Clinical AI · Resting-state fMRI · Scanner-Site-Invariant Classification</div><div style="display:flex;gap:0;margin-top:28px;border:1px solid #1a1a1a;border-radius:12px;overflow:hidden;max-width:700px"><div style="padding:20px 32px;flex:1;border-right:1px solid #1a1a1a;min-width:120px"><div style="font-size:2.2rem;font-weight:900;color:#e63946;line-height:1">0.7872</div>16 unmodified lines171819202122232425262766 unmodified lines949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179127 unmodified lines30730830931031131231331431531631731831932016 unmodified lines_MAX_WINDOWS = 30_FC_THRESHOLD = 0.2# CC200 atlas (Craddock 2012) → approximate Yeo 7-network parcellation_NET_NAMES = ["DMN", "Salience", "Frontoparietal", "Sensorimotor", "Visual", "Dorsal Attn", "Subcortical"]_NET_BOUNDS = [0, 38, 69, 99, 137, 165, 180, 200]_NET_COLORS = ["#e63946", "#f4a261", "#457b9d", "#2dc653", "#a8dadc", "#8b5cf6", "#6b7280"]_CKPTS = {"NYU": Path("checkpoints/nyu.ckpt"),"USM": Path("checkpoints/usm.ckpt"),66 unmodified linesimport matplotlib.pyplot as pltfrom PIL import Imagen_nets = len(_NET_NAMES)# Aggregate 200×200 saliency → 7×7 network-level matrixnet_sal = np.zeros((n_nets, n_nets))for i, (s1, e1) in enumerate(zip(_NET_BOUNDS[:-1], _NET_BOUNDS[1:])):for j, (s2, e2) in enumerate(zip(_NET_BOUNDS[:-1], _NET_BOUNDS[1:])):net_sal[i, j] = sal[s1:e1, s2:e2].mean()# Network importance: mean outgoing + incoming saliency per networknet_imp = np.array([sal[s:e, :].mean() + sal[:, s:e].mean()for s, e in zip(_NET_BOUNDS[:-1], _NET_BOUNDS[1:])])fig, axes = plt.subplots(1, 2, figsize=(14, 5.5))fig.patch.set_facecolor("#0d0d0d")# ── Left: 7×7 network heatmap ──────────────────────────────────────────ax = axes[0]ax.set_facecolor("#111")im = ax.imshow(net_sal, cmap="inferno", aspect="auto", interpolation="nearest")ax.set_title("FC Saliency by Brain Network", color="#bbb", fontsize=11, pad=14, fontweight="bold")ax.set_xticks(range(n_nets))ax.set_yticks(range(n_nets))ax.set_xticklabels(_NET_NAMES, rotation=40, ha="right", fontsize=9, color="#ccc")ax.set_yticklabels(_NET_NAMES, fontsize=9, color="#ccc")ax.tick_params(colors="#555", length=0)for sp in ax.spines.values():sp.set_color("#222")# Boundary lines between networksfor k in range(1, n_nets):ax.axhline(k - 0.5, color="#2a2a2a", lw=1.0)ax.axvline(k - 0.5, color="#2a2a2a", lw=1.0)# Annotate each cell with its valuevmax = net_sal.max()for i in range(n_nets):for j in range(n_nets):txt_color = "#111" if net_sal[i, j] > 0.6 * vmax else "#555"ax.text(j, i, f"{net_sal[i, j]:.3f}", ha="center", va="center",fontsize=6.5, color=txt_color)cb = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)cb.ax.yaxis.set_tick_params(color="#444", labelsize=7)plt.setp(cb.ax.yaxis.get_ticklabels(), color="#555")cb.set_label("Mean |∂p(ASD)/∂FC|", color="#444", fontsize=7.5)# ── Right: network importance bar chart ────────────────────────────────ax2 = axes[1]ax2.set_facecolor("#111")ax2.tick_params(colors="#555", labelsize=9)order = net_imp.argsort()[::-1]bars = ax2.barh(range(n_nets), net_imp[order],color=[_NET_COLORS[i] for i in order], alpha=0.88, edgecolor="none", height=0.65)ax2.set_yticks(range(n_nets))ax2.set_yticklabels([_NET_NAMES[i] for i in order], fontsize=9.5, color="#ddd")ax2.set_xlabel("Mean gradient magnitude", color="#555", fontsize=9)ax2.set_title("Network Importance for This Prediction", color="#bbb", fontsize=11, pad=14, fontweight="bold")ax2.invert_yaxis()for sp in ["top", "right"]:ax2.spines[sp].set_visible(False)for sp in ["bottom", "left"]:ax2.spines[sp].set_color("#222")# Value labels on barsx_max = net_imp.max()for bar, val in zip(bars, net_imp[order]):ax2.text(val + x_max * 0.015, bar.get_y() + bar.get_height() / 2,f"{val:.4f}", va="center", color="#555", fontsize=7.5)fig.suptitle(f"Gradient Saliency · p(ASD) = {p_mean:.3f} · {len(_models)}-model LOSO ensemble · CC200 → Yeo-7 networks",color="#444", fontsize=8.5, y=1.02,)plt.tight_layout()buf = io.BytesIO()plt.savefig(buf, format="png", dpi=140, bbox_inches="tight", facecolor="#0d0d0d")plt.close(fig)buf.seek(0)return Image.open(buf).copy()127 unmodified lines<div style="color:#333;font-size:0.72rem;letter-spacing:4px;text-transform:uppercase;margin-top:10px">Clinical AI · Resting-state fMRI · Scanner-Site-Invariant Classification</div><div style="color:#444;font-size:0.93rem;margin-top:18px;max-width:720px;line-height:1.75">1 in 44 children is diagnosed with ASD. Today, diagnosis takes years of behavioral observation —no biomarker exists. We trained a scanner-site-invariant GCN on 1,102 subjects across 17 institutionsand validated it on <span style="color:#e63946;font-weight:700">529 subjects the model never saw, from sites it was never trained on</span>.The result: <span style="color:#e63946;font-weight:700">AUC 0.7872</span> — not on held-out splits of the same scanner, butacross entirely different hospitals. Fine-tuned <span style="color:#f4a261;font-weight:700">Qwen2.5-7B on AMD MI300X</span>then translates raw connectivity patterns into structured clinical language a clinician can act on.</div><div style="display:flex;gap:0;margin-top:28px;border:1px solid #1a1a1a;border-radius:12px;overflow:hidden;max-width:700px"><div style="padding:20px 32px;flex:1;border-right:1px solid #1a1a1a;min-width:120px"><div style="font-size:2.2rem;font-weight:900;color:#e63946;line-height:1">0.7872</div>
app.py+78-23