VibecoderMcSwaggins commited on
Commit
518063b
·
1 Parent(s): c88f831

fix(ui): load NiiVue directly in js_on_load, remove head= dependency (#24)

Browse files

Root cause: The `head=` parameter injects a <script type="module"> that loads
NiiVue at page load time. If this ES module import fails (404, wrong MIME type,
or network error), it can block Gradio's Svelte app from hydrating, causing the
"Loading..." spinner to show forever.

Fix: Make js_on_load completely self-sufficient for NiiVue loading:
1. Embed NiiVue library URL in HTML via data-niivue-url attribute
2. js_on_load loads NiiVue directly via dynamic import() from this URL
3. Cache loaded Niivue in window.Niivue for subsequent uses
4. Remove head= parameter from launch() - no longer needed

This ensures Gradio always loads (even if NiiVue fails to load), and NiiVue
loading errors are isolated to the viewer component, not blocking the whole app.

Also: Add pyarrow to mypy overrides (proper fix for missing stubs).

All 136 tests pass. Lint, format, mypy clean.

pyproject.toml CHANGED
@@ -111,6 +111,7 @@ module = [
111
  "datasets.*",
112
  "niivue.*",
113
  "numpy.*",
 
114
  "pytest.*",
115
  # DeepISLES modules (only available in DeepISLES Docker image)
116
  "src.isles22_ensemble",
 
111
  "datasets.*",
112
  "niivue.*",
113
  "numpy.*",
114
+ "pyarrow.*",
115
  "pytest.*",
116
  # DeepISLES modules (only available in DeepISLES Docker image)
117
  "src.isles22_ensemble",
src/stroke_deepisles_demo/data/adapter.py CHANGED
@@ -269,7 +269,7 @@ class HuggingFaceDataset:
269
  Returns:
270
  Dict with dwi_bytes, adc_bytes, and optionally mask_bytes
271
  """
272
- import pyarrow.parquet as pq # type: ignore[import-untyped]
273
  from huggingface_hub import HfFileSystem
274
 
275
  from stroke_deepisles_demo.data.constants import ISLES24_NUM_FILES
 
269
  Returns:
270
  Dict with dwi_bytes, adc_bytes, and optionally mask_bytes
271
  """
272
+ import pyarrow.parquet as pq
273
  from huggingface_hub import HfFileSystem
274
 
275
  from stroke_deepisles_demo.data.constants import ISLES24_NUM_FILES