Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 MedClarify AI

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.

Python FastAPI React TypeScript Vite


Table of Contents


Features

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

Tech Stack

Backend

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

Frontend

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

Project Structure

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

Getting Started

Prerequisites

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-utils

macOS (Homebrew):

brew install tesseract poppler

Backend Setup

# 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

Frontend Setup

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 dev

Frontend runs at http://localhost:5173 by default.

The backend must be running before you use the frontend β€” the upload page calls POST /api/upload.


Environment Variables

backend/.env

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

frontend/.env

VITE_API_URL=http://localhost:8000
Variable Description
VITE_API_URL Base URL of the FastAPI backend

Never commit .env files with real values to version control.


API Reference

GET /

Health check.

{
  "status": "online",
  "service": "MedClarify AI",
  "version": "1.0.0"
}

POST /api/upload

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

How It Works

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

Running Tests

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

MedClarify AI β€” Helping patients understand their health, one report at a time.

About

Full-stack AI platform for intelligent pathology report analysis and medical data extraction.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages