Spaces:
Paused
Paused
File size: 2,362 Bytes
da7445d | 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | """
FastAPI application for the DQA-OpenEnv Environment.
Exposes the DqaOpenenvEnvironment over HTTP and WebSocket endpoints.
All routes are auto-generated by create_app() from openenv-core.
Endpoints (auto-generated):
POST /reset — Reset environment, returns initial observation
POST /step — Execute action, returns observation + reward
GET /state — Get current episode state
GET /health — Container health check
GET /docs — Auto-generated OpenAPI documentation
WS /ws — WebSocket for persistent low-latency sessions
"""
try:
from openenv.core.env_server.http_server import create_fastapi_app
except Exception as e:
raise ImportError(
"openenv-core is required. Install with: pip install openenv-core"
) from e
try:
from ..models import DQAAction, DQAObservation
from .dqa_openenv_environment import DqaOpenenvEnvironment
except (ModuleNotFoundError, ImportError):
try:
from models import DQAAction, DQAObservation
from server.dqa_openenv_environment import DqaOpenenvEnvironment
except ModuleNotFoundError:
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from models import DQAAction, DQAObservation
from server.dqa_openenv_environment import DqaOpenenvEnvironment
app = create_fastapi_app(
DqaOpenenvEnvironment,
DQAAction,
DQAObservation,
max_concurrent_envs=4,
)
@app.get("/", tags=["health"])
async def health_check():
"""
Root health check endpoint.
Required by Hugging Face Spaces infrastructure proxy.
Returns 200 OK so HF marks the Space as healthy.
"""
return {
"status": "ok",
"environment": "DQA-OpenEnv",
"version": "1.0.0",
"description": "Data Quality Assurance OpenEnv — RL environment for tabular data",
"endpoints": {
"reset": "/reset",
"step": "/step",
"state": "/state",
"websocket": "/ws",
"docs": "/docs"
}
}
@app.get("/health", tags=["health"])
async def health_alias():
return {"status": "ok"}
def main(host: str = "0.0.0.0", port: int = 7860):
"""Start the uvicorn server directly."""
import uvicorn
uvicorn.run(app, host=host, port=port)
if __name__ == "__main__":
main()
|