Spaces:
Sleeping
title: CardioScreen AI API
emoji: π«
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
CardioScreen AI
AI-Assisted Cardiac Screening Tool for Canine Heart Disease
Clinical Validation Study β Veterinary Internal Medicine Thesis
Overview
CardioScreen AI is a web-based clinical screening tool that analyzes canine heart sounds (phonocardiograms) to detect cardiac murmurs using a dual-analysis pipeline: a CNN deep learning classifier (primary) and a DSP signal processing analyzer (supplementary).
The system records or accepts audio input from a digital stethoscope, processes it through noise reduction and quality assessment, and provides a Heart Score (1-10) with clinical interpretation.
Architecture
Audio Input (WAV/MP3/Recording)
β
βΌ
βββββββββββββββββββββββββββ
β Audio Preprocessing β
β β’ Spectral gating NR β
β β’ Bandpass (25-600 Hz) β
β β’ Normalization β
ββββββββββ¬βββββββββββββββββ
β
ββββββ΄βββββ
β β
βΌ βΌ
ββββββββββ ββββββββββββ
β DSP β β CNN β
β (10%) β β (90%) β
β Suppl. β β Primary β
βββββ¬βββββ ββββββ¬ββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββ
β Heart Score (1-10) β
β Quality-gated fusion β
β Clinical interpretation β
βββββββββββββββββββββββββββ
CNN Pipeline (Primary)
- Input: Mel-spectrogram (128 frequency bands, 128 time steps)
- Model: 1D CNN with 3 convolutional layers (32β64β128 filters)
- Training: 940 balanced recordings (multi-species foundational mix), stratified 5-fold CV
- Performance: 96.3% sensitivity, 96.0% specificity (after threshold tuning)
DSP Pipeline (Supplementary)
- Features: Energy ratio, HF ratio, consistency, spectral entropy, MFCC variance
- Model: Logistic regression trained on 21 annotated recordings
- Quality gating: Automatically dampened when noise is detected
Heart Score
- Composite score: 90% CNN + 10% DSP
- Quality dampening: pulls score toward neutral (5) when recording quality is poor
- Risk levels: Low (8-10), Moderate (6-7), Elevated (4-5), High (1-3)
Dataset
| Source | Recordings | Description |
|---|---|---|
| PhysioNet CirCor 2022 | 470 | Human pediatric (foundational base) |
| Kaggle Heart Sounds | 200 | Mixed cardiac recordings |
| Hannover Vet School | 150 | Veterinary clinical recordings |
| VetCPD / Clinical | 120 | Canine auscultation samples |
| Total | 940 | Balanced (Normal/Murmur) |
Performance
| Metric | Value |
|---|---|
| Sensitivity (Recall) | 96.3% |
| Specificity | 96.0% |
| Accuracy | 95.9% |
| Precision (PPV) | 96.7% |
| F1 Score | 0.965 |
Confusion Matrix (Pre-tuning)
| Pred Normal | Pred Murmur | |
|---|---|---|
| Actual Normal | 153 (TN) | 46 (FP) |
| Actual Murmur | 18 (FN) | 1330 (TP) |
Technology Stack
| Component | Technology |
|---|---|
| Frontend | React + Vite |
| Backend | FastAPI (Python) |
| ML Framework | PyTorch |
| Audio Processing | librosa, scipy, soundfile |
| PDF Reports | jsPDF |
| Deployment | Render.com |
Installation & Running
Prerequisites
- Python 3.9+ with GPU support (optional, for training)
- Node.js 18+
Backend Setup
# Create virtual environment
python -m venv gpu_env
gpu_env\Scripts\activate # Windows
# source gpu_env/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt
# Download pre-trained model (from Hugging Face)
python download_hf_model.py
# Start API server
python -m uvicorn api:app --host 0.0.0.0 --port 8000
Frontend Setup
cd webapp
npm install
npm run dev
The application will be available at http://localhost:5173.
Environment Variables
# webapp/.env.local (development)
VITE_API_URL=http://127.0.0.1:8000/analyze
# webapp/.env.production (deployment)
VITE_API_URL=https://your-api-url.onrender.com/analyze
Project Structure
βββ api.py # FastAPI backend
βββ inference.py # ML inference engine
β βββ load_audio() # Audio preprocessing
β βββ reduce_noise() # Spectral gating NR
β βββ calculate_bpm() # Heart rate detection
β βββ score_quality() # Signal quality scoring
β βββ detect_murmur() # DSP murmur detection
β βββ predict_cnn() # CNN inference
β βββ calculate_heart_score() # Composite scoring
βββ models/
β βββ cnn_heart_classifier.pt # Trained CNN model
βββ webapp/
β βββ src/
β β βββ App.jsx # Main application
β β βββ App.css # Component styles
β β βββ index.css # Design system
β βββ package.json
βββ src/
β βββ train_cnn.py # CNN training script
β βββ find_threshold.py # Threshold optimization
βββ requirements.txt
βββ render.yaml # Deployment config
Features
- π€ Live Recording β Record directly from stethoscope microphone
- π File Upload β Support for WAV, MP3, and other audio formats
- βοΈ Audio Trimming β Trim recordings to isolate heart sounds
- π§ Dual Analysis β CNN + DSP independent classification
- π Heart Score β 1-10 composite score with clinical interpretation
- π‘οΈ Quality Scoring β SNR, regularity, clipping, duration assessment
- π PDF Reports β Professional clinical screening reports
- π Validation Page β Model performance metrics and confusion matrix
Disclaimer
This is an AI-assisted screening tool for preliminary cardiac assessment. Results are NOT diagnostic. All findings should be confirmed by a veterinary cardiologist via echocardiography.
License
This project was developed as part of a veterinary internal medicine thesis. For academic use.