CoolFace
Apppublic

Kwaseda/toxicity-score-api

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
App README

Toxicity Score API

Fast API for chat toxicity scoring & moderation.

![License](https://github.com/Kwaseda/toxicity-score-api/blob/main/LICENSE) ![Hugging Face Space](https://huggingface.co/spaces/Kwaseda/toxicity-score-api) ![RapidAPI](https://rapidapi.com/Kwaseda/api/toxicity-score-api)

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

bash
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:

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

3. Build and Run with Docker

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

4. Test the API

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

Project Structure

.
├── 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)