How yaswinkumar02/neuroscan-ai works
Purpose and Runtime Entry Point
NeuroScan AI is a local Streamlit clinical workstation for brain-MRI intake, tumor classification/segmentation, volumetric analysis, report-oriented clinical workflows, and role-specific access. Launch via python -m streamlit run app.py; the application entry point is app.py. Python/PyTorch provide model execution, with optional CUDA acceleration.
UI Orchestration and Role Boundaries
app.py is the primary controller for authentication, clinician diagnostic workflows, patient read-only history, and administrator management views. It coordinates inference, persistence, RAG, object storage, and visualization rather than exposing a separate web/API service. Streamlit presentation configuration resides in .streamlit/config.toml.
Authentication, RBAC, and Audit Persistence
database.py owns the relational persistence boundary: user credentials, roles, patient/scan records, and audit-oriented operations. The deployed local artifact is neuroscan.db; the README indicates SQLite and MySQL support. Password handling uses bcrypt with legacy-verification/migration behavior, while role isolation separates clinician, patient, and administrator actions.
MRI Intake Guardrail and Classification
Uploaded images first pass a medical-image validity gate implemented/trained through guardrail_train.py, with inference weights in models/best_guardrail.pth. Accepted scans proceed to the EfficientNet-B0 classifier checkpoint at models/best_efficientnet_b0.pth, producing one of Glioma, Meningioma, Pituitary, or No Tumor. convert_to_grayscale.py supports image normalization/preparation consistent with MRI-oriented processing.
Lesion Segmentation and Explainability
The segmentation stage produces pixel-level tumor masks after classification-oriented intake. Its U-Net/EfficientNet-B0 model artifact is present both at models/best_unet_effb0.pth and seg_models/best_unet_effb0.pth; seg_train.py is the training pipeline. The UI is expected to consume mask outputs for lesion area, overlays, and downstream volumetry; classifier training is defined in train.py.
Volumetric Reconstruction
volume_engine.py is the 2D-mask-to-3D analysis boundary. It applies Marching Cubes to multi-slice MRI/mask data to create brain/tumor surface meshes, compute tumor volume, and derive penetration/depth-style metrics for interactive visualization. This stage depends on ordered/co-registered scan slices and should distinguish inference masks from final clinical claims.
Clinical Knowledge and External AI
rag_engine.py provides local retrieval over markdown clinical material in knowledge_base/, including knowledge_base/glioma.md, knowledge_base/meningioma.md, and knowledge_base/general_patient_faq.md. Retrieved context grounds assistant responses; the README identifies Google Gemini as the multimodal generation provider, creating an external-service/privacy boundary for scan or question content.
Storage, Model Assets, and Operations
s3_storage.py encapsulates optional S3-backed object storage for scan-related artifacts, separating binary uploads/exports from relational metadata in database.py. Versioned model checkpoints and metrics live under models/ and seg_models/. verify.py validates runtime environment/CUDA readiness before operating or training the workstation.
Main entry points: app.py Streamlit controller · guardrail_train.py MRI validity gate · best_efficientnet_b0.pth Tumor classifier · best_unet_effb0.pth Lesion segmentation
Components 17
Clinical Workstation
- Streamlit controller · Coordinates role-specific clinical workflows.
app.py - Streamlit configuration
.streamlit/config.toml
MRI Analysis
- MRI validity gate · Rejects invalid intake images before diagnostic analysis.
guardrail_train.py - Guardrail weights
models/best_guardrail.pth - Tumor classifier · Classifies Glioma, Meningioma, Pituitary, or No Tumor.
models/best_efficientnet_b0.pth - Classifier training
train.py - MRI normalization
convert_to_grayscale.py - Lesion segmentation · Produces pixel-level tumor masks and overlays.
models/best_unet_effb0.pth - Segmentation training
seg_train.py - Volumetric reconstruction · Builds meshes and calculates tumor volume from ordered masks.
volume_engine.py - Runtime verification · Checks runtime and CUDA readiness.
verify.py
Data & Knowledge
- Clinical persistence · Manages credentials, roles, scan records, and audit operations.
database.py - Local clinical database
neuroscan.db - Clinical retrieval · Retrieves grounded clinical context for assistant responses.
rag_engine.py - Clinical knowledge base
Optional External Services
- Artifact storage adapter · Separates scan binaries and exports from relational metadata.
s3_storage.py - Google Gemini · External privacy boundary for scan or question content.
Connections 17
- Streamlit configuration → Streamlit controller: configures
- Streamlit controller → Clinical persistence: auth, RBAC, records
- Clinical persistence → Local clinical database: persists to
- Streamlit controller → MRI normalization: prepares uploads
- MRI normalization → MRI validity gate: normalized image
- Guardrail weights → MRI validity gate: loads
- MRI validity gate → Tumor classifier: accepted scan
- Classifier training → Tumor classifier: produces checkpoint
- Tumor classifier → Lesion segmentation: diagnostic intake
- Segmentation training → Lesion segmentation: produces checkpoint
- Lesion segmentation → Volumetric reconstruction: ordered masks
- Volumetric reconstruction → Streamlit controller: meshes and metrics
- Streamlit controller → Clinical retrieval: clinical question
- Clinical knowledge base → Clinical retrieval: retrieval corpus
- Clinical retrieval → Google Gemini: grounded context
- Streamlit controller → Artifact storage adapter: scan artifacts and exports
- Runtime verification → Streamlit controller: validates runtime