Add GET / -> /demo/ redirect for Space iframe
Browse filesHF Spaces iframes load the Space URL root, but our FastAPI app only
defined endpoint routes. Visitors saw FastAPI's stock {detail: Not Found}.
Redirect / to /demo/ so the Gradio "before vs after" UI is what humans
land on; the JSON API surface (/health, /reset, /step, /grade, /tasks)
is unchanged for OpenEnv judges.
Made-with: Cursor
- app_runtime.py +8 -0
app_runtime.py
CHANGED
|
@@ -27,6 +27,7 @@ from typing import Any, Dict, Optional
|
|
| 27 |
|
| 28 |
from fastapi import FastAPI, HTTPException, Query
|
| 29 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 30 |
from pydantic import BaseModel
|
| 31 |
|
| 32 |
from env import Action, Observation, OpenSOCEnv
|
|
@@ -169,6 +170,13 @@ def health():
|
|
| 169 |
return {"status": "ok", "env": "OpenSOC", "version": "1.0.0"}
|
| 170 |
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
def main() -> None:
|
| 173 |
import uvicorn
|
| 174 |
|
|
|
|
| 27 |
|
| 28 |
from fastapi import FastAPI, HTTPException, Query
|
| 29 |
from fastapi.middleware.cors import CORSMiddleware
|
| 30 |
+
from fastapi.responses import RedirectResponse
|
| 31 |
from pydantic import BaseModel
|
| 32 |
|
| 33 |
from env import Action, Observation, OpenSOCEnv
|
|
|
|
| 170 |
return {"status": "ok", "env": "OpenSOC", "version": "1.0.0"}
|
| 171 |
|
| 172 |
|
| 173 |
+
@app.get("/", include_in_schema=False)
|
| 174 |
+
def index():
|
| 175 |
+
# Spaces iframes load the root URL; send human visitors to the Gradio
|
| 176 |
+
# demo and leave the JSON API endpoints untouched for the OpenEnv judge.
|
| 177 |
+
return RedirectResponse(url="/demo/", status_code=307)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
def main() -> None:
|
| 181 |
import uvicorn
|
| 182 |
|