File size: 1,166 Bytes
bf96836
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Container startup preflight for Hugging Face Spaces."""

from __future__ import annotations

import importlib.util
import os
import sys


REQUIRED_MODULES = [
    "app",
    "charts",
    "corpora",
    "model_registry",
    "openrouter",
    "pricing",
    "provenance",
    "token_tax",
    "token_tax_ui",
    "tokenizer",
]


def _check_required_modules() -> None:
    missing = [
        module_name
        for module_name in REQUIRED_MODULES
        if importlib.util.find_spec(module_name) is None
    ]
    if missing:
        raise RuntimeError(
            "Space startup preflight failed. Missing runtime modules: "
            + ", ".join(sorted(missing))
        )


def main() -> None:
    _check_required_modules()

    from app import build_ui

    app = build_ui()
    app.launch(
        server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
        server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
        ssr_mode=False,
    )


if __name__ == "__main__":
    try:
        main()
    except Exception as exc:  # pragma: no cover - exercised in container
        print(str(exc), file=sys.stderr, flush=True)
        raise