Upload a medical lab report. Get instant, plain-language results.
MedClarify AI extracts text from lab reports (PDF or image), parses patient details and test results, evaluates each result against clinical reference ranges, and delivers a structured health summary β all locally, no third-party AI service involved.
- Features
- Tech Stack
- Project Structure
- Getting Started
- Environment Variables
- API Reference
- How It Works
- Running Tests
| Feature | Details | |
|---|---|---|
| π | Multi-format Upload | Accepts PDF, PNG, JPG, JPEG lab reports |
| π | Smart Text Extraction | Native PDF text extraction with Tesseract OCR fallback for scanned/image reports |
| π§Ή | Text Cleaning | Removes duplicate lines, fixes OCR noise, merges wrapped lines |
| π€ | Patient Info Parsing | Detects name, age, gender, and report date using regex heuristics |
| 𧬠| Lab Test Parsing | Extracts test name, value, unit, and reference range with a confidence score per test |
| π | Reference Range Evaluation | Flags results as NORMAL, HIGH, LOW, or CRITICAL β age and gender adjusted |
| π§ | Knowledge Engine | Plain-language clinical interpretation for every abnormal finding |
| π | Auto Summary | Generates a concise health summary with an overall extraction confidence score |
| Extraction Warnings | Surfaces low-confidence extractions and missing patient fields | |
| π | Charts & Metrics | Visual representation of lab results in the report viewer |
| π₯ | PDF Export | Download the full analysis as a PDF directly from the browser |
| Technology | Purpose |
|---|---|
| Python 3.11+ | Core language |
| FastAPI | REST API framework |
| Uvicorn | ASGI server |
| pypdf | Native PDF text extraction |
| Tesseract + pytesseract | OCR engine for scanned documents |
| pdf2image + Pillow | Converts PDF pages to images for OCR |
| Pydantic / pydantic-settings | Settings management and validation |
| python-dotenv | .env file loading |
| Technology | Purpose |
|---|---|
| React 18 + TypeScript | UI framework |
| Vite | Dev server and build tool |
| TailwindCSS | Utility-first styling |
| Radix UI | Accessible headless UI primitives |
| Framer Motion | Animations and transitions |
| Recharts | Data visualisation (charts) |
| Zustand | Client-side state management |
| React Router v6 | Client-side routing |
| Axios | HTTP client with upload progress tracking |
| jsPDF | In-browser PDF export |
| TanStack Query | Server-state and async data management |
MedClarify-AI/
β
βββ backend/
β βββ app/
β β βββ main.py # FastAPI app, CORS, router registration
β β βββ config.py # Pydantic settings β reads .env
β β βββ routes/
β β β βββ upload.py # POST /api/upload β full analysis pipeline
β β βββ services/
β β β βββ unified_extraction.py # Chooses PDF vs OCR extraction path
β β β βββ extraction_service.py # Native PDF text extraction (pypdf)
β β β βββ ocr_service.py # Tesseract OCR wrapper
β β β βββ reference_ranges.py # Clinical range evaluation (HIGH/LOW/CRITICAL)
β β β βββ knowledge_engine.py # Plain-language interpretations for abnormals
β β β βββ summary_engine.py # Overall health summary generator
β β β βββ parser/
β β β β βββ lab_parser.py # Lab test extraction (regex + heuristics)
β β β β βββ patient_parser.py # Patient demographic extraction
β β β β βββ text_cleaner.py # OCR noise removal and line deduplication
β β β βββ data/
β β β βββ knowledge_base.json # Clinical interpretation templates
β β β βββ reference_ranges.json # Normal range definitions per test
β β βββ utils/
β β βββ file_utils.py # PDF page-count helper
β βββ tests/ # Backend unit tests (pytest)
β βββ requirements.txt
β βββ .env.example
β
βββ frontend/
β βββ src/
β β βββ main.tsx # React entry point
β β βββ App.tsx # Root component with RouterProvider
β β βββ pages/
β β β βββ landing/
β β β β βββ LandingPage.tsx # Home page
β β β βββ reports/
β β β βββ UploadPage.tsx # File upload + analysis trigger
β β β βββ ViewerPage.tsx # Full report viewer
β β β βββ ReportsPage.tsx # Reports listing page
β β βββ components/
β β β βββ landing/ # Hero, Features, FAQ, HowItWorks, etc.
β β β βββ report/ # PatientCard, LabTable, AbnormalFindings,
β β β β # ChartsSection, ExportActions, SummaryCard, etc.
β β β βββ ui/ # Radix UI base components
β β βββ stores/
β β β βββ reportStore.ts # Zustand store for report state
β β βββ lib/
β β β βββ api/
β β β βββ api.ts # Axios API client (upload + error handling)
β β βββ layouts/ # Page layout wrappers
β β βββ routes/ # React Router route definitions
β β βββ types/ # TypeScript type definitions
β βββ index.html
β βββ package.json
β βββ vite.config.ts
β βββ tailwind.config.js
β βββ tsconfig.json
β
βββ .gitignore
βββ README.md
| Tool | Version | Install |
|---|---|---|
| Python | 3.11+ | python.org |
| Node.js | 18+ | nodejs.org |
| Tesseract OCR | 5.x | See below |
| Poppler | latest | Required by pdf2image |
Ubuntu / Debian:
sudo apt update && sudo apt install -y tesseract-ocr poppler-utilsmacOS (Homebrew):
brew install tesseract poppler# Clone the repo and enter the backend directory
cd MedClarify-AI/backend
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your values (see Environment Variables section below)
# Start the development server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000- API base:
http://localhost:8000 - Swagger UI (interactive docs):
http://localhost:8000/docs
cd MedClarify-AI/frontend
# Install Node dependencies
npm install
# Create and configure frontend env file
# Create a .env file and set the backend URL:
echo "VITE_API_URL=http://localhost:8000" > .env
# Start the dev server
npm run devFrontend runs at http://localhost:5173 by default.
The backend must be running before you use the frontend β the upload page calls
POST /api/upload.
APP_NAME=MedClarify AI
APP_VERSION=1.0.0
ENVIRONMENT=development
ALLOWED_ORIGINS=http://localhost:5173| Variable | Description | Default |
|---|---|---|
APP_NAME |
Application name shown in API responses | MedClarify AI |
APP_VERSION |
Version string | 1.0.0 |
ENVIRONMENT |
development or production |
development |
ALLOWED_ORIGINS |
Comma-separated allowed CORS origins | http://localhost:3000 |
VITE_API_URL=http://localhost:8000| Variable | Description |
|---|---|
VITE_API_URL |
Base URL of the FastAPI backend |
Never commit
.envfiles with real values to version control.
Health check.
{
"status": "online",
"service": "MedClarify AI",
"version": "1.0.0"
}Upload a medical report and receive a full analysis.
Request β multipart/form-data
| Field | Type | Accepted formats |
|---|---|---|
file |
File | .pdf, .png, .jpg, .jpeg |
Response 200 OK
{
"success": true,
"filename": "<uuid>.pdf",
"original_name": "lab_report.pdf",
"preview_text": "First 1000 characters of extracted text...",
"character_count": 4523,
"pages": 2,
"parsed_data": {
"patient": {
"name": "John Doe",
"age": "35",
"gender": "Male",
"report_date": "2026-07-15"
},
"laboratory_tests": [ ... ],
"abnormal_tests": [ ... ],
"interpretation": [ ... ],
"summary": { ... },
"confidence": 92,
"warnings": [],
"processing_metadata": {
"extraction_method": "pdf_text",
"ocr_pages": [],
"processing_time_ms": 340
}
}
}Error codes
| Code | Cause |
|---|---|
400 |
Empty file or unsupported file type |
500 |
Server error during extraction or parsing |
User uploads file (PDF / PNG / JPG)
β
βΌ
βββββββββββββββββββββ
β File Validation β type + size check
ββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Text Extraction β pypdf β Tesseract OCR fallback
ββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Text Cleaning β dedup, merge wrapped lines, fix OCR noise
ββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββ
β Parsing β
β βββ Patient info (name/age/gender)β
β βββ Lab tests (name/value/unit) β
ββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββ
β Reference Range Evaluation β NORMAL / HIGH / LOW / CRITICAL
ββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββ
β Knowledge Engine β plain-language interpretation
ββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Summary Generation β overall summary + confidence score
ββββββββββ¬ββββββββββββββββ
β
βΌ
JSON response β React frontend
The backend has a test suite under backend/tests/ covering extraction, OCR, reference ranges, summary engine, and the upload route.
cd backend
source .venv/bin/activate
# Run all tests
pytest tests/
# Run a specific test file
pytest tests/test_reference_ranges.py -v