CoolFace
Apppublic

vanilla14/openenv-content-moderation

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

๐Ÿ›ก๏ธ OpenEnv Content Moderation Environment

A real-world, production-grade content moderation RL environment built on the OpenEnv framework by Meta & Hugging Face.

![OpenEnv](https://github.com/meta-pytorch/OpenEnv) ![HF Space](https://huggingface.co/spaces/vanilla14/openenv-content-moderation) ![Docker](https://www.docker.com/) ![FastAPI](https://fastapi.tiangolo.com/)


๐Ÿ“Œ Overview & Motivation

Content moderation is one of the most critical challenges in modern platforms. This environment simulates real-world moderation where an AI agent must:

  • โ€”Classify content (safe, toxic, hate, spam)
  • โ€”Decide moderation action (approve, warn, remove)
  • โ€”Assess severity (none, low, medium, high)

๐Ÿ’ก Use Cases

  • โ€”๐Ÿง  Reinforcement Learning training
  • โ€”๐Ÿค– LLM benchmarking
  • โ€”๐Ÿ“Š Safety system research
  • โ€”โš™๏ธ Agent evaluation across difficulty levels

๐Ÿ—๏ธ Project Structure

openenv-content-moderation/
โ”‚
โ”œโ”€โ”€ app.py               # FastAPI server (main entrypoint)
โ”œโ”€โ”€ environment.py       # Core environment logic
โ”œโ”€โ”€ tasks.py             # Task datasets (easy/medium/hard/expert)
โ”œโ”€โ”€ grader.py            # Reward / grading logic
โ”œโ”€โ”€ models.py            # Pydantic models
โ”œโ”€โ”€ inference.py         # Baseline agent script
โ”‚
โ”œโ”€โ”€ openenv.yaml         # OpenEnv config
โ”œโ”€โ”€ pyproject.toml       # Project metadata
โ”œโ”€โ”€ Dockerfile           # Container setup
โ”œโ”€โ”€ requirements.txt     # Dependencies
โ”œโ”€โ”€ uv.lock              # Locked deps
โ”‚
โ””โ”€โ”€ server/
    โ”œโ”€โ”€ __init__.py
    โ””โ”€โ”€ app.py           # Server module entrypoint

๐Ÿงช Tasks

TaskDescriptionDifficulty
easyBinary classification (safe vs toxic)โญ Easy
mediumMulti-class classificationโญโญ Medium
hardFull moderation decisionโญโญโญ Hard
expertAmbiguous nuanced contentโญโญโญโญ Expert

๐Ÿ‘๏ธ Observation Space

json
{
  "content": "user text",
  "task": "easy | medium | hard | expert"
}

๐ŸŽฏ Action Space

label=<label>;decision=<decision>;severity=<severity>
FieldValues
labelsafe, toxic, hate, spam
decisionapprove, warn, remove
severitynone, low, medium, high

๐Ÿ† Reward Function

  • โ€”Label โ†’ +0.50
  • โ€”Decision โ†’ +0.29
  • โ€”Severity โ†’ +0.19

โœ” Scores are clamped between 0.01 and 0.98


๐Ÿ”Œ API Endpoints

EndpointMethodDescription
/resetPOSTStart new episode
/stepPOSTSubmit action
/stateGETCurrent state
/tasksGETList tasks
/graderPOSTScore action
/healthGETHealth check
/docsGETSwagger UI

โš™๏ธ Local Setup

bash
git clone https://github.com/Vanillaaz/openenv-content-moderation.git
cd openenv-content-moderation

pip install -r requirements.txt

uvicorn app:app --host 0.0.0.0 --port 8000 --reload

๐Ÿ‘‰ Open: http://localhost:8000/docs


๐Ÿณ Docker

bash
docker build -t openenv-content-moderation .
docker run -p 8000:8000 openenv-content-moderation

๐Ÿค– Running the Agent

bash
export API_BASE_URL="https://router.huggingface.co/v1"
export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
export HF_TOKEN="your_token"

python inference.py

๐Ÿ” Environment Variables

VariableDescription
APIBASEURLLLM endpoint
MODEL_NAMEModel used
HF_TOKENHugging Face key

๐ŸŒ Live Demo

  • โ€”HF Space: https://huggingface.co/spaces/vanilla14/openenv-content-moderation
  • โ€”API Docs: https://vanilla14-openenv-content-moderation.hf.space/docs
  • โ€”Health: https://vanilla14-openenv-content-moderation.hf.space/health

๐Ÿ“Š Baseline Scores

Baseline agent: Qwen/Qwen2.5-72B-Instruct

TaskScore Range
easy0.50 โ€“ 0.98
medium0.50 โ€“ 0.98
hard0.50 โ€“ 0.79
expert0.01 โ€“ 0.79

๐Ÿ‘ฉโ€๐Ÿ’ป Author

Venisha Dsouza Built for OpenEnv Hackathon ๐Ÿš€