Live Demo: Try MedXpert on Hugging Face Spaces
MedXpert is a full-stack, end-to-end medical imaging system that performs real medical reasoning.
It performs a complete diagnostic workflow:
- Automatically classifies X-ray view (Frontal or Lateral)
- Diagnoses 14 thoracic pathologies using a specialist model
- Explains its predictions with Grad-CAM heatmaps
- Generates clinical summaries for each finding using a Gemini-powered RAG pipeline
This system is built as a production-ready microservice with a dedicated API backend and a Streamlit UI frontend.
This project was built to showcase a modern, end-to-end AI engineering stack.
- 🤖 Multi-Stage AI Pipeline: A lightweight
MobileNetV3"AI Router" first identifies the X-ray view, then automatically routes the image to one of two specialistDenseNet-121models (Frontal/Lateral) for superior accuracy. - 💡 Explainable AI (XAI): Generates Grad-CAM heatmaps for every positive finding, allowing clinicians to visually verify why the model made its decision by highlighting the exact pixels it focused on.
- 📚 GenAI Knowledge Base (RAG): A 13-document medical knowledge base (built from
StatPearlsandJAMAreviews) is stored in aChromaDBvector store. The Gemini API synthesizes this information to provide concise, relevant summaries for each diagnosis. - 🧩 Microservice Architecture: A decoupled, high-performance FastAPI backend (for all AI/RAG logic) and a responsive Streamlit frontend (for the UI).
- 🐳 Container-Ready: The entire application stack (API and Frontend) is fully containerized with Docker and orchestrated with Docker Compose.
- ✅ Professionally Tested: The API backend is validated by a comprehensive Pytest suite of 114 tests, achieving 97% code coverage on the main API logic.
Explainable AI (Grad-CAM): To ensure clinical trust, we implemented Gradient-weighted Class Activation Mapping (Grad-CAM). We register forward and backward hooks on the final dense block of the DenseNet-121. By computing the gradients of the target pathology class (e.g., "Pneumonia") with respect to the feature maps, we derive a weighted activation map that localizes the region of interest.
The application runs as two separate services that communicate via a REST API. This architecture ensures scalability and separation of concerns.
| Component | Technology |
|---|---|
| Backend | FastAPI |
| Frontend | Streamlit |
| AI Models | MobileNetV3, DenseNet-121 |
| GenAI / RAG | Gemini API, ChromaDB, Sentence Transformers (all-mpnet-base-v2) |
| XAI | Grad-CAM |
| Deployment | Docker, Docker Compose |
| Testing | Pytest, Coverage |
There are two ways to run this project: locally (for development) or with Docker (for a production-like deployment).
This is the recommended method for testing and iterating.
Prerequisites:
- Conda (or venv)
- Python 3.11
-
Clone the Repository:
git clone https://github.com/your-username/MedXpert.git cd MedXpert -
Set Up Environment:
- Create and activate your Conda environment:
conda create -n medxpert python=3.11 conda activate medxpert
- Install all dependencies:
pip install -r requirements.txt pip install -r requirements-dev.txt
- Create and activate your Conda environment:
-
Set Up Secrets:
- Copy the example environment file:
copy .env.example .env
- Edit the
.envfile and add yourGEMINI_API_KEY.
- Copy the example environment file:
-
Run the Application:
-
Open two terminals and activate your
(medxpert)environment in both. -
In Terminal 1 (Run Backend API):
Makefile.bat run-api
(This runs:
python -m uvicorn src.api:app --reload) -
In Terminal 2 (Run Frontend App):
Makefile.bat run-app
(This runs:
streamlit run src/app.py)
-
-
Open the App:
- Open your browser and go to
http://localhost:8501.
- Open your browser and go to
Prerequisites:
- Docker Desktop (must be running)
- A
.envfile (see Step 3 above)
-
Build the Containers:
docker-compose build
-
Run the Application:
docker-compose up -d
(Use
docker-compose upwithout-dif you want to see the live logs in your terminal). -
Open the App:
- Open your browser and go to
http://localhost:8501.
- Open your browser and go to
-
To Stop:
docker-compose down
This project is built with a focus on quality, achieving 97% test coverage on the critical API logic and a 100% (114/114) pass rate.
- Activate your environment:
conda activate medxpert
- Run the test script:
scripts\run_tests.bat - A full coverage report will be generated in the
htmlcov/folder. Openhtmlcov/index.htmlto see a detailed, line-by-line breakdown.
Rishabh Dewangan
- Email:
rishabhcicdu@gmail.com
This project is licensed under the MIT License. See the LICENSE file for details.
