Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Swadhikaar (स्वाधिकार)

Built for the Great Indian AI Internship Challenge by Gnani.ai
Sovereign Indic Voice AI for Universal Healthcare, Emergency Operations & Generic Access


📌 Fast Links for Judges & Evaluators


Swadhikaar is an Indic voice-first care operations platform for proactive patient outreach, prescription literacy, hospital readiness (PM-JAY), triage, and longitudinal follow-up — powered by Gnani.ai Prisma v3.0 (STT) and Gnani.ai Timbre v3.0 (TTS).

The system combines:

  • Sovereign Indic speech intelligence (Gnani Prisma & Timbre across regional languages),
  • Realtime AI voice interactions over web kiosk & telephony,
  • Supabase-first backend architecture,
  • Ayushman Bharat Digital Mission (ABDM) FHIR R4 clinical compliance,
  • Role-based clinical operations dashboards with audit trails.

Scope

Swadhikaar models a citizen's complete care lifecycle — intake → understand → access → emergency → continuity — as one voice-first, bilingual platform. Core pillars:

  • Voice Walk-In Intake & Longitudinal Records: Hands-free kiosk case-taking and ABDM FHIR R4 clinical compliance.
  • Prescription Understanding & Generic Access: Optical character recognition → human verification gate → daily medication routine with Jan Aushadhi generic substitution (saving up to 88%), caregiver sharing, and adherence tracking.
  • PM-JAY Hospital Readiness: Location + care-need routing to empanelled hospitals (official NHA directory) with documentation checklists, voice assistance, and bed capacity intelligence.
  • Acute Emergency EMS (108 CAD): Real-time distress intake with automated SBAR clinical handoffs, AVPU neurological tracking, and biological CPR pacing.
  • Frontline Community Health (ASHA): Low-bandwidth offline screening portal for rural field health workers with local outbox synchronization.

Table of Contents

Overview

Swadhikaar focuses on operational reliability for health outreach programs:

  • automated follow-up and reminder calls,
  • multilingual patient interactions,
  • escalation-aware care workflows,
  • Supabase-backed state management and reporting.

Architecture

High-level flow:

  1. Frontend triggers workflows via Supabase Edge Functions.
  2. Edge Functions orchestrate call setup and domain operations.
  3. LiveKit worker handles live call interactions.
  4. Supabase stores all durable clinical and operational state.

Core principle: Supabase-first orchestration with a dedicated voice worker runtime.

Repository Structure

