Kwaseda/toxicity-score-api
0
Toxicity Score API
Fast API for chat toxicity scoring & moderation.
  
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-api2. Configure Environment
Create or update the .env file with your settings:
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.json3. Build and Run with Docker
docker build -t toxicity-api .
docker run -d -p 8000:8000 --name toxicity-api-container toxicity-api4. Test the API
- Health check:
curl http://localhost:8000/health- Predict toxicity:
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.txtLicense
This project is licensed under the Apache License 2.0. See LICENSE for details.
Built in public by Dominic Jesse Kwame Addo (Kwame Aseda)
