CoolFace
Apppublic

AbhishekKharat11/disaster_response_env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

🚨 Disaster Response Coordination Environment

![OpenEnv](https://github.com/meta-pytorch/OpenEnv) ![HuggingFace](https://huggingface.co/spaces) ![Python 3.10+](https://www.python.org) ![License: MIT](LICENSE)

An OpenEnv-compatible reinforcement learning environment where AI agents coordinate emergency response operations across real-world disaster scenarios.

🌟 What Makes This Unique

Most RL environments use abstract reward signals. This environment uses real-world disaster triage logic β€” the same frameworks used by actual emergency management agencies (ICS β€” Incident Command System). The agent must:

  • β€”Think like a commander, not just pick from discrete options
  • β€”Allocate scarce resources across competing life-or-death priorities
  • β€”Adapt as situations evolve with new information each step
  • β€”Communicate clearly β€” feedback explicitly rewards command-quality briefings

The grader uses a hybrid rule-based + LLM evaluation system, rewarding both correct allocation decisions and the quality of reasoning β€” perfect for training language models via GRPO.


🎯 Tasks

TaskNameDifficultyStepsResourcesScenarios
1Apartment Building FireEasy14 types3 zones
2Urban Earthquake β€” 4 DistrictsMedium34 types4 districts
3Category 5 HurricaneHard58 types6 zones

Task 1 β€” Apartment Building Fire (Easy)

A 10-storey building fire in downtown Bengaluru. Three areas need coverage:

  • β€”Area A (Floors 3-5): 12 trapped, accessible stairwell
  • β€”Area B (Floors 8-9): 25 trapped including children and elderly, elevator shaft on fire
  • β€”Area C (Street): 8 minor injuries, gas main risk

One step to deploy all resources. Maximum lives saved wins.

Task 2 β€” Urban Earthquake (Medium)

M6.8 earthquake, 4 districts, 3 steps. New information arrives each step β€” a gas leak update in Step 2, an aftershock in Step 3. The agent must adapt its strategy as the situation evolves.

Task 3 β€” Category 5 Hurricane (Hard)

Full city disaster. Six zones ranging from a chemical plant ammonia leak to hospital evacuation to water treatment contamination. A second storm band grounds boats mid-episode. Repairing the railway bridge doubles resource capacity for later steps β€” testing whether the agent can think strategically across time.


πŸ—οΈ Architecture

disaster_response_env/
β”œβ”€β”€ models.py                  # DisasterAction, DisasterObservation (Pydantic)
β”œβ”€β”€ client.py                  # DisasterResponseEnv (OpenEnv EnvClient)
β”œβ”€β”€ baseline_agent.py          # GPT-4o powered demonstration agent
β”œβ”€β”€ pyproject.toml             # Package config
β”œβ”€β”€ openenv.yaml               # OpenEnv manifest
└── server/
    β”œβ”€β”€ app.py                 # FastAPI app (create_app wrapper)
    β”œβ”€β”€ disaster_environment.py # Core env logic (Environment subclass)
    β”œβ”€β”€ scenarios.py           # All 3 task definitions
    β”œβ”€β”€ grader.py              # Hybrid rule-based + LLM grader
    β”œβ”€β”€ requirements.txt       # Server dependencies
    └── Dockerfile             # Container for HF Spaces

πŸš€ Quick Start

1. Install the client

bash
pip install git+https://huggingface.co/spaces/YOUR_USERNAME/disaster_response_env

2. Use the environment (async)

python
import asyncio
from disaster_response_env import DisasterAction, DisasterResponseEnv

async def main():
    async with DisasterResponseEnv(base_url="https://YOUR-SPACE.hf.space") as env:
        # Start Task 1 (Apartment Fire)
        obs = await env.reset()
        print(obs.situation_report)

        action = DisasterAction(
            response_plan=(
                "Immediate deployment: Area B is highest severity with 25 trapped including "
                "children on the crèche floor and elderly residents. Elevator shaft fire means "
                "aerial or stairwell B approach only. Prioritise 2 rescue teams to Area B "
                "immediately. Simultaneously deploy 2 fire trucks to Area A to contain spread "
                "and prevent Area B from worsening. Ambulances staged at both zones."
            ),
            resource_allocations={
                "ambulances": 2,       # Area B
                "rescue_teams": 2,     # Area B β€” all to highest severity
                "fire_trucks": 2,      # Area A β€” contain spread
                "paramedic_units": 1,  # Area C β€” street injuries
            },
            priority_areas=[
                "Area B β€” Floors 8-9",
                "Area A β€” Floors 3-5",
                "Area C β€” Surrounding Streets",
            ],
            rationale=(
                "Area B holds 25 lives including 4 children and 6 elderly β€” highest risk group. "
                "Stairwell A blocked, elevator shaft on fire β€” rescue teams are the only viable "
                "option. Area A gets fire trucks to prevent upward spread which would increase "
                "Area B casualties. Area C is ambulatory with minor injuries β€” 1 paramedic unit sufficient."
            ),
        )

        result = await env.step(action)
        print(f"Score: {result.observation.step_score}/10")
        print(result.observation.feedback)

asyncio.run(main())

3. Synchronous usage

python
from disaster_response_env import DisasterAction, DisasterResponseEnv

with DisasterResponseEnv(base_url="https://YOUR-SPACE.hf.space").sync() as env:
    obs = env.reset()
    result = env.step(DisasterAction(
        response_plan="...",
        resource_allocations={"rescue_teams": 2, "ambulances": 3},
        priority_areas=["Area B β€” Floors 8-9"],
        rationale="...",
    ))
    print(f"Score: {result.observation.step_score}/10")

πŸ€– Running the Baseline Agent

bash
export OPENAI_API_KEY=sk-...

# Run Task 1 (Fire)
python baseline_agent.py --base_url https://YOUR-SPACE.hf.space --task_level 1

# Run Task 2 (Earthquake)
python baseline_agent.py --base_url https://YOUR-SPACE.hf.space --task_level 2

# Run Task 3 (Hurricane)
python baseline_agent.py --base_url https://YOUR-SPACE.hf.space --task_level 3

# Run all 3 tasks sequentially
python baseline_agent.py --base_url https://YOUR-SPACE.hf.space --task_level 0

πŸ“Š Reward & Scoring

Each step returns:

  • β€”`reward`: Float in [0, 1] (step_score / 10) β€” for RL training loops
  • β€”`step_score`: Float in [0, 10] β€” detailed per-step score
  • β€”`final_score`: Float in [0, 10] β€” episode average (set when done=True)

Grading criteria (per step)

CriterionPoints
Highest-severity area prioritised2.5
Secondary areas addressed1.5
No over-allocation2.0
β‰₯50% resource utilisation1.5
Substantive response plan (>50 words)1.5
Clear rationale (>30 words)1.0
Total10.0

With OPENAI_API_KEY set: rule-based score (40%) + GPT-4o-mini quality evaluation (60%).


🐳 Local Development

bash
# Run server locally (no Docker)
pip install -e ".[server]"
cd server
uvicorn app:app --reload --port 7860

# Test with a quick action
python baseline_agent.py --base_url http://localhost:7860 --task_level 1

πŸ€— Deploying to Hugging Face Spaces

bash
# Login to Hugging Face
pip install huggingface_hub
huggingface-cli login

# Install OpenEnv CLI
pip install openenv-core

# Push to HF Spaces
cd disaster_response_env
openenv push --repo-id YOUR_USERNAME/disaster_response_env

Or manually:

  1. 1.Create a new Space at huggingface.co/new-space
  2. 2.Select Docker as the SDK
  3. 3.Push this repo to the Space's git remote

Set these Space secrets (Settings β†’ Repository Secrets):

  • β€”OPENAI_API_KEY β€” optional, enables LLM grading
  • β€”TASK_LEVEL β€” set to 1, 2, or 3

πŸ”— Use with RL Frameworks

TRL (GRPO)

python
from trl import GRPOConfig, GRPOTrainer
from disaster_response_env import DisasterAction, DisasterResponseEnv

# The environment provides reward via result.observation.reward
# Compatible with TRL's OpenEnv integration

Unsloth

Compatible with the OpenEnv Unsloth notebook


πŸ“ Observation Fields

FieldTypeDescription
situation_reportstrFull disaster briefing for this step
available_resourcesdictResource name β†’ count available
affected_areaslistArea objects with severity, population, needs
time_stepintCurrent step (0-indexed)
max_stepsintTotal steps in this task
doneboolTrue when episode ends
rewardfloatStep reward [0,1] for RL
step_scorefloatRaw step score [0,10]
final_scorefloat\NoneEpisode score when done
feedbackstrGrader feedback on last action
casualties_preventedintEstimated lives saved

License

MIT License β€” see LICENSE


Built for the OpenEnv Hackathon β€” March 2026. Solo entry.