How nandhu-10/brain-tumour-detection-system works
What this project is (type + purpose)
This is a single-service Flask web application that serves an AI inference workflow for brain tumor segmentation on MRI images. Users upload an image via a browser UI; the backend runs a PyTorch/MONAI UNet segmentation model (monai/model.pt), generates an overlay visualization, and returns a results page.
So the “system” is basically:
• A web UI (Jinja2 templates)
• A Flask backend (request handling + orchestration)
• An inference pipeline (MONAI/PyTorch model + preprocessing/postprocessing)
• A file-based persistence layer (uploads/results under static/)
Read the file tree as architecture hints
From the tree:
• app.py
Likely the entire Flask server: routes, file upload handling, model loading, inference call, saving images, returning templates.
• monai/model.pt
• templates/index.html, templates/result.html
Server-rendered pages. Suggests SSR via Flask/Jinja rather than a SPA.
• static/uploads, static/results
Persistent storage directories (local filesystem). These are important “components” because the app writes and reads from them.
• requirements.txt
What
For maximum accuracy/detail, split into “logical components” even if they run in one process:
Web Application (Flask)
• Flask App (app.py)
• Route: / (renders index.html)
• Route: /predict or /upload (name unknown; show “Upload/Infer endpoint”)
• Route: /result (renders result.html)
• Request handling: multipart/form-data upload, validation, error paths
Inference / ML Pipeline (inside backend)
Model inference is a subsystem and should be broken down:
• Pre-processing
• Load image (Pillow)
• Convert to tensor/array (NumPy)
• Resize/normalize (often MONAI transforms)
• Model Runner
• Load UNet weights from monai/model.pt (PyTorch torch.load)
• Run forward pass (GPU/CPU)
• Post-processing
• Convert mask to image
• Thresholding / argmax
• Generate overlay visualization (Matplotlib / Pillow compositing)
• Output artifact generation
• Save result images to static/results
Storage (local filesystem)
• Uploads folder: static/uploads
• Results folder: static/results
These are effectively your “datastore” in this project (not a DB).
Browser → Flask: HTTP GET /
• Flask renders templates/index.html
Browser → Flask: HTTP POST (image upload)
• multipart/form-data containing MRI image
Flask → File Storage (uploads): save uploaded file
• static/uploads/<file>
Flask → Inference Pipeline: run preprocessing + model inference + postprocessing
• Inference pipeline reads:
• uploaded image
• model weights (monai/model.pt)
Inference Pipeline → File Storage (results): save mask/overlay
• static/results/<overlay>.png etc.
Flask → Browser: HTTP response rendering templates/result.html
• HTML includes <img src="/static/results/..."> and maybe the original upload image.
Browser → Flask static: GET /static/... for images
• Browser fetches the original and overlay images from static endpoints.
• invalid file type/size → render error message on index
• model load failure → 500 error
Architectural patterns to highlight (specific to this repo)
• Monolith: one Python process (Flask + inference) rather than separate services.
• Server-side rendering: Jinja2 templates.
• File-based persistence: results stored on disk under static/.
• Offline-trained model artifact: model.pt is packaged with the app (no training pipeline in the repo tree).
• Synchronous inference (likely): request blocks until prediction is done; call this out (latency, scale implications).