Spaces:
Sleeping
Sleeping
File size: 3,351 Bytes
f235090 2fe683b f235090 2fe683b f235090 2fe683b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | ---
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
```python
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
```bash
# 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*
|