welcome to moderation_api_py a simple api that uses different AI models to moderate texts and images in a fast and efficient way using FastAPI and Celery.
Celery is used to perform the moderation tasks in the background and store the results in a Redis database.
- Image moderation1:
- nsfw score
- normal score
- summary
- Text moderation2 :
- toxicity
- severe toxicity
- obscene
- identity attack (refer to detoxify docs)
- insult
- threat
- sexual explicit content
- summary
- Video moderation :working (WIP)
- Moderation tasks execution queue with celery
- Moderation task monitoring dashboard with flower web portal on http://localhost:5555
- Authentication by api keys middleware is implemented.
Create a docker-compose.yml file:
services:
api:
image: ghcr.io/brahimabd98/moderation_api_py:main
ports:
- "8000:8000"
environment:
DATABASE_URL: "redis://redis:6379/0"
redis:
image: redis:alpine
ports:
- "6379:6379"
volumes:
- redis-data:/datadocker image :
docker pull ghcr.io/brahimabd98/moderation_api_py:mainStart a new terminal session and clone the project with this command :
git clone github.com/brahimabd98/moderation_api_py/cd into the project :
cd moderation_api_pyStart a new venv (optional):
python -m venv .venvInstall the project's dependencies:
pip install -r requirements requirements.txtset up the .env file (checkout .env.example)
cp .env.example .envstart the project
fastapi run main.py --port 8000- make sure you have a running Redis db instance, you can check their docs for more info
You can use the provided docker image :
docker pull ghcr.io/brahimabd98/moderation_api_py:mainswagger ui http://localhost:8000/docs
flower dashboard http://localhost:5555
- testing
- task re-execution policy
- rate limiting: limit the amount of request.
- api gateway
- task priority
- grafana and Prometheus integration
- multiple image processing
- html sanitization
- censorship: apply blur filter or text censorship of certain words
- measuring model performance
- text moderation : detoxify
- image moderation : Falconsai/nsfw_image_detection
- ethical considerations: as the author of the different AI models, these kinds of classifications shouldn't be taken at face value and human intervention should present for the final decision.
- performance: yet to be determined.
- Error handling: currently there's no proper error handling, so the server is prone to crashing
- logging: right there's no good structured logging we plan to add in the future
credit: Brahim, 2024


