A microservices-based system for content privacy protection, built for the TikTok competition. The system detects and provides masking coordinates for faces, personally identifiable information (PII), and location-sensitive content in images.
Note: The cloud micro-service code is in the
mainbrainch and the local mobile code is in themobile-appbranch.
- Hosted Swagger is here:
http://ec2-18-136-120-44.ap-southeast-1.compute.amazonaws.com:8000 - Postman Collection for indivisual microservice available in
\docs
The system consists of four containerized services:
- API Gateway (
src/app.py) - REST API with Flask and Swagger documentation - YOLO Service (
services/yolo/) - Computer vision for face detection and object recognition - LLM Service (
services/llm/) - OpenAI GPT-based PII detection in text - Location Service (
services/location/) - Google Gemini-based location analysis
- Face Detection: Uses YOLOv8 and Haar Cascade classifiers to detect faces
- Age Classification: OpenCV DNN model to identify minors for selective protection
- PII Detection: OpenAI GPT analysis of OCR text to identify personal information
- Location Analysis: Google Gemini analysis for location-sensitive content
- Object Detection: YOLO-based detection of vehicles, signs, and other objects
- Text Recognition: EasyOCR for extracting text from images
- YOLOv8n: Object detection model
- YOLOv8n-Face: Face detection model
- OpenCV DNN: Age classification model
- OpenAI GPT: Language model for PII analysis
- Google Gemini: Multimodal AI for location analysis
- EasyOCR: Text recognition
- Python 3.9+: Programming language
- Flask + Flask-RESTX: Web framework with API documentation
- OpenCV: Computer vision library
- Ultralytics: YOLO implementation
- LangChain: LLM integration framework
- Docker: Containerization
# Computer Vision
ultralytics # YOLO implementation
opencv-python-headless # Computer vision operations
pillow # Image processing
easyocr # Text recognition
# AI Integration
langchain # LLM framework
langchain-openai # OpenAI integration
google-genai # Gemini integration
pydantic # Data validation
# Web Framework
flask==2.3.3 # Web framework
flask-restx==1.1.0 # API documentation
requests==2.31.0 # HTTP client
- Docker and Docker Compose
- OpenAI API key
- Google Gemini API key (optional)
-
Clone the repository:
git clone https://github.com/FishPain/TikTok.git cd TikTok -
Set up environment variables:
cp .env.template .env # Edit .env file with your API keys -
Start the services:
./start.sh # or manually: docker-compose up --build -
Access the API:
- API Gateway: http://localhost:8000
- Swagger UI: http://localhost:8000/
All endpoints require API key authentication via x-api-key header.
curl -X POST \
-H "x-api-key: your_key" \
-F "file=@image.jpg" \
http://localhost:8000/api/mask/faceResponse:
{
"mask": [
{
"coordinate": "(100.5, 200.8, 150.2, 250.9)",
"reason": "visible face"
}
]
}curl -X POST \
-H "x-api-key: your_key" \
-F "file=@image.jpg" \
-F 'ocr_values=[{"text":"john@email.com","bbox":[100,200,300,220],"confidence":0.95}]' \
http://localhost:8000/api/mask/piicurl -X POST \
-H "x-api-key: your_key" \
-F "file=@image.jpg" \
http://localhost:8000/api/mask/locationcurl -H "x-api-key: your_key" http://localhost:8000/v1/healthTikTok/
├── docker-compose.yml # Service orchestration
├── Dockerfile # API Gateway container
├── requirements.txt # Gateway dependencies
├── start.sh # Deployment script
├── src/
│ ├── app.py # API Gateway
│ └── helper.py # Service utilities
└── services/
├── yolo/ # Computer Vision Service
│ ├── yolo.py # YOLO implementation
│ ├── Dockerfile # Container definition
│ ├── requirements.txt
│ └── models/ # AI model files
├── llm/ # Language Model Service
│ ├── pii.py # PII detection
│ ├── Dockerfile
│ └── requirements.txt
└── location/ # Location Service
├── location.py # Location analysis
├── Dockerfile
└── requirements.txt
graph TD
A[Client Request] --> B[API Gateway :8000]
B --> C{Request Type}
C -->|Face Detection| D[YOLO Service :8100]
C -->|PII Analysis| E[LLM Service :8200]
C -->|Location Analysis| F[Location Service :8300]
D --> G[YOLOv8 + Age Classification]
E --> H[OpenAI GPT Analysis]
F --> I[Gemini Multimodal AI]
G --> J[Coordinate Response]
H --> J
I --> J
J --> B
B --> K[Unified Response]
Services communicate via HTTP within Docker network:
- API Gateway → YOLO Service:
http://yolo-service:8100 - API Gateway → LLM Service:
http://llm-service:8200 - API Gateway → Location Service:
http://location-service:8300
API_SECRET_KEY=your_secret_key
OPENAI_API_KEY=your_openai_key
GEMINI_API_KEY=your_gemini_key
YOLO_SERVICE_URL=http://yolo-service:8100
LLM_SERVICE_URL=http://llm-service:8200
LOCATION_SERVICE_URL=http://location-service:8300# View logs
docker-compose logs -f
# Restart service
docker-compose restart yolo-service
# Stop all services
docker-compose down
# Rebuild
docker-compose up --buildAuthentication Errors (401)
- Check API key in request headers
- Verify API_SECRET_KEY environment variable
Service Connection Issues
- Ensure all services are running:
docker-compose ps - Check Docker network:
docker network ls - View service logs:
docker-compose logs [service-name]
Model Loading Issues
- YOLO models download automatically on first run
- Check model files exist in
services/yolo/models/ - Verify internet connection for model downloads
Port Conflicts
- Ensure ports 8000, 8100, 8200, 8300 are available
- Stop conflicting services or change ports in docker-compose.yml
curl -X POST -F "file=@image.jpg" http://localhost:8000/api/mask/locationResponse format:
{
"data": [
[50.0, 75.5, 180.3, 120.8],
[250.2, 300.1, 400.6, 380.9]
]
}curl -X POST \
-F "file=@image.jpg" \
-F 'ocr_values=[{"text": "john@email.com", "bbox": [100, 200, 300, 220], "confidence": 0.95}]' \
http://localhost:8000/api/mask/piiResponse format:
{
"data": [
[120.0, 200.5, 350.8, 230.2],
[400.1, 450.3, 600.7, 480.9]
]
}curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}],
"temperature": 0.7,
"max_tokens": 150
}'Once the services are running, you can access the interactive API documentation at:
- Swagger UI: http://localhost:8000/
- Model: YOLOv5s (small version for faster inference)
- Input: Image files (JPEG, PNG)
- Output: Object detections with bounding boxes and confidence scores
- Confidence Threshold: 0.5 (configurable)
- Use Cases: Face detection, location masking (signs, vehicles, buildings)
- Models: All OpenAI models (gpt-3.5-turbo, gpt-4, etc.)
- Input: Chat messages in OpenAI format
- Output: Generated responses with usage statistics
- Use Cases: Chat completions, PII detection in OCR text
- All services include structured logging
- Health check endpoints for monitoring
- Error handling with appropriate HTTP status codes
- Request/response logging for debugging
- Each service runs independently and can be scaled separately
- GPU support available for vision models (CUDA)
- Stateless design for horizontal scaling
- Docker networking for efficient inter-service communication
- API keys managed through environment variables
- Service isolation through Docker containers
- Internal network communication between services
- Input validation and error handling
- Create a new service directory under
src/services/ - Implement Flask application with health check and prediction endpoints
- Add Dockerfile and requirements.txt
- Update docker-compose.yml
- Add routes to API gateway
Each service can be tested independently or through the API gateway.
- Model loading failures: Check GPU/CPU compatibility and model downloads
- Service communication: Verify Docker network configuration
- API key issues: Ensure OpenAI API key is properly set in environment
Check service logs:
docker compose logs yolo-service
docker compose logs openai-service
docker compose logs api-gatewayThis project is open source and available under the MIT License.