Spaces:
Running
Running
File size: 2,006 Bytes
c937124 0ac5a7f c937124 f627411 c937124 0893c44 c937124 0ac5a7f f627411 0ac5a7f f627411 0ac5a7f f627411 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | ---
title: Pneumonia Detector
emoji: 🫁
colorFrom: purple
colorTo: red
sdk: gradio
sdk_version: 6.12.0
app_file: app.py
pinned: false
license: mit
short_description: Pneumonia detection from chest X-rays using ViT and Grad-CAM
tags:
- medical
- computer-vision
- pytorch
- chest-xray
- grad-cam
- vit
- explainability
- healthcare
---
# 🫁 Pneumonia Detector
Medical AI system for detecting pneumonia from chest X-ray images using Vision Transformer (ViT) with explainable Grad-CAM heatmaps.
## Features
- **Upload chest X-ray** — supports PNG, JPEG
- **AI prediction** — Normal or Pneumonia with confidence score
- **Grad-CAM heatmap** — visual explanation showing which regions the model focused on
- **Fast inference** — runs on CPU or GPU
## Model Details
| Attribute | Value |
|-----------|-------|
| Architecture | Vision Transformer (ViT) |
| Backbone | ViT-B/16 |
| Fine-tuned on | Chest X-ray dataset |
| Accuracy | 87% |
| AUC-ROC | 0.98 |
| Input size | 224x224 pixels |
## Training Details
| Parameter | Value |
|-----------|-------|
| Dataset | Chest X-ray (Pneumonia) |
| Train/Val/Test split | 80/10/10 |
| Epochs | 20 |
| Batch size | 32 |
| Learning rate | 1e-4 |
| Optimizer | AdamW |
| Hardware | Kaggle P100 (16GB) |
| Training time | ~3 hours |
## Performance Metrics
| Metric | Score |
|--------|-------|
| Accuracy | 87% |
| AUC-ROC | 0.98 |
| Precision | 85% |
| Recall | 89% |
| F1-Score | 87% |
*Tested on held-out test set of 624 images*
## How to Use
1. Upload a chest X-ray image (frontal view preferred)
2. Click **Submit**
3. View prediction + Grad-CAM heatmap
## Example Output
**Prediction:** Pneumonia (confidence: 94%)
**Heatmap:** Highlights upper right lung region
## Technical Stack
- PyTorch
- Hugging Face Transformers
- timm (Vision Models)
- Grad-CAM
- Gradio
## Run Locally
```bash
git clone https://huggingface.co/spaces/mou11/pneumonia-detector
cd pneumonia-detector
pip install -r requirements.txt
python app.py |