File size: 1,940 Bytes
a544a50
 
 
 
 
 
 
 
 
 
d77e99f
1973147
 
d77e99f
 
aff5726
 
 
 
 
 
 
 
 
 
d77e99f
a544a50
 
 
 
d77e99f
 
 
 
a544a50
 
 
 
 
1973147
08c3363
 
 
a544a50
 
 
 
 
 
aff5726
08c3363
a544a50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Entry point for Hugging Face Spaces deployment.

This module provides the entry point for deploying the stroke-deepisles-demo
application to Hugging Face Spaces. It handles environment detection and
configures Gradio appropriately for the deployment environment.

See:
    - docs/specs/07-hf-spaces-deployment.md
    - https://huggingface.co/docs/hub/spaces-sdks-docker
"""

from pathlib import Path

import gradio as gr

# CRITICAL: Allow direct file serving for local assets (niivue.js)
# This fixes the P0 "Loading..." bug on HF Spaces (Issue #11649)
# Must be called BEFORE creating any Blocks
_ASSETS_DIR = Path(__file__).parent / "src" / "stroke_deepisles_demo" / "ui" / "assets"
gr.set_static_paths(paths=[str(_ASSETS_DIR)])

from stroke_deepisles_demo.core.config import get_settings  # noqa: E402
from stroke_deepisles_demo.core.logging import setup_logging  # noqa: E402
from stroke_deepisles_demo.ui.app import get_demo  # noqa: E402
from stroke_deepisles_demo.ui.viewer import get_niivue_loader_path  # noqa: E402

# Initialize logging
settings = get_settings()
setup_logging(settings.log_level, format_style=settings.log_format)

# Create the demo instance at module level for Gradio
demo = get_demo()

if __name__ == "__main__":
    # Launch configuration
    # - server_name: 0.0.0.0 required for HF Spaces (Docker)
    # - server_port: 7860 is HF Spaces default
    # - theme: Gradio 6 uses launch() for theme
    # - css: Hide footer for cleaner look

    # Generate the NiiVue loader HTML file (creates if needed)
    niivue_loader = get_niivue_loader_path()

    demo.launch(
        server_name=settings.gradio_server_name,
        server_port=settings.gradio_server_port,
        share=settings.gradio_share,
        theme=gr.themes.Soft(),
        css="footer {visibility: hidden}",
        allowed_paths=[str(_ASSETS_DIR)],
        head_paths=[str(niivue_loader)],  # Official Gradio approach (Issue #11649)
    )