Spaces:
Sleeping
Sleeping
metadata
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
# Install dependencies
pip install -r requirements.txt
# Run the service
python app.py
Docker
# Build image
docker build -t baby-cry-ai .
# Run container
docker run -p 5000:5000 baby-cry-ai
π‘ API Reference
Health Check
GET /health
Response:
{
"status": "healthy",
"service": "baby-cry-ai"
}
Analyze Cry
POST /analyze-cry
Content-Type: multipart/form-data
Request:
audio: Audio file (WAV, MP3, OGG, FLAC, M4A, WebM)
Response:
{
"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
# 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
Supervised Model:
Wiam/baby-cry-classification-finetuned-babycry-v4- Fine-tuned specifically for baby cry classification
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
# 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