File size: 1,469 Bytes
7dab768
 
9b9b1cd
c51d36c
 
 
 
 
 
 
3be5901
 
 
 
 
 
 
 
 
 
 
 
 
4f5afca
7dab768
3be5901
 
 
 
 
 
 
7dab768
 
9b9b1cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dab768
9b9b1cd
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
59
"""Hugging Face Spaces launcher for the GCMD classifier MVP."""

import os
import sys
from pathlib import Path

SRC_PATH = Path(__file__).resolve().parent / "src"
if SRC_PATH.exists() and str(SRC_PATH) not in sys.path:
    sys.path.insert(0, str(SRC_PATH))

try:
    import spaces
except ImportError:

    class _SpacesFallback:
        @staticmethod
        def GPU(function=None):
            if function is None:
                return lambda inner_function: inner_function
            return function

    spaces = _SpacesFallback()

from gcmd_classifier.ui.gradio_app import GRADIO_CSS, create_demo  # noqa: E402


@spaces.GPU
def _zerogpu_startup_probe() -> str:
    """No-op ZeroGPU startup probe for Hugging Face Spaces detection."""
    return "ok"


demo = create_demo()


def gradio_server_name() -> str:
    """Return the configured Gradio bind host for local and Spaces runtime."""
    return os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0")


def gradio_server_port() -> int:
    """Return the configured Gradio bind port for local and Spaces runtime."""
    return int(os.environ.get("GRADIO_SERVER_PORT", "7860"))


def launch() -> None:
    """Launch the Gradio demo with Hugging Face compatible server settings."""
    demo.queue().launch(
        css=GRADIO_CSS,
        server_name=gradio_server_name(),
        server_port=gradio_server_port(),
        share=False,
        prevent_thread_lock=False,
    )


if __name__ == "__main__":
    launch()