Demo video: https://youtu.be/eC4Pf11Z2jo · Live app: https://med-voice-afia.onrender.com/elder/FJ8uBWhh2cVQ5CTUUyPK2Q · 1-page pitch: PITCH.md
Her prescription is in English. She only understands Kannada.
Gnani.ai Great Indian AI Internship Challenge, solo entry. Built on Gnani Prisma (speech-to-text) and Timbre (text-to-speech).
Many elders in Karnataka manage several tablets from a prescription written in English. They can't read it, so they rely on memory or wait for a family member to explain: when to take which tablet, before or after food, how many days are left. A wrong guess here is a real risk.
- The elder presses one big button and asks in spoken Kannada: "ಹಳದಿ ಮಾತ್ರೆ ಯಾವಾಗ ತಗೋಬೇಕು?" and hears the answer, with the tablet's photo on screen.
- The caregiver sets the prescription up once and confirms every field, then sees every question the elder asked in a log.
- It never invents medical advice. Answers come only from confirmed data, through fixed Kannada sentences. Anything else goes to "ask your doctor".
- Emergencies come first. Words like chest pain show a red screen with one-tap 108.
- Elder page (press the button and ask in Kannada): https://med-voice-afia.onrender.com/elder/FJ8uBWhh2cVQ5CTUUyPK2Q
- Caregiver page (set up your own elder): https://med-voice-afia.onrender.com/
- Question log of the demo elder: https://med-voice-afia.onrender.com/log/1
Things to try on the elder page: "ಇವತ್ತು ಯಾವ ಮಾತ್ರೆ ತಗೋಬೇಕು?" (today's list), "ಹಳದಿ ಮಾತ್ರೆ ಯಾವಾಗ ತಗೋಬೇಕು?", then "ಎಷ್ಟು ತಗೋಬೇಕು?" (it remembers the tablet), "ಕಿತ್ತಳೆ ಮಾತ್ರೆ ಯಾವಾಗ?" (not confirmed, so it refers you to the doctor), and "ಎದೆ ನೋವು ಆಗ್ತಿದೆ" (emergency screen).
Tips: hold the phone close, wait a second after pressing, then ask one question slowly and clearly in a quiet room.
The free server sleeps when idle, so the first request can take up to a minute.
Real voice clips, transcribed by Gnani Prisma and scored with scripts/batch_test.py against expected outcomes:
| Run | Score | Emergencies caught |
|---|---|---|
| First run on 38 clips, before any fixes | 25/38 (66%) | 8/8 |
| Same 38 clips after fixing the general bugs they revealed | 37/38 (97%) | 8/8 |
| 12 new clips, written and recorded after the fixes | 12/12 | 2/2 |
- The one miss was a whispered clip. Prisma heard nothing, and the app safely asked the elder to repeat.
- Fixes were general rules (for example, matching a tablet by a word only its label has, or understanding English describing words), not memorised test sentences.
- Prisma's transcripts kept the meaning in 37 of the first 38 clips; the first-run failures were in our own matching.
- Honest limits: one speaker so far (the author), and no phone-line (8 kHz) test yet. Later safety-review changes were re-checked on the 12 unseen sentences as text, not re-recorded.
- 140 automated tests (
cd backend ; python -m pytest -q).
- Emergency check runs first: phrases, word pairs (e.g. chest + pain) and fuzzy matching. The result is a red screen with one-tap 108, and a 108 button is always visible.
- Confirmed tablets only. The elder never hears about a tablet the caregiver hasn't checked.
- No AI-written medical text. Every answer is a fixed Kannada template filled with the caregiver's data.
- Never guesses. Two matching tablets → "which one?". Unclear question → one ask-back, then "ask your doctor". Unconfirmed tablet, unknown colour, dose change, missed or doubled dose → "ask your doctor".
- Follow-ups: a short question right after an answer ("ಎಷ್ಟು ತಗೋಬೇಕು?") keeps the same tablet for 5 minutes, and every answer starts by naming the tablet. "The other tablet" is never answered with the last one; the app asks which.
flowchart LR
subgraph Phone["Elder's phone (browser)"]
E["Elder page<br/>one button · ಕನ್ನಡ / English"]
end
subgraph Family["Caregiver's browser"]
C["Caregiver page<br/>tablets · photos · day plan"]
L["Question log"]
end
subgraph Render["Render: one Docker service (FastAPI + built React app)"]
API["REST API"]
P["Answer pipeline<br/>safety → intent → matching → template"]
end
DB[("Supabase Postgres<br/>profiles · medicines · question log")]
STT["Gnani Prisma<br/>speech → Kannada text"]
TTS["Gnani Timbre<br/>Kannada text → speech"]
E -- "16 kHz WAV" --> API
C -- "add / confirm / photo" --> API
L --> API
API --> P
P -- "audio + keyterms" --> STT
P -- "fixed Kannada sentence" --> TTS
API <--> DB
API -- "answer text + voice + tablet photos" --> E
- One service, one origin: the API and the React app are served together over HTTPS, which the browser microphone requires.
- The data lives in Supabase, not in the container, so it survives redeploys. A GitHub Actions job pings
/api/health/dbto keep the free server awake. - Voice is never stored. Only the transcript, the outcome and the answer go into the caregiver's log.
sequenceDiagram
actor Elder
participant UI as Elder page
participant API as FastAPI /ask
participant Prisma as Gnani Prisma
participant D as decide()
participant Timbre as Gnani Timbre
participant DB as Postgres
Elder->>UI: press button, speak
UI->>UI: record, convert to 16 kHz mono WAV
UI->>API: POST /api/elder/{token}/ask (audio)
API->>DB: confirmed tablets + last question
API->>Prisma: audio + keyterms (the elder's own tablet words)
Prisma-->>API: Kannada transcript
API->>D: transcript, tablets, last question
D-->>API: outcome + template + fields (+ tablets named)
API->>Timbre: filled Kannada sentence
Timbre-->>API: speech (WAV)
API->>DB: log question, outcome, answer
API-->>UI: text (kn + en), voice, tablet photos
UI-->>Elder: shows the answer and plays it
backend/app/core/pipeline.py. It's a pure function with no network or database, so every rule is unit-tested. The first rule that applies wins:
| # | Check | Outcome |
|---|---|---|
| 1 | Emergency words / word pairs / fuzzy (safety.py) |
emergency: red screen, one-tap 108 |
| 2 | Asking to change, stop, skip or double a dose; missed dose | referral: "ask your doctor" |
| 3 | "Which tablets today / at night?" | answered: list built from confirmed tablets only; a symptom or nothing scheduled → referral |
| 4 | Two tablets match equally ("ಬಿಳಿ ಮಾತ್ರೆ" when two are white) | clarify_which: "which one?" with both photos |
| 5 | A colour no confirmed tablet has | referral |
| 6 | Follow-up within 5 minutes of the last answer (same tablet, unless "the other one") | carries the tablet or question forward |
| 7 | Only the tablet's name ("ಹಳದಿ ಮಾತ್ರೆ") | answered: short summary (when, food, dose) |
| 8 | Tablet known, question unclear | clarify_question once, then referral |
| 9 | Question known, tablet unknown | clarify_repeat: "say its colour or name" |
| 10 | Both known | answered from a fixed template, or referral if the caregiver left that field empty or the course is over |
| Module | Responsibility |
|---|---|
core/safety.py |
Emergency detection: spoken-Kannada phrases, word pairs, fuzzy match (a short transcript is never matched as a fragment of a longer phrase) |
core/intent.py |
Question type: CHANGE, SCHEDULE, DAYS_LEFT, FOOD, WHEN, HOW_MANY, PURPOSE, by keyword priority, then fuzzy |
core/matching.py |
Which tablet: generic words removed, English describing words translated, a word only one label has, a colour tie-break, unconfirmed colours flagged |
core/answers.py + templates/kn.json, en.json |
Fill fixed sentences; a missing placeholder raises an error instead of inventing text |
core/pipeline.py |
decide() (rules) + run() (Prisma → decide → Timbre → log) |
audio.py, gnani/stt.py, gnani/tts.py |
Audio format checks, Prisma with keyterms (retries without them if rejected), Timbre |
main.py |
REST routes, health checks, serving the React build |
erDiagram
PROFILE ||--o{ MEDICINE : has
PROFILE ||--o{ QUESTION_LOG : records
MEDICINE |o--o{ QUESTION_LOG : "is about"
PROFILE {
int id
string elder_name
string language
string share_token "private elder link"
}
MEDICINE {
int id
string label "how the elder says it"
string name "on the prescription"
string color_word
string dose
list times "morning / afternoon / night"
string food "before / after / any"
int days_total
date start_date
string purpose "only if written"
string photo_path "shrunk JPEG"
bool confirmed "hidden from the elder until true"
}
QUESTION_LOG {
int id
datetime created_at
string transcript
string intent
string outcome
string answer_text
}
| Method | Route | Used by |
|---|---|---|
| POST / GET / PATCH | /api/profiles, /api/profiles/{id} |
Caregiver: create, view, rename the elder |
| POST / PUT / DELETE | /api/profiles/{id}/medicines, /api/medicines/{id} |
Caregiver: add, edit, remove tablets |
| POST | /api/medicines/{id}/confirm |
Caregiver: confirm a tablet |
| GET | /api/profiles/{id}/log |
Caregiver: question log |
| GET | /api/elder/{token} |
Elder page: confirmed tablets only |
| POST | /api/elder/{token}/ask |
Elder: audio in → answer, voice, photos out |
| GET | /api/health, /api/health/db |
Render health check, keep-alive |
| Model | Used for | Settings |
|---|---|---|
Prisma speech-to-text (/stt/v3) |
The elder's spoken question | prisma-v3.0, kn-IN, format=codemix; the elder's own medicine words are sent as keyterms (falls back to no keyterms on INVALID_CONTEXT) |
Timbre text-to-speech (/api/v1/tts/inference) |
Speaking every answer | timbre-v2.5, voice Saanvi, kn-IN, speed 0.9 |
- Solo, in about a week, with two AI assistants:
- Claude: product and safety design, the task specs, all Kannada text (spoken style), the core matching and safety logic, test design, code review, and UI.
- Freebuff (DeepSeek): bulk coding from those specs, one task at a time (T0–T9).
- The task specs are kept in
docs/build/;docs/LEARN.mdhas my notes on each step. - Workflow: spec → Freebuff implements → Claude reviews → tests → real-voice batch test → fix general bugs → re-test on unseen clips. A separate review pass (Claude Fable) looked only for wrong medical answers and missed emergencies.
- Stack: FastAPI + SQLModel, React + TypeScript (Vite, Tailwind), a single Docker service on Render, Supabase Postgres (Singapore), and a GitHub Actions keep-alive. The browser records 16 kHz WAV itself, so no audio conversion is needed on the user's side.
| Part | What it does |
|---|---|
backend/app/main.py |
FastAPI routes (profiles, medicines, elder view, /ask, health) and serving of the built frontend |
backend/app/core/ |
The answer flow: safety → intent → medicine matching → template answers |
backend/app/gnani/ |
Prisma and Timbre wrappers, with a mock mode for working without credits |
frontend/src/pages/ |
Caregiver setup, caregiver question log, elder voice page |
scripts/batch_test.py |
Runs a folder of recorded clips through /ask and scores them against test_audio/expected.csv |
scripts/to_8khz.sh |
Downsamples a folder of clips to 8 kHz mono WAV (phone quality) |
Dockerfile |
Multi-stage build: Node builds the frontend, Python + ffmpeg serves API and UI |
Requirements: Python 3.11+ and Node 20+. (ffmpeg is only used inside the Docker image.)
# 1. environment (never commit .env)
cp .env.example .env # then fill in the values below
# 2. backend
python -m venv venv
venv/Scripts/python.exe -m pip install -r backend/requirements.txt # Windows
# source venv/bin/activate && pip install -r backend/requirements.txt # macOS/Linux
cd backend
python seed.py # prints the profile id, share token and elder link
uvicorn app.main:app --reload # http://127.0.0.1:8000# 3. frontend, in a second terminal
cd frontend
npm install
npm run dev # http://localhost:5173, /api proxied to :8000Open http://localhost:5173, add and confirm a medicine, then open the
elder link it shows. Press the big button, ask, listen.
cd frontend && npm run build # writes frontend/dist
cd ../backend && uvicorn app.main:appNow http://127.0.0.1:8000 serves the app itself, and refreshing
/elder/<token> still works (unknown non-API paths return index.html).
Copy .env.example to .env. Nothing secret belongs in a tracked file.
| Name | Required | What it is |
|---|---|---|
GNANI_API_KEY |
yes, when MOCK_GNANI=false |
Gnani API key. Read only from the environment, never printed or logged |
GNANI_BASE_URL |
yes, when MOCK_GNANI=false |
Gnani API base URL (e.g. https://api.vachana.ai) |
MOCK_GNANI |
no (default true) |
true returns a fixed transcript and silent audio, so the app runs without spending credits. Must be false when deployed |
DATABASE_URL |
no (default sqlite:///./app.db) |
sqlite:///./app.db locally, postgresql+psycopg://... in production |
GNANI_STT_MODEL, GNANI_STT_FORMAT, GNANI_STT_KEYTERMS |
no | Prisma model (prisma-v3.0), input format (codemix), and whether to bias recognition with the medicine words |
GNANI_TTS_MODEL, GNANI_TTS_VOICE, GNANI_TTS_SPEED |
no | Timbre model (timbre-v2.5), voice (Saanvi), speaking speed (0.9) |
PORT |
set by the host | Uvicorn port in the container (Render sets it) |
The database code is identical for SQLite and Postgres — only DATABASE_URL
changes, and tables are created on startup in both cases.
cd backend
python -m pytest # core logic, routes, Gnani wrappers (mock mode)cd frontend
npm run lint
npm run buildscripts/batch_test.py sends every clip listed in test_audio/expected.csv
through /ask and writes test_audio/results.csv with the transcript, outcome,
matched tablet label and pass/fail, then prints overall accuracy, emergency
recall and per-outcome counts.
# server running in another terminal, with MOCK_GNANI=false and the key in .env
python scripts/batch_test.py --profile-id <id printed by seed.py>Each clip is asked on its own throwaway profile (cloned from the seeded
profile's confirmed medicines), so one question can never be treated as a
follow-up of the previous one. Useful flags: --limit 3, --out path.csv,
--base-url, --timeout. To try the plumbing without credits, add
--allow-mock with MOCK_GNANI=true.
Clips in other formats can be normalised first (needs ffmpeg):
bash scripts/to_8khz.sh test_audio test_audio_8khzOne Docker web service serving API and UI from the same HTTPS origin (the microphone requires a secure origin, so a single origin is the simple choice). Database: a free Supabase Postgres project.
-
Supabase → New project (free tier). Choose a region near you and save the database password somewhere safe.
-
In the project, open Connect (or Project Settings → Database) and copy the Session pooler connection string. It looks like
postgresql://postgres.<ref>:<password>@aws-0-<region>.pooler.supabase.com:5432/postgres. -
Change the prefix to the Psycopg form the app expects:
postgresql+psycopg://postgres.<ref>:<password>@aws-0-<region>.pooler.supabase.com:5432/postgres. If the password contains@,:,/or#, percent-encode it. -
Render → New → Web Service → connect the GitHub repo.
- Language/runtime: Docker (Render finds the
Dockerfileat the repo root). - Instance type: free.
- Health check path:
/api/health/db.
- Language/runtime: Docker (Render finds the
-
Add environment variables in Render (Environment tab):
DATABASE_URL= thepostgresql+psycopg://...string from step 3GNANI_API_KEY= your Gnani keyGNANI_BASE_URL= your Gnani base URLMOCK_GNANI=false
-
Deploy. First build takes a few minutes (Node build + Python install + ffmpeg).
-
Check
https://<service>.onrender.com/api/health→{"ok": true}and/api/health/db→{"ok": true}. Tables are created on the first startup. -
Seed the deployed database once, from your machine, pointing at the same Postgres URL:
DATABASE_URL="postgresql+psycopg://..." python backend/seed.pyThen add real medicines through the caregiver page and open the elder link on a phone.
Free tier sleeps: an idle service spins down after a few minutes, and the next request takes ~30–60 seconds. Open the URL a minute before any demo, then refresh. The keep-alive workflow below pings the service so it stays awake — see Keep-alive.
Data survives redeploys because it lives in Supabase, not in the container — the container's filesystem is thrown away on every deploy.
.github/workflows/keepalive.yml calls GET <APP_URL>/api/health/db every 10
minutes (and on demand), retries once after 30 seconds, and fails the run if the
endpoint does not answer 2xx. That keeps the free Render instance from falling
asleep and doubles as an uptime check on the database.
The workflow never contains the URL. It reads the repository variable
APP_URL, so each fork or deployment points at its own service:
- GitHub repo → Settings → Secrets and variables → Actions.
- Open the Variables tab → New repository variable.
- Name
APP_URL, value your service URL with no trailing slash, e.g.https://my-app.onrender.com. - Actions → Keep-alive → Run workflow to test it manually. The run
log should print
OK: HTTP 200and{"ok":true}.
If APP_URL is not set, the job skips with a notice instead of failing, so a
fresh clone is never red. Nothing secret is involved — the URL is public — which
is why it is a variable and not a secret. GitHub's scheduled runs can be delayed
by a few minutes at busy times, which is fine for a keep-alive.
- Demo data is synthetic. Voice recordings are not stored; only the text transcript is logged, for the caregiver.
- Secrets live only in the host's environment variables, and the database's public Data API is switched off.
- Before real use: consent from the elder and caregiver, data kept in India, deletion on request, and access control, in line with India's DPDP Act 2023.
- Tested with one speaker; next is more voices and ages, plus phone-line audio.
- No login yet. The caregiver pages are open to anyone with the link, which is fine for a demo with synthetic data but not for real use.
- With only one confirmed tablet, any question is taken to be about that tablet.
- "ಎಲ್ಲಾ ಮಾತ್ರೆ ತಗೊಂಡೆ" ("I took all the tablets") deliberately counts as an emergency: a false alarm is safer than a missed overdose.
- Next: phone-call access for feature phones, more Indian languages, reminders, and a pharmacist review of the Kannada templates.