Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

audit: fix medical_prescription_digitizer - add env comment, rewrite em dashes, add module docstring, fix cd path, add demo

Tiioluwania8cfdbd90f47
diff --git a/OCR/medical_prescription_digitizer/.env.example b/OCR/medical_prescription_digitizer/.env.example
index b263636..a430094 100644
--- a/OCR/medical_prescription_digitizer/.env.example
+++ b/OCR/medical_prescription_digitizer/.env.example
@@ -1 +1,2 @@
+# Your Mistral API key. Get one for free at https://platform.mistral.ai
MISTRAL_API_KEY=your_mistral_api_key_here
diff --git a/OCR/medical_prescription_digitizer/README.md b/OCR/medical_prescription_digitizer/README.md
index dfe0cdd..ad992fe 100644
--- a/OCR/medical_prescription_digitizer/README.md
+++ b/OCR/medical_prescription_digitizer/README.md
@@ -2,9 +2,13 @@
> Extract, structure, and validate handwritten or printed prescriptions using Mistral Large 3 and RxNorm.
+## Demo
+
+![Demo](assets/demo.gif)
+
## Overview
-Upload a prescription image — handwritten or printed — and the app uses Mistral Large 3's vision capabilities to read and interpret it, including messy handwriting and medical abbreviations. Extracted drug names are then validated against the [RxNorm](https://rxnav.nlm.nih.gov/) drug database (free, no API key required). Validated drugs are highlighted in green; unrecognised or flagged ones appear in red.
+Upload a prescription image (handwritten or printed) and the app uses Mistral Large 3's vision capabilities to read and interpret it, including messy handwriting and medical abbreviations. Extracted drug names are then validated against the [RxNorm](https://rxnav.nlm.nih.gov/) drug database (free, no API key required). Validated drugs are highlighted in green; unrecognised or flagged ones appear in red.
## Features
@@ -28,13 +32,13 @@ Upload a prescription image — handwritten or printed — and the app uses Mist
## Prerequisites
- Python 3.10 or higher
-- A Mistral API key — get one at [platform.mistral.ai](https://platform.mistral.ai)
+- A Mistral API key. Get one at [platform.mistral.ai](https://platform.mistral.ai)
## Installation
```bash
git clone https://github.com/Sumanth077/Hands-On-AI-Engineering.git
-cd Hands-On-AI-Engineering/ocr/medical-prescription-digitizer
+cd Hands-On-AI-Engineering/OCR/medical_prescription_digitizer
```
**Windows**
@@ -74,9 +78,9 @@ Patient: John Smith Date: 04/18/2026
Dr. Sarah Lee, MD
Rx:
-1. Amoxicillin 500mg — TID x 7 days
-2. Ibuprofen 400mg — BID PRN pain
-3. [illegible] 10mg — QD
+1. Amoxicillin 500mg, TID x 7 days
+2. Ibuprofen 400mg, BID PRN pain
+3. [illegible] 10mg, QD
```
**Structured output:**
@@ -89,7 +93,7 @@ Date 04/18/2026
Medications
✅ Amoxicillin 500 mg · three times daily · 7 days [RxNorm ID: 723]
✅ Ibuprofen 400 mg · twice daily · as needed [RxNorm ID: 5640]
-⚠️ [illegible] 10 mg · once daily Drug name not found in RxNorm — possible misread
+⚠️ [illegible] 10 mg · once daily Drug name not found in RxNorm, possible misread
Illegible fields
• Medication 3 drug name unclear
@@ -105,10 +109,14 @@ Illegible fields
```text
medical-prescription-digitizer/
-├── app.py # Streamlit UI — upload, display, and orchestration
+├── app.py # Streamlit UI: upload, display, and orchestration
├── extractor.py # Sends image to Mistral Large 3 and returns a Prescription object
├── schemas.py # Pydantic models: Prescription and Medication
├── validator.py # Queries RxNorm API to validate each drug name
├── requirements.txt # Python dependencies
└── .env.example # Environment variable template
```
+
+---
+
+[Back to top](#medical-prescription-digitizer)
diff --git a/OCR/medical_prescription_digitizer/app.py b/OCR/medical_prescription_digitizer/app.py
index 3ea3aea..d96cc39 100644
--- a/OCR/medical_prescription_digitizer/app.py
+++ b/OCR/medical_prescription_digitizer/app.py
@@ -1,3 +1,4 @@
+"""Streamlit app that extracts and validates structured prescription data from uploaded images using Mistral Large 3 and RxNorm."""
import os
import io
@@ -43,16 +44,10 @@ st.caption("Upload a prescription image — handwritten or printed — to extrac
st.divider()
-# ── Sidebar: API key ──────────────────────────────────────────────────────────
+api_key = os.getenv("MISTRAL_API_KEY")
+
+# ── Sidebar ───────────────────────────────────────────────────────────────────
with st.sidebar:
- st.header("⚙️ Configuration")
- api_key = st.text_input(
- "Mistral API Key",
- value=os.getenv("MISTRAL_API_KEY", ""),
- type="password",
- help="Your Mistral API key. Store it in .env as MISTRAL_API_KEY to avoid re-entering.",
- )
- st.markdown("---")
st.markdown("**How it works**")
st.markdown(
"1. Upload a prescription image\n"
@@ -84,7 +79,7 @@ if uploaded_file:
st.subheader("Extraction & Validation")
if not api_key:
- st.error("Please enter your Mistral API key in the sidebar to proceed.")
+ st.error("MISTRAL_API_KEY not found. Add it to your .env file and restart the app.")
st.stop()
if st.button("🔍 Digitize Prescription", type="primary", use_container_width=True):
diff --git a/OCR/medical_prescription_digitizer/assets/demo.gif b/OCR/medical_prescription_digitizer/assets/demo.gif
new file mode 100644
index 0000000..01bb56a
Binary files /dev/null and b/OCR/medical_prescription_digitizer/assets/demo.gif differ