A microservice to run nsfw.js for images on IPFS.
- Node 16.x (LTS)
- Python (Windows / Mac OS X Requires Python 2.7)
- Running IPFS daemon or public IPFS gateway (not recommended, can be configured with environment variable)
npm install
In a separate terminal, after installing a local IPFS daemon (see requirements):
ipfs daemon
Run (auto-reloading) dev server with full debug enabled:
env DEBUG=* npm run-script dev
$ curl -s http://localhost:3423/classify/bafkreiam7vh2raw2chmx6gllup6sd32xsicwus2riglpjtzlygz4lzmxbm | jq
(Wait a while... IPFS is slow. :/)
{
"classification": {
"neutral": 0.9980410933494568,
"drawing": 0.001135041005909443,
"porn": 0.00050011818530038,
"hentai": 0.00016194644558709115,
"sexy": 0.00016178081568796188
},
"modelCid": "QmfBNCmYLxwTr3CHaknd5HdzA6uXcTZqn1hsuLf8mRc3xS",
"nsfwServerVersion": "0.9.0"
}
Run in production mode:
env NODE_ENV=production NSFW_SERVER_PORT=3342 npm start
npm test
docker build -t nsfw-server .
docker run --env NODE_ENV=production -p 9000:3423 -t nsfw-server
To classify an IPLD CID:
/classify/<cid>
We're using TensorFlow's decodeImage, which detects and supports BMP, GIF, JPEG and PNG formats.
nsfw-server is configured through the following environment variables:
IPFS_GATEWAY_URL
: Gateway to use for loading images. Defaults tohttp://localhost:8080
(local node).NSFW_SERVER_HOST
: Host to run server on. Defaults tolocalhost
.NSFW_SERVER_PORT
: Port to run server on. Defaults to3423
.DEBUG
: Debug verbosity level.NODE_ENV
: Node environment. Set toproduction
in ... production. Defaults todevelopment
.NSFW_MODEL
: NSFW model to use.