CoolFace
Apppublic

Abka18/greenFlag

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

Relationship Compass Backend

FastAPI backend for the GreenFlag / Relationship Compass app.

Endpoints

MethodPathDescription
GET/Service health response for platform/browser probes
GET/healthService health response
POST/analyzeEmotion detection via SamLowe/roberta-base-go_emotions, with Indonesian auto-translation
POST/translateIndonesian to English translation for frontend previews
POST/transcribeAudio transcription via openai/whisper-base
POST/chatProtected relationship-data chat endpoint

POST /analyze

Request body (JSON):

json
{ "text": "I feel really anxious about this situation." }

Response:

json
{
  "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):

json
{ "text": "hari ini aku merasa nyaman dan damai" }

Response:

json
{
  "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:

json
{ "text": "Transcribed speech goes here." }

Frontend Integration

Set these environment variables in your React frontend:

env
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/transcribe

All 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

env
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-en

Do not use ALLOWED_ORIGINS=* in production.

Models Used

Models are downloaded automatically from the Hugging Face Hub on first startup.