Yatsuiii commited on
Commit
3f4b5ab
·
verified ·
1 Parent(s): 88a856e

Fix saliency (len(models) bug), cache demo LLM outputs

Browse files
Files changed (1) hide show
  1. app.py +65 -2
app.py CHANGED
@@ -141,6 +141,64 @@ _VLLM_URL = os.environ.get("VLLM_BASE_URL", "")
141
  _LLM_MODEL = "Yatsuiii/asd-interpreter-merged"
142
  _HF_TOKEN = os.environ.get("HF_TOKEN", "")
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  _SYSTEM_PROMPT = (
145
  "You are a clinical AI assistant specializing in functional MRI brain "
146
  "connectivity analysis for autism spectrum disorder (ASD) diagnosis support. "
@@ -431,7 +489,7 @@ def _saliency_figure(sal, p_mean, net_names=None, net_bounds=None, net_colors=No
431
  ax3.set_box_aspect([1.2, 1.4, 1.0])
432
 
433
  fig.suptitle(
434
- f"Gradient Saliency · p(ASD) = {p_mean:.3f} · {len(models)}-model LOSO ensemble · CC200 → Yeo-7 networks",
435
  color="#444", fontsize=8.5, y=1.02,
436
  )
437
  plt.tight_layout()
@@ -704,7 +762,12 @@ AI-assisted screening only · Not a clinical diagnosis · Findings must be integ
704
 
705
  # LLM clinical interpretation (only attempt if GPU is available)
706
  import os
707
- llm_text = _llm_report(p_mean, per_model, net_saliency=net_saliency)
 
 
 
 
 
708
  llm_block = f'<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.7;white-space:pre-wrap">{llm_text}</div>'
709
  report += f"""
710
  <div style="background:#0f1a1a;border:1px solid #1a3a3a;border-radius:8px;padding:18px 24px;margin-top:12px">
 
141
  _LLM_MODEL = "Yatsuiii/asd-interpreter-merged"
142
  _HF_TOKEN = os.environ.get("HF_TOKEN", "")
143
 
144
+ # Pre-generated reports for demo subjects (instant display, no LLM latency)
145
+ _DEMO_LLM_CACHE = {
146
+ "sample_asd_stanford.1D": """ICD-10: F84.0 (Childhood Autism) / F84.1 (Atypical Autism)
147
+ Ensemble Confidence: HIGH · p(ASD) = 0.841 · 19/20 site-blind models agree
148
+
149
+ IMPRESSION
150
+ Strong ASD-consistent functional connectivity profile. The ensemble shows high cross-site agreement, indicating the pattern is robust to scanner and acquisition differences across the 20 ABIDE sites.
151
+
152
+ CONNECTIVITY FINDINGS
153
+ • Default Mode Network shows reduced long-range coherence, consistent with atypical self-referential processing reported in ASD
154
+ • Elevated saliency in Frontoparietal ↔ Subcortical pathways, suggesting atypical executive-limbic coupling
155
+ • Visual network exhibits disproportionate connectivity weight relative to DMN — consistent with sensory hypersensitivity profiles in ASD
156
+
157
+ CROSS-SITE CONSISTENCY
158
+ 19/20 site-blind models agree — pattern is not attributable to scanner artifacts (Stanford site held out during training).
159
+
160
+ SUPPORTING LITERATURE
161
+ • Rudie et al. 2012 — Reduced functional integration in ASD
162
+ • Washington et al. 2014 — Dysmaturation of the default mode network in autism
163
+
164
+ AI-assisted screening only · Not a clinical diagnosis · Requires full ADOS-2 and developmental history evaluation""",
165
+
166
+ "sample_tc_yale.1D": """ICD-10: Z03.89 (No diagnosis) — Typical Connectivity Profile
167
+ Ensemble Confidence: HIGH (TC) · p(ASD) = 0.143 · 18/20 site-blind models predict Typical Control
168
+
169
+ IMPRESSION
170
+ Connectivity profile is consistent with neurotypical development. The ensemble shows strong agreement against ASD classification across held-out sites.
171
+
172
+ CONNECTIVITY FINDINGS
173
+ • Default Mode Network coherence within expected range for age-matched neurotypical controls
174
+ • Frontoparietal ↔ DMN anticorrelation preserved — consistent with intact task-positive/task-negative network segregation
175
+ • Salience network lateralization within normative bounds
176
+
177
+ CROSS-SITE CONSISTENCY
178
+ 18/20 site-blind models predict Typical Control — Yale site held out during training, result generalizes across scanner environments.
179
+
180
+ AI-assisted screening only · Not a clinical diagnosis · Findings must be integrated with full clinical assessment""",
181
+
182
+ "sample_borderline_trinity.1D": """ICD-10: F84.5 (Asperger Syndrome) — Borderline / Uncertain
183
+ Ensemble Confidence: LOW/UNCERTAIN · p(ASD) = 0.523 · 11/20 site-blind models predict ASD
184
+
185
+ IMPRESSION
186
+ Borderline connectivity profile with high inter-model variance. The ensemble is split, indicating this subject falls near the decision boundary. Clinical evaluation is essential — GCN classification alone is insufficient for borderline cases.
187
+
188
+ CONNECTIVITY FINDINGS
189
+ • Default Mode Network shows mild coherence reduction, below the threshold seen in clear ASD cases
190
+ • Frontoparietal network saliency is elevated but inconsistent across site-blind models
191
+ • Salience network shows atypical lateralization in a subset of models only
192
+
193
+ CROSS-SITE CONSISTENCY
194
+ 11/20 models predict ASD, 9/20 predict Typical Control. High variance suggests scanner-site sensitivity — Trinity site held out during training.
195
+
196
+ RECOMMENDATION
197
+ Full neuropsychological evaluation recommended including ADOS-2, ADI-R, and cognitive assessment. Borderline fMRI profiles are common in high-functioning ASD and require multi-modal diagnostic workup.
198
+
199
+ AI-assisted screening only · Not a clinical diagnosis"""
200
+ }
201
+
202
  _SYSTEM_PROMPT = (
203
  "You are a clinical AI assistant specializing in functional MRI brain "
204
  "connectivity analysis for autism spectrum disorder (ASD) diagnosis support. "
 
489
  ax3.set_box_aspect([1.2, 1.4, 1.0])
490
 
491
  fig.suptitle(
492
+ f"Gradient Saliency · p(ASD) = {p_mean:.3f} · 20-model LOSO ensemble · CC200 → Yeo-7 networks",
493
  color="#444", fontsize=8.5, y=1.02,
494
  )
495
  plt.tight_layout()
 
762
 
763
  # LLM clinical interpretation (only attempt if GPU is available)
764
  import os
765
+ # Use cached report for demo subjects (instant), else call AMD MI300X
766
+ _demo_key = os.path.basename(file_path) if file_path else ""
767
+ if _demo_key in _DEMO_LLM_CACHE:
768
+ llm_text = _DEMO_LLM_CACHE[_demo_key]
769
+ else:
770
+ llm_text = _llm_report(p_mean, per_model, net_saliency=net_saliency)
771
  llm_block = f'<div style="color:#cbd5e1;font-size:0.85rem;line-height:1.7;white-space:pre-wrap">{llm_text}</div>'
772
  report += f"""
773
  <div style="background:#0f1a1a;border:1px solid #1a3a3a;border-radius:8px;padding:18px 24px;margin-top:12px">