How aka-sa/medilens works
1. Purpose and Repository Reality
MediLens is specified as a local AI prescription-analysis workflow for Indian handwritten/printed prescriptions: image input becomes structured medication JSON, then patient-facing safety guidance. The checked-in repository is presently documentation/artifact-only; no application, model, validator, UI, dataset, or dependency source paths appear in the tree. Primary available artifacts are README.md and p3/output.json.
2. Intended Entry Points
• The documented user entry point is a Streamlit prescription-image upload interface, but its implementation is not present.
• The intended programmatic inference entry point uses Hugging Face Transformers with Qwen2VLForConditionalGeneration, AutoProcessor, and qwen_vl_utils.
• p3/output.json is the only structured runtime-like artifact available and likely represents a generated or expected output sample.
• README.md is the authoritative design specification in this checkout.
3. Image-to-Structure Inference Stage
The core intended stage accepts a prescription image and constructs a multimodal chat request asking Qwen2-VL to extract JSON. Qwen2-VL’s vision encoder, vision-language fusion, and language decoder are responsible for handwriting/OCR interpretation, abbreviation expansion, and schema-like extraction.
Expected boundary: raw, sensitive prescription image → generated text/JSON. The model is intended to be loaded from a local fine-tuned model directory, supporting privacy-oriented local processing. Grounding artifacts: README.md, p3/output.json.
4. Fine-Tuned Model Asset
The architecture centers on Qwen/Qwen2-VL-2B-Instruct, fine-tuned using LoRA on 100+ image-to-structured-JSON prescription pairs. The base/fine-tuned model and LoRA adapters are described but absent from this repository, so deployment requires separately provisioned model weights and processor assets.
Material runtime: Python, PyTorch, Transformers, Qwen VL utility package; optional bitsandbytes 4-bit quantization. GPU acceleration is expected but CPU inference is supported. Grounding path: README.md.
5. Structured Prescription Contract
Model output is intended to carry patient demographics, prescription date, clinician/clinic, and an ordered medication list. Each medication captures normalized and brand/generic identities, form/strength, frequency pattern plus human-readable timing, duration, and instructions.
This JSON contract is the critical handoff between probabilistic model inference and deterministic downstream safety/display layers. Parsing and schema validation are architecturally necessary because generated model text must be converted into reliable structured data. Grounding artifacts: p3/output.json, README.md.
6. Safety Validation Boundary
A Python safety validator is intended to consume extracted medications and produce warnings for drug interactions, allergies, and age/dosage constraints. It relies on a local interaction database described as covering 500+ common interactions, with severity levels from low to critical.
Inputs beyond prescription extraction include a user allergy profile and patient age. The validator is a high-risk boundary: uncertain model extraction must be surfaced alongside safety results and remain subject to pharmacist/clinician verification. No validator/database implementation is checked in. Grounding path: README.md.
7. Presentation and External Dependencies
The planned Streamlit UI transforms normalized medications into patient-friendly cards and visible safety warnings. It is not a network service in the documented current design: processing, model execution, and sensitive images are intended to remain local, with images not retained permanently.
External dependencies are model assets from Hugging Face/Qwen and Python ML libraries; the documented future API, mobile app, pharmacy integration, and dashboards are roadmap items rather than current repository components. Grounding path: README.md.
Main entry points: output.json Normalized prescription · README.md Architecture specification
Components 16
Checked-in artifacts
This checkout contains design documentation and a sample output only.
- Architecture specification · Authoritative description of the intended workflow.
README.md - Sample prescription JSON · Only structured runtime-like artifact in the checkout.
p3/output.json
Intended local workflow
Planned components are not implemented in this repository.
- Prescription upload UI · Planned local image-upload entry point.
- Prescription image · Handwritten or printed prescription image.
- Multimodal extraction request · Requests structured medication JSON from the image.
- Generated model text · Probabilistic extraction output before parsing.
- JSON parsing & schema validation · Converts generated text into reliable prescription data.
- Normalized prescription · Patient, clinician, date, and ordered medication details.
p3/output.json - Patient guidance cards · Medication instructions and visible warnings for review.
Model runtime
Separately provisioned local model assets.
- Qwen2-VL inference · Vision, fusion, and language decoding interpret prescriptions.
- Fine-tuned Qwen + LoRA · Separately provisioned Qwen2-VL weights, adapters, and processor.
- Python ML stack · Uses Transformers, PyTorch, qwen_vl_utils, and optional 4-bit quantization.
Safety boundary
Deterministic checks require clinician or pharmacist verification.
- Allergy profile & age · Additional inputs for safety checks.
- Safety validator · Planned interaction, allergy, and age/dosage checks.
- Interaction database · Planned local database of common interactions and severity.
- Pharmacist / clinician review · Required verification for uncertain extraction and safety results.
Connections 18
- Architecture specification → Prescription upload UI: specifies
- Architecture specification → Qwen2-VL inference: specifies
- Architecture specification → Safety validator: specifies
- Sample prescription JSON → Normalized prescription: illustrates contract
- Prescription upload UI → Prescription image: accepts
- Prescription image → Multimodal extraction request: attached to
- Multimodal extraction request → Qwen2-VL inference: runs locally
- Fine-tuned Qwen + LoRA → Qwen2-VL inference: loaded by
- Python ML stack → Qwen2-VL inference: supports
- Qwen2-VL inference → Generated model text: generates
- Generated model text → JSON parsing & schema validation: parsed and validated
- JSON parsing & schema validation → Normalized prescription: produces
- Normalized prescription → Safety validator: medications
- Allergy profile & age → Safety validator: patient context
- Interaction database → Safety validator: interaction rules
- Normalized prescription → Patient guidance cards: medication details
- Safety validator → Patient guidance cards: warnings
- Patient guidance cards → Pharmacist / clinician review: requires verification