Yatsuiii commited on
Commit
3d9e4e3
·
verified ·
1 Parent(s): d1d5a5f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +76 -9
app.py CHANGED
@@ -130,13 +130,38 @@ def _saliency_figure(sal, p_mean):
130
  ax.axhline(k - 0.5, color="#2a2a2a", lw=1.0)
131
  ax.axvline(k - 0.5, color="#2a2a2a", lw=1.0)
132
 
133
- # Annotate each cell with its value
134
  vmax = net_sal.max()
 
135
  for i in range(n_nets):
136
  for j in range(n_nets):
137
- txt_color = "#111" if net_sal[i, j] > 0.6 * vmax else "#555"
 
 
 
 
 
 
 
 
 
138
  ax.text(j, i, f"{net_sal[i, j]:.3f}", ha="center", va="center",
139
- fontsize=6.5, color=txt_color)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  cb = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
142
  cb.ax.yaxis.set_tick_params(color="#444", labelsize=7)
@@ -281,16 +306,58 @@ LOSO AUC = 0.7872 · 529 held-out subjects · 4 institutions
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
 
 
130
  ax.axhline(k - 0.5, color="#2a2a2a", lw=1.0)
131
  ax.axvline(k - 0.5, color="#2a2a2a", lw=1.0)
132
 
133
+ # Find top-5 off-diagonal edges (i != j) and top-3 for callouts
134
  vmax = net_sal.max()
135
+ edge_scores = []
136
  for i in range(n_nets):
137
  for j in range(n_nets):
138
+ if i != j:
139
+ edge_scores.append((net_sal[i, j], i, j))
140
+ edge_scores.sort(reverse=True)
141
+ top5_cells = {(i, j) for _, i, j in edge_scores[:5]}
142
+ top3_edges = edge_scores[:3]
143
+
144
+ # Annotate each cell with its value; highlight top-5 with white border
145
+ for i in range(n_nets):
146
+ for j in range(n_nets):
147
+ txt_color = "#111" if net_sal[i, j] > 0.6 * vmax else "#666"
148
  ax.text(j, i, f"{net_sal[i, j]:.3f}", ha="center", va="center",
149
+ fontsize=6.5, color=txt_color, zorder=3)
150
+ if (i, j) in top5_cells:
151
+ rect = plt.Rectangle((j - 0.48, i - 0.48), 0.96, 0.96,
152
+ linewidth=1.8, edgecolor="#ffffff",
153
+ facecolor="none", zorder=4)
154
+ ax.add_patch(rect)
155
+
156
+ # Callout labels for top-3 cross-network edges
157
+ for rank, (score, i, j) in enumerate(top3_edges):
158
+ label = f"#{rank+1} {_NET_NAMES[i]}↔{_NET_NAMES[j]}"
159
+ ax.annotate(label,
160
+ xy=(j, i), xytext=(n_nets - 0.3, rank * 0.85 - 0.3),
161
+ fontsize=6, color="#fb923c", fontweight="600",
162
+ arrowprops=dict(arrowstyle="-", color="#fb923c",
163
+ lw=0.7, connectionstyle="arc3,rad=0.1"),
164
+ ha="left", va="center", zorder=5)
165
 
166
  cb = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
167
  cb.ax.yaxis.set_tick_params(color="#444", labelsize=7)
 
306
  imp = "Indeterminate. Full evaluation recommended."
307
  cons = f"Only {consensus}/4 models agree — specialist input required."
308
 
309
+ # ICD-10 and citation grounding
310
+ if p_mean > 0.6:
311
+ icd = "F84.0 (Childhood Autism) / F84.1 (Atypical Autism)"
312
+ refs = [
313
+ ("Rudie et al. 2012", "Reduced functional integration and segregation of distributed neural systems underlying social and emotional information processing in autism spectrum disorders"),
314
+ ("Monk et al. 2009", "Abnormalities of intrinsic functional connectivity in autism spectrum disorders"),
315
+ ("Washington et al. 2014", "Dysmaturation of the default mode network in autism"),
316
+ ]
317
+ elif p_mean < 0.4:
318
+ icd = "Z03.89 (No diagnosis — screening negative)"
319
+ refs = [
320
+ ("Buckner et al. 2008", "The brain's default network — anatomy, function, and relevance to disease"),
321
+ ("Fox et al. 2005", "The human brain is intrinsically organized into dynamic anticorrelated functional networks"),
322
+ ]
323
+ else:
324
+ icd = "Z03.89 (Inconclusive — further evaluation required)"
325
+ refs = [
326
+ ("Ecker et al. 2010", "Describing the brain in autism in five dimensions — magnetic resonance imaging-assisted diagnosis"),
327
+ ("Tyszka et al. 2014", "Largely typical patterns of resting-state functional connectivity in high-functioning adults with autism"),
328
+ ]
329
+
330
+ fi = "".join(f"<li style='margin:5px 0;color:#cbd5e1;line-height:1.55'>{f}</li>" for f in findings)
331
+ refs_html = "".join(
332
+ f"<div style='margin:4px 0;font-size:0.76rem'><span style='color:#fb923c;font-weight:600'>{r[0]}</span> "
333
+ f"<span style='color:#5e6675'>— {r[1]}</span></div>"
334
+ for r in refs
335
+ )
336
+
337
  report = f"""<div style="background:#161922;border:1px solid #252a35;border-radius:8px;padding:18px 24px;margin-top:10px">
338
+ <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>
339
+
340
+ <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:16px">
341
+ <div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px;margin-bottom:3px">ICD-10 Classification</div>
342
+ <div style="color:#cbd5e1;font-size:0.84rem;line-height:1.4">{icd}</div></div>
343
+ <div><div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1px;margin-bottom:3px">Ensemble Confidence</div>
344
+ <div style="color:#cbd5e1;font-size:0.84rem">{conf:.1f}% · p(ASD) = {p_mean:.3f} · {len(_models)}-model LOSO</div></div>
345
+ </div>
346
+
347
+ <div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Impression</div>
348
+ <div style="color:#f4f4f5;font-size:0.92rem;margin-bottom:14px;line-height:1.55">{imp}</div>
349
+
350
+ <div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:4px;font-weight:500">Connectivity Findings</div>
351
  <ul style="margin:0 0 14px 0;padding-left:18px;font-size:0.88rem">{fi}</ul>
352
+
353
  <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>
354
+ <div style="color:#cbd5e1;font-size:0.86rem;margin-bottom:14px;line-height:1.55">{cons}</div>
355
+
356
+ <div style="color:#8b95a7;font-size:0.68rem;text-transform:uppercase;letter-spacing:1.5px;margin-bottom:6px;font-weight:500">Supporting Literature</div>
357
+ <div style="margin-bottom:14px">{refs_html}</div>
358
+
359
  <div style="border-top:1px solid #252a35;padding-top:10px;color:#5e6675;font-size:0.74rem;line-height:1.5">
360
+ 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>"""
361
 
362
  return verdict, ensemble, report, sal_img
363