gramsetu

🌾 GramSetu

AI-powered government form assistant for rural India
Voice-first Β· Multilingual Β· Zero typing required

Python Next.js FastAPI LangGraph Docker


What is GramSetu?

GramSetu (β€œVillage Bridge”) is an autonomous AI agent that fills Indian government forms on behalf of citizens β€” in their own language, using their real data from DigiLocker, with zero manual typing.

A citizen opens the web app and says: β€œΰ€°ΰ€Ύΰ€Άΰ€¨ ΰ€•ΰ€Ύΰ€°ΰ₯ΰ€‘ ΰ€šΰ€Ύΰ€Ήΰ€Ώΰ€β€ (I need a ration card). GramSetu detects the intent, fetches the citizen’s Aadhaar, PAN, and address from DigiLocker, validates every field with deterministic checks, fills the government portal using live browser automation (Playwright), handles the OTP β€” and sends back a confirmation with a downloadable receipt.

The user never types their Aadhaar number, address, or any document numbers.

Built For


Key Features

Feature Description
πŸ—£οΈ Realtime Voice STT WebSocket-based live transcription via Sarvam AI β€” speak and see words appear instantly
πŸ€– 11 Government Forms Ration card, PAN, Voter ID, Pension, Ayushman Bharat, MNREGA, PM-KISAN, and more
πŸ” Scheme Discovery LLM-powered search across myscheme.gov.in, india.gov.in to find eligible schemes
πŸ” DigiLocker Auto-Fill All personal data fetched automatically β€” user only confirms
🌐 Live Browser Automation Playwright fills real government portals; live JPEG screenshots stream to the UI
βœ… Deterministic Safety Verhoeff checksum for Aadhaar, PAN format validation, cross-field consistency checks
πŸ”Š Text-to-Speech Sarvam Bulbul TTS for spoken responses in 11 Indian languages
🌍 11 Languages Hindi, English, Bengali, Tamil, Telugu, Marathi, Gujarati, Kannada, Malayalam, Punjabi, Urdu

Architecture

User (Web App β€” Voice / Text)
         β”‚
         β–Ό
   FastAPI server.py (:8000)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  /api/chat          β€” Text conversation                      β”‚
   β”‚  /api/voice         β€” Audio upload β†’ Sarvam/Groq/NVIDIA STT  β”‚
   β”‚  /api/voice/realtime β€” WebSocket live STT (Sarvam streaming)  β”‚
   β”‚  /api/schemes       β€” LLM-powered scheme discovery            β”‚
   β”‚  /api/tts           β€” Text-to-speech (Sarvam Bulbul)          β”‚
   β”‚  /ws/browser/{id}   β€” Live Playwright screenshot stream       β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
   LangGraph v3 State Machine (5 Nodes)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  1. TRANSCRIBE     β†’ Sarvam / Groq Whisper / NeMo    β”‚
   β”‚  2. DETECT_INTENT  β†’ Keyword + LLM fallback          β”‚
   β”‚  3. DIGILOCKER     β†’ Auto-fetch all citizen data      β”‚
   β”‚  4. CONFIRM        β†’ User verifies (YES/NO only)      β”‚
   β”‚  5. FILL_FORM      β†’ Playwright live browser fill     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
   Reliability Layer
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  β€’ Verhoeff checksum (Aadhaar)                        β”‚
   β”‚  β€’ PAN / IFSC / PIN code format validation            β”‚
   β”‚  β€’ Cross-field consistency (name β‰  father, etc.)      β”‚
   β”‚  β€’ Confidence threshold gate (0.98+)                  β”‚
   β”‚  β€’ Human review for risky/low-confidence submissions  β”‚
   β”‚  β€’ Dry-run fill plan before live automation           β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

AI Provider Strategy

Task Primary Fallback
Intent Classification Groq llama-3.1-8b-instant (~50ms) Keyword-based (instant)
Conversational Chat Groq llama-3.3-70b-versatile NVIDIA NIM
Speech-to-Text Sarvam Saaras v1 Groq Whisper Large v3 β†’ NVIDIA Parakeet
Text-to-Speech Sarvam Bulbul v1 β€”
Scheme Research Groq 70B with web search Local curated database
Field Extraction Groq 70B β€”
Vision (Portal OCR) NVIDIA LLaMA 3.2 11B Vision Groq Vision Preview
Translation Groq 70B β€”

