A suite of FastAPI microservices that turn raw blood/lab biomarker reports into AI-generated clinical insights, follow-up questions, recommendations, and test suggestions.
LabLens Health Insights API is a collection of independently deployable FastAPI services that analyze comprehensive lab reports (100+ biomarkers) and produce structured, patient-friendly clinical output. Each service accepts a lab report (plus optional patient intake profile and follow-up answers) and uses large language models — OpenAI GPT-4o with a Google Gemini fallback — to generate functional-medicine style analysis.
A rule-based and statistical Dynamic Pattern Detector augments the LLM prompts by surfacing biomarker correlations, clinically meaningful ratios (e.g. Triglyceride/HDL, Cholesterol/HDL, BUN/Creatinine, Neutrophil/Lymphocyte), and emerging multi-system patterns before the report is sent to the model.
- Follow-up Questions API — Generates 5–10 contextual follow-up questions from a lab report, then produces multiple-choice answer options for each question via a two-step LLM process.
- Clinical Notes API — Produces comprehensive clinical notes split into Concerns & Conditions, Positive Findings, and a Summary, plus per-category summaries across nine health categories (longevity, metabolic, cardiovascular, hormonal, immune, nutritional, organ health, performance, preventive).
- Recommendations API — Generates personalized diet (include/exclude), activity, and supplement recommendations grounded in the lab data and clinician notes.
- Follow-up Tests API — Recommends additional lab tests for diagnostic clarification, monitoring, or confirmation of abnormalities.
- Dynamic Pattern Detector — Statistical correlation, ratio analysis, novel/borderline pattern detection, and an adaptive ML layer (RandomForest / IsolationForest / DBSCAN) with online confidence scoring.
- Resilient LLM layer — OpenAI primary with automatic Gemini fallback, rate limiting, and robust JSON parsing of model output.
- Abnormality & borderline detection — Flags high/low markers and biomarkers within 5% of reference-range limits.
- Language: Python 3.9
- API framework: FastAPI + Uvicorn
- Validation: Pydantic v1
- LLMs: OpenAI GPT-4o (
openai), Google Gemini (REST viarequests) - ML / analytics: scikit-learn, NumPy
- Config: python-dotenv
- Deployment: Render (multi-service
render.yaml)
cd 3api
pip install -r requirements.txtCreate a 3api/.env file (see the included placeholders):
OPENAI_API_KEY=your_openai_api_key_here
GEMINI_API_KEY=your_gemini_api_key_hereEach API runs as its own Uvicorn app:
cd 3api
uvicorn follow_up_api:app --reload --port 8001
uvicorn clinical_notes_api:app --reload --port 8003
uvicorn recommendations_api:app --reload --port 8004
uvicorn follow_up_tests_api:app --reload --port 8005Interactive API docs are available at http://localhost:<port>/docs for each service, and a /health endpoint reports LLM availability.
render.yaml defines four Render web services (one per API), each built with build.sh and supplied OPENAI_API_KEY / GEMINI_API_KEY as environment variables.
Usama Bin Ejaz — AI/ML Engineer | Data Scientist | Founder, UBE Labs
- GitHub: github.com/ube09
- Website: usamabinejaz.com