swadhikaar/
|- frontend/               # Next.js application (patient/doctor/admin experiences)
|- backend/                # Voice worker runtime + data seed scripts
|  `- voice_agent/         # LiveKit worker, prompts, and voice pipeline logic
|- supabase/
|  |- migrations/          # Database schema migrations
|  `- functions/           # Edge Functions for orchestration
`- dataset/                # Seed data CSVs

Tech Stack

  • Sovereign Speech Engine: Gnani.ai Prisma v3.0 (Indic-auto STT) & Gnani.ai Timbre v3.0 (Indic TTS)
  • Frontend: Next.js 16, React 19, TypeScript, Tailwind CSS, Lucide
  • Data + Auth + Realtime: Supabase (Postgres with RLS & Migrations)
  • Clinical Standards: ABDM FHIR R4 Bundle exports
  • Voice Runtime (Telephony): LiveKit Agents (Python) with Indic failover support
  • Reasoning / LLM: Google Gemini & Groq LLaMA-3.3-70B

Prerequisites

  • Node.js 20+
  • Python 3.11+
  • Supabase CLI
  • LiveKit Cloud project
  • Provider keys (as needed): Supabase, LiveKit, Google, Deepgram, Groq, optional TTS providers

Configuration

Frontend

Create frontend/.env.local:

NEXT_PUBLIC_SUPABASE_URL=https://<project-ref>.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=<anon-key>

Backend worker

Create backend/.env from backend/.env.example and fill values.

Required baseline:

SUPABASE_URL=https://<project-ref>.supabase.co
SUPABASE_SERVICE_ROLE_KEY=<service-role-key>
SUPABASE_KEY=<service-role-key>

LIVEKIT_URL=wss://<livekit-project>.livekit.cloud
LIVEKIT_API_KEY=<livekit-api-key>
LIVEKIT_API_SECRET=<livekit-api-secret>

# Sovereign Indic Voice Engine (Gnani.ai)
PRIMARY_STT_PROVIDER=gnani
FAST_TTS_PROVIDER=gnani
GNANI_API_KEY=<gnani-api-key>
GNANI_STT_MODEL=prisma-v3.0
GNANI_TTS_MODEL=timbre-v3.0

# Multi-tier Speech & LLM Fallbacks
GOOGLE_API_KEY=<google-api-key>
DEEPGRAM_API_KEY=<deepgram-api-key>
GROQ_API_KEY=<groq-api-key>
MURF_API_KEY=<murf-api-key>
SARVAM_API_KEY=<sarvam-api-key>

Supabase function secrets

Set function runtime secrets in Supabase:

supabase secrets set SUPABASE_URL="https://<project-ref>.supabase.co"
supabase secrets set SUPABASE_SERVICE_ROLE_KEY="<service-role-key>"
supabase secrets set LIVEKIT_URL="wss://<livekit-project>.livekit.cloud"
supabase secrets set LIVEKIT_API_KEY="<livekit-api-key>"
supabase secrets set LIVEKIT_API_SECRET="<livekit-api-secret>"
supabase secrets set SIP_TRUNK_ID="<sip-trunk-id>"

Getting Started

1) Install frontend dependencies

cd frontend
npm install

2) Install backend dependencies

pip install -r backend/requirements.txt

3) Link Supabase project and deploy functions

supabase link --project-ref <project-ref>
supabase functions deploy start-voice-call --no-verify-jwt
supabase functions deploy export-abdm --no-verify-jwt
supabase functions deploy triage-assess --no-verify-jwt
supabase functions deploy risk-predict --no-verify-jwt
supabase functions deploy incident-complete --no-verify-jwt

incident-complete authenticates with a shared secret instead of a JWT, so set it before deploying:

supabase secrets set ACUTE_INGRESS_SECRET=<random-32-bytes>

4) Run voice worker

# Local development — hot-reloads on file change.
python backend/voice_agent/agent.py dev

# Demos and anything that places real calls — no hot reload.
python backend/voice_agent/agent.py start

Use start for a demo. In dev mode the worker restarts when any file under the project changes, and a restart mid-call drops the call — including a call the place-due-recovery-calls cron placed a few seconds earlier.

5) Run frontend

cd frontend
npm run dev

Edge Functions

  • start-voice-call: room + SIP call orchestration
  • export-abdm: ABDM export reference generation
  • triage-assess: triage severity evaluation
  • risk-predict: risk scoring endpoint
  • incident-complete: acute → continuity seam. A completed emergency incident upserts a patient by ABHA ID (phone fallback), writes a FHIR Encounter (+ Condition when coded), and enrols the patient in the Post-Discharge Recovery protocol by scheduling Day 1/3/7/14/30 voice calls. Idempotent per incident — replaying a delivery resolves the same patient and adds no duplicate Encounter or call. Requires header x-acute-secret.

Local development

npx supabase start                       # Postgres + API + Studio in Docker
npx supabase functions serve incident-complete \
  --env-file supabase/functions/.env.local --no-verify-jwt

supabase/functions/.env.local holds ACUTE_INGRESS_SECRET and is gitignored.

Two checks, both runnable:

node supabase/functions/_shared/acute-seam.test.ts     # pure logic: schedule math, validation
docker exec -i supabase_db_swadhikaar psql -U postgres -d postgres \
  -v ON_ERROR_STOP=1 -f - < supabase/verify-seam.sql   # schema contract

The SQL check exists because both real defects found in this seam lived in index definitions, not in code, and no unit test could see them: a partial unique index cannot arbitrate ON CONFLICT, and fhir_resources had no uniqueness at all. It also asserts the API-role grants added in 003_api_role_grants.sql are present — without those every table returns permission denied, because current Supabase versions no longer grant DML on public by default and RLS policies cannot substitute for a missing GRANT.

Voice Pipeline

Swadhikaar runs a sovereign Indic-first voice intelligence pipeline:

  • Primary STT: Gnani.ai Prisma v3.0 (Sub-200ms Indic auto code-mixing Hinglish transcription)
  • Primary TTS: Gnani.ai Timbre v3.0 (Empathetic 24kHz vernacular voice synthesis with authentic currency & numeral cadence)
  • Primary LLM: Sovereign Indic Triage Engine (Evon v3.3 architecture with Gemini 2.5 Flash & Groq failover)

Resilient Multi-Tier Fallback Chain:

  • STT Fallback: Deepgram Nova-3 (automatic failover if Gnani key is unset or network error occurs)
  • TTS Fallback: Murf Falcon -> Sarvam Bulbul -> Rime Coda -> Google Cloud
  • LLM Failover: Google Gemini 2.5 Flash -> Groq Llama 3.3 70B -> LiveKit Cloud Inference

Runtime behavior:

  • PRIMARY_STT_PROVIDER defaults to gnani.
  • FAST_TTS_PROVIDER defaults to gnani.
  • Both STT and TTS automatically failover to secondary providers if keys are missing or provider limits are exceeded.

Development Notes

  • Keep only one frontend lockfile source of truth (frontend/package-lock.json).
  • Do not commit secrets in .env files.
  • Use UUID patient IDs for persisted entities.
  • If telephony is on Twilio trial, outbound calling can be limited to verified numbers.

Troubleshooting

  • 401 on Edge Functions: deploy with --no-verify-jwt for non-authenticated demo paths.
  • CORS failures: ensure functions are redeployed after header changes.
  • SIP call not ringing: check trunk policy, caller ID policy, and destination country permissions.
  • Groq 429: reduce context/tokens or rely on Gemini fallback.
  • Silent calls with TTS errors: inspect selected TTS provider logs and switch provider if codec mismatch occurs.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages