BrainGemma3D / README.md
giuseppericcio's picture
Update README.md
2c4154f verified

A newer version of the Gradio SDK is available: 6.8.0

Upgrade
metadata
title: BrainGemma3D
emoji: πŸš€
colorFrom: gray
colorTo: blue
sdk: gradio
sdk_version: 6.6.0
app_file: app.py
pinned: false
license: cc-by-4.0
short_description: 🧠Brain Report Automation via Inflated ViT in 3D

🧠 BrainGemma3D Dashboard

Interactive web dashboard for generating medical reports from 3D brain MRI volumes (NIfTI format) using the BrainGemma3D model with LIME interpretability analysis.

BrainGemma3D Kaggle Notebook
MedGemma Challenge

🌐 Live Demo

Try it now on HuggingFace Spaces:
πŸš€ Launch Dashboard

No installation required! Simply upload your NIfTI file and get instant AI-powered radiology reports with interpretability visualizations.


πŸ“‹ Features

  • βœ… Upload NIfTI files (.nii / .nii.gz) for 3D brain MRI volumes
  • βœ… Multi-planar visualization (Axial, Coronal, Sagittal views)
  • βœ… Automatic medical report generation powered by BrainGemma3D
  • βœ… LIME Interpretability - Visualize which brain regions support the diagnosis
  • βœ… PDF Export - Professional radiology report with multi-planar reconstructions
  • βœ… Configurable parameters (temperature, max tokens, custom instructions)
  • βœ… Real-time progress tracking during inference
  • βœ… Responsive UI optimized for medical imaging workflows

πŸš€ Quick Start

Option 1: Use HuggingFace Spaces (Recommended)

Simply visit the BrainGemma3D Dashboard Space in your browser. No installation needed!

Option 2: Run Locally

If you want to run the dashboard on your own hardware:

# Clone the repository
git clone https://huggingface.co/spaces/giuseppericcio/BrainGemma3D
cd BrainGemma3D

# Install dependencies
pip install -r requirements.txt

# Run the app
python app.py

The model will be automatically downloaded from HuggingFace on first run (~3.5 GB).


πŸ“– How to Use

1. Upload NIfTI File

  • Click "Upload NIfTI File"
  • Select a .nii or .nii.gz file from your filesystem
  • The file must be a 3D brain MRI volume (e.g., FLAIR, T1, T2, etc.)
  • Automatic multi-planar preview will be displayed

2. Enter Patient Information (Optional)

For complete PDF reports, you can provide:

  • Patient name
  • Patient ID / MRN
  • Exam date
  • Referring physician
  • Institution

3. Configure Generation Parameters (Optional)

Expand "βš™οΈ Generation Parameters" to adjust:

  • Additional Instructions: Extra instructions or questions about the image
  • Max Tokens: Maximum report length (50-512)
  • Temperature: Creativity level (0.0 = deterministic, 2.0 = very creative)
  • Top-p: Nucleus sampling (0.9 recommended)
  • Repetition Penalty: Penalty for repetitions (1.2 recommended)

4. Generate Report

  • Click "πŸš€ Generate"
  • Wait for the progress bar (7 steps):
    1. Loading NIfTI file
    2. Normalizing volume
    3. Preparing prompt
    4. BrainGemma3D inference
    5. Formatting report
    6. LIME interpretability analysis
    7. Completion

5. View Results

πŸ“‹ Diagnostic Report

Medical report generated in Markdown format with generation metadata

πŸ”¬ LIME Interpretability

2Γ—3 grid visualization showing:

  • Top row: 3 original representative slices from the volume
  • Bottom row: Same slices with LIME overlay

Color legend:

  • πŸ”΄ Red = Regions strongly supporting the diagnosis
  • πŸ”΅ Blue = Regions contradicting or weakening the diagnosis
  • βšͺ White/Gray = Neutral or minimal impact

This helps understand which brain areas influenced the model's diagnosis.

πŸ” 3D Volume Viewer

Explore the MRI volume interactively:

  • Axial: Horizontal slices (top-down)
  • Coronal: Frontal slices
  • Sagittal: Lateral slices

Use the sliders to navigate through the slices.

6. Export PDF

Click "πŸ“„ Download PDF Report" to generate a professional radiology report with:

  • Institutional header
  • Patient information
  • Multi-planar reconstructions
  • Complete report text
  • Physician signature section
  • AI disclaimer

πŸ“‚ Example Files

You can test the dashboard with publicly available brain MRI datasets:

BraTS (Brain Tumors):

  • Download from: BraTS 2020
  • Example: BraTS20_Training_001_flair.nii.gz

MPI-Leipzig Mind-Brain-Body (Healthy Controls):


πŸ› οΈ Technical Details

Hardware Requirements (Local Installation)

Component Minimum Recommended
GPU 8GB VRAM (e.g., RTX 2080) 16GB+ VRAM (e.g., A100, RTX 3090)
RAM 16GB 32GB+
Storage 10GB free 20GB+ free

Note: HuggingFace Spaces runs on shared infrastructure with resource limits. For heavy usage or faster inference, consider running locally.

Generation Times (HF Spaces)

Component Typical Time Notes
Report Generation 10-15s BrainGemma3D inference
LIME Analysis 2-3 min 50 samples (configurable)
PDF Export <1s Report rendering
TOTAL ~2.5-3.5 min Complete workflow

Times may vary based on Space availability and queue status.

LIME Samples vs Quality

lime_samples Time Explanation Quality
10 ~30s Low (quick testing)
25 ~1 min Medium (acceptable)
50 ~2 min Good (dashboard default)
100 ~4 min High (research grade)

Dashboard uses 50 samples to balance speed and quality. Research papers typically use 100.


⚠️ Limitations & Best Practices

File Size Limits

  • HuggingFace Spaces has upload limits (typically ~100-200 MB per file)
  • Most NIfTI files are 5-50 MB, so this should not be an issue
  • For very large files, consider running locally

Supported MRI Sequences

  • βœ… FLAIR (Recommended)
  • βœ… T1-weighted
  • βœ… T2-weighted
  • βœ… T1-contrast enhanced
  • ⚠️ Other sequences may work but are not validated

Privacy & Security

  • Do NOT upload files containing identifiable patient information (PHI)
  • Files uploaded to HuggingFace Spaces are processed in memory and not permanently stored
  • For clinical data, always run locally or use de-identified data
  • Comply with HIPAA, GDPR, and local data protection regulations

πŸ”’ Medical Disclaimer

⚠️ IMPORTANT: This dashboard is for research and educational purposes only.

  • ❌ NOT for clinical diagnosis or patient care decisions
  • ❌ NOT a substitute for professional medical judgment
  • ❌ NOT validated for clinical use or regulatory approval
  • ⚠️ LIME interpretability is explanatory, not diagnostic

AI-generated reports may contain errors, hallucinations, or incomplete information. LIME visualizations show which regions influenced the model but do not guarantee clinical relevance.

Always consult qualified healthcare professionals for medical diagnosis and treatment.


πŸ“Š Performance Benchmarks

Accuracy Metrics (BraTS 2020 dataset)

Metric BrainGemma3D Baseline
BLEU-4 0.287 0.234
METEOR 0.412 0.368
CIDEr 1.456 1.102
Clinical Accuracy 89.3% 76.8%

See Model Card for detailed evaluation.


🀝 Contributing

Found a bug or have a feature request? Contributions are welcome!


πŸ™ Acknowledgements

This project was developed by:

Mariano Barone Β· Francesco Di Serio Β· Giuseppe Riccio Β· Antonio Romano Β· Vincenzo Moscato

Department of Electrical Engineering and Information Technology
University of Naples Federico II, Italy

Built With


πŸ”— Related Links

Documentation & Resources

Technical References

Datasets


Built with ❀️ for the MedGemma Impact Challenge πŸ†

Advancing Medical AI with Google's Health AI Developer Foundations