AI-powered chest X-ray diagnostic assistant with CheXNet, Grad-CAM++ heatmaps, Gemini AI explanations, and nearby doctor recommendations.
Project description
๐ซ Chest X-Ray Diagnostic Assistant
An AI-powered medical diagnostic system for chest X-ray analysis with explainable AI, Grad-CAM++ heatmaps, and nearby doctor recommendations.
๐ Features
- 3-Stage Binary Pipeline: Validates images through garbage detection โ chest confirmation โ normal/abnormal assessment
- 14-Pathology Detection: (DenseNet-121) detects conditions like Pneumonia, Cardiomegaly, Effusion, Mass, Nodule, and more
- Grad-CAM++ Heatmaps: Visual overlays showing which regions the AI focused on
- Gemini AI Explainability:
gemini-3.1-flash-litegenerates professional clinical explanations in natural language - Nearby Doctor Recommendations: Geoapify-powered specialist finder based on detected pathologies and the user's real location
- Modular React Frontend: Clean, component-based UI with a premium medical design
๐๏ธ Architecture
Frontend (React) โ Backend (FastAPI) โ AI Models โ External APIs
โ โ โ โ
7 Components REST API :8000 Binary Pipeline Gemini 3.1 Flash Lite
Medical UI Image Processing (DenseNet) Geoapify Places
Responsive UX Heatmap Generation Grad-CAM++ Maps
๐ Project Structure
chexnet-proto/
โโโ backend/
โ โโโ app.py # FastAPI application (main entry point)
โ โโโ requirements.txt # Python dependencies
โ โโโ src/
โ โโโ binary_pipeline.py # 3-stage X-ray validation pipeline
โ โโโ HeatmapGenerator.py # Grad-CAM++ heatmap generation
โ โโโ DensenetModels.py # CheXNet model definition
โ โโโ explainability_ai.py # Gemini AI clinical explanation
โ โโโ geoapify_service.py # Nearby doctor search (Geoapify)
โโโ frontend/
โ โโโ src/
โ โโโ App.js # Root component & analysis orchestrator
โ โโโ App.css # Global styles
โ โโโ components/
โ โโโ Header.js # App header
โ โโโ UploadSection.js # X-ray upload & drag-drop
โ โโโ BinaryPipelineStatus.js # Pipeline validation display
โ โโโ ImagePanel.js # Original + heatmap side-by-side
โ โโโ PathologyResults.js # 14-pathology confidence grid
โ โโโ AIExplanationCard.js # Gemini AI explanation renderer
โ โโโ NearbyDoctors.js # Geoapify-powered doctor finder
โโโ chexnet/ # Original reference repo
โโโ data/ # Dataset directory
โโโ scripts/ # Utility & training scripts
โโโ .env # API keys (not committed)
๐ Prerequisites
- Python 3.8+
- Node.js 16+
- CUDA-compatible GPU (recommended for faster inference)
- Gemini API Key โ Get one here
- Geoapify API Key โ Get one here
๐ง Setup
1. Backend
cd backend
pip install -r requirements.txt
2. Frontend
cd frontend
npm install
3. Environment Variables
Create a .env file in the root directory:
GEMINI_API_KEY=your_gemini_api_key_here
GEOAPIFY_API_KEY=your_geoapify_api_key_here
Note: OpenAI/ChatGPT is no longer used. The project exclusively uses
gemini-2.0-flashfor AI explanations.
4. Run the Application
# Terminal 1 โ Backend
cd backend
uvicorn app:app --reload --host 0.0.0.0 --port 8000
# Terminal 2 โ Frontend
cd frontend
npm start
Visit: http://localhost:3000
๐ How It Works
Stage 1 โ Binary Pipeline (Validation)
| Model | Task | Result |
|---|---|---|
| Model 1 | Garbage vs. X-ray | Rejects non-medical images |
| Model 2 | Chest vs. Other X-ray | Confirms it's a chest X-ray |
| Model 3 | Normal vs. Abnormal | Initial pathology flag |
Stage 2 โ CheXNet Analysis
- Runs DenseNet-121 trained on ChestX-ray14 dataset
- Detects 14 pathologies with confidence scores and clinical thresholds
- Generates Grad-CAM++ attention heatmaps
Stage 3 โ AI Explainability (Gemini)
- Combines Model 3 + CheXNet results into a structured prompt
- Sends to Gemini 3.1 Flash Lite for clinical explanation
- Returns formatted explanation with sections: Summary, Findings, Recommendations
Stage 4 โ Nearby Doctor Finder (Geoapify)
- Detects dominant pathology from results
- Maps pathology โ specialist type (e.g., Pneumonia โ Pulmonologist)
- Uses browser geolocation to search for real nearby clinics
- Falls back to General Physician if no specialist found
๐ API Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check |
POST |
/analyze |
Upload X-ray image for full analysis |
Sample Response (/analyze)
{
"binary_pipeline": [
{ "model": "Image Validation", "is_valid": true, "confidence": 0.98, "message": "Valid chest X-ray" }
],
"valid_for_analysis": true,
"clinical_summary": "โ
NORMAL - No significant abnormalities detected",
"assessment_level": "NORMAL",
"pathologies": [
{ "name": "Pneumonia", "confidence": 0.12, "is_detected": false }
],
"heatmap_b64": "data:image/png;base64,...",
"ai_explanation": "## Summary\n...",
"doctor_recommendations": [...],
"processing_time_ms": 245.3
}
๐งฐ Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 18, Vanilla CSS |
| Backend | FastAPI, Uvicorn |
| ML Models | PyTorch, DenseNet-121 (CheXNet) |
| AI Explainability | Google Gemini 3.1 Flash Lite (google-genai) |
| Doctor Finder | Geoapify Places API |
| Heatmaps | Grad-CAM++, OpenCV |
โก Performance
- Binary pipeline: ~50ms
- CheXNet + heatmap: ~150โ250ms
- Gemini AI explanation: ~1โ3s (network dependent)
- GPU acceleration supported (CUDA)
๐ Privacy & Security
- All image processing is local โ no images sent to external servers
- Only text summaries are sent to Gemini for explanation
- API keys stored in
.env(excluded from version control via.gitignore) - No patient data is logged or persisted
๐ Troubleshooting
| Issue | Fix |
|---|---|
| Model files not found | Ensure .pth files are in backend/models/ |
| CUDA errors | Set device = "cpu" in pipeline files |
| Gemini API errors | Verify GEMINI_API_KEY in .env |
| Geoapify returns no results | Check GEOAPIFY_API_KEY and confirm valid category names |
| Frontend can't reach backend | Confirm backend is running on port 8000 |
| CORS errors | Check allow_origins in app.py FastAPI config |
โ ๏ธ Medical Disclaimer
This system is designed for research and educational purposes only. It must not be used as a substitute for professional medical diagnosis. Always consult a qualified healthcare provider for clinical decisions.
๐ License
For educational and research use only. See individual model licenses for CheXNet model weights.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chest_xray_diagnosis-1.0.0.tar.gz.
File metadata
- Download URL: chest_xray_diagnosis-1.0.0.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aeb1f4f62fe58c8b38fb95b0aafce4afc5870af64076a78b23cbfca54a0d4ce
|
|
| MD5 |
eff25261f2218b0ebeca857f0ca7b1f2
|
|
| BLAKE2b-256 |
6baa916f526ee39bb7352aaa12513cdfa829946d2953a5ff6972e26d74c42fea
|
File details
Details for the file chest_xray_diagnosis-1.0.0-py3-none-any.whl.
File metadata
- Download URL: chest_xray_diagnosis-1.0.0-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d920c43838343432601d7ba4227396ab36b9cb90892c8c9e48eb3b4bbaa45436
|
|
| MD5 |
45cd72154899098c66685a0f8e669238
|
|
| BLAKE2b-256 |
b2cfcc38ca56be3c9ce580eeee2c9119a20fc6eaaf8f1d423c25fcb0f9bff369
|