Full-stack Flask web app for chest X-ray pneumonia detection using ResNet-50 + FastAI.
pneumonia_app/
├── app.py ← Flask backend
├── requirements.txt ← Python dependencies
├── templates/
│ └── index.html ← Full frontend UI
└── static/
└── uploads/ ← Uploaded X-ray images
pip install -r requirements.txtpython app.pyhttp://localhost:5000
pip install fastaifrom fastai.vision.all import *
# Load Kaggle dataset
path = Path('chest_xray')
dls = ImageDataLoaders.from_folder(
path, valid='val',
item_tfms=Resize(224),
batch_tfms=aug_transforms()
)
# Train ResNet-50
learn = vision_learner(dls, resnet50, metrics=accuracy)
learn.fine_tune(5)
learn.export('pneumonia_model.pkl')Replace the mock_predict() function with:
from fastai.vision.all import load_learner, PILImage
learn = load_learner('pneumonia_model.pkl')
def real_predict(filepath):
img = PILImage.create(filepath)
pred, pred_idx, probs = learn.predict(img)
return str(pred), float(probs[pred_idx])- Drag & drop X-ray upload
- 3-class classification: Normal / Bacterial / Viral Pneumonia
- Confidence score with animated ring chart
- Grad-CAM heatmap overlay
- Probability bars for all classes
- ICD-10 code mapping
- Patient ID tracking
- Clinical recommendation
- Analysis history
- Downloadable clinical report
- HIPAA-aware pipeline design
Kaggle: Chest X-Ray Images (Pneumonia)
- 5,856 images | 3 classes | Train/Val/Test split
- Backend: Python, Flask
- AI Model: FastAI v2, ResNet-50, PyTorch
- Explainability: Grad-CAM
- Frontend: Vanilla HTML/CSS/JS (no framework needed)