A simple REST API built with Flask and NudeNet for detecting and tagging NSFW content in images.
Supports file uploads and remote image URLs (single or multiple).
- 🔥 Fast inference — NudeNet model preloaded at container startup
- 🖼️ Flexible input — Upload files or pass one/many image URLs
- ⚡ Production-ready — Gunicorn + Dockerfile included
- 🛡️ Safe defaults — File type validation, download timeouts
- ✅ Health check —
/healthendpoint for container orchestration
GET /healthReturns:
{ "status": "ok" }POST /detect
Content-Type: multipart/form-data
Form field: file=@/path/to/image.jpgExample:
curl -X POST http://localhost:8080/detect \
-F "file=@/path/to/image.jpg"POST /detect
Content-Type: application/json
Body:
{
"image_url": "https://example.com/image.jpg"
}{
"ok": true,
"mode": "urls",
"count": 2,
"results": [
{
"source": "https://example.com/a.jpg",
"detections": [
{ "class": "EXPOSED_ANUS", "score": 0.98, "box": [0.2, 0.3, 0.5, 0.7] }
]
},
{
"source": "https://example.com/b.png",
"error": "HTTP 404"
}
]
}detections: each detection containsclass(NSFW label),score(confidence), andbox(normalized bounding box[x_min, y_min, x_max, y_max]).error: returned if the file/URL failed.
git clone https://github.com/yourusername/nsfw-tagging-api.git
cd nsfw-tagging-api
pip install -r requirements.txtpython app.py
# or specify port:
python app.py --port 8080Server runs at http://127.0.0.1:8080.
docker build -t nsfw-tagging-api .docker run --rm -p 8080:8080 nsfw-tagging-apicurl -X POST http://127.0.0.1:8080/detect \
-F "file=@/path/to/image.jpg"- Python 3.11+
- Flask + Flask-RESTful
- NudeNet (downloads pretrained models)
- Requests
Ensure your container/machine has enough memory (>=512 MB recommended).
MIT © 2025 [Hrishikesh Kanade]