Home

Awesome

nsfw-detector-api

A simple PoC (Proof of Concept) NSFW Detector API Server using NsfwSpy.js model.

nsfw-detector-api is a core dependency of nostr-filter-relay.

Getting Started

Published docker image is available in ghcr.io. Run it instantly:

docker run --init --rm -p 8081:8081 ghcr.io/atrifat/nsfw-detector-api:main

or using docker image with CUDA drivers included and NVIDIA docker runtime:

docker run --gpus all --init --rm -p 8081:8081 ghcr.io/atrifat/nsfw-detector-api:main-cuda

You can also clone this repository to run or modify it locally

git clone https://github.com/atrifat/nsfw-detector-api
cd nsfw-detector-api

install its dependencies

npm install

and run it using command

npm run start

or run it using node command directly

node src/index.mjs

If you want to test the API server, you can use GUI tools like Postman or using curl.

Send request by using image URL:

curl --header "Content-Type: application/json" \
  --header "Authorization: Bearer myapitokenchangethislater" \
  --request POST \
  --data '{"url":"https://example.org/image.jpg"}' \
  http://localhost:8081/predict

or send request by using base64 string of the image:

curl --header "Content-Type: application/json" \
  --header "Authorization: Bearer myapitokenchangethislater" \
  --request POST \
  --data '{"data":"base64stringhere"}' \
  http://localhost:8081/predict_data

The output is JSON which consists of four predicted classes (based on NsfwSpy.js) as follows:

{
    "data": {
        "hentai": 0.00016754239914007485,
        "neutral": 0.9930612444877625,
        "pornography": 0.0058021554723382,
        "sexy": 0.0009690204169601202,
        "predictedLabel": "neutral"
    }
}

License

MIT

Author