Spaces:
Paused
Paused
Download server/app.py from Adity00/dqa-openenv: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/spaces/Adity00/dqa-openenv/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/Adity00/dqa-openenv/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Adity00/dqa-openenv/resolve/main/server/app.py
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, | |
| ) | |
| 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" | |
| } | |
| } | |
| 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() | |