File size: 7,236 Bytes
5d14125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# πŸ—οΈ Medical AI System - Project Structure

## πŸ“ Complete Directory Structure

```
hackathon15092025/
β”œβ”€β”€ πŸ“‹ Documentation
β”‚   β”œβ”€β”€ README.md                    # Main project overview
β”‚   β”œβ”€β”€ README_FETAL.md             # Fetal plane classification guide
β”‚   β”œβ”€β”€ DOCUMENTATION.md            # Comprehensive system documentation
β”‚   └── PROJECT_STRUCTURE.md        # This file - project organization
β”‚
β”œβ”€β”€ 🌐 Web Interface
β”‚   β”œβ”€β”€ index.html                  # Main dashboard with navbar and iframes
β”‚   └── static/
β”‚       └── css/
β”‚           └── style.css           # Satoshi font styling for Streamlit
β”‚
β”œβ”€β”€ 🀱 Pregnancy Risk Prediction System
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app.py                  # Streamlit web app (Port 8501)
β”‚   β”‚   └── pregnancy_risk_prediction.py  # Model training script
β”‚   └── models/
β”‚       β”œβ”€β”€ pregnancy_risk_model.pkl     # Trained Random Forest model
β”‚       β”œβ”€β”€ label_encoder.pkl            # Label encoder
β”‚       └── feature_columns.pkl          # Feature column names
β”‚
β”œβ”€β”€ πŸ”¬ Fetal Ultrasound Classification System
β”‚   β”œβ”€β”€ fetal_plane_app.py          # Streamlit web app (Port 8502)
β”‚   β”œβ”€β”€ fetal_plane_classifier.py   # ViT model training script
β”‚   β”œβ”€β”€ train_fetal_model.py        # Standard training script
β”‚   β”œβ”€β”€ train_fetal_model_thermal.py # Thermal-safe training for M4
β”‚   └── models/
β”‚       └── fetal_plane_model/       # Trained Vision Transformer model
β”‚           β”œβ”€β”€ config.json
β”‚           β”œβ”€β”€ model.safetensors
β”‚           β”œβ”€β”€ preprocessor_config.json
β”‚           β”œβ”€β”€ label_encoder.pkl
β”‚           └── checkpoint-*/        # Training checkpoints
β”‚
β”œβ”€β”€ πŸ“Š Datasets
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ Dataset - Updated.csv   # Pregnancy risk dataset (1,187 records)
β”‚   β”‚   └── Dataset/                # Additional audio data
β”‚   └── FETAL_PLANES_ZENODO/        # Fetal ultrasound dataset
β”‚       β”œβ”€β”€ FETAL_PLANES_DB_data.csv     # Labels (12,400 images)
β”‚       β”œβ”€β”€ FETAL_PLANES_DB_data.xlsx    # Excel version
β”‚       β”œβ”€β”€ Images/                       # Ultrasound images (PNG format)
β”‚       └── README.md                     # Dataset documentation
β”‚
└── βš™οΈ Configuration & Dependencies
    β”œβ”€β”€ requirements.txt             # Pregnancy risk dependencies
    └── requirements_fetal.txt      # Fetal plane dependencies (Apple Silicon)
```

## πŸš€ Application Ports & URLs

| Application | Port | URL | Description |
|-------------|------|-----|-------------|
| **Main Dashboard** | - | `file://index.html` | HTML dashboard with navigation |
| **Pregnancy Risk** | 8501 | `http://localhost:8501` | Risk prediction interface |
| **Fetal Planes** | 8502 | `http://localhost:8502` | Ultrasound classification |

## πŸ“± Navigation Structure

### Main Dashboard (index.html)
```
🏠 Home
β”œβ”€β”€ Welcome section
β”œβ”€β”€ Feature overview
└── System introduction

🀱 Pregnancy Risk (iframe: localhost:8501)
β”œβ”€β”€ Patient information form
β”œβ”€β”€ Risk prediction results
β”œβ”€β”€ Feature importance analysis
└── Medical recommendations

πŸ”¬ Fetal Planes (iframe: localhost:8502)
β”œβ”€β”€ Image upload interface
β”œβ”€β”€ Ultrasound classification
β”œβ”€β”€ Confidence scores
└── Anatomical plane identification

πŸ“‹ Documentation
β”œβ”€β”€ Performance metrics
β”œβ”€β”€ Model specifications
β”œβ”€β”€ Training results
└── Technical details

ℹ️ About
β”œβ”€β”€ System overview
β”œβ”€β”€ Technology stack
β”œβ”€β”€ Performance metrics
└── Privacy & security
```