Supported Forms β€” 11 Types

Category Form Real Portal
🏠 Welfare Ration Card (BPL/APL) nfsa.gov.in
🏠 Welfare Old Age / Widow / Disability Pension nsap.nic.in
🏠 Welfare Ayushman Bharat PMJAY (β‚Ή5L health cover) pmjay.gov.in
🏠 Welfare MNREGA Job Card (100 days work) nrega.nic.in
πŸͺͺ Identity PAN Card onlineservices.nsdl.com
πŸͺͺ Identity Voter ID voters.eci.gov.in
πŸͺͺ Identity Caste Certificate (SC/ST/OBC) services.india.gov.in
πŸͺͺ Identity Birth Certificate crsorgi.gov.in
🌾 Agriculture PM-KISAN Samman Nidhi (β‚Ή6,000/year) pmkisan.gov.in
🌾 Agriculture Kisan Credit Card (farm loans) kisancreditcard.in
🏦 Banking Jan Dhan Account (zero balance) pmjdy.gov.in

Adding a new form = 1 Pydantic model + 1 entry in SCHEMA_REGISTRY. Voice, validation, DigiLocker auto-fill, and browser automation work automatically.


Quick Start

Prerequisites

# Clone
git clone https://github.com/Vickyrrrrrr/gramsetu.git
cd gramsetu

# Configure
cp .env.example .env
# β†’ Fill in GROQ_API_KEY and SARVAM_API_KEY

# Build and run everything
docker compose up --build

Option B: Local Development

# Clone
git clone https://github.com/Vickyrrrrrr/gramsetu.git
cd gramsetu

# Python backend
python -m venv .venv
.venv\Scripts\activate          # Windows
# source .venv/bin/activate     # macOS/Linux
pip install -r requirements.txt
playwright install chromium

# Configure environment
cp .env.example .env
# β†’ Fill in GROQ_API_KEY and SARVAM_API_KEY

# Start backend
python server.py
# β†’ http://localhost:8000

# Start frontend (new terminal)
cd webapp
npm install
npm run dev
# β†’ http://localhost:3000

Environment Variables

# ── Required ──────────────────────────────────────────
GROQ_API_KEY=gsk_your_key_here        # LLM inference (free tier)
SARVAM_API_KEY=sk_your_key_here       # Indian STT/TTS

# ── Optional ──────────────────────────────────────────
NVIDIA_API_KEY=nvapi-your-key-here    # Vision + ASR fallback
NVIDIA_BASE_URL=https://integrate.api.nvidia.com/v1

# ── Server ────────────────────────────────────────────
PORT=8000
HOST=0.0.0.0
BACKEND_URL=http://localhost:8000     # Used by Next.js proxy

Project Structure

