Spaces:
Sleeping
Sleeping
Download server/app.py from anmol1620/cloud-env-openenv: direct link, hf CLI and curl.
- Browser
- Download file 813 Bytes
-
https://huggingface.co/spaces/anmol1620/cloud-env-openenv/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/anmol1620/cloud-env-openenv/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/anmol1620/cloud-env-openenv/resolve/main/server/app.py
813 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from env import CloudEnv | |
| app = FastAPI() | |
| env = None | |
| # --------- API --------- | |
| class Action(BaseModel): | |
| action: int | |
| def home(): | |
| return {"message": "Cloud OpenEnv is running "} | |
| def reset(): | |
| global env | |
| env = CloudEnv("easy") | |
| state = env.reset() | |
| return state.__dict__ | |
| def step(action: Action): | |
| global env | |
| state, reward, done, _ = env.step(action.action) | |
| return { | |
| "state": state.__dict__, | |
| "reward": reward, | |
| "done": done | |
| } | |
| def get_state(): | |
| global env | |
| return env.state().__dict__ | |
| def main(): | |
| import uvicorn | |
| uvicorn.run("app:app", host="0.0.0.0", port=7860) | |
| if __name__ == "__main__": | |
| main() |