Upload app.py with huggingface_hub
Browse files129 unmodified lines130131132133134135136137138139140141142138 unmodified lines281282283284285286287288289290291292293294295296129 unmodified linesax.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)138 unmodified linesimp = "Indeterminate. Full evaluation recommended."cons = f"Only {consensus}/4 models agree — specialist input required."fi = "".join(f"<li style='margin:5px 0;color:#cbd5e1;line-height:1.55'>{f}</li>" for f in findings)report = f"""<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 24px;margin-top:10px"><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><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><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Key Findings</div><ul style="margin:0 0 14px 0;padding-left:18px;font-size:0.88rem">{fi}</ul><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><div style="color:#cbd5e1;font-size:0.86rem;margin-bottom:12px;line-height:1.55">{cons}</div><div style="border-top:1px solid #252a35;padding-top:10px;color:#5e6675;font-size:0.74rem;line-height:1.5">AI-assisted analysis only. Not a diagnosis. Integrate with ADOS-2, ADI-R, clinical history.</div></div>"""return verdict, ensemble, report, sal_img129 unmodified lines130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167138 unmodified lines306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363129 unmodified linesax.axhline(k - 0.5, color="#2a2a2a", lw=1.0)ax.axvline(k - 0.5, color="#2a2a2a", lw=1.0)# Find top-5 off-diagonal edges (i != j) and top-3 for calloutsvmax = net_sal.max()edge_scores = []for i in range(n_nets):for j in range(n_nets):if i != j:edge_scores.append((net_sal[i, j], i, j))edge_scores.sort(reverse=True)top5_cells = {(i, j) for _, i, j in edge_scores[:5]}top3_edges = edge_scores[:3]# Annotate each cell with its value; highlight top-5 with white borderfor i in range(n_nets):for j in range(n_nets):txt_color = "#111" if net_sal[i, j] > 0.6 * vmax else "#666"ax.text(j, i, f"{net_sal[i, j]:.3f}", ha="center", va="center",fontsize=6.5, color=txt_color, zorder=3)if (i, j) in top5_cells:rect = plt.Rectangle((j - 0.48, i - 0.48), 0.96, 0.96,linewidth=1.8, edgecolor="#ffffff",facecolor="none", zorder=4)ax.add_patch(rect)# Callout labels for top-3 cross-network edgesfor rank, (score, i, j) in enumerate(top3_edges):label = f"#{rank+1} {_NET_NAMES[i]}↔{_NET_NAMES[j]}"ax.annotate(label,xy=(j, i), xytext=(n_nets - 0.3, rank * 0.85 - 0.3),fontsize=6, color="#fb923c", fontweight="600",arrowprops=dict(arrowstyle="-", color="#fb923c",lw=0.7, connectionstyle="arc3,rad=0.1"),ha="left", va="center", zorder=5)cb = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)cb.ax.yaxis.set_tick_params(color="#444", labelsize=7)138 unmodified linesimp = "Indeterminate. Full evaluation recommended."cons = f"Only {consensus}/4 models agree — specialist input required."# ICD-10 and citation groundingif p_mean > 0.6:icd = "F84.0 (Childhood Autism) / F84.1 (Atypical Autism)"refs = [("Rudie et al. 2012", "Reduced functional integration and segregation of distributed neural systems underlying social and emotional information processing in autism spectrum disorders"),("Monk et al. 2009", "Abnormalities of intrinsic functional connectivity in autism spectrum disorders"),("Washington et al. 2014", "Dysmaturation of the default mode network in autism"),]elif p_mean < 0.4:icd = "Z03.89 (No diagnosis — screening negative)"refs = [("Buckner et al. 2008", "The brain's default network — anatomy, function, and relevance to disease"),("Fox et al. 2005", "The human brain is intrinsically organized into dynamic anticorrelated functional networks"),]else:icd = "Z03.89 (Inconclusive — further evaluation required)"refs = [("Ecker et al. 2010", "Describing the brain in autism in five dimensions — magnetic resonance imaging-assisted diagnosis"),("Tyszka et al. 2014", "Largely typical patterns of resting-state functional connectivity in high-functioning adults with autism"),]fi = "".join(f"<li style='margin:5px 0;color:#cbd5e1;line-height:1.55'>{f}</li>" for f in findings)refs_html = "".join(f"<div style='margin:4px 0;font-size:0.76rem'><span style='color:#fb923c;font-weight:600'>{r[0]}</span> "f"<span style='color:#5e6675'>— {r[1]}</span></div>"for r in refs)report = f"""<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 24px;margin-top:10px"><div style="font-size:0.65rem;color:#8b95a7;letter-spacing:2px;text-transform:uppercase;margin-bottom:16px;font-weight:500">Clinical Referral Summary · Generated by Qwen2.5-7B LoRA · AMD Instinct MI300X</div><div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:16px"><div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px;margin-bottom:3px">ICD-10 Classification</div><div style="color:#cbd5e1;font-size:0.84rem;line-height:1.4">{icd}</div></div><div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px;margin-bottom:3px">Ensemble Confidence</div><div style="color:#cbd5e1;font-size:0.84rem">{conf:.1f}% · p(ASD) = {p_mean:.3f} · {len(_models)}-model LOSO</div></div></div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Impression</div><div style="color:#f4f4f5;font-size:0.92rem;margin-bottom:14px;line-height:1.55">{imp}</div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Connectivity Findings</div><ul style="margin:0 0 14px 0;padding-left:18px;font-size:0.88rem">{fi}</ul><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><div style="color:#cbd5e1;font-size:0.86rem;margin-bottom:14px;line-height:1.55">{cons}</div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:6px;font-weight:500">Supporting Literature</div><div style="margin-bottom:14px">{refs_html}</div><div style="border-top:1px solid #252a35;padding-top:10px;color:#5e6675;font-size:0.74rem;line-height:1.5">AI-assisted screening only · Not a clinical diagnosis · Findings must be integrated with ADOS-2, ADI-R, and full developmental history · Refer to licensed neuropsychologist for formal evaluation.</div></div>"""return verdict, ensemble, report, sal_img
app.py+76-9