A fast accurate API for detecting NSFW images.
Go to file
Amir Boroumand 4ce040a5b2
Image url support (#3)
* Update main.py

* Update ci.yml

* Update README.md

* Update requirements.txt

* Create models.py

* Update main.py

* Update test_main.py

* Update README.md

* Update models.py

* Update test_main.py

* Update main.py

* Update main.py

* Update models.py

* Update main.py
2024-05-31 17:12:37 -04:00
.github/workflows Image url support (#3) 2024-05-31 17:12:37 -04:00
.coveragerc Update .coveragerc 2024-04-22 15:35:06 -04:00
.gitignore Initial commit 2024-04-22 09:22:04 -04:00
Dockerfile Update Dockerfile 2024-04-22 12:58:55 -04:00
LICENSE Initial commit 2024-04-22 09:22:04 -04:00
main.py Image url support (#3) 2024-05-31 17:12:37 -04:00
models.py Image url support (#3) 2024-05-31 17:12:37 -04:00
README.md Image url support (#3) 2024-05-31 17:12:37 -04:00
requirements.txt Image url support (#3) 2024-05-31 17:12:37 -04:00
SECURITY.md Create SECURITY.md 2024-04-22 13:16:55 -04:00
sunflower.jpg Updates 2024-04-22 13:50:21 -04:00
test_main.py Image url support (#3) 2024-05-31 17:12:37 -04:00
test-requirements.txt Updates 2024-04-22 14:27:29 -04:00

logo

Python CI codecov

Safe Content AI

A fast accurate API for detecting NSFW images. Ideal for content moderation on digital platforms.

This project uses Python, FastAPI framework, Transformers library, and TensorFlow.

TensorFlow will automatically detect and use the GPU if the underlying hardware supports it.

Features

🐳 Quick Start using Docker

docker run -p 8000:8000 steelcityamir/safe-content-ai:latest

Test using curl

curl -X POST "http://127.0.0.1:8000/v1/detect" \
     -H "Content-Type: multipart/form-data" \
     -F "file=@/path/to/your/image.jpeg"

Getting Started

Prerequisites

Ensure you have Python 3.7+ installed on your system.

Installation

Clone the repository to your local machine:

git clone https://github.com/steelcityamir/safe-content-ai.git

Navigate to the cloned directory:

cd safe-content-ai

Create a virtual environment

python -m venv venv
source venv/bin/activate

Install the required libraries using pip:

pip install -r requirements.txt

Running the API

Start the API server from your command line:

uvicorn main:app --reload

The API server runs on port 8000.

API usage

POST /v1/detect

This endpoint allows users to upload an image file, which is then processed to determine if the content is NSFW (Not Safe For Work). The response includes whether the image is considered NSFW and the confidence level of the prediction.

Request

  • URL: /v1/detect
  • Method: POST
  • Content-Type: multipart/form-data
  • Body:
    • file (required): The image file to be classified.

Response

  • Content-Type: application/json
  • Body:
    {
      "file_name": "string",
      "is_nsfw": "boolean",
      "confidence_percentage": "number"
    }
    

Curl

curl -X POST "http://127.0.0.1:8000/v1/detect" \
     -H "Content-Type: multipart/form-data" \
     -F "file=@/path/to/your/image.jpeg"

POST /v1/detect/urls

This endpoint allows users to provide image URLs, which are then processed to determine if the content is NSFW (Not Safe For Work). The response includes whether each image is considered NSFW and the confidence level of the prediction.

Request

  • URL: /v1/detect/urls
  • Method: POST
  • Content-Type: application/json
  • Body:
    {
     "urls": [
       "https://example.com/image1.jpg",
       "https://example.com/image2.jpg",
       "https://example.com/image3.jpg",
       "https://example.com/image4.jpg",
       "https://example.com/image5.jpg"
     ]
    }
    

Response

  • Content-Type: application/json
  • Body:
    [
      {
        "url": "string",
        "is_nsfw": "boolean",
        "confidence_percentage": "number"
      }
    ]
    

Curl

curl -X POST "http://127.0.0.1:8000/v1/detect/urls" \
     -H "Content-Type: application/json" \
     -d '{
           "urls": [
             "https://example.com/image1.jpg",
             "https://example.com/image2.jpg",
             "https://example.com/image3.jpg",
             "https://example.com/image4.jpg",
             "https://example.com/image5.jpg"
           ]
         }'

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, please open an issue in the GitHub issue tracker for this project.