AI-powered medical prescription explainer β decode any prescription into plain English, detect drug interactions, and listen to your medication instructions.
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.
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"]
}
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
βββββββββββββββββββ
| 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 |
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
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
- Python 3.11+
- Node 20+
- Docker Desktop
- Tesseract OCR 5.x (Windows installer)
- Google Gemini API key (free tier)
git clone https://github.com/your-username/rxsense-ai.git
cd rxsense-ai
cp .env.example .env
# Edit .env β add your GOOGLE_API_KEYdocker compose up -d
# starts PostgreSQL + Rediscd backend
python -m venv .venv
# Windows
.venv\Scripts\activate.bat
# macOS / Linux
source .venv/bin/activate
pip install -r requirements.txtpython -m knowledge_base.scripts.ingest_medlineplus
# Ingests ~47 chunks for 12 drugs into FAISS index# 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- Frontend: http://localhost:5173
- API docs: http://localhost:8000/docs
- Celery monitor: http://localhost:5555 (if Flower running)
POST /api/v1/prescriptions/submit
Content-Type: application/json
{ "text": "Amoxicillin 500mg twice daily for 7 days" }{ "job_id": "abc123", "status": "queued" }GET /api/v1/prescriptions/jobs/{job_id}{
"job_id": "abc123",
"status": "complete",
"result": {
"entities_found": 1,
"drugs": [...],
"interactions": [],
"disclaimer": "..."
}
}POST /api/v1/prescriptions/image
Content-Type: multipart/form-data
file: <image file>
handwritten: falseGET /api/v1/prescriptions/jobs/{job_id}/pdfGET /api/v1/health# 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)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:
- Drug name is embedded and searched against the FAISS knowledge base
- Top-5 most semantically similar passages are retrieved
- Gemini is instructed to explain the drug using only the retrieved context
- 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.
- 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)
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.
MIT License β see LICENSE for details.
Built by Karan Β· 2026