Spaces:
Sleeping
Sleeping
|
Download README.md from changweikoy/backendAPI: direct link, hf CLI and curl.
- Browser
- Download file 3.35 kB
-
https://huggingface.co/spaces/changweikoy/backendAPI/resolve/main/README.md
- Command line
-
hf download hf://spaces/changweikoy/backendAPI/README.md
-
curl -L -o README.md https://huggingface.co/spaces/changweikoy/backendAPI/resolve/main/README.md
3.35 kB
metadata
title: AikoDiary Backend
emoji: π
colorFrom: purple
colorTo: pink
sdk: docker
pinned: false
license: mit
app_port: 7860
AikoDiary Backend API
A mental health journaling companion powered by Gemini AI, providing:
- π€ AI Chat - Empathetic conversation sessions using Gemini AI
- π€ Speech-to-Text - Voice input using Google Cloud Speech API
- π Sentiment Analysis - Anxiety, stress, and normal state detection
- π Emotion Detection - Facial emotion recognition from camera frames
- π Utility Fusion - Combined mental health score calculation
API Endpoints
Conversation
| Endpoint | Method | Description |
|---|---|---|
/start_conversation |
POST | Start new AI chat session |
/send_message |
POST | Send message, get AI response with sentiment |
/get_conversation |
GET | Get conversation history |
/end_conversation |
POST | End conversation session |
Speech-to-Text
| Endpoint | Method | Description |
|---|---|---|
/stt_start |
POST | Start STT recording session |
/stt_send_chunk |
POST | Send audio chunk |
/stt_stop |
POST | Stop recording, get transcript |
/stt_cancel |
POST | Cancel recording session |
/stt |
POST | Simple file upload STT |
Sentiment Analysis
| Endpoint | Method | Description |
|---|---|---|
/sentiment_initialize |
POST | Initialize sentiment model |
/sentiment_predict |
POST | Predict sentiment for text |
/sentiment_status |
GET | Get model status |
Emotion Detection
| Endpoint | Method | Description |
|---|---|---|
/emotion_initialize |
POST | Initialize emotion detector |
/emotion_detect |
POST | Detect emotion from image |
/emotion_status |
GET | Get detector status |
System
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/calculate_utility_scores |
POST | Calculate fused mental health scores |
Environment Variables (Secrets)
Set these in Hugging Face Space Settings > Repository secrets:
| Variable | Required | Description |
|---|---|---|
GEMINI_API_KEY |
β Yes | Google Gemini API key |
GCP_SERVICE_ACCOUNT_FILE |
Optional | Path to GCP credentials JSON |
SPEECH_LANGUAGE_CODE |
Optional | Speech recognition language (default: en-US) |
Usage Example
import requests
# Start conversation
response = requests.post(
"https://your-space.hf.space/start_conversation",
json={"session_id": "user_123"}
)
print(response.json())
# Send message
response = requests.post(
"https://your-space.hf.space/send_message",
json={
"session_id": "user_123",
"message": "I'm feeling stressed today"
}
)
print(response.json())
Local Development
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export GEMINI_API_KEY=your_api_key
# Run locally
python app.py
# Or with gunicorn
gunicorn --bind 0.0.0.0:7860 app:app
Tech Stack
- Framework: Flask + Gunicorn
- AI: Google Gemini API
- Speech: Google Cloud Speech-to-Text
- ML: scikit-learn (SVM sentiment classifier)
- Emotion: FER (Facial Emotion Recognition)
Built with β€οΈ for mental health awareness