Spaces:
Runtime error
Runtime error
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,148 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
## Overview
|
| 10 |
-
|
| 11 |
-
This application bridges the gap between high-level cloud machine learning and low-level embedded hardware. It evaluates patient vitals using an ensemble of classifiers, provides strict clinical explainability, and compresses these Python-trained models into raw C-code ready to be flashed onto IoT devices.
|
| 12 |
-
|
| 13 |
-
### Key Engineering Features
|
| 14 |
-
|
| 15 |
-
- **Edge Computing & TinyML**: Transpiles complex Scikit-Learn models into highly optimized, dependency-free **C-code headers**. This allows predictive intelligence to be deployed directly to the edge, enabling offline, ultra-low latency, and privacy-preserving inference.
|
| 16 |
-
- **INT8 Quantization Engine**: Mathematically scales 64-bit floating-point weights down to 8-bit integers, effectively shrinking the flash memory payload by **~75%** for resource-constrained microcontrollers.
|
| 17 |
-
- **Dynamic Hardware Profiling**: The deployment suite actively simulates target hardware (e.g., *ESP32, Arduino Nano 33 BLE, Raspberry Pi Pico*) to calculate expected inference latency metrics (in µs) and final byte-size footprints prior to flashing.
|
| 18 |
-
- **Interpretable AI (SHAP)**: Solves the medical "black box" concern by generating real-time SHAP feature impact analyses. This visualization proves exactly *why* the AI assigned a specific risk score based on individual patient variables.
|
| 19 |
-
- **Soft-Voting Ensemble**: Rather than relying on a single algorithm, the backend aggregates outputs across five independent models (Random Forest, SVM, KNN, Logistic Regression, Neural Network) to output the highest-confidence predictions.
|
| 20 |
-
|
| 21 |
-
## Architecture
|
| 22 |
-
|
| 23 |
-
The project follows a decoupled, modular design pattern separating the client interface from the ML processing pipeline.
|
| 24 |
-
|
| 25 |
-
```mermaid
|
| 26 |
-
flowchart TD
|
| 27 |
-
%% Define styles
|
| 28 |
-
classDef frontend fill:#ff4b4b,stroke:#a30000,stroke-width:2px,color:#fff;
|
| 29 |
-
classDef backend fill:#009688,stroke:#004d40,stroke-width:2px,color:#fff;
|
| 30 |
-
classDef ml_node fill:#f2c94c,stroke:#b28900,stroke-width:2px,color:#333;
|
| 31 |
-
classDef edge_tech fill:#2d9cdb,stroke:#106093,stroke-width:2px,color:#fff;
|
| 32 |
-
classDef db fill:#9b59b6,stroke:#4a235a,stroke-width:2px,color:#fff;
|
| 33 |
-
|
| 34 |
-
%% Core Components
|
| 35 |
-
UI[🖥️ Streamlit Frontend<br/>Interactive Dashboard]:::frontend
|
| 36 |
-
API[⚙️ FastAPI Backend<br/>Routing & API Logic]:::backend
|
| 37 |
-
DB[(🗄️ SQLite DB<br/>Patient History)]:::db
|
| 38 |
-
|
| 39 |
-
UI <-->|REST API JSON| API
|
| 40 |
-
API <-->|Read / Write| DB
|
| 41 |
-
|
| 42 |
-
%% ML Subgraph
|
| 43 |
-
subgraph ML [🧠 Machine Learning & Inference Pipeline]
|
| 44 |
-
ENS{Ensemble Engine<br/>Soft-Voting}:::ml_node
|
| 45 |
-
Models[Classifiers:<br/>RF, SVM, LogReg, NN, KNN]:::ml_node
|
| 46 |
-
SHAP[🔍 SHAP Explainer]:::ml_node
|
| 47 |
-
end
|
| 48 |
-
|
| 49 |
-
%% Edge Quantization Subgraph
|
| 50 |
-
subgraph Quantization [⚡ Hardware Export]
|
| 51 |
-
TRANS[C-Code Transpiler<br/>INT8 Quantization]:::edge_tech
|
| 52 |
-
HEADER((tinyml_model.h)):::edge_tech
|
| 53 |
-
MCU>ESP32 / Cortex-M Node]:::edge_tech
|
| 54 |
-
end
|
| 55 |
-
|
| 56 |
-
API -->|Predict Request| ENS
|
| 57 |
-
ENS --> Models
|
| 58 |
-
API -->|Explain Request| SHAP
|
| 59 |
-
SHAP -.-> Models
|
| 60 |
-
API -->|Export Request| TRANS
|
| 61 |
-
TRANS --> HEADER
|
| 62 |
-
HEADER -->|Flash Firmware| MCU
|
| 63 |
-
```
|
| 64 |
-
|
| 65 |
-
### Modular Repository Structure
|
| 66 |
-
|
| 67 |
-
```text
|
| 68 |
-
TinyML-Dashboard/
|
| 69 |
-
├── backend/ # FastAPI server, ML pipelines, SQLite API, C-code logic
|
| 70 |
-
├── frontend/ # Streamlit UI mapping, Plotly charts, web routing
|
| 71 |
-
├── model/ # Local cache of serialized SciKit-Learn .pkl weights
|
| 72 |
-
├── data/ # Patient cohort CSVs for MLOps retraining pipelines
|
| 73 |
-
├── tests/ # Full PyTest suite for backend continuous integration
|
| 74 |
-
├── .github/workflows/ # CI/CD actions for auto-syncing to Hugging Face
|
| 75 |
-
└── docker-compose.yml # Orchestration spec for local containerized deployment
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
## Setup & Installation
|
| 79 |
-
|
| 80 |
-
### Requirements
|
| 81 |
-
- Python 3.9 or higher
|
| 82 |
-
- Git
|
| 83 |
-
|
| 84 |
-
### Installation Steps
|
| 85 |
-
|
| 86 |
-
1. **Clone the repository:**
|
| 87 |
-
```bash
|
| 88 |
-
git clone https://github.com/IDKHowToCodeFR/TinyML-Heart-Health-Monitoring-Dashboard.git
|
| 89 |
-
cd TinyML-Heart-Health-Monitoring-Dashboard
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
2. **Install global requirements:**
|
| 93 |
-
```bash
|
| 94 |
-
pip install -r requirements.txt
|
| 95 |
-
pip install -r backend/requirements.txt
|
| 96 |
-
pip install -r frontend/requirements.txt
|
| 97 |
-
```
|
| 98 |
-
|
| 99 |
-
3. **Train the baseline local `.pkl` models (Required on first run):**
|
| 100 |
-
```bash
|
| 101 |
-
cd backend
|
| 102 |
-
python models.py
|
| 103 |
-
cd ..
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
## Usage
|
| 107 |
-
|
| 108 |
-
### 🚀 Quick Start (Windows)
|
| 109 |
-
We've bundled an automated startup script that boots both environments natively:
|
| 110 |
-
```bash
|
| 111 |
-
run.bat
|
| 112 |
-
```
|
| 113 |
-
|
| 114 |
-
### ���� Docker Deployment
|
| 115 |
-
To avoid local python pathing issues, you can spin up the application via Docker Compose:
|
| 116 |
-
```bash
|
| 117 |
-
docker-compose up --build
|
| 118 |
-
```
|
| 119 |
-
*The Streamlit interface will bind automatically to `http://localhost:8501`, connecting directly to the internal API.*
|
| 120 |
-
|
| 121 |
-
### 🛠️ Manual Startup
|
| 122 |
-
If you prefer running the stack manually in separate terminal instances:
|
| 123 |
-
|
| 124 |
-
**Start the Backend:**
|
| 125 |
-
```bash
|
| 126 |
-
cd backend
|
| 127 |
-
uvicorn main:app --host 0.0.0.0 --port 8000
|
| 128 |
-
```
|
| 129 |
-
**Start the Frontend:**
|
| 130 |
-
```bash
|
| 131 |
-
cd frontend
|
| 132 |
-
streamlit run Home.py
|
| 133 |
-
```
|
| 134 |
-
|
| 135 |
-
## Development & Automation
|
| 136 |
-
|
| 137 |
-
### API Documentation
|
| 138 |
-
FastAPI serves auto-generated interactive documentation. While the backend is running, you can hit the endpoints directly at:
|
| 139 |
-
- **Swagger UI:** `http://localhost:8000/docs`
|
| 140 |
-
- **ReDoc:** `http://localhost:8000/redoc`
|
| 141 |
-
|
| 142 |
-
### CI/CD Pipelines
|
| 143 |
-
The project utilizes GitHub actions natively located in `.github/workflows/`:
|
| 144 |
-
1. **PyTest Validation**: Verifies endpoint data sanitization and schema parameters immediately on Push/Pull Requests.
|
| 145 |
-
2. **Hugging Face Sync**: Auto-deploys `main` branch updates precisely to the Hugging Face Space Docker container ensuring CI/CD alignment.
|
| 146 |
-
|
| 147 |
-
## Support & License
|
| 148 |
-
This project is licensed under the MIT License. Designed as a scalable, educational, and fully interpretable Edge-based Machine Learning architecture.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Tinyml Backend
|
| 3 |
+
emoji: 🫀
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|