Deploying a Private Image Moderation API with NSFW JS via Docker

nsfw jsdocker deploymentprivate image moderation apihttp apiimage classification
Published·Modified·

NSFW JS is a simple JavaScript library open-sourced on GitHub that helps you quickly identify inappropriate images. While not perfect, it is quite accurate (small models around 90%, medium models around 93%) and continues to improve.

Deploy NSFW JS with Docker

A user has already packaged NSFW JS into a Docker image and provided REST API support. After deployment, you can call it via HTTP API. Additionally, ImgURL Pro will soon support NSFW JS image moderation, making private Docker deployment of NSFW JS a prerequisite. Let's proceed with the installation.

# Copy the command below to deploy NSFW JS
docker run -d -p 127.0.0.1:5000:5000/tcp \
  --env PORT=5000 \
  --restart=always \
  eugencepoi/nsfw_api:latest

Note: After deployment, the service only supports access from 127.0.0.1 locally and cannot be accessed publicly. If you need public access, remove 127.0.0.1: from the port mapping.

Testing

After deployment, you can test if it was successful using the curl command:

curl -X GET -H 'Content-Type: application/json' "http://127.0.0.1:5000?url=https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"

If successful, it will return JSON content in the following format:

{
    "score": 0.00016061133646871895,
    "url": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
}

Note: According to tests by xiaoz, if the image URL contains a port number, it will fail to recognize and report an error.

Return Field Explanation

score represents the image score, ranging from 0 to 1. A score of 1 indicates it is definitely adult content, while 0 means it is not. Based on xiaoz's tests, a score greater than 0.9 can be considered adult content.

For more usage instructions, please refer to the introduction on Docker Hub: https://hub.docker.com/r/eugencepoi/nsfw_api

Similar Services

If you do not want to build your own image moderation API, you can also check out two other free image recognition (moderation) interfaces: Sharing 2 Free Foreign Image Recognition (Moderation) Interfaces. Unfortunately, the free versions have quota limits.

Summary

By deploying NSFW JS via Docker, you can easily set up an image moderation server that supports HTTP APIs without quota or quantity restrictions. Tests by xiaoz show that while the accuracy is average, it is free and open-source.