Socket
Socket
Sign inDemoInstall

nsfw-filter

Package Overview
Dependencies
119
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nsfw-filter

A minimal library that helps filter out NSFW images.


Version published
Weekly downloads
110
increased by74.6%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

NSFW Filter

An npm library that helps filter out inappropriate images using AI.

Current version


Installation

npm i nsfw-filter

Usage

import NSFWFilter from 'nsfw-filter';

const isSafe = await NSFWFilter.isSafe(image);

Full example

import { useState } from 'react';
import NSFWFilter from 'nsfw-filter';

function ImageUploader() {
  const [imageUrl, setImageUrl] = useState('');

  const handleImageUpload = async (event) => {
    const file = event.target.files[0];

    // Check to see if the image is appropriate
    const isSafe = await NSFWFilter.isSafe(file);
    if (!isSafe) return 'Image is not appropriate';

    // Process the image if it is safe
    if (file) {
      const reader = new FileReader();
      reader.onloadend = () => {
        setImageUrl(reader.result);
      };
      reader.readAsDataURL(file);
    }
  };

  return (
    <div>
      <input type="file" onChange={handleImageUpload} />
      {imageUrl && <img src={imageUrl} alt="Uploaded" />}
    </div>
  );
}

export default ImageUploader;

Real world usage

nsfw-filter is currently used in production to process hundreds of thousands of images for a popular image restoration service called restorePhotos. It helps prevent people from uploading inappropriate pictures. See how it's used here.

How it works

This library uses both Tensorflow.js, an OSS library for machine learning models, and nsfwjs to predict whether a given image is NSFW (Not Safe For Work).

Keywords

FAQs

Last updated on 23 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc