Flask-based REST API for ML-powered stress detection from eye images.
pip install -r requirements.txtpython app.pyServer will start on http://localhost:5000
GET /
GET /health
POST /predict
Body (multipart/form-data):
- image: File (required) - Eye image (JPG/PNG)
- age: Integer (optional) - User age (default: 30)
Response:
{
"success": true,
"prediction": {
"stress_level": "Normal" | "Stress",
"stress_probability": 0.76,
"stress_percentage": 76.0,
"confidence": "High" | "Medium" | "Low"
},
"pupil_detection": {...},
"iris_detection": {...},
"measurements": {...}
}
Frontend (React)
↓
Flask API (Port 5000)
↓
├── Detection Pipeline
├── Measurement Pipeline
└── ML Model (TensorFlow)
Python_Backend/
├── app.py # Flask application
├── config.py # Configuration
├── requirements.txt # Dependencies
├── detection/ # Eye detection modules
├── measurement/ # Pupil & iris measurements
├── pipeline/ # ML inference pipeline
├── layers/ # Custom TensorFlow layers
├── utils/ # Preprocessing utilities
└── Model/ # Trained model files
Edit config.py to customize:
- Model path
- Detection thresholds
- Stress classification threshold
- Image preprocessing parameters
- Check
Model/best_dual_stream_age_aware_model.kerasexists - Verify TensorFlow installation:
python -c "import tensorflow; print(tensorflow.__version__)"
- Ensure image clearly shows pupil and iris
- Try different lighting conditions
- Image should be at least 200x200 pixels
- Check Flask CORS configuration in
app.py - Frontend must run on port 5173 or 5174
- Type: Dual-stream CNN (Pupil + Iris)
- Architecture: EfficientNetB0 + Weighted Feature Fusion
- Training Accuracy: 99.91% AUC-PR
- Input: Eye images (224x224x5 channels)
- Output: Stress probability (0-1)
- Average inference time: ~2-3 seconds
- Supports concurrent requests (Flask threaded mode)
- Model loaded once at startup
- File validation (image types only)
- Size limits enforced
- Temporary files auto-deleted
- No sensitive data stored
- This backend is independent from the Node.js server
- Both servers run simultaneously
- Node.js handles: Auth, MongoDB, file storage
- Flask handles: ML predictions only