CoolFace
Apppublic

uten4211/T1_T2_FLAIR_MRI

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

๐Ÿง  MRI Simulator: T1-Weighted, T2-Weighted & FLAIR

A simple interactive MRI simulation app built with Streamlit. It loads a high-resolution brain phantom (.mat file) from Google Drive and lets you explore how MRI parameters affect image contrast for three common sequences: T1w, T2w, and FLAIR.


๐Ÿ“‹ Requirements

  • โ€”Python 3.10 or higher
  • โ€”Internet connection (to auto-download the brain phantom on first run)

๐Ÿš€ Getting Started

1. Clone or download this project

bash
git clone <your-repo-url>
cd <project-folder>

2. (Optional) Create a virtual environment

bash
python -m venv venv
source venv/bin/activate        # macOS / Linux
venv\Scripts\activate           # Windows

3. Install dependencies

bash
pip install -r requirements.txt

4. โš ๏ธ Create Streamlit configuration file (Required)

bash
mkdir -p .streamlit

Then create .streamlit/config.toml:

toml
[server]
headless = true
port = 8501
enableCORS = false
enableXsrfProtection = false

[theme]
base = "light"

5. Run the app

bash
streamlit run app.py

The app will open at http://localhost:8501.

Note: On first run, BrainHighResolution.mat (~50 MB) will be downloaded automatically from Google Drive. This only happens once.

๐Ÿ“ Project Structure

project/
โ”œโ”€โ”€ .streamlit/
โ”‚   โ””โ”€โ”€ config.toml         โ† required to avoid configuration error
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .gitattributes          โ† Git LFS tracking for large files
โ””โ”€โ”€ README.md

๐Ÿ•น๏ธ How to Use

Use the sidebar sliders to adjust MRI parameters:

ParameterDescriptionAffects
TR (ms)Repetition TimeT2-Weighted, FLAIR
TE (ms)Echo TimeT2-Weighted, FLAIR
TI (ms)Inversion TimeFLAIR only
  • โ€”T1-Weighted โ€” fixed at TR = 600 ms, TE = 15 ms
  • โ€”T2-Weighted โ€” responds to TR and TE sliders
  • โ€”FLAIR โ€” responds to TR, TE, and TI sliders (set TI โ‰ˆ 2500 ms to null CSF)

๐Ÿ”ฌ MRI Sequences Explained

T1-Weighted

Short TR + Short TE โ†’ highlights fat/white matter, CSF appears dark.

T2-Weighted

Long TR + Long TE โ†’ highlights fluid/CSF (bright), white matter appears darker.

FLAIR

Inversion Recovery that suppresses CSF signal โ€” making periventricular lesions more visible.


๐ŸŒ Deploy on Hugging Face Spaces

  1. 1.Create a new Space at huggingface.co/spaces with Streamlit SDK
  2. 2.Push all files including .streamlit/config.toml and .gitattributes
  3. 3.The YAML header in this README is automatically read by Hugging Face to configure the Space
bash
git lfs install
git add .
git commit -m "Initial commit"
git push

๐Ÿ› ๏ธ Troubleshooting

ProblemSolution
Configuration error on startupEnsure the YAML front matter at the top of README.md is present and valid
.streamlit/config.toml missingCreate it manually as shown in Step 4 above
App not loading dataCheck internet connection โ€” .mat file downloads on first run
Port already in useChange port = 8501 in config.toml to e.g. 8502
Large file push rejectedRun git lfs install and ensure .gitattributes is committed

๐Ÿ“š Data Source

Brain phantom data: BrainHighResolution.mat โ€” loaded from Google Drive (file ID: 1vdV5xDNfAiHvmKuH5DPi1YJ5Ptl927nk).

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference