Spaces:
Running on Zero
A newer version of the Gradio SDK is available:
6.8.0
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.
π 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
.niior.nii.gzfile 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):
- Loading NIfTI file
- Normalizing volume
- Preparing prompt
- BrainGemma3D inference
- Formatting report
- LIME interpretability analysis
- 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):
- Download from: MPI-Leipzig Mind-Brain-Body
- Requires registration (free for researchers)
π οΈ 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!
- Report Issues: GitHub Issues
- Submit PRs: GitHub Repository
π 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
- Google MedGemma β Medical domain language model
- Google MedSigLIP β Medical vision encoder
- Hugging Face Transformers β Model framework
π Related Links
Documentation & Resources
- π€ Model Card: praiselab-picuslab/BrainGemma3D
- π Dashboard (This Space): BrainGemma3D-Dashboard
- π» GitHub Repository: PRAISELab-PicusLab/BrainGemma3D
- π Paper: ArXiv (Coming soon)
Technical References
- Gradio Documentation: https://gradio.app/docs
- NiBabel (NIfTI Processing): https://nipy.org/nibabel
- LIME Paper: "Why Should I Trust You?" - Ribeiro et al., 2016
- MedGemma Model Family: https://huggingface.co/google/medgemma
Datasets
- BraTS 2020: 369 brain tumor MRI cases with clinical annotations from TextBraTS 2021
- Healthy Controls: 99 preprocessed healthy brain scans (skull-stripped, normalized) from MPI-Leipzig Mind-Brain-Body
Built with β€οΈ for the MedGemma Impact Challenge π
Advancing Medical AI with Google's Health AI Developer Foundations