Skip to content

Kakarot35/RxSense-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RxSense AI 🩺

AI-powered medical prescription explainer β€” decode any prescription into plain English, detect drug interactions, and listen to your medication instructions.


What it does

Medical prescriptions are written in clinical shorthand most patients can't read. RxSense AI accepts a prescription image or text, extracts drug entities using NLP, retrieves verified medical information via a RAG pipeline, and generates a plain-language explanation covering dosage, side effects, and warnings β€” with audio playback and PDF export.

WHO estimates 237 million medication errors occur annually. RxSense AI is built to reduce that gap between clinical communication and patient understanding.


Demo

Input:  "Amoxicillin 500mg twice daily for 7 days"

Output: {
  "drug": "amoxicillin",
  "dosage": "500mg",
  "frequency": "twice daily",
  "explanation": "You have been prescribed Amoxicillin, an antibiotic used to
                  treat bacterial infections. Take one 500mg capsule twice a day β€”
                  once in the morning and once in the evening β€” for 7 days.
                  Common side effects include nausea, diarrhoea, and skin rash.
                  Always complete the full course even if you feel better.
                  Always follow your doctor's specific instructions.",
  "confidence": 0.87,
  "sources": ["MedlinePlus"]
}

System architecture

User Input (image / text)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L1 β€” Input     β”‚  OpenCV preprocessing β†’ Tesseract OCR (printed)
β”‚                 β”‚  TrOCR (handwritten) β†’ raw text
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L2 β€” Extract   β”‚  spaCy NER β†’ DRUG Β· DOSAGE Β· FREQUENCY Β· ROUTE
β”‚                 β”‚  Latin abbreviation expansion (b.d. β†’ twice daily)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L3 β€” Retrieve  β”‚  PubMedBERT embeddings β†’ FAISS HNSW index
β”‚                 β”‚  Top-5 chunks from MedlinePlus / FDA knowledge base
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L4 β€” Generate  β”‚  Gemini LLM (RAG-grounded, temp=0)
β”‚                 β”‚  Confidence threshold β†’ safe fallback if score < 0.65
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L5 β€” Output    β”‚  JSON Β· PDF (ReportLab) Β· MP3 (gTTS) Β· React UI
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

Feature Status
Text prescription input βœ…
Image prescription input (printed) βœ…
Handwritten prescription (TrOCR) βœ…
Medical NER extraction βœ…
Latin abbreviation expansion βœ…
RAG-grounded explanations βœ…
Drug interaction detection βœ…
Confidence thresholding + safe fallback βœ…
Async job queue (Celery + Redis) βœ…
Text-to-Speech audio output βœ…
PDF summary report export βœ…
React frontend with job polling βœ…
BioBERT NER model πŸ”œ Phase 3
JWT authentication πŸ”œ Phase 3
EHR / FHIR integration πŸ”œ Phase 3
Multilingual support πŸ”œ Phase 3

Tech stack

Backend

  • Python 3.11, FastAPI, Uvicorn
  • LangChain β€” RAG orchestration
  • FAISS β€” vector similarity search (HNSW index)
  • Google Gemini API β€” LLM generation
  • Celery + Redis β€” async task queue
  • PostgreSQL β€” audit logging
  • spaCy β€” NER and text processing
  • sentence-transformers β€” embeddings (all-MiniLM-L6-v2)

OCR

  • OpenCV β€” image preprocessing (deskew, binarise, denoise)
  • Tesseract 5 β€” printed text OCR
  • TrOCR (microsoft/trocr-base-handwritten) β€” handwritten OCR

Output

  • gTTS β€” Text-to-Speech MP3 generation
  • ReportLab β€” PDF report generation

Frontend

  • React + TypeScript (Vite)
  • Axios + custom polling hook

Infrastructure

  • Docker + Docker Compose
  • Redis (Celery broker + interaction cache)
  • PostgreSQL 16

Project structure

