File size: 1,401 Bytes
13b4881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0a7466
 
13b4881
 
 
 
 
 
d0a7466
 
 
13b4881
aa50c6c
13b4881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""FastAPI application for the Carrom environment."""

import os

from openenv.core.env_server.http_server import create_app

from carrom_env.models import Action, Observation
from server.carrom_environment import CarromEnvironment

# Use custom visual Gradio UI when web interface is enabled
_enable_web = os.getenv("ENABLE_WEB_INTERFACE", "false").lower() in ("true", "1", "yes")

if _enable_web:
    from server.gradio_ui import build_carrom_ui

    _gradio_app = build_carrom_ui()
    # Streaming generators (animation frames) require an explicit queue.
    _gradio_app.queue(default_concurrency_limit=4)

    from openenv.core.env_server.http_server import create_fastapi_app

    # Create the base API app (reset/step/state/health/schema endpoints)
    app = create_fastapi_app(CarromEnvironment, Action, Observation)

    # Mount the Gradio UI at "/" so HF Spaces' root-path iframe shows it.
    # Mounting the same Blocks at multiple paths breaks the SSE/queue
    # routing, so keep this to a single mount.
    import gradio as gr
    app = gr.mount_gradio_app(app, _gradio_app, path="/")
else:
    app = create_app(
        CarromEnvironment,
        Action,
        Observation,
        env_name="carrom_env",
    )


def main() -> None:
    """Entry point for direct execution."""
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)


if __name__ == "__main__":
    main()