How wakassodev/brain_tumor_classification works
Step 1: Identify the project type and purpose
• This is a monolithic, full-stack Python web application built with Streamlit that serves a deep-learning pipeline for classifying brain MRI scans.
• Purpose: Allow users (clinicians, researchers) to upload MRI images, select a model (Xception or custom CNN), receive a tumor classification with confidence scores, view saliency maps, and get an AI-powered explanation of the prediction.
Step 2: Analyze the file structure
• Top-level files only, no subdirectories:
• app.py (or myApp.py in README) – entry point, handles UI and service logic
• cnn_model.h5 – custom CNN weights
• xception_model.weights.h5 – transfer-learning weights
• requirements.txt – Python dependencies (Streamlit, TensorFlow/Keras, OpenCV, Plotly, Google AI SDK)
• .env (not in repo but implied) – holds GOOGLE_API_KEY
• No database or message queue; all inference is in-process.
• Monolith pattern: UI, business logic, and model inference reside in one service.
Step 3: Extract additional insights from README
• Streams:
• Streamlit UI for image upload, model selection, and results display
• OpenCV for preprocessing (resizing, normalization)
• TensorFlow/Keras for loading and running models
• Saliency map generation module
• Plotly for bar-chart visualization
• Google Generative AI API for textual explanation via env var GOOGLE_API_KEY
1. User Browser (Client)
2. Streamlit Server (app.py)
– UI Layer
– Controller Layer
3. Preprocessing Module (OpenCV)
4. Model Inference Module
• Custom CNN (.h5)
• Xception Transfer-Learning (.weights.h5)
5. Saliency Map Generator
6. Explanation Service (Google Gen AI API)
7. Visualization Module (Plotly)
8. Environment & Config (env vars, .env file)
1. Client → Streamlit UI: upload image + select model
2. Streamlit UI → Preprocessing: raw image → processed tensor
3. Preprocessing → Model Inference: tensor → chosen model → class probabilities
4. Model Inference → Saliency Generator: tensor + model → saliency map
5. Model Inference & Saliency → Explanation Service: send data + GOOGLE_API_KEY → receive text explanation
6. Streamlit UI ← Visualization:
• Bar chart (Plotly) ← probabilities
• Saliency map overlay
• Text explanation
7. Streamlit UI → Client: rendered UI with results
c. Architectural patterns & principles:
• Layered architecture: Presentation (Streamlit UI), Application Logic (preprocessing & orchestration), ML (model inference), Integration (external API).
• Configuration externalized via env vars (.env).
• Monolith deploys as one container/process.
d. Key technologies/frameworks:
• Python 3.x, Streamlit
• TensorFlow & Keras
• OpenCV (cv2)
• Plotly
• Google Generative AI SDK
• Virtual environment (venv)
Step 5: Tailoring guidelines for a full-stack ML web app
• Split between Client (web browser) and Server (Streamlit)
• Model selection as a decision branch in the inference pipeline
• Flow from raw input → preprocessing → inference → postprocessing → UI
• External dependency (Google Gen AI) as an integration point
• Client: light blue rectangle
Step 7: Capture essential architectural elements
• Do not over-fragment: keep roughly 6–8 components