Chest X-Ray AI Analysis is a two-service web application for educational and research use. It runs a PyTorch chest X-ray model, returns prediction scores for supported findings, and generates Grad-CAM visual explanations for findings that pass the configured probability threshold.
The project includes:
- a
FastAPIbackend for inference and heatmap generation - a
React + Vitefrontend for upload, review, and legal pages - separate container definitions for frontend and backend
- Cloud Run deployment guidance for public demo hosting
- Chest X-ray inference with
TorchXRayVision DenseNet121 - Grad-CAM heatmaps for eligible findings
- Strict upload validation for type, size, and image dimensions
- No intentional image retention after processing
- Minimal logging and demo-oriented rate limiting
- Separate frontend and backend deployment targets
frontend/: React application served as a static sitesrc/api/: FastAPI app and request handlingsrc/inference/: prediction pipelinesrc/model/: model loadingsrc/visualization/: Grad-CAM generation and overlaysdeploy/: deployment configuration files
Windows PowerShell:
py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1If PowerShell blocks activation, use:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.\.venv\Scripts\Activate.ps1pip install -r requirements.txtuvicorn src.api.main:app --reload --host 127.0.0.1 --port 8000cd frontend
npm install
npm run devThe frontend runs on http://localhost:5173 by default and expects the backend at http://127.0.0.1:8000 unless VITE_API_BASE_URL is set.
Example backend environment variables are provided in .env.example.
Important settings:
MODEL_NAMEDEVICECORS_ORIGINS_RAWGRADCAM_MIN_PROBABILITYUPLOAD_MAX_SIZE_MBMAX_IMAGE_PIXELSALLOWED_CONTENT_TYPES_RAWRATE_LIMIT_REQUESTS_PER_MINUTE
Frontend:
VITE_API_BASE_URL: backend base URL used by the React app
Accepts a chest X-ray image and returns:
- top predicted finding
- probability scores for all supported findings
- default Grad-CAM result for the top finding when available
Generates a Grad-CAM heatmap for a selected class when its probability is at least the configured threshold.
The app is designed to run as two separate services:
- backend on Cloud Run
- frontend on Cloud Run
Deployment references:
DEPLOY_CLOUD_RUN.mdcloudbuild-api.yamlfrontend/cloudbuild.yamlDockerfile.apifrontend/Dockerfile
This repository is configured for a public educational demo, not a clinical system.
Implemented controls include:
- strict CORS support
- upload size and MIME restrictions
- image dimension checks
- no persistent storage of uploaded images
- minimal logs
- response
no-storeheaders
Additional deployment notes are documented in SECURITY_NOTES.md.
This project is for education, research, and technical demonstration only. It is not a medical device and must not be used for diagnosis, treatment, or clinical decision-making.
This project is released under the license in LICENSE.