sbathina/chest-xray-xai-demo
๐ซ Chest X-Ray AI with Explainability
๐จ Educational Use Only This application is NOT a medical diagnostic tool.
Overview
This project is a publicly deployable medical imaging AI demo that shows how a deep learning model analyzes a chest X-ray and highlights the image regions that most influenced its prediction.
The app is built to demonstrate:
- deep learning inference on chest X-rays
- model interpretability using Grad-CAM
- plain-English explanation of model behavior
- responsible AI safeguards for healthcare-related demos
What the App Does
- Accepts a chest X-ray image upload
- Uses a pretrained DenseNet-121 model from TorchXRayVision
- Predicts probabilities across multiple thoracic findings
- Generates a Grad-CAM heatmap for the highest-scoring finding
- Displays a human-readable explanation of what the heatmap means
Why This Project Matters
Medical AI systems are often difficult to interpret. This project focuses on transparency rather than diagnosis. The goal is to make model behavior easier to inspect and communicate, especially for demos, portfolios, and educational audiences.
Model
- Architecture: DenseNet-121
- Library: TorchXRayVision
- Task: Multi-label chest X-ray classification
- Pretrained on: NIH ChestX-ray14, CheXpert, MIMIC-CXR, and other public chest X-ray sources packaged through TorchXRayVision
Explainability
This app uses Grad-CAM to visualize which parts of the image were most influential for a selected prediction. The heatmap is an interpretability aid, not clinical evidence.
LLM Explanation
The app supports two explanation modes:
- Local mode: If Ollama is running locally, the app can use a local LLM such as TinyLlama
- Public Hugging Face mode: If Ollama is unavailable, the app uses a deterministic fallback explanation so the demo remains fully public and free
Responsible AI Disclaimer
- This demo does not diagnose disease
- It does not replace a clinician
- It must not be used for treatment or medical decision-making
- It is intended for educational, interpretability, and portfolio purposes only
Tech Stack
- Streamlit
- PyTorch
- TorchXRayVision
- OpenCV
- PIL
- NumPy
- Grad-CAM
- Ollama (optional, local only)
- Hugging Face Spaces
Project Structure
.
โโโ app.py
โโโ requirements.txt
โโโ README.md
โโโ llm/
โ โโโ __init__.py
โ โโโ explain.py
โโโ explainability/
โ โโโ __init__.py
โ โโโ gradcam.py
โโโ xray_model/
โโโ __init__.py
โโโ model.pyRunning Locally
source venv/bin/activate
pip install -r requirements.txt
python -m streamlit run app.pyDeploying to Hugging Face Spaces
- Create a new Streamlit Space
- Upload all files in this repo
- Make sure the README.md front matter remains at the top
- Hugging Face will install dependencies from requirements.txt
- The app will automatically use fallback explanations when no local Ollama service is available
๐ฉโโ๏ธ Responsible AI Notice
This demo visualizes how an AI system responds to medical images. It does not replace medical professionals or provide medical advice.
