A lightweight Rust-powered HTTP microservice to identify toxic or NSFW text in real-time. Perfect for moderation bots, public APIs, or internal tools.
- ✅ Detects toxicity, obscenity, sexual explicitness, and more
- ⚙️ Configurable thresholds per category
- 🌀 Supports both GET and POST (
/check) - 🛡️ Auto retries, timeout protection, and flags for review
- ✅ Simple live demo at
/with examples and an input form
git clone https://github.com/AshokShau/toxicity-detector.git
cd toxicity-detector
# Build the server (Docker or local):
docker build -t toxicity-detector .
docker run -d -p 5001:5001 --name toxic-api toxicity-detector🔗 Visit http://localhost:5001 / in your browser to test.
/check?text=your+message
&toxicity_threshold=0.5
&nsfw_threshold=0.2
curl -X POST http://localhost:5001/check \
-H "Content-Type: application/json" \
-d '{
"text": "send me your nudes",
"toxicity_threshold": 0.5,
"nsfw_threshold": 0.2
}'Response example:
{
"text": "send me your nudes",
"is_bad": true,
"scores": {
"toxicity": 43.38,
"sexual_explicit": 76.13,
...
},
"thresholds": {
"toxicity": 50.0,
"sexual_explicit": 20.0
},
"flags": {
"is_toxic": true,
"is_nsfw": true,
"needs_review": true
}
}The root path serves a small HTML interface where you:
- Enter any string in the form
- See results instantly
- Find GET/POST links & sample
curlcommands
This makes testing very straightforward for users or bots.
toxicity_threshold,nsfw_threshold— float values between0–1- Lower thresholds → stricter moderation
- Default values:
0.8(toxicity),0.7(nsfw) max_retries= 2,timeout= 10s (server-side)
- Docker: Use the provided
Dockerfile - Self-hosted VPS: Install Python 3.11+, dependencies, then run
- Based on Detoxify
- This repo is MIT-licensed — feel free to adapt & improve
Fix a bug? Want new features (like auth, bulk-check)? PRs are welcome!
Thanks for using Toxicity Detector! cc @AshokShau 💙