A lightweight FastAPI wrapper around the Detoxify library for toxicity detection in text. This API allows you to quickly detect toxic content in text using pre-trained models.
This project provides a simple REST API for the Detoxify library, which uses deep learning models to identify toxic content in text. The API can detect various types of toxicity, including:
- Toxicity
- Severe toxicity
- Obscenity
- Threat
- Insult
- Identity-based hate
- Docker and Docker Compose (recommended)
- Python 3.10+ (for local development)
docker run -d \
--name detoxify-api \
-v "$(pwd)/.cache/application:/root/.cache" \
-v "$(pwd)/.cache/packages:/.cached_packages" \
-p 8000:8000 \
ghcr.io/ceraia/detoxify-api:latestThe easiest way to run the API is using Docker:
docker-compose upThis will start the API server on port 8000.
- Install the required dependencies:
pip install -r requirements.txt- Start the API server:
uvicorn toxicity_api:app --host 0.0.0.0 --port 8000POST /predict
{
"text": "The text you want to analyze for toxicity"
}{
"toxicity": 0.05,
"severe_toxicity": 0.01,
"obscene": 0.02,
"threat": 0.01,
"insult": 0.03,
"identity_hate": 0.01
}The values are probabilities between 0 and 1, where higher values indicate higher likelihood of that category of toxicity.
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text":"This is a test message"}'toxicity_api.py- FastAPI application that serves the toxicity detection endpointDockerfile- Configuration for building the Docker imagedocker-compose.yml- Configuration for running the servicerequirements.txt- Python dependencies
This project is a simple API wrapper around the Detoxify library. All rights to the underlying models, libraries, and resources belong to their respective owners. This project does not claim ownership over any third-party components used, including but not limited to the Detoxify library and its pre-trained models.
- The Detoxify library is developed and maintained by Unitary AI: https://github.com/unitaryai/detoxify
- FastAPI is developed by Sebastián Ramírez: https://github.com/tiangolo/fastapi
Please note that the Detoxify models have their own licensing terms. Refer to the Detoxify repository for details on model licensing.