gramsetu/
β”œβ”€β”€ server.py                    # FastAPI entrypoint β€” all API endpoints
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ Dockerfile                   # Backend container (uvicorn server:app)
β”œβ”€β”€ docker-compose.yml           # Full-stack: backend + webapp
β”œβ”€β”€ .env.example                 # Environment template
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ graph.py             # LangGraph 5-node state machine (core pipeline)
β”‚   β”‚   β”œβ”€β”€ schema.py            # Pydantic models for all 11 forms + SCHEMA_REGISTRY
β”‚   β”‚   β”œβ”€β”€ portal_registry.py   # Government portal URLs and selectors
β”‚   β”‚   └── form_fill_agent.py   # Playwright browser automation agent
β”‚   β”‚
β”‚   β”œβ”€β”€ llm_client.py            # Multi-provider LLM client (Groq + NVIDIA + Sarvam)
β”‚   β”œβ”€β”€ schemes.py               # LLM-powered scheme discovery engine
β”‚   β”œβ”€β”€ database.py              # SQLite/Supabase storage layer
β”‚   β”œβ”€β”€ digilocker_client.py     # DigiLocker API client (demo data for now)
β”‚   β”œβ”€β”€ security.py              # Rate limiter, PII encryption, input sanitization
β”‚   β”œβ”€β”€ reliability.py           # Deterministic safety layer before automation
β”‚   β”œβ”€β”€ voice_tts.py             # Text-to-speech (Sarvam Bulbul)
β”‚   β”œβ”€β”€ sarvam_client.py         # Sarvam AI direct API wrapper
β”‚   └── stagehand_client.py      # Browser fill plan generator
β”‚
β”œβ”€β”€ agent_core/
β”‚   └── validator.py             # Rule-based validators (Aadhaar, PAN, IFSC, DOB, etc.)
β”‚
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ language_utils.py        # Script-based language detection (11 languages)
β”‚   └── voice_handler.py         # Audio transcription (Sarvam β†’ Groq β†’ NVIDIA cascade)
β”‚
β”œβ”€β”€ webapp/                      # Next.js 14 frontend
β”‚   β”œβ”€β”€ app/app/page.tsx         # Main chat UI (1600+ lines)
β”‚   β”œβ”€β”€ next.config.js           # API proxy configuration
β”‚   └── Dockerfile               # Frontend container
β”‚
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ mock_portal.html         # Pixel-faithful GOI portal replica for demos
β”‚   └── admin.html               # Admin dashboard
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ checkpoints.db           # LangGraph session checkpoints (SQLite)
β”‚   β”œβ”€β”€ gramsetu.db              # Application database
β”‚   └── schemes.json             # Fallback scheme data
β”‚
β”œβ”€β”€ deploy/
β”‚   β”œβ”€β”€ prometheus/              # Prometheus config
β”‚   └── grafana/                 # Grafana dashboards
β”‚
β”œβ”€β”€ tests/                       # Test suite
β”‚
└── .github/workflows/           # CI/CD (lint, test, Docker build, deploy)

API Reference

Base URL: http://localhost:8000

Method Endpoint Description
POST /api/chat Send a text message, get AI response
POST /api/voice Upload audio file β†’ transcribed text + AI response
WS /api/voice/realtime Realtime STT β€” stream PCM audio, get live transcripts
POST /api/otp/{user_id} Submit OTP to resume a suspended form session
POST /api/schemes Discover eligible government schemes
POST /api/tts Text-to-speech (returns audio/wav)
GET /api/mcp-status Status of all backend services
GET /api/health Health check + active session count
GET /api/impact Impact metrics (forms filled, users served)
GET /api/receipt/{id} Downloadable HTML receipt for submitted forms
WS /ws/browser/{user_id} Live JPEG stream of Playwright browser automation

Realtime Voice (WebSocket)

// Connect
const ws = new WebSocket('ws://localhost:8000/api/voice/realtime')

// Start session
ws.send(JSON.stringify({ type: 'start', language: 'hi' }))

// Stream 16kHz PCM audio
ws.send(pcmAudioBuffer)  // ArrayBuffer of Int16Array

// Receive transcripts
ws.onmessage = (event) => {
  const data = JSON.parse(event.data)
  // { type: 'transcript', text: 'ΰ€°ΰ€Ύΰ€Άΰ€¨ ΰ€•ΰ€Ύΰ€°ΰ₯ΰ€‘ ΰ€šΰ€Ύΰ€Ήΰ€Ώΰ€', is_final: true }
}

// Stop
ws.send(JSON.stringify({ type: 'stop' }))

How It Works β€” User Flow

1. User speaks or types: "I need a ration card" (any language)
         β”‚
         β–Ό
2. TRANSCRIBE β€” Sarvam Saaras converts voice β†’ text
         β”‚
         β–Ό
3. DETECT INTENT β€” Keywords + LLM identify: form_type = "ration_card"
         β”‚
         β–Ό
4. DIGILOCKER β€” Auto-fetch Aadhaar, PAN, address, bank details
         β”‚
         β–Ό
5. CONFIRM β€” Show pre-filled form summary with confidence scores
   🟒 High confidence (DigiLocker)  🟑 Estimated  πŸ”΄ Needs review
   User says YES or corrects specific fields
         β”‚
         β–Ό
6. RELIABILITY GATE β€” Verhoeff checksum, format validation,
   cross-field checks, confidence threshold, human review gate
         β”‚
         β–Ό
