A FastAPI-based content moderation service using BERT for text classification. This service provides an API endpoint that can analyze text content for various types of harmful content, similar to OpenAI's moderation API.
This service uses the ifmain/ModerationBERT-En-02 model, which is a fine-tuned BERT model specifically designed for content moderation. The model can detect and classify content across 11 different categories:
The model outputs both binary classifications (flagged/not flagged) and confidence scores for each category, allowing for fine-grained content analysis.
version: '3.8'
services:
moderation-api:
image: ghcr.io/haouarihk/moderationapi:main-cpu
ports:
- 8000:8000
restart: unless-stopped
version: '3.8'
services:
moderation-api:
image: ghcr.io/haouarihk/moderationapi:main
ports:
- 8000:8000
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
The API will be available at http://localhost:8000
Analyzes text content for harmful content.
{
"input": [
"Your text to analyze here",
"Multiple texts can be analyzed at once"
]
}
{
"id": "modr-xxxxxx",
"model": "ModerationBERT-En-02",
"results": [
{
"flagged": true,
"categories": {
"sexual": false,
"hate": true,
"harassment": false,
"self_harm": false,
"sexual_minors": false,
"hate_threatening": false,
"violence_graphic": false,
"self_harm_intent": false,
"self_harm_instructions": false,
"harassment_threatening": false,
"violence": false
},
"category_scores": {
"sexual": 0.123,
"hate": 0.789,
"harassment": 0.234,
"self_harm": 0.045,
"sexual_minors": 0.012,
"hate_threatening": 0.345,
"violence_graphic": 0.067,
"self_harm_intent": 0.089,
"self_harm_instructions": 0.023,
"harassment_threatening": 0.156,
"violence": 0.234
}
}
]
}
If you prefer using Docker directly:
# Pull the CPU image
docker pull ghcr.io/haouarihk/moderationapi:latest-cpu
# Run the container
docker run -p 8000:8000 ghcr.io/haouarihk/moderationapi:latest-cpu
For local development, you'll need:
git clone https://github.com/haouarihk/moderationAPI.git
cd moderationAPI
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000
No environment variables are required for basic operation.
This project uses separate GitHub Actions workflows for CPU and GPU images:
GPU Image Workflow (.github/workflows/docker-build-gpu.yml):
latestCPU Image Workflow (.github/workflows/docker-build-cpu.yml):
latest-cpuBoth workflows:
[Add your license here]
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)A FastAPI-based content moderation service using BERT for text classification. This service provides an API endpoint that can analyze text content for various types of harmful content, similar to OpenAI's moderation API.
This service uses the ifmain/ModerationBERT-En-02 model, which is a fine-tuned BERT model specifically designed for content moderation. The model can detect and classify content across 11 different categories:
The model outputs both binary classifications (flagged/not flagged) and confidence scores for each category, allowing for fine-grained content analysis.
version: '3.8'
services:
moderation-api:
image: ghcr.io/haouarihk/moderationapi:main-cpu
ports:
- 8000:8000
restart: unless-stopped
version: '3.8'
services:
moderation-api:
image: ghcr.io/haouarihk/moderationapi:main
ports:
- 8000:8000
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
The API will be available at http://localhost:8000
Analyzes text content for harmful content.
{
"input": [
"Your text to analyze here",
"Multiple texts can be analyzed at once"
]
}
{
"id": "modr-xxxxxx",
"model": "ModerationBERT-En-02",
"results": [
{
"flagged": true,
"categories": {
"sexual": false,
"hate": true,
"harassment": false,
"self_harm": false,
"sexual_minors": false,
"hate_threatening": false,
"violence_graphic": false,
"self_harm_intent": false,
"self_harm_instructions": false,
"harassment_threatening": false,
"violence": false
},
"category_scores": {
"sexual": 0.123,
"hate": 0.789,
"harassment": 0.234,
"self_harm": 0.045,
"sexual_minors": 0.012,
"hate_threatening": 0.345,
"violence_graphic": 0.067,
"self_harm_intent": 0.089,
"self_harm_instructions": 0.023,
"harassment_threatening": 0.156,
"violence": 0.234
}
}
]
}
If you prefer using Docker directly:
# Pull the CPU image
docker pull ghcr.io/haouarihk/moderationapi:latest-cpu
# Run the container
docker run -p 8000:8000 ghcr.io/haouarihk/moderationapi:latest-cpu
For local development, you'll need:
git clone https://github.com/haouarihk/moderationAPI.git
cd moderationAPI
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000
No environment variables are required for basic operation.
This project uses separate GitHub Actions workflows for CPU and GPU images:
GPU Image Workflow (.github/workflows/docker-build-gpu.yml):
latestCPU Image Workflow (.github/workflows/docker-build-cpu.yml):
latest-cpuBoth workflows:
[Add your license here]
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)