HEALTH
Diagnostics Summarizer: lab reports explained
Explains lab reports, with range bars drawn by code, not the model.
Mine: the consumer app (reading the PDF, the English and Hindi explanation, the Devanagari PDF); the clinic white-label (range bars placed by Python, a fixed 0-100 score that replaces the model's, the branded report); the Docker packaging of the clinic build (the first Diagnostics Summarizer Dockerfile was a teammate's)
Built with: Python, Gradio, Gemini 2.5 Flash, PyMuPDF, Playwright (PDF rendering), Plotly, Docker, Hugging Face Spaces
At a glance
- In the clinic build, the range bars and the 0-100 score are computed in Python, never by the model.
- Explains a report in plain Hindi or English, with a Devanagari PDF (consumer app).
- The model still labels each marker High, Low or Borderline; no code re-checks it.
The problem
A lab report is dense. One page can hold thirty results, each with a unit and a reference interval printed beside it. Most readers want two things: which numbers fall outside their range, and what those numbers mean, in a language they read comfortably. A language model is good at the second part. It writes plain explanations in Hindi or English without effort. It is less trustworthy with the first part, because it can misread a value, invent a range or score the whole report by its own sense of severity. On a medical document those are the parts a reader most needs to trust, so I wanted them to come from code.
What I built
Medical disclaimer
Diagnostics Summarizer takes a lab report PDF, pulls out the text with PyMuPDF and sends it to Gemini 2.5 Flash. The consumer app asks for a plain written explanation. The business and clinic builds ask for structured JSON instead: for each out-of-range marker the model returns the value, the printed range and a label. In its fullest form, the clinic build, the printed report has a plain overview, the flagged markers and questions to take to a doctor.
It exists in three versions. The consumer app explains a report in Hindi or English and prints a Devanagari PDF, but it has no range bars and no score. The business report from March 2026 places the range bars in Python, but the model still sets the score. The clinic build from May 2026, a white-label for diagnostic clinics, also computes the score in code, and it writes English only.
Solid: rules · Dashed fence: model · Diamond: gate · Cyan: data
How it flows
- Mar 2026, consumer app: explains a report in Hindi or English. The model writes everything; there are no range bars and no score.
- Mar 2026, business report: the range bars move from the model to Python. The model still sets the score.
- May 2026, a white-label for diagnostic clinics: the score moves to Python too. It writes English only.
In that clinic build, range-bar positions and the 0-100 score are computed in Python, never by the model.[1] Each pin goes where the value falls against the printed range. The score starts at 100 and loses fixed points for each flagged marker, and it replaces whatever score the model returned.
Solid: rules · Dashed fence: model · Diamond: gate · Cyan: data
How it flows
- PyMuPDF pulls the text out of the report PDF.
- The model returns JSON with each out-of-range marker's value, its printed range and a High, Low or Borderline label. A prompt rule tells it to judge only against the printed range; no code re-checks the label.
- Python sets the 0-100 score from those labels and writes over the score the model returned.
- Python places each pin from the value and the printed range. The normal band always sits in the middle of the track.
- Headless Chromium prints the report to PDF.
Key decisions
Each decision moved one judgement from the model into code, or tied the model to the page the reader holds.
Range bars placed by Python, not by the model
- Alternative rejected
- Asking the model for each pin's position on a 0-100 track, as the first business build did
- Why
- Arithmetic on the printed numbers is exact and gives the same answer every time, and it needs no extra model output. I moved it to Python the same day, in a commit titled Latency Control Code; the code calls it an engine for instant plots.
A fixed score rubric that replaces the model's
- Alternative rejected
- Letting the model judge clinical severity and pick a holistic 0-100 score, as all three business builds did
- Why
- A judged score cannot be checked by the reader. The rubric takes 5 points off for each High or Low and 2 for each Borderline, so the same labels always give the same score, and anyone can recompute it by hand.
Flag a marker only against the report's own printed range
- Alternative rejected
- Letting the model use general medical knowledge or a lab's commentary to decide what counts as abnormal
- Why
- Labs print their own reference intervals, and these differ between labs and methods. Holding the model to the printed range keeps every label tied to the sheet in the reader's hand. It is a prompt rule, not a code check.
The third decision is the weakest of the three, and I say so under the limitations below.
How it was proven
Neither repository has a test suite or an evaluation set, so this page makes no accuracy claim. What I can show is where each rule lives, and what the real code does with input whose answer is known.
The receipts name both functions, the file, the lines and the commit, and describe what each one does without copying the source.[1] A second receipt sets out which version computes the bars, the score and the labels.[2]
For the pair below I wrote a synthetic example. It is a dense report with 29 invented results, plus the JSON a model would return for it, with eight markers out of range. I then ran the clinic build’s own scoring, bar and template code on that JSON, with no model call. The PDF was printed with the same page settings the app uses.
Both images are a synthetic example, with no real patient, lab or clinic. The JSON carried a score of 74, standing in for a model’s own judgement. The rubric replaced it with 69: five High or Low labels at 5 points each, and three Borderline labels at 2. Each pin sits where its value falls against the printed range, which you can check against the dense report in the first image. Haemoglobin at 11.2 against 12.0 to 15.0 sits just left of the green band, for example.
Outcomes
Three working versions came out of about two months, between 15 Mar and 18 May 2026. The consumer app explains a report in plain Hindi or English. The business report adds range bars that no longer depend on the model’s arithmetic. The clinic build adds a score anyone can recompute and white-label settings for a clinic’s name, colour and logo.
The consumer app also runs as a public demo on Hugging Face Spaces. It sleeps when idle and wakes on a visit, and it is not linked from this page. That demo is the consumer version, so it shows the plain explanation, not the range bars or the score.
I make no claim that a clinic runs the white-label build. It is ready to brand and deploy, and that is all this page says about it.
Limitations and what I’d change
- The model labels each marker High, Low or Borderline, and no code re-checks that label against the printed range, although the pin colour and the score both read it. I would recompute the label in Python from the parsed value and range, and flag any disagreement.
- The bars use the model’s transcription of each value and range, not the PDF text itself. A range the code cannot read puts the pin in the middle of the normal band. I would parse the numbers from the extracted text and show that a range was not read instead of guessing.
- There is no evaluation set, and the clinic build writes English only. I would build a set of synthetic reports with known answers before claiming anything about accuracy, and bring the Hindi output to the clinic template.
Credits and permissions
Origin
My own project. Of the 13 commits in the Diagnostics Summarizer repository, one is a teammate’s: the first Dockerfile, added in March 2026. The teammate stays unnamed. Both clinic-build commits are mine. Every report on this page is synthetic: invented values, with no real patient, lab or clinic shown.
Links and sources
- Rules receipt: the two functions in the clinic build (app.py at 4f7726a), checked 26 Nov 2026
- Versions receipt: which build computes what, checked 26 Nov 2026