Zakha123-cyber
Initial deployment: SWARA API with eye tracking, facial expression, and gesture detection
8e73bed
metadata
title: SWARA - AI Public Speaking Evaluation
emoji: π€
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
π€ SWARA API - AI-Powered Public Speaking Evaluation
API backend untuk sistem evaluasi public speaking berbasis AI.
π Fitur
- β Async Video Processing - Non-blocking video analysis dengan RQ (Redis Queue)
- β Multi-Model AI - Eye tracking, facial expression, gesture detection
- β Level-based Evaluation - 5 level kesulitan dengan indikator berbeda
- β RESTful API - FastAPI dengan OpenAPI documentation
- β Cloud Redis - Upstash Redis untuk production
- β Progress Tracking - Real-time progress updates untuk analysis
ποΈ Arsitektur
βββββββββββββββββββββββββββββββββββββββββββ
β Docker Container β
β β
β ββββββββββββββββ ββββββββββββββββ β
β β FastAPI βββββΆβ Redis β β
β β (Port 7860) β β (Queue & KV) β β
β ββββββββββββββββ ββββββββββββββββ β
β β β β
β β POST /analyze β β
β β return task_id β β
β β βΌ β
β β ββββββββββββββββ β
β β β RQ Worker β β
β β β (Background) β β
β β ββββββββββββββββ β
β β β β
β β GET /task/{id} β β
β ββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββ
π Quick Start
Prerequisites
- Docker & Docker Compose
- Python 3.10+ (untuk development tanpa Docker)
1. Clone & Setup
# Clone repository (if applicable)
cd API-MODEL
# Copy environment file
cp .env.example .env
# Edit .env jika perlu (optional untuk local development)
2. Run dengan Docker Compose
# Build dan start semua services
docker-compose up --build
# Atau run di background
docker-compose up -d --build
# Lihat logs
docker-compose logs -f
# Stop services
docker-compose down
API akan tersedia di: http://localhost:7860
3. Akses Documentation
- Swagger UI: http://localhost:7860/docs
- ReDoc: http://localhost:7860/redoc
- OpenAPI JSON: http://localhost:7860/openapi.json
π API Endpoints
1. Health Check
GET /health
Response:
{
"status": "healthy",
"version": "1.0.0",
"redis_connected": true,
"timestamp": "2025-11-10T10:00:00"
}
2. Upload Video untuk Analysis
POST /api/v1/analyze
Content-Type: multipart/form-data
Parameters:
video(file): Video file (max 50MB, max 1 minute)level(int): Level 1-5user_id(string, optional): User identifier
Response:
{
"task_id": "abc123def456",
"status": "pending",
"message": "Video uploaded successfully. Processing has been queued.",
"created_at": "2025-11-10T10:00:00"
}
3. Get Task Status
GET /api/v1/task/{task_id}
Response (Processing):
{
"task_id": "abc123def456",
"status": "processing",
"progress": {
"current_step": "processing",
"percentage": 45.5,
"message": "Analyzing facial expressions..."
},
"created_at": "2025-11-10T10:00:00"
}
Response (Completed):
{
"task_id": "abc123def456",
"status": "completed",
"result": {
"level": 2,
"video_metadata": {
"duration": 58.5,
"fps": 30,
"resolution": "1920x1080",
"file_size": 15728640
},
"main_indicators": {
"kontak_mata": {
"score": 4,
"raw_data": {...}
}
},
"bonus_indicators": {
"first_impression": {
"detected": true,
"raw_data": {...}
},
"face_expression": {...},
"gesture": {...}
},
"processing_time": 42.3
},
"created_at": "2025-11-10T10:00:00",
"completed_at": "2025-11-10T10:01:00"
}
4. Delete Task
DELETE /api/v1/task/{task_id}
π§ͺ Testing dengan cURL
Upload Video
curl -X POST "http://localhost:7860/api/v1/analyze" `
-F "video=@test_video.mp4" `
-F "level=2" `
-F "user_id=user123"
Check Status
curl "http://localhost:7860/api/v1/task/abc123def456"
π οΈ Development Setup (Tanpa Docker)
1. Install Dependencies
# Create virtual environment
python -m venv venv
.\venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
2. Setup Redis (Local atau Upstash)
Option A: Local Redis (dengan Docker)
docker run -d -p 6379:6379 redis:7-alpine
Option B: Upstash Redis (Gratis)
- Daftar di https://upstash.com
- Create Redis database
- Copy connection string ke
.env:
REDIS_URL=redis://default:YOUR_PASSWORD@YOUR_ENDPOINT:6379
3. Run API Server
python -m app.main
4. Run Worker (Terminal terpisah)
python -m app.worker
π Project Structure
API-MODEL/
βββ app/
β βββ __init__.py
β βββ main.py # FastAPI app
β βββ config.py # Configuration
β βββ models.py # Pydantic models
β βββ tasks.py # Background tasks
β βββ worker.py # RQ worker
β βββ api/
β β βββ routes.py # API endpoints
β βββ core/
β β βββ redis_client.py # Redis connection
β β βββ storage.py # File storage
β βββ services/
β βββ video_processor.py # Main orchestrator
β βββ eye_tracking.py # Eye tracking service
β βββ facial_expression.py # Facial expression service
β βββ gesture_detection.py # Gesture detection service
βββ models/ # AI model files
βββ temp/ # Temporary video storage
βββ logs/ # Application logs
βββ docker-compose.yml
βββ Dockerfile
βββ requirements.txt
βββ README.md
βοΈ Configuration
Edit .env file untuk konfigurasi:
# Environment
ENV=development
# Redis (Upstash atau local)
REDIS_URL=redis://localhost:6379
# API
API_HOST=0.0.0.0
API_PORT=7860
# Processing
MAX_VIDEO_SIZE_MB=50
MAX_VIDEO_DURATION_SECONDS=60
TASK_TIMEOUT_SECONDS=300
# Logging
LOG_LEVEL=INFO
π Monitoring
View Logs
# API logs
docker-compose logs -f api
# Worker logs
docker-compose logs -f worker
# Redis logs
docker-compose logs -f redis
# All logs
docker-compose logs -f
Check Redis Queue
# Connect to Redis container
docker exec -it swara-redis redis-cli
# Check queue length
LLEN swara:tasks
# View all keys
KEYS *
# Get task data
GET task:abc123def456
π§ Troubleshooting
Problem: Redis connection failed
Solution:
# Check Redis is running
docker-compose ps
# Restart Redis
docker-compose restart redis
# Check Redis logs
docker-compose logs redis
Problem: Worker not processing tasks
Solution:
# Check worker logs
docker-compose logs worker
# Restart worker
docker-compose restart worker
# Check if worker is running
docker-compose ps worker
Problem: Video file too large
Solution:
- Compress video atau gunakan format yang lebih efisien
- Increase
MAX_VIDEO_SIZE_MBdi.env
π Next Steps (TODO)
Untuk complete implementation, Anda perlu:
Refactor existing code ke services:
-
app/services/eye_tracking.py- darieye_tracking_production.py -
app/services/facial_expression.py- darifacial_expression.py -
app/services/gesture_detection.py- darigesture_detection.py
-
Add audio processing:
-
app/services/audio_processor.py- untuk tempo, artikulasi, jeda - Speech-to-text integration
- Kata pengisi & kata tidak senonoh detection
-
Add NLP processing:
-
app/services/nlp_processor.py- untuk kesesuaian topik, struktur kalimat - Topic matching
- Sentence structure analysis
-
Optimization:
- Implement frame sampling (5 fps instead of 30 fps)
- Model loading optimization
- Memory management
Testing:
- Unit tests
- Integration tests
- Load testing
π’ Deployment ke HuggingFace Spaces
1. Create Space
- Go to https://huggingface.co/spaces
- Create new Space (Docker type)
- Clone repository
2. Prepare Files
# Add Dockerfile for HF Spaces
# (sudah ada di repository)
3. Setup Secrets
Di HuggingFace Space settings, add secrets:
REDIS_URL- Upstash Redis URLENV- production
4. Push & Deploy
git push origin main
HuggingFace akan auto-deploy!
π Support
Untuk pertanyaan atau issues, contact SWARA team.
Built with β€οΈ by SWARA Team for LIDM Competition 2025