Abka18/greenFlag
0
Relationship Compass Backend
FastAPI backend for the GreenFlag / Relationship Compass app.
Endpoints
POST /analyze
Request body (JSON):
{ "text": "I feel really anxious about this situation." }Response:
{
"emotions": { "fear": 0.72, "sadness": 0.12, "...": "..." },
"primaryEmotion": "fear",
"emotionalState": {
"state": "fear",
"intensity": "High",
"needsAttention": false,
"description": "Detected fear with 72% confidence"
},
"success": true,
"translatedText": null,
"translationStatus": "skipped",
"translation": {
"sourceLanguage": "unknown",
"targetLanguage": "en",
"status": "skipped",
"translatedText": null
},
"needsAttention": false
}POST /translate
Request body (JSON):
{ "text": "hari ini aku merasa nyaman dan damai" }Response:
{
"text": "hari ini aku merasa nyaman dan damai",
"translatedText": "today I feel comfortable and peaceful",
"sourceLanguage": "id",
"targetLanguage": "en",
"translationStatus": "translated",
"success": true
}POST /transcribe
Request: multipart/form-data with an audio file field (.webm, .mp3, .wav, etc.)
Response:
{ "text": "Transcribed speech goes here." }Frontend Integration
Set these environment variables in your React frontend:
VITE_SENTIMENT_API_URL=https://<your-space>.hf.space/analyze
VITE_TRANSLATE_API_URL=https://<your-space>.hf.space/translate
VITE_TRANSCRIBE_API_URL=https://<your-space>.hf.space/transcribeAll endpoints (except /health) require a Supabase-issued Authorization: Bearer <jwt> header; the token is validated against Supabase Auth on every call and the caller's user_id is derived from it. There is no separate X-API-Key shared secret — do not ship one from the browser.
Required Backend Environment
SUPABASE_URL=https://<project>.supabase.co
SUPABASE_SERVICE_ROLE_KEY=<service role key — server-only, bypasses RLS>
MASTER_ENCRYPTION_KEY=<base64 32-byte AES-256 KEK for wrapping per-user DEKs>
DINOIKI_API_KEY=<AI provider key for /chat>
LOG_SALT=<random string; rotates log-side IP correlation>
ALLOWED_ORIGINS=https://your-frontend-domain.example,http://localhost:5173
MAX_TEXT_LENGTH=5000
MAX_AUDIO_SIZE_MB=25
ENABLE_TRANSLATION=true
TRANSLATION_MODEL=Helsinki-NLP/opus-mt-id-enDo not use ALLOWED_ORIGINS=* in production.
Models Used
- `SamLowe/roberta-base-go_emotions` — multi-label emotion classification
- `Helsinki-NLP/opus-mt-id-en` — Indonesian to English translation before emotion classification
- `openai/whisper-base` — multilingual speech recognition
Models are downloaded automatically from the Hugging Face Hub on first startup.
