⸻
A local-first EKG analysis system combining:
- Machine learning (signal-based rhythm classification)
- On-demand screen capture
- AI-assisted clinical interpretation
- Clear confidence gating and safety constraints
This project is designed for edge / local execution, minimizing cloud dependency for core analysis and supporting real-world clinical workflows.
⚠️ This is a research / educational prototype.
It is not a medical device and must not be used for clinical decision-making without proper validation and regulatory approval.
EKG_AISystem/ │ ├── ekg_analyzer.py # Screen capture + AI chat interface ├── logs/ # Captured frames + AI responses ├── .venv/ # Analyzer virtual environment │ ├── ekg_ml/ │ ├── train_baseline.py │ ├── predict_from_signal.py │ ├── predict_from_image.py │ ├── preview_beats.py │ ├── extract_beats.py │ ├── models/ │ ├── data/ │ ├── .venv/ # ML virtual environment │ └── README.md
Important:
This project intentionally uses two virtual environments:
- One for the Analyzer UI + screen capture
- One for the ML pipeline
This avoids dependency conflicts (NumPy, pandas, wfdb, OpenCV).
- Windows 10/11
- Python 3.11 (recommended)
- PowerShell
- Git
- Internet access for OpenAI API (Analyzer only)
git clone https://github.com/YOUR_USERNAME/EKG_AI_System.git
cd EKG_AI_System
⸻
Analyzer Environment (Screen Capture + AI)
2️⃣ Create and Activate Analyzer venv
py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1
3️⃣ Install Analyzer Dependencies
python -m pip install --upgrade pip
python -m pip install numpy==1.26.4 scipy matplotlib scikit-learn joblib
python -m pip install pandas==2.2.3 wfdb==4.2.0
python -m pip install opencv-python==4.10.0.84 pillow mss openai
4️⃣ Verify Analyzer Environment
python -c "import cv2, wfdb, pandas, sklearn; print('OK')"
⸻
ML Environment (Training + Inference)
5️⃣ Create and Activate ML venv
cd ekg_ml
py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1
6️⃣ Install ML Dependencies
python -m pip install --upgrade pip
python -m pip install numpy==1.26.4 scipy matplotlib scikit-learn joblib
python -m pip install pandas==2.2.3 wfdb==4.2.0
python -m pip install opencv-python==4.10.0.84 pillow
7️⃣ Verify ML Environment
python -c "import numpy, pandas, wfdb, cv2, sklearn; print('OK')"
⸻
Using Two PowerShell Terminals (Recommended)
Open two PowerShell terminals in VS Code:
Terminal A — Analyzer
cd EKG_AISystem
.\.venv\Scripts\Activate.ps1
python ekg_analyzer.py
This launches:
• The capture control window
• The chat UI
• Snapshot logging to logs/
⸻
Terminal B — ML Inference
cd EKG_AISystem\ekg_ml
.\.venv\Scripts\Activate.ps1
This terminal is used to:
• Train models
• Run predictions on saved images or signals
⸻
Training the Baseline Model
python train_baseline.py
Expected output:
• Class distribution warning (normal — dataset imbalance)
• Classification report
• Model saved to:
ekg_ml/models/baseline_rf.joblib
⸻
Predicting From a Signal (NPZ)
python predict_from_signal.py
Outputs:
• Top rhythm predictions with confidence
⸻
Predicting From a Screenshot Image
From the repo root (Analyzer env):
python .\ekg_ml\predict_from_image.py --image .\logs\frame_YYYYMMDD_HHMMSS.png
Important notes:
• The image must exist
• The model expects 252 features, not raw pixels
• The script internally converts image → signal proxy
⸻
Common Errors & Fixes
❌ ModuleNotFoundError: No module named 'cv2'
Cause: Wrong virtual environment active
Fix: Activate the correct .venv before running
⸻
❌ ValueError: X has 65536 features, expected 252
Cause: Raw image passed directly into ML model
Fix: Use predict_from_image.py, not the RF model directly
⸻
❌ wfdb / pandas StringArray TypeError
Cause: pandas version mismatch
Fix: Ensure:
numpy==1.26.4
pandas==2.2.3
wfdb==4.2.0
⸻
❌ Python was not found (Microsoft Store)
Cause: Windows App Execution Alias
Fix:
• Settings → Apps → Advanced App Settings
• Disable Python aliases
⸻
❌ KeyboardInterrupt when viewing plots
Cause: Matplotlib window closed manually
Fix: This is safe — no action needed
⸻
Design Philosophy
• Local ML first
• AI as decision-support, not authority
• Confidence-aware outputs
• Clinician-in-the-loop by default
• Clear separation of UI and ML concerns
⸻
Disclaimer
This project is intended for:
• Research
• Education
• Prototyping
• Workflow exploration
It is not FDA-approved and must not be used for patient care.
⸻
Future Directions
• Beat-level waveform reconstruction from images
• Multimodal fusion (EKG + vitals + context)
• Hardware-integrated assistants
• Robotics and bedside device workflows
• Wearable AI interfaces
⸻
## License
This project is **closed-source proprietary software**.
No use, redistribution, modification, or commercial deployment is permitted
without explicit written authorization from the author.
See the `LICENSE` file for full terms.
---