Skip to content

A simple Node.js server to run nsfw.js for images from IPFS and return its results.

License

Notifications You must be signed in to change notification settings

ipfs-search/nsfw-server

Repository files navigation

nsfw-server

Pipeline Status Maintainability Test Coverage Backers on Open Collective Sponsors on Open Collective

A microservice to run nsfw.js for images on IPFS.

Requirements

Getting started

Install Node dependencies

npm install

Start IPFS node

In a separate terminal, after installing a local IPFS daemon (see requirements): ipfs daemon

Start server

Run (auto-reloading) dev server with full debug enabled: env DEBUG=* npm run-script dev

Example usage

$ 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"
}

Production server

Run in production mode:

env NODE_ENV=production NSFW_SERVER_PORT=3342 npm start

Run tests

npm test

Docker support

Build docker image (tagged as nsfw-server)

docker build -t nsfw-server .

Run docker image in production on port 9000

docker run --env NODE_ENV=production -p 9000:3423 -t nsfw-server

API

To classify an IPLD CID:

/classify/<cid>

Supported formats

We're using TensorFlow's decodeImage, which detects and supports BMP, GIF, JPEG and PNG formats.

Configuration

nsfw-server is configured through the following environment variables:

  • IPFS_GATEWAY_URL: Gateway to use for loading images. Defaults to http://localhost:8080 (local node).
  • NSFW_SERVER_HOST: Host to run server on. Defaults to localhost.
  • NSFW_SERVER_PORT: Port to run server on. Defaults to 3423.
  • DEBUG: Debug verbosity level.
  • NODE_ENV: Node environment. Set to production in ... production. Defaults to development.
  • NSFW_MODEL: NSFW model to use.

About

A simple Node.js server to run nsfw.js for images from IPFS and return its results.

Topics

Resources

License

Stars

Watchers

Forks