Spaces:
Sleeping
Sleeping
|
Download README.md from Vizxal/Cat-Rescue: direct link, hf CLI and curl.
- Browser
- Download file 3.75 kB
-
https://huggingface.co/spaces/Vizxal/Cat-Rescue/resolve/main/README.md
- Command line
-
hf download hf://spaces/Vizxal/Cat-Rescue/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Vizxal/Cat-Rescue/resolve/main/README.md
3.75 kB
| title: Cat Rescue | |
| emoji: ๐ฑ | |
| colorFrom: blue | |
| colorTo: green | |
| sdk: docker | |
| pinned: false | |
| # ๐ฑ Cat Rescue โ OpenEnv Environment | |
| > A grid-based reinforcement learning environment where an AI agent navigates rooms to rescue trapped cats. | |
| ๐ฎ **Live Demo:** https://vizxal-cat-rescue.hf.space | |
| ๐ค **HF Space:** https://huggingface.co/spaces/Vizxal/Cat-Rescue/tree/main | |
| --- | |
| ## ๐ฎ Game Concept | |
| The agent starts at the top-left corner of a grid and must reach every cat before the step budget runs out. Static walls block movement on higher levels, and moving obstacles patrol the grid on the hardest level. | |
| | Level | Grid | Cats | Obstacles | | |
| |-------|------|------|-----------| | |
| | 1 | 3 ร 3 | 1 | None | | |
| | 2 | 5 ร 5 | 2 | Static walls | | |
| | 3 | 7 ร 7 | 3 | Static walls + 2 moving | | |
| ### Actions | |
| | Integer | Direction | | |
| |---------|-----------| | |
| | `0` | UP | | |
| | `1` | DOWN | | |
| | `2` | LEFT | | |
| | `3` | RIGHT | | |
| ### Rewards | |
| | Event | Reward | | |
| |-------|--------| | |
| | Every step taken | `โ0.1` | | |
| | Hit a wall / boundary | `โ0.3` | | |
| | Rescue a cat | `+1.0` | | |
| | All cats rescued (bonus) | `+2.0` | | |
| --- | |
| ## ๐ Project Structure | |
| ``` | |
| Cat-Rescue/ | |
| โโโ environment.py # Core game logic โ CatRescueEnv | |
| โโโ rewards.py # Reward schedule โ CatRescueRewards | |
| โโโ grader.py # Episode scoring โ CatRescueGrader | |
| โโโ server.py # FastAPI server (OpenEnv HTTP API) | |
| โโโ index.html # Human playable UI | |
| โโโ Dockerfile # Container build for HF Spaces | |
| โโโ requirements.txt # Python dependencies | |
| ``` | |
| --- | |
| ## ๐ Running Locally | |
| ```bash | |
| # Install dependencies | |
| pip install -r requirements.txt | |
| # Start the server | |
| uvicorn server:app --host 0.0.0.0 --port 7860 | |
| ``` | |
| Open the interactive API docs at **[http://localhost:7860/docs](http://localhost:7860/docs)** | |
| --- | |
| ## ๐ณ Running with Docker | |
| ```bash | |
| # Build the image | |
| docker build -t cat-rescue . | |
| # Run the container | |
| docker run -p 7860:7860 cat-rescue | |
| ``` | |
| --- | |
| ## ๐ API Endpoints | |
| ### `GET /` | |
| Serves the human playable UI. | |
| ### `POST /reset` | |
| Start a new episode. Re-initialises the environment. | |
| **Request body:** | |
| ```json | |
| { "level": 1, "max_steps": 200, "seed": 42 } | |
| ``` | |
| ### `POST /step` | |
| Take one action. Returns the new observation, reward, done flag, and info dict. | |
| **Request body:** | |
| ```json | |
| { "action": 0 } | |
| ``` | |
| **Response:** | |
| ```json | |
| { | |
| "observation": { "grid": [...], "agent_pos": [0,1], "cats_rescued": 0 }, | |
| "reward": -0.1, | |
| "done": false, | |
| "info": { "event": "step", "cats_rescued": 0, "step_count": 1 } | |
| } | |
| ``` | |
| ### `GET /state` | |
| Read the current grid state without advancing the episode. | |
| ### `POST /grade` | |
| Score a completed episode log. | |
| **Request body:** | |
| ```json | |
| { | |
| "episode_log": [ | |
| { "action": 1, "reward": -0.1, "done": false, "info": {} } | |
| ] | |
| } | |
| ``` | |
| --- | |
| ## ๐ค Quickstart Agent Loop | |
| ```python | |
| import requests | |
| import random | |
| BASE = "https://vizxal-cat-rescue.hf.space" | |
| # 1. Start a new episode on level 2 | |
| obs = requests.post(f"{BASE}/reset", json={"level": 2, "seed": 0}).json() | |
| done = False | |
| episode_log = [] | |
| # 2. Run a random agent | |
| while not done: | |
| action = random.randint(0, 3) | |
| resp = requests.post(f"{BASE}/step", json={"action": action}).json() | |
| done = resp["done"] | |
| episode_log.append({ | |
| "action": action, | |
| "reward": resp["reward"], | |
| "done": resp["done"], | |
| "info": resp["info"], | |
| }) | |
| # 3. Grade the episode | |
| result = requests.post(f"{BASE}/grade", json={"episode_log": episode_log}).json() | |
| print(result) | |
| ``` | |
| --- | |
| ## ๐๏ธ Deploying to Hugging Face Spaces | |
| 1. Create a new Space with **Docker** as the SDK | |
| 2. Push this repository to the Space | |
| 3. HF Spaces automatically builds the Dockerfile and routes traffic to port `7860` | |
| --- | |
| ## ๐ License | |
| MIT |