world-simulator / app.py
DeltaZN
fix(hf): serve lobby at root, ship built frontend, honor proxy headers
6c64b04
Raw
History Blame Contribute Delete
1.26 kB
from __future__ import annotations
import os
import sys
from pathlib import Path
# The project uses a src-layout. On Hugging Face Spaces the package is not
# pip-installed (requirements.txt lists runtime deps directly, because HF runs
# pip install before copying the repo into the build context), so make the
# src/ directory importable here. Harmless locally where the package is already
# installed in editable mode.
sys.path.insert(0, str(Path(__file__).parent / "src"))
from world_simulator.api.gradio_app import create_gradio_app
app = create_gradio_app(
config_path=Path(os.getenv("WORLD_SIMULATOR_CONFIG", "config/game.modal.local.json")),
static_dir=Path(os.getenv("WORLD_SIMULATOR_STATIC_DIR", "dist/frontend")),
)
def _server_port() -> int:
value = os.getenv("GRADIO_SERVER_PORT")
return int(value) if value else 7860
if __name__ == "__main__":
import uvicorn
# Run with uvicorn rather than gr.Server.launch(): launch() does not start
# the event queue for the Gradio lobby mounted at /connect, which leaves its
# buttons inert. Uvicorn fires the mount's startup events so events work.
uvicorn.run(
app,
host=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
port=_server_port(),
)