Spaces:
Sleeping

backendAPI / README.md
changweikoy's picture
Deploy app.py with ML models and dependencies
2fe683b
|
Raw History Blame Contribute Delete
3.35 kB
---
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*