NeuroAssist is a Flask-based clinical decision support prototype for brain tumor workflows. It combines MRI ingestion, 3D Attention U-Net segmentation, derived imaging metrics, structured neuro-oncology intake, lightweight RAG retrieval, and Groq-backed report generation into a single local project.
neuroassist/: the main web application, routes, templates, config, database helpers, RAG utilities, and testsdata_pipeline.py: MRI preprocessing, inference orchestration, tumor volume metrics, and lobe involvement logicLoad_model.py: cached model loader for the trained segmentation checkpointget_labels.py: exports annotated PNG slices and a summary montage from predicted masksInput_preprocessing/: standalone NIfTI<->DICOM conversion utilitiesTumor Model/: trained model weights used by the segmentation pipelineData/: local data workspace for imaging assets and experimentsutils/andgioblastoma.ipynb: notebook-era experimentation helpers and research code
- A clinician creates a session from the landing page.
- The app accepts either NIfTI uploads or DICOM folder uploads.
- DICOM uploads are converted to NIfTI when needed.
- The segmentation model runs inference and computes: whole tumor, NCR, ED, ET volumes, diameter, centroid, and lobe involvement.
- Annotated tumor slice PNGs are written under
neuroassist/static/annotated/. - Imaging results are stored in PostgreSQL.
- The clinician completes the structured intake form in the session view.
- Completeness scoring, RAG lookup, and LLM report generation produce a structured final report.
- The report view renders the persisted diagnostic summary plus annotated slices.
neuroassist/app.py: Flask app factory, runtime folder creation, DB bootstrap, blueprint registrationneuroassist/routes/session.py: session creation, record directory, live session state for the UIneuroassist/routes/upload.py: MRI upload handling, DICOM conversion, inference, ingest into DBneuroassist/routes/chat.py: intake validation, completeness updates, RAG lookup, final report generationneuroassist/routes/report.py: report page, print view, annotated-slice gallery
neuroassist/services/llm.py: Groq chat client, retry handling, JSON extraction, response normalizationneuroassist/services/context_builder.py: combines patient profile, imaging metrics, context fields, and RAG chunks into prompt contextneuroassist/services/completeness.py: weighted field coverage scoring for the intake formneuroassist/services/rag.py: embeddings + vector or lexical retrieval fromknowledge_chunksneuroassist/services/embeddings.py: sentence-transformers embeddings with deterministic hashed fallbackneuroassist/services/unet_ingest.py: derived imaging heuristics and persistence intoimaging_reports
neuroassist/db/schema.sql creates:
patientssessionspatient_contextmessagesquestions_askedimaging_reportsdiagnostic_reportsknowledge_chunks
The knowledge base supports pgvector when available and falls back to a DOUBLE PRECISION[] embedding column if the extension is missing.
- Python 3.10+ recommended
- PostgreSQL running locally
- A trained segmentation model at
Tumor Model/best_attention_unet_v2.keras - Enough RAM/VRAM for TensorFlow inference
From the repo root:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtThis repo now uses a single shared env file:
- root
.env
There is no longer a separate neuroassist/.env.
Important variables in the root .env:
DATABASE_URLPOSTGRES_ADMIN_DBAUTO_BOOTSTRAP_DBLLM_PROVIDERGROQ_API_KEYGROQ_MODELGROQ_BASE_URLMODEL_PATHEMBED_MODELPORT
The app expects PostgreSQL and reads its connection string from the root .env.
Current default value:
DATABASE_URL=postgresql://postgres:Admin%40123@localhost:5433/neuroassistImportant notes:
Admin%40123is the URL-encoded form of the passwordAdmin@123- the README example assumes PostgreSQL is listening on port
5433 - if your local PostgreSQL uses the default port
5432, updateDATABASE_URLin.env - the app can work with plain PostgreSQL even if
pgvectoris not installed
Verify that your server is up and reachable with psql:
psql -h localhost -p 5433 -U postgres -d postgresIf your server is on a different port, use that port instead and update .env.
The repo currently expects:
- username:
postgres - password:
Admin@123 - database name:
neuroassist
If your local PostgreSQL credentials are different, change the root .env instead of changing code.
This is optional because the bootstrap script can create it for you, but if you want to do it yourself:
CREATE DATABASE neuroassist;You can run that inside psql after connecting to the postgres database.
From inside neuroassist/ run:
cd neuroassist
python -m db.init_dbThis will:
- create the target database if it does not already exist
- initialize the connection pool
- apply
schema.sql - run lightweight compatibility updates for older local databases
Still from inside neuroassist/:
python -m scripts.seed_knowledge_baseThis inserts the curated WHO 2021, VASARI, and RANO chunks into knowledge_chunks.
pgvector is supported but not required.
- if
pgvectoris available,knowledge_chunks.embeddingis created asvector(384) - if it is not available, the schema falls back to
DOUBLE PRECISION[]
So the project still runs without pgvector; vector search simply becomes less optimized.
After setup, these tables should exist:
patientssessionspatient_contextmessagesquestions_askedimaging_reportsdiagnostic_reportsknowledge_chunks
Run these from inside neuroassist/:
cd neuroassist
python -m db.init_db
python -m scripts.seed_knowledge_baseseed_knowledge_base inserts a small curated WHO 2021 / VASARI / RANO reference set used by the RAG layer.
Run the Flask app from inside neuroassist/:
cd neuroassist
python app.pyOpen http://localhost:5000.
- Preferred: a folder containing the four BraTS-style modalities
- Supported modality names:
t1/t1w,t1ce/t1wce,t2/t2w,flair - The upload route can also assemble modality sets from zipped NIfTI folders
- A single 4D NIfTI volume is still accepted as a fallback
- Preferred: a folder with modality subfolders such as
t1,t1w,t1ce,t1wce,t2,t2w, andflair - Zipped DICOM folders are also supported
- Conversion is handled through
Input_preprocessing/dicom_to_nii_pipeline.py
Run tests from inside neuroassist/:
cd neuroassist
python -m unittest tests.test_llm tests.test_upload_modalities -vCurrent tests cover:
- LLM JSON parsing and retry behavior
- final report context composition
- modality alias detection and canonical NIfTI case assembly
- The report generator is wired to Groq in the current code path.
- Large data folders, model weights, uploads, and generated static assets are intentionally ignored by git.
- The preprocessing scripts in
Input_preprocessing/are utility scripts and are not part of the Flask request path except for DICOM-to-NIfTI conversion.
Raj Patel Linkedin: https://www.linkedin.com/in/raj-patel5/