Pycon Tanzania 2026

How We Built an Offline Patient Feedback System on a 14-Core CPU Using Python, Small Open-Source Models, and a Local Quantized LLM

PyCon Long Talk, 30 min Data, AI & ML Intermediate
Thursday 26 November 15:00 to 15:30 Main Hall, Binary Labs, Dar es Salaam

Hospitals get thousands of patient comments no one can read. Cloud LLMs are often blocked by privacy laws, poor connectivity and no GPU. At Aga Khan University Hospital Nairobi we built Lantern, which runs fully offline on a 14-core CPU. It uses small open models like RoBERTa and MiniLM for every comment and a local 4-bit Qwen3-8B only for uncertain cases. I will share Python patterns that made it work: caching, safe JSON parsing, checkpointing and fallbacks.

‎
‎What this talk is about:
‎
‎Most patient feedback in hospitals sits unread because reading thousands of free-text comments manually is impossible. Cloud LLMs would help, but in Kenyan hospitals you cannot send patient data to the cloud due to the Data Protection Act, you have no GPU, and internet is not guaranteed.
‎
‎At The Aga Khan University Hospital, Nairobi, we built Lantern, a patient feedback analytics platform that runs 100 percent on-premises on a 14-core CPU server with no internet at runtime.
‎
‎What I will cover:
‎
‎The constraint: Why we could not use cloud APIs and why we designed for CPU only.
‎Two kinds of models: How we split work between small encoder models for every comment (cardiffnlp twitter-roberta for sentiment, DistilRoBERTa for emotion, MiniLM for embeddings, spaCy for extraction) and a 4-bit quantized Qwen3-8B served locally via Ollama for only the hard cases, summaries, and staff Q and A using FAISS.
‎The core pattern: Encoder-first cascade plus batch pre-computation. The API never waits for an LLM.
‎7 real failures and fixes from production:
‎Fingerprint hashing to skip unchanged comments
‎Resumable ingestion with checkpointing
‎Split and retry when the LLM returns broken JSON
‎Stripping reasoning traces from Qwen3
‎Tuning Ollama context and threads for a 14-core server
‎Graceful fallbacks with VADER, TF-IDF and k-means when models fail
‎Packaging everything offline with locked wheels and model files
‎
‎What you will take away:
‎
‎You will leave with reusable Python patterns for running AI on modest hardware, a clear framework for picking the smallest model that does the job, code for safe LLM JSON parsing and caching, and a practical playbook for shipping offline AI that complies with privacy laws. This is useful for anyone building AI for healthcare, government, or any resource-constrained environment in Africa.
‎

#Python Core#AI