CoolFace
Apppublic

sbathina/chest-xray-xai-demo

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

๐Ÿซ 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

  1. 1.Accepts a chest X-ray image upload
  2. 2.Uses a pretrained DenseNet-121 model from TorchXRayVision
  3. 3.Predicts probabilities across multiple thoracic findings
  4. 4.Generates a Grad-CAM heatmap for the highest-scoring finding
  5. 5.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

text
.
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ llm/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ explain.py
โ”œโ”€โ”€ explainability/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ gradcam.py
โ””โ”€โ”€ xray_model/
    โ”œโ”€โ”€ __init__.py
    โ””โ”€โ”€ model.py

Running Locally

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python -m streamlit run app.py

Deploying 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.