7. FILL FORM β€” Playwright opens real portal, fills field by field
   Live screenshots stream to the web app via WebSocket
         β”‚
         β–Ό
8. OTP β€” Portal asks for OTP β†’ graph SUSPENDS β†’ user sends OTP
         β”‚
         β–Ό
9. DONE β€” Confirmation + reference number + downloadable receipt

Reliability Layer

GramSetu never trusts the LLM blindly. A deterministic safety layer runs before any live form submission:

Check What It Does
Verhoeff Checksum Validates Aadhaar numbers mathematically (12-digit + checksum)
PAN Format Validates ABCDE1234F pattern + holder category letter
IFSC Format 4 letters + 0 + 6 alphanumeric
Phone Validation 10 digits, starts with 6-9, strips +91 prefix
PIN Code 6 digits, first digit 1-9
Date of Birth Age β‰₯ 18, ≀ 150, not in future
Cross-Field Name β‰  father name, mobile prefix valid, PIN code valid
Confidence Gate All fields must be β‰₯ 98% confidence for auto-submit
Human Review Low-confidence, OTP steps, or PII changes require explicit review
Dry-Run Plan Generate fill plan before touching real portals

Voice Support β€” 11 Languages

Language Code Script Detection
Hindi hi Devanagari \u0900-\u097F
Bengali bn Bengali \u0980-\u09FF
Tamil ta Tamil \u0B80-\u0BFF
Telugu te Telugu \u0C00-\u0C7F
Marathi mr Devanagari + keyword disambiguation
Gujarati gu Gujarati \u0A80-\u0AFF
Kannada kn Kannada \u0C80-\u0CFF
Malayalam ml Malayalam \u0D00-\u0D7F
Punjabi pa Gurmukhi \u0A00-\u0A7F
Urdu ur Arabic \u0600-\u06FF
English en Latin (default fallback)

Language is auto-detected from the Unicode script of the input text. Romanized Hindi/Tamil/Telugu are detected via keyword matching.


Security

Feature Implementation
PII Encryption Fernet (AES-128-CBC) for all PII in checkpoints
PII Redaction Aadhaar shown as XXXX-XXXX-1234 in logs and UI
Rate Limiting 60 req/min per IP (in-memory, no Redis needed)
Input Sanitization XSS prevention, control char removal, length limits
OTP Validation 4-6 digits only, supports Hindi word-to-digit (β€œΰ€ΰ€• ΰ€¦ΰ₯‹ ΰ€€ΰ₯€ΰ€¨β€)
Session Cleanup Auto-expire after 24 hours
Git Security .env gitignored, API keys never committed

Docker

Full Stack (Backend + Web App)

cp .env.example .env
# Fill in API keys
docker compose up --build
Service Port Description
gramsetu-backend 8000 FastAPI + all endpoints
gramsetu-webapp 3000 Next.js frontend

Backend Only

docker compose up --build backend

The backend Dockerfile:


Tests

python -m pytest tests/ -v

Demo Setup

Your Laptop
β”œβ”€β”€ FastAPI server.py       β†’  localhost:8000
└── Next.js web app         β†’  localhost:3000

Steps

# Terminal 1 β€” Backend
cd gramsetu
.venv\Scripts\activate
python server.py

# Terminal 2 β€” Frontend
cd gramsetu\webapp
npm run dev

Demo Script

  1. Open localhost:3000 on the big screen
  2. Type or speak: β€œΰ€°ΰ€Ύΰ€Άΰ€¨ ΰ€•ΰ€Ύΰ€°ΰ₯ΰ€‘ ΰ€šΰ€Ύΰ€Ήΰ€Ώΰ€β€
  3. GramSetu replies in Hindi, identifies the form
  4. Say β€œΰ€Ήΰ€Ύΰ€β€ (yes) β†’ Playwright browser opens, live form fill begins
  5. Screenshots stream into the web app floating preview panel
  6. Enter mock OTP β†’ form β€œsubmitted” with confirmation + receipt

Contributing

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT


Built for the people who need it most.
GramSetu β€” bridging the digital divide, one form at a time. 🌾