Downloads · 30 days
0
ulhaqdhifulloh/emotion-detection
emotion-detection is a machine learning model from ulhaqdhifulloh. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Server FastAPI untuk menyajikan model emosi PyTorch dengan endpoint sederhana dan konfigurasi minimal. Image Docker hanya berisi API (tanpa website).
Downloads · 30 days
0
Access
Public
Updated Oct 15, 2025
Repo size
112 MB
Likes
0
Public
Click a slice to open those files.
.pth112 MB · 100%
From the Hugging Face model README
Server FastAPI untuk menyajikan model emosi PyTorch dengan endpoint sederhana dan konfigurasi minimal. Image Docker hanya berisi API (tanpa website).
GET /health, POST /predict (gambar tunggal), POST /predict-batch (banyak gambar)cnn_emotion_model_v6-2.pth)CHECKPOINT_PATH (wajib, kecuali Anda mount ke /models/cnn_emotion_model_v6-2.pth)IMG_SIZE (default 224)CORS_ALLOW_ORIGINS (default *; contoh yang direkomendasikan: https://mental-healt-be.xianly.cloud,http://localhost:3001,https://soulspace-rust.vercel.app)pip install -r requirements.txt
# Jalankan dari root repo (emotion-detection)
$env:CHECKPOINT_PATH = ".\\models\\fine-tune\\cnn_emotion_model_v6-2.pth"
uvicorn api/main:app --host 0.0.0.0 --port 8000
export CHECKPOINT_PATH="/absolute/path/to/models/fine-tune/cnn_emotion_model_v6-2.pth"
uvicorn main:app --host 0.0.0.0 --port 8000
Build image dari folder api:
docker build -t emotion-api .
Jalankan container (model sudah termasuk di image) dan expose port 3003:
Windows PowerShell (jalankan dari root repo):
docker run --rm -p 3003:3003 emotion-api:latest
macOS/Linux (bash, jalankan dari root repo):
docker run --rm -p 3003:3003 emotion-api:latest
Alternatif: gunakan file env khusus Docker (--env-file) untuk override konfigurasi (mis. IMG_SIZE, CORS_ALLOW_ORIGINS). Model sudah berada di /app/cnn_emotion_model_v6-2.pth.
Windows PowerShell (jalankan dari folder api di VPS):
docker run --rm -p 3003:3003 ^
--env-file api/.env.docker ^
emotion-api:latest
macOS/Linux (bash, jalankan dari folder api di VPS):
docker run --rm -p 3003:3003 \
--env-file api/.env.docker \
emotion-api:latest
Catatan:
web-app/index.html secara terpisah.api/cnn_emotion_model_v6-2.pth sudah di-upload ke VPS (file model biasanya di-ignore Git).curl http://localhost:3003/health.api (termasuk cnn_emotion_model_v6-2.pth) ke VPS.api lalu build image:
docker build -t emotion-api .docker run --rm -p 3003:3003 --env-file .env.docker emotion-api:latestcurl http://localhost:3003/health..env.docker lalu jalankan container baru.--env-file untuk konfigurasi tambahan..env yang berisi perintah set ... hanya berlaku untuk run lokal di PowerShell, bukan untuk Docker. Untuk Docker gunakan -e atau --env-file dengan format KEY=VALUE.GET /health
POST /predict
file (gambar), query: tta (bool), fp16 (bool){
"emotion": "joy",
"confidence": 0.92,
"probs": {"anger":0.01, "fear":0.02, "joy":0.92, "sad":0.05},
"entropy": 0.35,
"latency_ms": 23.5,
"device": "cpu",
"tta_used": false,
"fp16_used": false
}
POST /predict-batch
files (banyak gambar), query: tta, fp16Jalankan dari root repo (emotion-detection/):
curl http://localhost:8000/health
curl -X POST "http://localhost:8000/predict?tta=false&fp16=true" \
-F "file=@./images/test/joy_WIN_20251009_00_23_41_Pro.jpg"
curl -X POST "http://localhost:8000/predict-batch?tta=true&fp16=true" \
-F "files=@./images/test/joy_WIN_20251009_00_23_41_Pro.jpg" \
-F "files=@./images/test/sad_WIN_20251009_00_23_53_Pro.jpg"
Website saat ini mengunggah gambar ke /predict. Sketsa kode di frontend:
async function predictEmotionViaAPI(faceCanvas, apiBaseUrl, tta, fp16) {
const blob = await new Promise(res => faceCanvas.toBlob(res, 'image/jpeg', 0.9));
const form = new FormData();
form.append('file', blob, 'face.jpg');
const url = `${apiBaseUrl}/predict?tta=${tta}&fp16=${fp16}`;
const resp = await fetch(url, { method: 'POST', body: form });
return resp.json();
}
CHECKPOINT_PATH mengarah ke file yang valid dan dapat diakses di container.CORS_ALLOW_ORIGINS ke origin situs Anda (mis. http://localhost:5500).API dipelihara di api/ dengan fokus minimal pada server.