rxsense-ai/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                  # FastAPI entry point
β”‚   β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”‚   └── config.py            # pydantic-settings
β”‚   β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   β”‚   β”œβ”€β”€ prescriptions.py     # all prescription endpoints
β”‚   β”‚   β”‚   └── health.py
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ ocr.py               # OCR pipeline
β”‚   β”‚   β”‚   β”œβ”€β”€ ner.py               # NER extraction
β”‚   β”‚   β”‚   β”œβ”€β”€ ner_legacy.py        # rule-based fallback
β”‚   β”‚   β”‚   β”œβ”€β”€ rag.py               # RAG pipeline
β”‚   β”‚   β”‚   β”œβ”€β”€ interactions.py      # drug interaction checker
β”‚   β”‚   β”‚   β”œβ”€β”€ interactions_rules.py
β”‚   β”‚   β”‚   β”œβ”€β”€ tts.py               # text-to-speech
β”‚   β”‚   β”‚   └── pdf_export.py        # PDF generation
β”‚   β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”‚   └── faiss_store.py       # FAISS vector store
β”‚   β”‚   └── workers/
β”‚   β”‚       β”œβ”€β”€ celery_app.py        # Celery configuration
β”‚   β”‚       └── tasks.py             # async tasks
β”‚   β”œβ”€β”€ knowledge_base/
β”‚   β”‚   └── scripts/
β”‚   β”‚       └── ingest_medlineplus.py
β”‚   β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx
β”‚   β”‚   └── hooks/
β”‚   β”‚       └── usePrescription.ts
β”‚   └── package.json
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ .env.example
└── README.md

Getting started

Prerequisites

1. Clone and configure

git clone https://github.com/your-username/rxsense-ai.git
cd rxsense-ai

cp .env.example .env
# Edit .env β€” add your GOOGLE_API_KEY

2. Start infrastructure

docker compose up -d
# starts PostgreSQL + Redis

3. Install backend dependencies

cd backend
python -m venv .venv

# Windows
.venv\Scripts\activate.bat

# macOS / Linux
source .venv/bin/activate

pip install -r requirements.txt

4. Ingest knowledge base

python -m knowledge_base.scripts.ingest_medlineplus
# Ingests ~47 chunks for 12 drugs into FAISS index

5. Start services

# Terminal 1 β€” Celery worker
celery -A app.workers.celery_app worker --loglevel=info --concurrency=2 --pool=solo

# Terminal 2 β€” API server
uvicorn app.main:app --reload --port 8000

# Terminal 3 β€” Frontend
cd ../frontend
npm install
npm run dev

6. Open the app


API reference

Submit a prescription (async)

POST /api/v1/prescriptions/submit
Content-Type: application/json

{ "text": "Amoxicillin 500mg twice daily for 7 days" }
{ "job_id": "abc123", "status": "queued" }

Poll job status

GET /api/v1/prescriptions/jobs/{job_id}
{
  "job_id": "abc123",
  "status": "complete",
  "result": {
    "entities_found": 1,
    "drugs": [...],
    "interactions": [],
    "disclaimer": "..."
  }
}

Upload prescription image

POST /api/v1/prescriptions/image
Content-Type: multipart/form-data

file: <image file>
handwritten: false

Download PDF report

GET /api/v1/prescriptions/jobs/{job_id}/pdf

Health check

GET /api/v1/health

Environment variables

# Required
GOOGLE_API_KEY=AIza...

# Database
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/rxexplainer
REDIS_URL=redis://localhost:6379/0

# App
ENVIRONMENT=development
DEBUG=true
CHROMA_PERSIST_DIR=./chroma_db
LOG_LEVEL=INFO

# Optional
DRUGBANK_API_KEY=       # enables real interaction API (falls back to rules without it)
GOOGLE_TTS_KEY=         # enables WaveNet voices (falls back to gTTS without it)

How RAG prevents hallucinations

Standard LLMs generate medical information from training data β€” which may be outdated, incomplete, or simply wrong for specific drug formulations. RxSense AI uses Retrieval-Augmented Generation:

  1. Drug name is embedded and searched against the FAISS knowledge base
  2. Top-5 most semantically similar passages are retrieved
  3. Gemini is instructed to explain the drug using only the retrieved context
  4. If cosine similarity score < 0.65, the system returns a safe fallback instead of generating

Every output is traceable to a source document. The model cannot fabricate information it wasn't given.


Roadmap

  • JWT authentication + per-user rate limiting
  • Alembic database migrations + audit logging
  • BioBERT / scispaCy NER model (removes drug name whitelist)
  • DailyMed bulk ingestion (50,000+ drugs)
  • Docker production deployment (Railway / Render)
  • Prometheus + Grafana monitoring
  • Multilingual NER + TTS
  • EHR integration (HL7 FHIR)
  • AR prescription overlay (mobile)

Disclaimer

RxSense AI is a patient education tool only. It does not constitute medical advice, clinical decision support, or a substitute for pharmacist or physician consultation. Always follow your prescribing doctor's specific instructions.


License

MIT License β€” see LICENSE for details.


Built by Karan Β· 2026

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors