Use demo cache immediately and memoize results
Browse files298 unmodified lines299300301302303304221 unmodified lines526527528529530531225 unmodified lines75775875976076176276376476576613 unmodified lines780781782783784785786298 unmodified lines# ── model loading ──────────────────────────────────────────────────────────_model_cache: dict[str, list] = {}def get_models(atlas: str = "cc200"):global _model_cache221 unmodified linesreturn "", "", "", Nonepath = Path(file_path)atlas_key = "cc200" # default; overridden below for .1D filestry:if path.suffix == ".npz":225 unmodified lines# LLM clinical interpretation via AMD MI300X vLLM endpoint# Fall back to demo cache for known subjects if endpoint is down_demo_key = os.path.basename(file_path) if file_path else ""llm_text = _llm_report(p_mean, per_model, net_saliency=net_saliency)if llm_text.startswith("[LLM unavailable") and _demo_key in _DEMO_LLM_CACHE:llm_text = _DEMO_LLM_CACHE[_demo_key]import re as _redef _md_to_html(txt):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)13 unmodified linesAI-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# ── Static HTML sections ───────────────────────────────────────────────────298 unmodified lines299300301302303304305221 unmodified lines527528529530531532533534535536537225 unmodified lines76376476576676776876977077177213 unmodified lines786787788789790791792793794298 unmodified lines# ── model loading ──────────────────────────────────────────────────────────_model_cache: dict[str, list] = {}_result_cache: dict[str, tuple[str, str, str, object]] = {}def get_models(atlas: str = "cc200"):global _model_cache221 unmodified linesreturn "", "", "", Nonepath = Path(file_path)cache_key = str(path)if cache_key in _result_cache:return _result_cache[cache_key]demo_key = path.nameatlas_key = "cc200" # default; overridden below for .1D filestry:if path.suffix == ".npz":225 unmodified lines# LLM clinical interpretation via AMD MI300X vLLM endpoint# Fall back to demo cache for known subjects if endpoint is downif demo_key in _DEMO_LLM_CACHE:llm_text = _DEMO_LLM_CACHE[demo_key]else:llm_text = _llm_report(p_mean, per_model, net_saliency=net_saliency)import re as _redef _md_to_html(txt):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)13 unmodified linesAI-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>"""result = (verdict, ensemble, report, sal_img)_result_cache[cache_key] = resultreturn result# ── Static HTML sections ───────────────────────────────────────────────────
app.py+13-5