--- 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