Skip to content

AndresDevvv/image-moderation-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

image-moderation-api

Hugging Face

A minimal FastAPI service for image moderation (binary NSFW detection) using prithivMLmods/Nsfw_Image_Detection_OSS.

Start the server

1) Create and activate a virtual environment

python3 -m venv venv
source venv/bin/activate

On Windows (PowerShell):

python -m venv venv
.\venv\Scripts\Activate.ps1

2) Install dependencies

python -m pip install --upgrade pip
python -m pip install --no-input torch torchvision fastapi uvicorn pillow transformers

Alternative: if you prefer dependency pinning from a file, you can generate one first with

python -m pip freeze > requirements.txt

3) Run the app

uvicorn app:app --host 0.0.0.0 --port 8000

The service will be available at http://localhost:8000.

On first startup, the model weights are downloaded on demand, so the first run may take a bit longer.

Quick test

curl -X 'POST' \
  'http://localhost:8000/classify' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@TRUcIH-U3IZYUqVF.avif;type=image/avif'

Expected response shape:

{
  "filename": "TRUcIH-U3IZYUqVF.avif",
  "predictions": [
    {
      "label": "NSFW",
      "score": 0.9461
    },
    {
      "label": "SFW",
      "score": 0.0539
    }
  ]
}

Model Reference

This API uses the Hugging Face model:

  • prithivMLmods/Nsfw_Image_Detection_OSS
  • Labels: Class 0: SFW, Class 1: NSFW
  • Task: Image classification
  • Framework: Transformers (AutoImageProcessor, AutoModelForImageClassification)

Runtime and Deployment

The API is designed to run correctly on CPU-only environments and does not require a GPU.

For practical usage, keep RAM realistic for your traffic pattern (the model is compact and inference is lightweight for a vision classifier; small to moderate concurrent workloads are suitable on standard CPU instances).

Intended Use

This service is intended for image moderation workloads such as content filtering, platform safety checks, dataset cleaning, and enterprise policy enforcement.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages