CoolFace
Apppublic

kritikabme/ecg-arrhythmia-analysis

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

ECG Arrhythmia Analysis System

Kritika Patidar · SGSITS Indore · B.Tech Biomedical Engineering

Research-grade pipeline: Pan-Tompkins QRS detection → HRV analysis → 1D-CNN arrhythmia classification Dataset: MIT-BIH Arrhythmia Database (PhysioNet) | Classes: Normal · PVC · LBBB · RBBB

Project Structure

ecg-arrhythmia-system/
├── notebooks/
│   └── ECG_Arrhythmia_Analysis.ipynb    ← Full research notebook (run first)
├── app/
│   ├── app.py                            ← Gradio deployment
│   ├── model.py                          ← ECGResNet1D architecture
│   ├── preprocessing.py                  ← Pan-Tompkins + HRV + utilities
│   ├── requirements.txt                  ← Dependencies
│   ├── README.md                         ← HF Spaces card
│   └── ecg_model.pth                     ← Trained weights (generated by notebook)
└── README.md                             ← This file

Quickstart (Windows, Python 3.13)

1. Install dependencies

powershell
"C:\Program Files\Python313\python.exe" -m pip install -r app\requirements.txt

2. Run the research notebook

Open notebooks/ECG_Arrhythmia_Analysis.ipynb in Jupyter:

powershell
"C:\Program Files\Python313\python.exe" -m pip install jupyter
"C:\Program Files\Python313\python.exe" -m jupyter notebook notebooks\

The notebook will:

  • —Download MIT-BIH records from PhysioNet (first run only, ~300 MB cached)
  • —Run Pan-Tompkins QRS detection
  • —Compute HRV metrics
  • —Train ECGResNet1D (~50 epochs, ~20 min on CPU / ~3 min on GPU)
  • —Export app/ecg_model.pth

3. Run Gradio app locally

powershell
cd app
"C:\Program Files\Python313\python.exe" app.py

Open http://localhost:7860


Deploy to HuggingFace Spaces (Never sleeps)

Step 1 — Create a new Space

  1. 1.Go to https://huggingface.co/new-space
  2. 2.Space name: ecg-arrhythmia-analysis
  3. 3.SDK: Gradio
  4. 4.Hardware: CPU Basic (free tier, no sleeping on Spaces)
  5. 5.Visibility: Public

Step 2 — Upload files

bash
# Clone your new space locally
git clone https://huggingface.co/spaces/<YOUR_HF_USERNAME>/ecg-arrhythmia-analysis
cd ecg-arrhythmia-analysis

# Copy the app files
cp ../ecg-arrhythmia-system/app/* .

# If you have trained weights, add them:
# cp ../ecg-arrhythmia-system/app/ecg_model.pth .
# For large model files (>100 MB), use Git LFS:
# git lfs install
# git lfs track "*.pth"

git add .
git commit -m "Initial deployment: ECG arrhythmia analysis system"
git push

Step 3 — Verify

  • —Space URL: https://huggingface.co/spaces/<YOUR_HF_USERNAME>/ecg-arrhythmia-analysis
  • —HF Spaces never sleep (unlike Streamlit Community Cloud)
  • —Build logs: Space page → "App" tab → "Logs"

Security on HuggingFace Spaces

HF Spaces runs in an isolated container:

  • —No API keys needed (wfdb streams PhysioNet openly)
  • —Input validation is handled in app.py (file size, format, signal length)
  • —No user data is stored (all processing is in-memory per request)
  • —.gitignore the ecg_model.pth from public repos if it contains sensitive data

Notebook Outputs (Figures)

FileContents
preprocessing_comparison.pngRaw vs baseline-removed vs clean ECG
pan_tompkins_pipeline.png5-stage Pan-Tompkins visualisation
hrv_dashboard.pngTachogram + Poincaré + PSD
beat_morphology.pngMean morphology per class
training_history.pngLoss, accuracy, LR schedule
evaluation_results.pngConfusion matrix + ROC curves
gradcam_visualization.pngGrad-CAM saliency per class

Model Performance (typical MIT-BIH results)

MetricValue
Test Accuracy~98–99%
Normal AUC~0.999
PVC AUC~0.997
LBBB AUC~0.999
RBBB AUC~0.998
QRS Sensitivity~99.2%
QRS PPV~99.3%

Results vary with train/test split and random seed.


IEEE Paper Template

bibtex
@article{patidar2025ecg,
  title   = {ECG Arrhythmia Classification Using 1D Residual CNNs
             with Pan-Tompkins QRS Detection and HRV Analysis
             on the MIT-BIH Arrhythmia Database},
  author  = {Patidar, Kritika},
  journal = {IEEE Transactions on Biomedical Engineering},
  year    = {2025},
  note    = {Preprint — SGSITS Indore}
}

Target conferences / journals:

  • —IEEE EMBC (Engineering in Medicine and Biology Conference)
  • —IEEE Transactions on Biomedical Engineering
  • —Computers in Biology and Medicine (Elsevier)
  • —Biomedical Signal Processing and Control (Elsevier)

References

  1. 1.Pan J, Tompkins WJ. A Real-Time QRS Detection Algorithm. IEEE Trans Biomed Eng. 1985;32(3):230–236.
  2. 2.Task Force of ESC/NASPE. Heart Rate Variability: Standards of Measurement, Physiological Interpretation and Clinical Use. Circulation. 1996;93(5):1043–1065.
  3. 3.Moody GB, Mark RG. The Impact of the MIT-BIH Arrhythmia Database. IEEE Eng Med Biol. 2001;20(3):45–50.
  4. 4.He K, Zhang X, Ren S, Sun J. Deep Residual Learning for Image Recognition. CVPR. 2016.
  5. 5.Selvaraju RR et al. Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization. ICCV. 2017.
  6. 6.Loshchilov I, Hutter F. Decoupled Weight Decay Regularization. ICLR. 2019.

⚠️ Disclaimer: This system is for research purposes only and is not intended for clinical diagnosis or medical decision-making.