Spaces:
Sleeping
Sleeping
Merge pull request #4 from Vishal-VK18/singleshot
Browse filesFiles changed (4)
- DockerfileAdded+45
- README.md+166-1
- __pycache__/server.cpython-312.pyc
- requirements.txtAdded+12
123456789101112131415161718192021222324252627282930313233343536373839404142434445# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ# Cat Rescue OpenEnv โ Dockerfile# Compatible with Hugging Face Spaces (port 7860 required)## Build: docker build -t cat-rescue .# Run: docker run -p 7860:7860 cat-rescue# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Use the official slim Python 3.12 image as the baseFROM python:3.12-slim
# โโ Metadata โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโLABEL maintainer="Cat Rescue Team"LABEL description="Cat Rescue OpenEnv โ Meta ร PyTorch Hackathon"
# โโ System setup โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ# Set the working directory inside the containerWORKDIR /app
# Prevent Python from writing .pyc files and enable unbuffered stdout/stderr# (unbuffered output is important for real-time logs in HF Spaces)ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1
# โโ Install dependencies โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ# Copy only requirements first so Docker can cache this layerCOPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r requirements.txt
# โโ Copy application code โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ# Copy all project files into the container's working directoryCOPY environment.py .COPY rewards.py .COPY grader.py .COPY server.py .
# โโ Expose the port โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ# HuggingFace Spaces routes external traffic to port 7860EXPOSE 7860
# โโ Launch command โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ# Start the FastAPI app via uvicorn on 0.0.0.0:7860CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]1"# Cat Rescue OpenEnv"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166# ๐ฑ Cat Rescue โ OpenEnv Environment> **Meta ร PyTorch OpenEnv Hackathon by Scaler**> A grid-based reinforcement learning environment where an AI agent navigates rooms to rescue trapped cats.---## ๐ฎ Game ConceptThe 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)โโโ Dockerfile # Container build for HF Spacesโโโ requirements.txt # Python dependencies```---## ๐ Running Locally```bash# Install dependenciespip install -r requirements.txt# Start the serveruvicorn 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 imagedocker build -t cat-rescue .# Run the containerdocker run -p 7860:7860 cat-rescue```---## ๐ API Endpoints### `GET /`Health check โ confirms the server is up.### `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```pythonimport requestsBASE = "http://localhost:7860"# 1. Start a new episode on level 2obs = requests.post(f"{BASE}/reset", json={"level": 2, "seed": 0}).json()done = Falseepisode_log = []# 2. Run a random agentwhile not done:action = random.randint(0, 3) # replace with your policyresp = 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 episoderesult = requests.post(f"{BASE}/grade", json={"episode_log": episode_log}).json()print(result)```---## ๐๏ธ Deploying to Hugging Face Spaces1. 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`.---## ๐ LicenseMIT โ built for the **Meta ร PyTorch OpenEnv Hackathon by Scaler**.
123456789101112# Cat Rescue OpenEnv โ Python dependencies# Install with: pip install -r requirements.txt
# Web serverfastapi==0.115.12uvicorn[standard]==0.34.0
# OpenEnv base interfaceopenenv-core
# Data validation (FastAPI depends on this)pydantic==2.11.1DockerfileAdded+45
README.md+166-1
__pycache__/server.cpython-312.pyc
requirements.txtAdded+12