Skip to content
Proyek

Tentang

High-performance, self-hosted NSFW detection API powered by NSFWJS.

AI dan pembelajaran mesin

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
Mengumpulkan riwayat
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

nsfwjs-docker

Docker Pulls License GitHub Stars

High-performance, self-hosted NSFW detection API powered by NSFWJS.

  • Accuracy: ~93%;
  • Latency: ~80ms per prediction;
  • Input: JPEG, PNG, WebP, AVIF, TIFF, GIF (first frame), raw pixel data;
  • Output: 5-class classification — Neutral, Drawing, Sexy, Hentai, Porn;
  • Multi-architecture: Supports both x64 and arm64.
  • Lightweight: Runs under 200 MB of RAM.

Table of Contents

Installation

docker run -p 3333:3333 -d --name nsfwjs andresribeiroo/nsfwjs

# Optional: require an API key for /classify
docker run -p 3333:3333 -d --name nsfwjs -e API_KEY=your-secret andresribeiroo/nsfwjs

Usage

POST the raw image bytes to /classify with Content-Type: application/octet-stream.

Example Response:

HTTP/1.1 200 OK
Content-Type: application/json
{
  "prediction": [
    { "className": "Neutral", "probability": 0.637 },
    { "className": "Drawing", "probability": 0.360 },
    { "className": "Hentai", "probability": 0.002 },
    { "className": "Sexy", "probability": 0.000 },
    { "className": "Porn", "probability": 0.000 }
  ]
}

The probability of each category ranges from 0 (lowest) to 1 (highest).

Health check

GET /status returns 200 with { "ok": true } once the model is loaded and the server is accepting requests.

Authentication

Authentication is optional. Start the container with API_KEY set to require a key on POST /classify:

docker run -p 3333:3333 -d --name nsfwjs -e API_KEY=your-secret andresribeiroo/nsfwjs

Send the key as a bearer token or in the X-API-Key header:

curl -X POST \
  -H "Authorization: Bearer your-secret" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @image.jpg \
  http://localhost:3333/classify

Requests without a valid key return 401 Unauthorized with { "error": "unauthorized" }. When API_KEY is unset, no authentication is required.

Errors

An empty body, or bytes that cannot be decoded as an image, return 400 Bad Request with { "error": "invalid image" }. Any other failure returns 500.

Examples

Node.js / Browser

const res = await fetch("http://localhost:3333/classify", {
  method: "POST",
  headers: { "Content-Type": "application/octet-stream" },
  body: imageBlobOrBuffer,
});
if (!res.ok) throw new Error(`classify failed: ${res.status}`);
const { prediction } = await res.json();

Python

import requests

with open("image.jpg", "rb") as f:
    resp = requests.post(
        "http://localhost:3333/classify",
        data=f,
        headers={"Content-Type": "application/octet-stream"},
    )
resp.raise_for_status()
print(resp.json()["prediction"])
# [{ className: "Neutral", probability: 0.637 }, ...]

httpie

http POST localhost:3333/classify Content-Type:application/octet-stream @image.jpg

curl

curl -X POST \
  -H "Content-Type: application/octet-stream" \
  --data-binary @image.jpg \
  http://localhost:3333/classify

Performance

This container is built for speed:

  • SIMD-accelerated image processing — sharp (powered by libvips) handles image decoding and resizing to 224×224 before inference, taking advantage of SIMD instructions on compatible CPUs.
  • jemalloc allocator — The Docker image links against jemalloc, which reduces fragmentation and improves memory usage under concurrent workloads compared to the glibc allocator.
  • Model failure safety — If an error occurs during model inference, the underlying TensorFlow tensors are immediately disposed of. This architectural fallback completely prevents CPU memory leaks under any failure condition.
  • Raw binary transport — The API accepts application/octet-stream instead of multipart form data or base64-encoded JSON. This avoids the overhead of multipart parsing and base64 expansion, resulting in faster decoding and lower network transfer times.

Build from source

docker build -t nsfwjs .
docker run -p 3333:3333 nsfwjs

Local development

Requires Node.js 26 or newer.

npm install                                                # install dependencies
npm rebuild @tensorflow/tfjs-node --build-from-source      # rebuild TensorFlow, required on arm64
npm run dev                                                # watch mode (restarts on file changes)
npm run start                                              # production mode

Type checking and formatting:

npm run typecheck
npm run check
npm run format

The server listens on port 3333.

Jelajahi proyek terkait

Memuat…