Team Ai
Apppublic

Bagusan21/TensorFlow-Nsfw

sourceHugging Faceupdated 6mo agoView on Hugging Face
1likes
App README

๐Ÿš€ NSFW Detection API (TensorFlow + NSFWJS)

High-performance NSFW image detection API using TensorFlow.js (Node) and NSFWJS. Optimized for Hugging Face Spaces (Docker) with queue system, caching, and FFmpeg preprocessing.


โœจ Features

  • โ€”๐Ÿ”ž NSFW Detection (Porn / Sexy / Hentai)
  • โ€”โšก Queue system (anti overload)
  • โ€”๐Ÿง  LRU Cache (faster repeated scans)
  • โ€”๐Ÿ–ผ๏ธ Image normalization via FFmpeg
  • โ€”๐ŸŒ Supports:
  • โ€”Image URL
  • โ€”File Upload (multipart)
  • โ€”Base64 buffer
  • โ€”๐Ÿณ Ready for HuggingFace Docker Spaces

๐Ÿ“ฆ API Endpoints

  1. 1.Detect from URL

POST /detect/url Content-Type: application/json

Body:

{ "url": "https://example.com/image.jpg" }


  1. 1.Upload File

POST /detect/upload Content-Type: multipart/form-data

Form:

file: (image file)


  1. 1.Base64

POST /detect/base64 Content-Type: application/json

Body:

{ "data": "base64string..." }


๐Ÿ“ค Response Example

{ "isNSFW": true, "score": 0.87, "percent": 87, "nsfw": { "porn": 87, "sexy": 65, "hentai": 12 }, "sfw": { "neutral": 5, "drawing": 3 } }


โš™๏ธ Local Development

Install dependencies

npm install

Run server

npm start

Server runs on:

http://localhost:7860


๐Ÿณ Run with Docker

Build image

docker build -t nsfw-api .

Run container

docker run -p 7860:7860 nsfw-api


๐Ÿค— Deploy to Hugging Face Spaces

  1. 1.Create new Space
  2. 2.Select Docker SDK
  3. 3.Upload files:

Dockerfile package.json server.js nsfw.js

  1. 1.Done โœ…

API will be available at:

https://<your-space>.hf.space


โšก Performance Tips

  • โ€”Increase concurrency:

const CONCURRENCY = 2

  • โ€”Use lighter model:

nsfw.load()

  • โ€”Reduce FFmpeg scale for faster processing

โš ๏ธ Limits

  • โ€”Max file size: 5MB
  • โ€”Queue limit: 20
  • โ€”Default concurrency: 1

๐Ÿ›  Tech Stack

  • โ€”Node.js
  • โ€”Express
  • โ€”TensorFlow.js (tfjs-node)
  • โ€”NSFWJS
  • โ€”FFmpeg

๐Ÿ“„ License

MIT


๐Ÿ’ฌ Notes

  • โ€”Model loaded once (fast inference)
  • โ€”Cache avoids duplicate processing
  • โ€”FFmpeg improves input consistency

Enjoy ๐Ÿš€