File size: 1,218 Bytes
db24169
 
 
0043197
db24169
0043197
 
 
 
 
db24169
 
0043197
 
db24169
 
 
 
 
 
 
 
 
 
 
 
0043197
 
 
 
 
 
 
 
 
 
 
 
db24169
0043197
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
from environment.server import CannonWallEnvironment
import uvicorn
from fastapi import FastAPI
from fastapi.responses import RedirectResponse

# Import Gradio and mount it
import gradio as gr
from ui.demo import demo as gradio_demo

api = FastAPI(title="Cannon & Wall β€” RedBlue Arena")
env = CannonWallEnvironment()

# ── Environment API routes ──────────────────────────────────────────────────

@api.post("/reset")
def reset(stage: int = 1):
    return env.reset(stage=stage)

@api.post("/step")
def step(action: dict):
    return env.step(action)

@api.get("/state")
def state():
    return env.state

@api.get("/health")
def health():
    return {"status": "ok"}

# Redirect bare root to /ui/ so judges land on the demo
@api.get("/")
def root():
    return RedirectResponse(url="/ui/")

# ── Mount Gradio at /ui ─────────────────────────────────────────────────────
api = gr.mount_gradio_app(api, gradio_demo, path="/ui")

if __name__ == "__main__":
    uvicorn.run(api, host="0.0.0.0", port=7860)