File size: 1,888 Bytes
29db30b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
"""
NEXUS - HuggingFace Spaces Entry Point

Launches the Streamlit demo for the NEXUS Maternal-Neonatal Care Platform.
Built with Google HAI-DEF models for the MedGemma Impact Challenge 2026.
"""

import os
import subprocess
import sys
from pathlib import Path

# Ensure src/ is on the Python path for imports
ROOT = Path(__file__).parent
SRC_DIR = ROOT / "src"
if str(SRC_DIR) not in sys.path:
    sys.path.insert(0, str(SRC_DIR))

# Set environment defaults for HF Spaces
os.environ.setdefault("STREAMLIT_SERVER_PORT", "7860")
os.environ.setdefault("STREAMLIT_SERVER_ADDRESS", "0.0.0.0")
os.environ.setdefault("STREAMLIT_SERVER_HEADLESS", "true")
os.environ.setdefault("STREAMLIT_BROWSER_GATHER_USAGE_STATS", "false")


def main():
    app_path = SRC_DIR / "demo" / "streamlit_app.py"
    if not app_path.exists():
        print(f"ERROR: Streamlit app not found at {app_path}")
        sys.exit(1)

    port = os.environ.get("PORT", os.environ["STREAMLIT_SERVER_PORT"])
    os.environ["STREAMLIT_SERVER_PORT"] = str(port)

    try:
        subprocess.run(
            [
                sys.executable, "-m", "streamlit", "run",
                str(app_path),
                f"--server.port={port}",
                f"--server.address={os.environ['STREAMLIT_SERVER_ADDRESS']}",
                f"--server.headless={os.environ['STREAMLIT_SERVER_HEADLESS']}",
                f"--browser.gatherUsageStats={os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS']}",
            ],
            check=True,
            env={**os.environ, "PYTHONPATH": str(SRC_DIR)},
        )
    except subprocess.CalledProcessError as e:
        print(f"ERROR: Streamlit process exited with code {e.returncode}")
        sys.exit(e.returncode)
    except FileNotFoundError:
        print("ERROR: Streamlit not installed. Run: pip install streamlit")
        sys.exit(1)


if __name__ == "__main__":
    main()