Download server.py from Varshith226/propagationshield-env: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Varshith226/propagationshield-env/resolve/main/server.py
- Command line
-
hf download hf://spaces/Varshith226/propagationshield-env/server.py
-
curl -L -o server.py https://huggingface.co/spaces/Varshith226/propagationshield-env/resolve/main/server.py
1.05 kB
| from fastapi import FastAPI | |
| from env.models import Action | |
| from env.environment import PropagationShieldEnvironment | |
| import asyncio | |
| app = FastAPI(title="PropagationShield Environment Server") | |
| env = PropagationShieldEnvironment() | |
| async def reset_endpoint(config: dict = {}): | |
| obs, state = env.reset(config) | |
| # We return the dict version of the Pydantic models for the JSON response | |
| return {"observation": obs.model_dump(), "state": state.model_dump()} | |
| async def step_endpoint(action: Action): | |
| try: | |
| # Wrapping in timeout as required by Section 8.5 | |
| obs, rewards, done, info = await asyncio.wait_for( | |
| asyncio.to_thread(env.step, action), | |
| timeout=30.0 | |
| ) | |
| return { | |
| "observation": obs.model_dump(), | |
| "reward": rewards, | |
| "done": done, | |
| "info": info | |
| } | |
| except asyncio.TimeoutError: | |
| return {"reward": {"total": 0.0}, "done": True, "info": {"error": "timeout"}} |