baby-cry-ai / README.md
Pranjal2510
Baby-Cry-Analysis Api
9b4e272
|
Raw
History Blame
4.79 kB
---
title: Baby Cry Ai
emoji: 😻
colorFrom: yellow
colorTo: indigo
sdk: gradio
sdk_version: 6.3.0
app_file: app.py
pinned: false
license: mit
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# πŸ‘Ά Baby Cry AI Service
A Flask microservice that analyzes baby cry audio to identify the reason for crying using an ensemble of Hugging Face models.
## 🎯 Features
- **Ensemble Model Approach**: Combines supervised and zero-shot classification for improved accuracy
- **Single Load Architecture**: Models loaded once at startup for optimal performance
- **Docker Ready**: Production-ready containerized deployment
- **REST API**: Simple POST endpoint for audio analysis
## πŸ—οΈ Architecture
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Baby Cry AI Service β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ app.py (Flask API) β”‚
β”‚ └── POST /analyze-cry β”‚
β”‚ └── inference.py β”‚
β”‚ β”œβ”€β”€ Supervised Model (Wiam/baby-cry-*) β”‚
β”‚ └── Zero-Shot Model (laion/clap-htsat-unfused) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
## πŸš€ Quick Start
### Local Development
```bash
# Install dependencies
pip install -r requirements.txt
# Run the service
python app.py
```
### Docker
```bash
# Build image
docker build -t baby-cry-ai .
# Run container
docker run -p 5000:5000 baby-cry-ai
```
## πŸ“‘ API Reference
### Health Check
```http
GET /health
```
**Response:**
```json
{
"status": "healthy",
"service": "baby-cry-ai"
}
```
### Analyze Cry
```http
POST /analyze-cry
Content-Type: multipart/form-data
```
**Request:**
- `audio`: Audio file (WAV, MP3, OGG, FLAC, M4A, WebM)
**Response:**
```json
{
"cry_detected": true,
"top_reason": "hunger",
"scores": {
"hunger": 0.45,
"belly_pain": 0.20,
"tired": 0.15,
"discomfort": 0.12,
"burping": 0.08
},
"disclaimer": "AI-generated suggestion, not a medical diagnosis. Please consult a healthcare professional for medical advice."
}
```
### Example Usage
```bash
# Using curl
curl -X POST http://localhost:5000/analyze-cry \
-F "audio=@baby_cry.wav"
# Using Python requests
import requests
with open("baby_cry.wav", "rb") as f:
response = requests.post(
"http://localhost:5000/analyze-cry",
files={"audio": f}
)
print(response.json())
```
## 🏷️ Cry Categories
| Label | Description |
|-------|-------------|
| `hunger` | Baby is hungry (rhythmic "neh" sound) |
| `belly_pain` | Stomach discomfort (sharp, high-pitched) |
| `tired` | Baby needs sleep (heavy, yawning cry) |
| `discomfort` | General discomfort (fussy, whiny) |
| `burping` | Needs to burp (repetitive sounds) |
## 🧠 Models Used
1. **Supervised Model**: `Wiam/baby-cry-classification-finetuned-babycry-v4`
- Fine-tuned specifically for baby cry classification
2. **Zero-Shot Model**: `laion/clap-htsat-unfused`
- CLAP model for audio-text matching
- Provides additional context via natural language prompts
## πŸ“ Project Structure
```
baby-cry-ai-service/
β”œβ”€β”€ app.py # Flask entry point
β”œβ”€β”€ inference.py # Model loading & inference logic
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ Dockerfile # Container configuration
β”œβ”€β”€ .env.example # Environment variables template
└── README.md # Documentation
```
## βš™οΈ Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `PORT` | `5000` | Server port |
| `FLASK_DEBUG` | `false` | Enable debug mode |
## πŸ”§ Production Deployment
For production, the Docker image uses Gunicorn with:
- Single worker (due to model memory requirements)
- 120s timeout for large audio files
- Health check endpoint
```bash
# Production run with custom port
docker run -p 8080:5000 -e PORT=5000 baby-cry-ai
```
## ⚠️ Disclaimer
This service provides AI-generated suggestions only and should **NOT** be used as a substitute for professional medical advice. Always consult with a healthcare professional for concerns about your baby's health.
## πŸ“„ License
MIT License