Yatsuiii commited on
Commit
9fe6799
·
1 Parent(s): e6b302b

Use demo cache immediately and memoize results

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -299,6 +299,7 @@ def _llm_report(p_mean: float, per_model: list, net_saliency: dict | None = None
299
  # ── model loading ──────────────────────────────────────────────────────────
300
 
301
  _model_cache: dict[str, list] = {}
 
302
 
303
  def get_models(atlas: str = "cc200"):
304
  global _model_cache
@@ -526,6 +527,11 @@ def run_gcn(file_path):
526
  return "", "", "", None
527
 
528
  path = Path(file_path)
 
 
 
 
 
529
  atlas_key = "cc200" # default; overridden below for .1D files
530
  try:
531
  if path.suffix == ".npz":
@@ -757,10 +763,10 @@ CC200 LOSO AUC = 0.7298 · HO = 0.7212 · AAL = 0.6959 · 1,102 subjects · 20 s
757
 
758
  # LLM clinical interpretation via AMD MI300X vLLM endpoint
759
  # Fall back to demo cache for known subjects if endpoint is down
760
- _demo_key = os.path.basename(file_path) if file_path else ""
761
- llm_text = _llm_report(p_mean, per_model, net_saliency=net_saliency)
762
- if llm_text.startswith("[LLM unavailable") and _demo_key in _DEMO_LLM_CACHE:
763
- llm_text = _DEMO_LLM_CACHE[_demo_key]
764
  import re as _re
765
  def _md_to_html(txt):
766
  txt = _re.sub(r'^#{1,3}\s*(.+)$', r'<h4 style="color:#94a3b8;margin:1em 0 0.3em;font-size:0.9rem">\1</h4>', txt, flags=_re.MULTILINE)
@@ -780,7 +786,9 @@ CC200 LOSO AUC = 0.7298 · HO = 0.7212 · AAL = 0.6959 · 1,102 subjects · 20 s
780
  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>
781
  </div>"""
782
 
783
- return verdict, ensemble, report, sal_img
 
 
784
 
785
 
786
  # ── Static HTML sections ───────────────────────────────────────────────────
 
299
  # ── model loading ──────────────────────────────────────────────────────────
300
 
301
  _model_cache: dict[str, list] = {}
302
+ _result_cache: dict[str, tuple[str, str, str, object]] = {}
303
 
304
  def get_models(atlas: str = "cc200"):
305
  global _model_cache
 
527
  return "", "", "", None
528
 
529
  path = Path(file_path)
530
+ cache_key = str(path)
531
+ if cache_key in _result_cache:
532
+ return _result_cache[cache_key]
533
+
534
+ demo_key = path.name
535
  atlas_key = "cc200" # default; overridden below for .1D files
536
  try:
537
  if path.suffix == ".npz":
 
763
 
764
  # LLM clinical interpretation via AMD MI300X vLLM endpoint
765
  # Fall back to demo cache for known subjects if endpoint is down
766
+ if demo_key in _DEMO_LLM_CACHE:
767
+ llm_text = _DEMO_LLM_CACHE[demo_key]
768
+ else:
769
+ llm_text = _llm_report(p_mean, per_model, net_saliency=net_saliency)
770
  import re as _re
771
  def _md_to_html(txt):
772
  txt = _re.sub(r'^#{1,3}\s*(.+)$', r'<h4 style="color:#94a3b8;margin:1em 0 0.3em;font-size:0.9rem">\1</h4>', txt, flags=_re.MULTILINE)
 
786
  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>
787
  </div>"""
788
 
789
+ result = (verdict, ensemble, report, sal_img)
790
+ _result_cache[cache_key] = result
791
+ return result
792
 
793
 
794
  # ── Static HTML sections ───────────────────────────────────────────────────