Skip to content

A real-time API for scoring toxicity in text, built with FastAPI and DistilBERT.

License

Notifications You must be signed in to change notification settings

Kwaseda/toxicity-score-api

Repository files navigation

Toxicity Score API

Fast API for chat toxicity scoring & moderation.

License Hugging Face Space RapidAPI

Features

  • Fine-tuned DistilBERT model for six toxicity categories plus non-toxic
  • Fast inference via FastAPI + Uvicorn
  • Containerized with Docker, deployable on Hugging Face Spaces & RapidAPI
  • Configurable thresholds and batch support

Quickstart

1. Clone the Repository

git clone https://github.com/Kwaseda/toxicity-score-api.git
cd toxicity-score-api

2. Configure Environment

Create or update the .env file with your settings:

MODEL_DIR=./enhanced_toxic_comment_model
MAX_LENGTH=256
BATCH_LIMIT=100
PORT=7860
TOXICITY_THRESHOLD=0.5
THRESHOLDS_PATH=./enhanced_toxic_comment_model/thresholds.json

3. Build and Run with Docker

docker build -t toxicity-api .
docker run -d -p 7860:7860 --name toxicity-api-container toxicity-api

4. Test the API

  • Health check:
curl http://localhost:7860/health
  • Predict toxicity:
curl -X POST http://localhost:7860/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "Your sample comment"}'

Project Structure

toxicity-score-api
├── core_api_refactored.py       # Main FastAPI application
├── Dockerfile                   # Container definition
├── requirements.txt             # Python dependencies
├── .env                         # Environment variables for configuration
├── .gitignore                   # Ignored files
└── enhanced_toxic_comment_model/
    ├── config.json
    ├── model.safetensors
    ├── thresholds.json
    ├── tokenizer_config.json
    ├── tokenizer.json
    ├── special_tokens_map.json
    └── vocab.txt

License

This project is licensed under the Apache License 2.0. See LICENSE for details.


Built in public by Dominic Jesse Kwame Addo (Kwame Aseda)

About

A real-time API for scoring toxicity in text, built with FastAPI and DistilBERT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published