How wills17/brain-cancer-prediction works
Project Type and Purpose
• This is a full-stack ML web application:
• Front-end: HTML/CSS/JS (templates + static assets)
• Back-end: Flask server (app.py / app_r.py)
• ML inference: Keras & TFLite models under Models/
• Optional training pipeline scripts (brain_cancer_code.py)
• Cloud deployment on Render (render.yaml)
File Structure
• Top-level files:
• app.py → main Flask routes using .h5 model
• app_r.py → Flask routes using .tflite
• brain_cancer_predict.py → standalone inference test
• brain_cancer_code.py → training script
• render.yaml → Render.com deployment config
• requirements.txt
• Directories:
• Models/ → stored ML artifacts (H5, TFLite)
• templates/ → Jinja2 HTML views (home, about, predict, results)
• static/ → JS, CSS, preview images
• Config & Dependencies:
• render.yaml (deployment)
• requirements.txt (Flask, tflite-runtime, numpy, pillow, OpenCV-headless)
Main Components
a. Client (Browser)
• UI pages (templates/*.html)
• Static assets (styles.css, scripts.js)
• Drag & drop upload widget
b. Web Server (Flask)
• Entrypoints: app.py / app_r.py
• Route handlers:
• GET / → home.html
• GET /about → about.html
• GET /predict → predict.html
• POST /predict → process upload, call inference
• GET /results → results.html
• File upload handling, temporary storage
• Report generation (downloadable diagnosis)
c. ML Inference Layer
• Keras model loader (.h5) or TFLite runtime (.tflite)
• Prediction function (preprocess image → model.predict → JSON result)
d. Optional Training Pipeline
• Script brain_cancer_code.py (EfficientNetB0 base, training on Dataset.zip)
• Outputs new .h5 to Models/
e. Deployment Environment
• Render.com (render.yaml)
• Python environment (requirements.txt)
Relationships & Data Flow
1. User opens browser → requests home page
2. Browser downloads HTML/CSS/JS from Flask static/templates
3. User selects/uploads MRI image → JS sends POST to /predict
4. Flask route receives image → saves to server → calls inference function
5. Inference function loads model (H5 or TFLite) → returns class label + confidence
6. Flask returns results page + optional downloadable report
7. Browser displays prediction
Architectural Patterns & Principles
• MVC-like separation:
• Model → ML artifacts under Models/
• View → Jinja2 templates + static
• Controller → Flask route handlers
• Single monolith service with clearly delineated layers
• Separation of inference (app_r.py for TFLite) vs training script
• Front-end: browser & static/templates
• Back-end: Flask
• ML: Models + inference code
• Deployment: Render