## πŸ”§ Technical Architecture

### Frontend Layer
- **HTML5 Dashboard**: Responsive design with Satoshi font
- **CSS3 Styling**: Modern UI with gradients and animations
- **JavaScript Navigation**: Seamless page transitions
- **Iframe Integration**: Borderless embedding of Streamlit apps

### Backend Layer
- **Streamlit Apps**: Interactive web interfaces
- **Python ML Models**: scikit-learn and PyTorch
- **Apple Silicon Optimization**: MPS acceleration
- **Local Processing**: No external API dependencies

### Data Layer
- **CSV Datasets**: Structured medical data
- **PNG Images**: Ultrasound imaging data
- **Pickle Models**: Serialized trained models
- **JSON Configs**: Model configurations

## 🎯 Model Specifications

### Pregnancy Risk Model
```yaml
Algorithm: Random Forest Classifier
Accuracy: 100%
Features: 11 clinical parameters
Dataset: 1,187 patient records
Inference: <1ms
Model Size: 2.3MB
Framework: scikit-learn
```

### Fetal Plane Model
```yaml
Algorithm: Vision Transformer (ViT-Base-Patch16-224)
Validation Accuracy: 91.69%
Classes: 9 anatomical planes
Dataset: 12,400 ultrasound images
Inference: <100ms
Model Size: 346MB
Framework: PyTorch + Transformers
Optimization: Apple Silicon MPS
```

## πŸ”„ Deployment Workflow

### 1. Environment Setup
```bash
# Activate global environment
globalvenv

# Install dependencies
pip install -r requirements.txt
pip install -r requirements_fetal.txt
```

### 2. Model Training (Optional)
```bash
# Train pregnancy risk model
python src/pregnancy_risk_prediction.py

# Train fetal plane model (thermal-safe)
python train_fetal_model_thermal.py
```

### 3. Application Startup
```bash
# Terminal 1: Pregnancy Risk App
python -m streamlit run src/app.py --server.port 8501 --server.headless true

# Terminal 2: Fetal Plane App
python -m streamlit run fetal_plane_app.py --server.port 8502 --server.headless true

# Terminal 3: Main Dashboard
open index.html
```

## πŸ“Š Performance Monitoring

### System Resources (Apple Silicon M4)
- **CPU Usage**: 5.4% (idle)
- **Memory Usage**: 65.3%
- **GPU (MPS)**: Active acceleration
- **Temperature**: Stable (thermal management)

### Application Performance
- **Dashboard Load**: <1s
- **Streamlit Apps**: <3s startup
- **Model Inference**: Real-time
- **Navigation**: Instant transitions

## πŸ”’ Security & Privacy

### Data Protection
- βœ… **Local Processing**: No external data transmission
- βœ… **No Persistent Storage**: Patient data not saved
- βœ… **HIPAA Compliance**: Privacy-by-design architecture
- βœ… **Secure Models**: No data leakage in weights

### Access Control
- πŸ” **Local Access Only**: localhost binding
- πŸ” **No Authentication**: Suitable for controlled environments
- πŸ” **Audit Logging**: Terminal output for monitoring
- πŸ” **Error Handling**: Graceful failure modes

## πŸš€ Future Enhancements

### Planned Features
- [ ] **Multi-language Support**: International deployment
- [ ] **Real-time Monitoring**: System health dashboard
- [ ] **API Integration**: RESTful endpoints
- [ ] **Mobile Optimization**: Responsive design improvements

### Technical Improvements
- [ ] **Model Versioning**: MLOps pipeline
- [ ] **A/B Testing**: Model comparison framework
- [ ] **Performance Metrics**: Real-time monitoring
- [ ] **Auto-scaling**: Dynamic resource allocation

---

*Last Updated: January 2025*
*Version: 1.0*
*Platform: Apple Silicon Optimized*
*Status: Production Ready*