Skip to content

About

InfoMeds.AI: explainable-AI system that reads lab reports and handwritten prescriptions (OCR + fine-tuned Bio_ClinicalBERT) and explains results in plain language. FastAPI + React.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

InfoMeds.AI: Explainable AI Healthcare Management System

InfoMeds.AI helps patients understand their medical reports and prescriptions through Explainable AI (XAI). It reads uploaded lab reports and handwritten prescriptions with OCR, analyzes them with fine-tuned clinical transformer models, and explains the results in plain language. It also tracks a patient's health over time.

Core Features

1. Intelligent Report Analysis (XAI)

  • Input: Upload a medical report image (JPG/PNG).
  • OCR: EasyOCR for text detection and Microsoft TrOCR for handwriting, with GPT-4o Vision as an advanced pipeline for difficult handwritten documents.
  • NLP / Deep Learning:
    • BioBERT multi-task model (fine-tuned from Bio_ClinicalBERT): named-entity recognition and dosage tagging.
    • Hybrid lab classifier: labels each parameter High, Low or Normal.
    • LLM summary: a patient-friendly clinical summary. If the cloud AI is unavailable, a rule-based engine takes over.
  • Education: each parameter card explains what the biomarker is (e.g. "Neutrophils: soldiers against bacteria").

2. Prescription Scanner

  • Extracts the patient, date and medications (dosage, frequency, duration) from handwritten prescriptions.
  • Checks for dosage clashes and keeps a list of scanned prescriptions.
  • Medication Scheduler builds a daily schedule from the extracted medicines.

3. Longitudinal History & Record Mapping

  • Medical Archive: stores every report and lets you reopen any past analysis.
  • Trend analysis: compares new results with earlier ones (e.g. "Hemoglobin improved from 11.2 to 13.5").
  • Record mapping: links related reports and generates a correlation analysis across them.

4. Patient Dashboard, Chat & Reports

  • Personalized dashboard with a 0–100 Health Score based on the latest findings.
  • AI Chat Assistant that answers questions using the context of a report.
  • PDF export of analysis results.

Tech Stack

Layer Technologies
Frontend React 19 (Vite), Tailwind CSS + custom CSS
Backend FastAPI, Uvicorn, SQLite (patient_history.db)
Auth JWT (python-jose), bcrypt password hashing
AI / ML PyTorch, Hugging Face Transformers (Bio_ClinicalBERT), EasyOCR, TrOCR, OpenAI GPT-4o
Reports ReportLab (PDF)

Prerequisites

  • Python 3.11
  • Node.js v20.19+
  • An OpenAI API key, needed for GPT-4o OCR and summaries
  • Optional: an NVIDIA GPU with CUDA, for training

Setup

git clone https://github.com/kartz404/XAI_MedicalAnalysis.git
cd XAI_MedicalAnalysis

1. Backend

cd backend
python -m venv venv
venv\Scripts\activate          # Windows  (macOS/Linux: source venv/bin/activate)
pip install -r requirements.txt
copy .env.example .env         # macOS/Linux: cp .env.example .env

Edit backend/.env:

Variable Description
OPENAI_API_KEY Required. Used by the OCR and LLM services
GEMINI_API_KEY Optional. Reserved for the Gemini integration

.env is git-ignored. Never commit API keys.

2. Model weights (not in this repo)

The trained weights are about 430 MB each, over GitHub's 100 MB file limit. Get them from the project authors, or train them yourself (see below), and place them here:

backend/models/saved/biobert_multitask.pth
backend/models/saved/hybrid_lab_classifier.pth

3. Frontend

cd ../frontend
npm install

Running

Terminal 1: Backend

cd backend
venv\Scripts\activate
python -m uvicorn main:app --reload

API: http://127.0.0.1:8000. Interactive docs: http://127.0.0.1:8000/docs.

The first start takes a while because it loads BioBERT, EasyOCR and TrOCR.

Terminal 2: Frontend

cd frontend
npm run dev

Open http://localhost:5173, register an account and start uploading reports.

Training the Models (Optional)

cd backend
venv\Scripts\python.exe scripts/generate_data.py   # synthetic dataset with simulated OCR noise
venv\Scripts\python.exe scripts/train.py           # fine-tune BioBERT multi-task heads
venv\Scripts\python.exe scripts/train_hybrid.py    # train the hybrid lab classifier

API Overview

Method Endpoint Purpose
POST /register, /token Sign up / log in (JWT)
GET / PUT /users/me, /users/profile Profile
POST /analyze Analyze a lab report image
POST /scan-prescription Extract a handwritten prescription
GET /history, /reports/{id}, /prescriptions Archive
POST /chat Context-aware AI assistant
POST /generate-pdf Export results as PDF
POST / GET /map-records, /mapped-records, /mapped-records/{id}/generate-correlation Record mapping & correlation

The full schema is at /docs while the backend is running.

Project Structure

├── backend/
│   ├── main.py            # FastAPI app & routes
│   ├── database.py        # SQLite access
│   ├── models/            # BioBERT multi-task, hybrid classifier, LSTM definitions
│   ├── services/          # OCR, NLP, BioBERT, LSTM, LLM, auth services
│   ├── scripts/           # Data generation, training and API test scripts
│   ├── data/              # Synthetic training data
│   └── requirements.txt
├── frontend/
│   └── src/
│       ├── pages/         # Home, Analysis, Prescription Scanner, Mapping, Archive, Profile
│       └── components/    # Auth, Chat Assistant, Medication Scheduler, Navbar, UI kit
└── HOW_TO_RUN.md          # Step-by-step demo guide

Data & Privacy

Real patient documents and the local patient database are intentionally excluded from this repository (Dataset/ and *.db are git-ignored). Train only on synthetic or properly anonymized data.

Changelog

  • Security: Removed hard-coded OpenAI API keys from services/ocr_service.py and services/llm_service.py. Keys now come from OPENAI_API_KEY in backend/.env.
  • Dependencies: Added the missing openai, torch, transformers and python-dotenv to requirements.txt. The backend failed to start without openai.
  • Repository cleanup: History rewritten to remove patient data, the virtualenv, build output and large model weights. Added .gitignore and backend/.env.example.
  • Docs: The README now describes the real OCR/ML pipeline (EasyOCR, TrOCR, GPT-4o, BioBERT) and the current API.

About

InfoMeds.AI: explainable-AI system that reads lab reports and handwritten prescriptions (OCR + fine-tuned Bio_ClinicalBERT) and explains results in plain language. FastAPI + React.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages