Spaces:
Sleeping
Sleeping
File size: 6,619 Bytes
e47f979 3cf5a89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | ---
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
```bash
# 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
```bash
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.
|