Spaces:
Running on Zero
Running on Zero
| """Hugging Face Spaces entry point. | |
| Spaces' Gradio SDK looks for a module-level `demo` in the file named by `app_file` | |
| in README.md and launches it. We can't name this `app.py` (it would collide with the | |
| `app/` package), so the README points `app_file` at `space_app.py`. | |
| Local development still uses `python -m app.main`; this module only exists for Spaces. | |
| """ | |
| from __future__ import annotations | |
| import os | |
| # Disable Gradio 6 SSR before anything imports/launches gradio. Gradio's own | |
| # default is client-side (SSR off), but the HF Spaces runtime turns SSR ON in the | |
| # container — it puts a Node SSR proxy in front of the Python backend, and that | |
| # layer fails to relay the API schema on Spaces, surfacing in the browser as | |
| # "Could not get API info. Connection errored out." SSR is only a first-paint | |
| # optimization; client-side rendering restores the direct frontend↔backend link. | |
| # HF sets GRADIO_SSR_MODE itself, so this must OVERRIDE (not setdefault); HF also | |
| # owns the launch() call, so the env var — not a launch(ssr_mode=…) kwarg — is the | |
| # only lever that reaches the Spaces launch. | |
| os.environ["GRADIO_SSR_MODE"] = "false" | |
| from app.main import build_app | |
| # Module-level `demo` is the canonical HF Spaces contract — the runtime finds and | |
| # launches it. Building at import is intended here (Spaces imports this file). | |
| demo = build_app() | |
| if __name__ == "__main__": | |
| demo.launch() | |