File size: 1,260 Bytes
1f1fdda
 
 
17f0444
1f1fdda
 
17f0444
 
 
 
 
 
 
6c64b04
1f1fdda
 
c58d3eb
 
1f1fdda
 
 
8c23bc3
1f1fdda
8c23bc3
1f1fdda
 
 
8c23bc3
 
 
 
 
 
 
 
 
1f1fdda
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
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(),
    )