Live demo: GradCAM-on-upload¶
The Space above is the live Gradio demo embedded inline. If the iframe is slow to load (Hugging Face Spaces sleep after 48h of inactivity and cold-start in 30-60s), open it directly at huggingface.co/spaces/t22000t/clinical-ai-gradcam-demo.
What you can do¶
- Try a MedNIST example. Six pre-loaded tiles (one per class) under the upload widget. Click one to populate the input.
- Upload your own image. PNG or JPEG, up to 5 MB. DICOM is rejected by extension and magic-byte sniff; EXIF is stripped before any model inference.
- Confirm no PHI. Tick the "no patient-identifiable information" checkbox above the run button. The run button is disabled until you do; the server-side function also re-checks defensively.
- Run inference. You get four outputs:
- Predicted class with calibrated probability
- Original input and GradCAM heatmap side-by-side at 320 px per panel
- Per-class probability bar chart with raw and temperature-calibrated bars
- Expected Calibration Error for both, so you can see what calibration buys you
- Browse the "known failure modes" panel. Four pre-rendered confident misclassifications under different augmentation scenarios. The GradCAM heatmap visibly drifts off the anatomy on each.
What the demo will not do¶
- It will not classify real clinical images correctly. The model was trained on MedNIST: 64x64 grayscale anatomical-class tiles. Any full-resolution clinical image you upload will be downsampled and predicted out-of-distribution. That is the lesson of the failure-modes panel.
- It will not accept DICOM uploads. Per the safety layer.
- It will not store your uploads.
analytics_enabled=False; no flagging directory; the temporary file is read once and discarded.
Reproducing the demo locally¶
The Space sources are at demo/ in this repo. To run locally:
git clone https://github.com/timothy22000/clinical-ai-curriculum
cd clinical-ai-curriculum/demo
pip install -r requirements.txt
python app.py # opens at http://127.0.0.1:7860
The trained DenseNet121 checkpoint (densenet121_mednist.pt) and the temperature-scaling sidecar (calibration_temperature.json) are already in demo/. If you want to retrain from scratch:
Takes ~5-25 minutes depending on GPU/MPS/CPU. Mirrors the Chapter 3 recipe in the notebook.
Regenerating the "known failure modes" panel¶
The 4 pre-rendered failure-mode PNGs are produced by scripts/generate_failure_modes.py. Re-running the script picks the most-confidently-wrong MedNIST tile per augmentation scenario (rotated, noisy, low-contrast, inverted) and renders fresh composites.