Spaces:
Paused

dqa-openenv / server /app.py
neelshingavi's picture
fix: switch create_app to create_fastapi_app — remove Gradio root mount causing 404
da7445d
Raw History Blame Contribute Delete
2.36 kB
"""
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()