A full-stack AI-powered content moderation platform that automatically analyzes uploaded images for policy violations, provides structured moderation verdicts, supports user appeals, and enables administrators to manage moderation policies and review flagged content.
<<<<<<< HEAD
Primary: Google Gemini API
- Advanced image understanding
- Detailed reasoning and explanations
- 3 retry attempts with exponential backoff
- Automatic failover on errors
Fallback: Hugging Face CLIP (Local)
- Zero API costs, no billing required
- Runs entirely on your hardware
- Automatic activation when Gemini fails
- Threshold-based content detection
- Multiple category detection simultaneously =======
- π₯ Demo Video: https://drive.google.com/file/d/1Vk4xPetkZFP1pO5qVXTuiaBqZbqvKm4V/view?usp=sharing
- π Repository: https://github.com/MuhammadHaris249518/Modera
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
This project was developed as part of a Full-Stack Engineering Internship Assessment.
The platform allows users to upload images for AI-powered moderation screening while providing administrators with tools to review appeals, manage moderation policies, and oversee platform activity.
The application demonstrates full-stack development, REST API design, authentication and authorization, MongoDB data modeling, AI integration, and Dockerized deployment.
- User Registration & Login
- Secure JWT Authentication
- Image Upload & Moderation
- View Submission History
- Submit Appeals Against Decisions
- Track Appeal Status
- Admin Dashboard
- Review Appeals Queue
- Policy Configuration Management
- User Monitoring
- Manual Verdict Overrides
- Moderation Control Panel
The moderation engine analyzes uploaded images and generates:
- Classification Result
- Confidence Score (0-100)
- Reasoning Summary
- Final Verdict
- Multiple category detection
- Threshold-based decisions
Detection Categories:
- Safe Image
- Violence
- Weapon
- Adult Content
- Drugs
<<<<<<< HEAD Possible outcomes:
- Approved
- Flagged for Review
- Blocked =======
- β Approved
β οΈ Flagged for Review- β Blocked
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
- Next.js 15
- React 19
- TypeScript
- Tailwind CSS
- ShadCN UI
- Axios
- FastAPI
- Python 3.11
- Pydantic
- JWT Authentication
- MongoDB
- Primary: Google Gemini API (cloud-based)
- Fallback: Hugging Face CLIP (local inference)
- Model:
openai/clip-vit-base-patch32 - No API key required
- CPU/CUDA support
- Model:
- Docker
- Docker Compose
<<<<<<< HEAD
βββββββββββββββββββ
β Frontend β
β Next.js / React β
ββββββββββ¬βββββββββ
β REST API
βΌ
βββββββββββββββββββ
β FastAPI β
β Business Logic β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β AI Moderation Engine β
β βββββββββββββββββββββββββββββββββ β
β β 1. Google Gemini API (Primary)β β
β β - 3 retry attempts β β
β β - Exponential backoff β β
β βββββββββββββ¬ββββββββββββββββββββ β
β β On failure β
β βΌ β
β βββββββββββββββββββββββββββββββββ β
β β 2. Hugging Face CLIP (Fallback)β β
β β - Local inference β β
β β - No API key needed β β
β β - Threshold-based decisionsβ β
β βββββββββββββ¬ββββββββββββββββββββ β
β β On failure β
β βΌ β
β βββββββββββββββββββββββββββββββββ β
β β 3. Basic Metadata (Last Resort)β β
β β - Image size/brightness β β
β βββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β MongoDB β
βββββββββββββββββββ
=======
βββββββββββββββββββββββββββ
β Frontend β
β Next.js + React β
ββββββββββββββ¬βββββββββββββ
β REST API
βΌ
βββββββββββββββββββββββββββ
β FastAPI β
β Business Logic Layer β
ββββββββββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β AI Moderation Layer β
β Gemini API β
ββββββββββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β MongoDB β
β Persistent Storage β
βββββββββββββββββββββββββββ
>>>>>>> 93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
<<<<<<< HEAD
- User uploads an image
- Backend encodes image to base64
- Sends to Gemini API with moderation prompt
- Gemini analyzes and returns JSON response
- Response is parsed and normalized
- Results stored in MongoDB
- User receives verdict
If Gemini fails (timeout, rate limit, 403, network error):
- System automatically switches to Hugging Face
- CLIP model classifies image against 5 categories
- Each category evaluated against threshold (default: 60%)
- Multiple categories can be flagged simultaneously
- Results converted to project format
- If HF also fails, uses basic metadata fallback
WEAPON_THRESHOLD = 0.60 # 60% confidence
VIOLENCE_THRESHOLD = 0.60 # 60% confidence
ADULT_THRESHOLD = 0.60 # 60% confidence
DRUG_THRESHOLD = 0.60 # 60% confidenceLogic:
- If ANY harmful category exceeds its threshold β
status: "harmful" - Otherwise β
status: "safe" - Multiple categories can be triggered simultaneously
=======
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
Modera/
β
βββ backend/
β βββ app/
β β βββ api/ # API routes
β β βββ models/ # Database models
β β βββ schemas/ # Pydantic schemas
β β βββ services/ # Business logic
β β β βββ ai_service.py # Main AI orchestration
β β β βββ huggingface_service.py # HF CLIP fallback
β β βββ core/ # Configuration & security
β β βββ db/ # Database connection
β β βββ main.py # FastAPI app entry
β β
β βββ requirements.txt
β βββ Dockerfile
β βββ .env
β
βββ frontend/
β βββ src/
β β βββ app/ # Next.js pages
β β βββ components/ # React components
β β βββ services/ # API clients
β β βββ hooks/ # Custom hooks
β β βββ lib/ # Utilities
β β
β βββ package.json
β βββ Dockerfile
β βββ .env.local
β
βββ docker-compose.yml
βββ README.md
βββ docs/Stores: <<<<<<< HEAD
- User information
- Credentials (hashed passwords)
- Roles (user/admin)
- Email verification status =======
- User Profile Information
- Authentication Credentials
- User Roles
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
Stores: <<<<<<< HEAD
- Uploaded image metadata
- Moderation results (from AI)
- Verdict information
- Confidence scores
- Submission timestamps
- AI provider used (gemini/huggingface/basic_fallback) =======
- Uploaded Image Metadata
- Moderation Results
- Verdict Information
- Submission Timestamps
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
Stores: <<<<<<< HEAD
- Appeal requests
- Appeal status (pending/approved/rejected)
- Administrative decisions
- Appeal reasoning =======
- Appeal Requests
- User Justification
- Appeal Status
- Administrative Decisions
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
Stores: <<<<<<< HEAD
- Confidence thresholds
- Moderation settings
- Enforcement configurations
- Category-specific rules =======
- Confidence Thresholds
- Moderation Rules
- Category Configuration
The user uploads an image through the web interface.
The backend forwards the image to the AI moderation service.
The AI evaluates the image and produces:
- Classification Results
- Confidence Scores
- Reasoning Summaries
The moderation engine determines whether the image should be:
- Approved
- Flagged for Review
- Blocked
Results are stored in MongoDB and become available in the user's submission history.
Users can challenge moderation decisions through the appeal system.
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
The platform uses JWT-based authentication and role-based access control.
- Upload Images
- View Personal History
- Submit Appeals
- Track Appeal Status
- Review Appeals
- Configure Policies
- Manage Moderation Decisions
- Access Administrative Features
POST /api/auth/register
POST /api/auth/loginPOST /api/submissions
GET /api/submissions
GET /api/submissions/{id}POST /api/appeals
GET /api/appeals
PATCH /api/appeals/{id}GET /api/policies
PUT /api/policies/{id}# Database
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=moderation_db
# Security
SECRET_KEY=your-secret-key-here
# AI Configuration
AI_PROVIDER=gemini # Options: gemini, local_fallback
GEMINI_API_KEY=your_gemini_api_key # Optional - uses HF fallback if missing
GEMINI_MODEL=gemini-3.5-flash
# CORS
FRONTEND_ORIGIN=http://localhost:3000
# Admin (development only)
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=Admin123!NEXT_PUBLIC_API_URL=http://localhost:8000<<<<<<< HEAD
=======
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
- Python 3.11+
- Node.js 18+
- MongoDB (local or cloud)
- Git
<<<<<<< HEAD
# Navigate to backend directory
cd Modera/backend
=======
## Start the Application
```bash
docker-compose up --build| Service | URL |
|---|---|
| Frontend | http://localhost:3000 |
| Backend API | http://localhost:8000 |
| API Documentation | http://localhost:8000/docs |
| MongoDB | localhost:27017 |
cd backend
>>>>>>> 93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
# Create virtual environment
python -m venv venv<<<<<<< HEAD
venv\Scripts\activate
source venv/bin/activate
=======
venv\Scripts\activate>>>>>>> 93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
pip install -r requirements.txt<<<<<<< HEAD
uvicorn app.main:app --reload
Backend will run at: http://localhost:8000
### Frontend Setup
=======
### Run Backend
```bash
uvicorn app.main:app --reload
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
# Navigate to frontend directory
cd Modera/frontend
# Install dependencies
npm install
# Run development server
npm run dev<<<<<<< HEAD Frontend will run at: http://localhost:3000
Frontend will run at:
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
- Docker
- Docker Compose
# From project root
docker-compose up --build| Service | URL |
|---|---|
| Frontend | http://localhost:3000 |
| Backend | http://localhost:8000 |
| API Docs | http://localhost:8000/docs |
| MongoDB | localhost:27017 |
Configuration:
- Model:
gemini-3.5-flash(configurable) - Retries: 3 attempts
- Backoff: Exponential (1s, 2s, 4s)
- Timeout: Default (60s)
Advantages:
- High accuracy
- Detailed reasoning
- Context understanding
- Fast response times
Requirements:
- Google Cloud account
- Gemini API key
- Billing enabled (pay-per-use)
Get API Key:
- Visit https://aistudio.google.com/app/apikey
- Create new API key
- Add to
.envasGEMINI_API_KEY
Configuration:
- Model:
openai/clip-vit-base-patch32 - Size: ~600MB (downloaded once, cached)
- Device: Auto-detects CUDA/CPU
- Thresholds: 60% default (configurable)
Advantages:
- No API costs
- No billing required
- Runs locally
- Privacy-friendly
- Works offline
Requirements:
- PyTorch (~2GB)
- Transformers library
- ~1GB disk space for model
First Run:
- Model downloads automatically to
~/.cache/huggingface/hub - Takes 2-5 minutes depending on connection
- Cached for all future runs
Hardware Compatibility:
- CPU: Intel Xeon (works, slower)
- GPU: NVIDIA Quadro T2000 (4GB VRAM) - recommended
- RAM: 16GB minimum
- OS: Windows, Mac, Linux
If both AI services fail:
- Analyzes image dimensions
- Calculates average brightness
- Returns safe by default
- No content understanding
{
"graphicViolence": {
"detected": false,
"confidence": 0.0,
"reason": "Not detected"
},
"weaponsContraband": {
"detected": true,
"confidence": 85.5,
"reason": "Detected by Hugging Face: Weapon"
},
"provider": "huggingface",
"model": "openai/clip-vit-base-patch32",
"reasoning": "Hugging Face detected: Weapon"
}When using Hugging Face fallback, additional fields are included:
{
"provider": "huggingface",
"hf_scores": {
"Weapon": 0.91,
"Violence": 0.45,
"Adult Content": 0.03,
"Drugs": 0.02,
"Safe Image": 0.04
},
"hf_status": "harmful"
}Edit backend/app/services/huggingface_service.py:
WEAPON_THRESHOLD = 0.60 # 0.0 to 1.0
VIOLENCE_THRESHOLD = 0.60 # 0.0 to 1.0
ADULT_THRESHOLD = 0.60 # 0.0 to 1.0
DRUG_THRESHOLD = 0.60 # 0.0 to 1.0Guidelines:
- Lower (0.50): More sensitive, more false positives
- Higher (0.70): Less sensitive, fewer false positives
- Current (0.60): Balanced approach
Edit .env:
# Use Gemini (requires API key)
AI_PROVIDER=gemini
# OR use Hugging Face only (no API key)
AI_PROVIDER=local_fallbackNote: Even with AI_PROVIDER=gemini, the system automatically falls back to Hugging Face if Gemini fails.
- JWT Authentication <<<<<<< HEAD
- Password Hashing (bcrypt) =======
- Password Hashing
- Protected API Routes
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
- Role-Based Access Control
- Input Validation <<<<<<< HEAD
- Secure Environment Variables
- No hardcoded credentials
- Add valid
GEMINI_API_KEYto.env - Upload image through frontend
- Check backend logs for:
"provider": "gemini" - Verify detailed AI analysis in response
- Remove or invalidate
GEMINI_API_KEY - Upload image through frontend
- First upload: Model downloads (~600MB, 2-5 min)
- Check backend logs for:
"provider": "huggingface" - Verify threshold-based results
Upload images containing:
- Weapons only β Should detect Weapon
- Violence only β Should detect Violence
- Both weapon + violence β Should detect both
- Safe content β Should return safe
Error: Failed to load Hugging Face model
Solutions:
- Check internet connection (first download only)
- Verify disk space (~1GB required)
- Check Python version (3.11+)
- Reinstall:
pip install --upgrade torch transformers
Error: PERMISSION_DENIED
Solutions:
- Enable "Generative Language API" in Google Cloud Console
- Set up billing account
- Verify API key has no restrictions
- Wait 5-10 minutes after enabling API
Error: Address already in use
Solutions:
# Windows - Find and kill process
netstat -ano | findstr :8000
taskkill /PID <PID> /F
# Or change ports in docker-compose.ymlSolutions:
- Start MongoDB:
mongod - Or use Docker:
docker-compose up mongodb - Check
MONGODB_URLin.env
Minimum:
- CPU: Intel Xeon or equivalent
- RAM: 16GB
- Storage: 5GB free space
- GPU: Optional (CUDA supported)
Recommended:
- CPU: Intel Xeon (10th Gen+) or AMD Ryzen
- RAM: 16GB+
- Storage: 10GB+ SSD
- GPU: NVIDIA Quadro T2000 (4GB VRAM) or better
| Model | First Run | Subsequent | Memory |
|---|---|---|---|
| Gemini | ~2s | ~1-2s | Minimal |
| Hugging Face | ~5-10s | ~3-5s | ~1.5GB |
| Basic Fallback | <1s | <1s | Minimal |
- Update
CLASSIFICATION_LABELSinhuggingface_service.py - Add threshold constant
- Update
CATEGORY_THRESHOLDSmapping - Add category mapping in
ai_service.py
Logs are output to console with levels:
- INFO: Normal operations
- ERROR: Failures and exceptions
- Debug: Detailed debugging (enable in production)
- Fork the repository
- Create feature branch
- Make changes
- Test thoroughly
- Submit pull request
- Environment Variable Configuration
- Multi-Image Upload Support
- Analytics Dashboard
- Policy Versioning
- Audit Logs
- Cloud Storage Integration
- Real-Time Notifications
- Advanced Reporting
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b
- Full-Stack Web Development
- REST API Design
- MongoDB Data Modeling
- Authentication & Authorization
- AI Integration
- Appeal Workflow
- Administrative Controls
- Dockerized Deployment
- Clean Software Architecture
Muhammad Haris
Full Stack Developer
<<<<<<< HEAD GitHub: https://github.com/MuhammadHaris249518/Modera
LinkedIn: https://linkedin.com/in/yourprofile
For issues or questions:
- Check Troubleshooting section
- Review API documentation at http://localhost:8000/docs
- Open GitHub issue
- Dual AI model architecture
- Hugging Face CLIP integration
- Threshold-based moderation
- Multiple category detection
- Automatic failover system
- Multi-image uploads
- Analytics dashboard
- Policy versioning
- Audit logging
- Cloud storage support
- Real-time notifications
- Batch processing
- Custom model fine-tuning ======= GitHub: https://github.com/MuhammadHaris249518
LinkedIn: https://linkedin.com/in/your-linkedin-profile
93c2fc6bb610c32a5ba7a3171df6230c7b213c2b