File size: 1,571 Bytes
18d028b
 
 
 
 
 
 
 
 
9ad7573
18d028b
 
 
 
51fa863
 
 
 
 
 
 
9ad7573
 
 
 
 
 
18d028b
 
 
7dc8ce6
 
 
 
62443b6
 
7dc8ce6
18d028b
961668b
 
 
7dc8ce6
961668b
18d028b
 
 
 
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
"""Hugging Face Space entry point.

HF Spaces auto-discovers `app.py` at the repo root and launches whatever
Gradio interface it builds. Keep this file thin — real UI lives in
`signbridge.space`.
"""

from __future__ import annotations

import logging
import os

from dotenv import load_dotenv

# CRITICAL: load .env BEFORE importing signbridge.* — the recognizer's
# DEFAULT_VLM_MODEL constant is read from os.environ at module-load
# time. If we waited until main(), env vars set in .env would never
# reach the constant and the recognizer would fall back to a model
# that doesn't exist on the AMD endpoint (404 Not Found).
load_dotenv()

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)

from signbridge.space import build_demo  # noqa: E402


def main() -> None:
    # Make gradio's `_check_localhost` pre-flight skip itself — on HF Spaces
    # Docker the loopback connect-back occasionally races the bind and trips
    # the "When localhost is not accessible" guard. Setting SYSTEM=spaces
    # mirrors what the gradio-SDK runtime sets and is the documented escape
    # hatch. share=True was used earlier as a backup but HF Spaces warns it
    # is unsupported; SYSTEM=spaces alone is now sufficient.
    os.environ.setdefault("SYSTEM", "spaces")
    demo = build_demo()
    demo.queue().launch(
        server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
        server_port=int(os.getenv("GRADIO_SERVER_PORT", "7860")),
        show_error=True,
    )


if __name__ == "__main__":
    main()