A safety-grounded voice AI for Telugu-speaking farmers.
A farmer speaks a question in rural Telugu. They get spoken advice back in under 3 seconds. No smartphone required. No literacy required. No internet beyond 2G.
Python
FastAPI
LangGraph
License
The Problem
Telangana has 5.8 million smallholder farmer households. When a crop gets sick, the nearest expert is the pesticide shop owner — whose advice is commercially motivated and often dangerous. Farmers are routinely told to use banned chemicals, apply overdoses, or spray days before harvest. This is a primary driver of farmer debt in India.
Existing agricultural AI is built for smartphones and English. It doesn't reach the people who need it.
What KrishiVaani Does
Voice-in, voice-out advisory pipeline in Telugu. The key technical contribution is a post-LLM safety verification layer that intercepts every response containing chemical names or dosages, cross-checks them against an ICAR ground-truth database, and corrects or blocks them before the farmer hears the answer. It is a hallucination kill-switch for chemical advice.
The ICAR layer is the only component that matters for safety. Ablation: remove it → all metrics go to 0%.
Latency
Measured end-to-end on text pipeline (LLM + routing + memory, no external TTS):
Metric
Value
p50
0.018s
p95
0.158s
Requests under 3s
100%
Accuracy (ROUGE-L)
Mean ROUGE-L: 0.071 against a 35-item held-out Telugu agri Q&A set.
This is a baseline. The fine-tuned Gemma-2-2B is not yet uploaded — the system currently runs the deterministic Telugu advisory fallback. Fine-tuning on more KCC data is the next step.
Quickstart
bash
1git clone https://github.com/asheesh07/krishivaani.git
2cd krishivaani
3pip install -r requirements.txt
4cp .env.example .env
5# fill in HF_TOKEN at minimum6uvicorn main:app --reload
Check what's configured:
GET /ready
Send a text query (no audio needed to test):
bash
1curl -X POST http://localhost:8000/chat/text \2 -H "Content-Type: application/json"\3 -d '{"user_input": "వరికి యూరియా ఎంత వేయాలి?"}'
Send a voice query:
bash
1curl -X POST http://localhost:8000/chat/voice \2 -F "file=@query.wav"\3 --output response.wav
API
Endpoint
Input
Output
Purpose
POST /chat
Telugu text + session_id
8kHz WAV
Main pipeline
POST /chat/text
Telugu text + session_id
JSON text
Debug / no audio
POST /chat/voice
WAV upload
8kHz WAV
Full voice loop
GET /ready
—
dependency status
Pre-flight check
GET /health
—
model + version
Liveness probe
DELETE /session
session_id
—
Clear memory
All voice output is 8kHz mono WAV — tuned for 2G bandwidth and basic Android media players.
Architecture Decisions
Why LangGraph instead of a monolithic prompt?
Each node has a single responsibility and can fail independently. The ICAR verification node intercepts after the LLM regardless of what the LLM decided — you can't do that cleanly inside a single prompt chain.
Why a rule-based router instead of LLM-based intent classification?
Latency and reliability. The keyword classifier adds <1ms and has zero failure modes. For a 7-class problem with Telugu agricultural vocabulary, keyword matching is sufficient and auditable.
Why SQLite instead of a vector store?
Farmers ask sequential follow-up questions in a session, not semantic searches across history. Ordered turn storage with a 6-turn window is the right model.
Why 8kHz output audio?
Nyquist limit for voice intelligibility is ~4kHz. 8kHz WAV is half the size of 16kHz with no perceptible quality loss for speech on phone speakers.
Why does the ICAR layer only run on DISEASE and FERTILIZER intents?
Running it on irrigation or weather queries would produce false positives (e.g., flagging "nitrogen" in a weather context). Scope restriction is how you get 0% false positive rate.
Configuration
Copy .env.example to .env. Only HF_TOKEN is required to run the text pipeline. Everything else degrades gracefully.
Variable
Required
Purpose
HF_TOKEN
For LLM
Gemma-2-2B inference via Groq
HF_MODEL_ID
For LLM
Your fine-tuned model repo
OPENWEATHER_API_KEY
For weather queries
Free at openweathermap.org
AGMARKNET_API_KEY
For mandi price queries
Free at data.gov.in
BHASHINI_API_KEY
Optional TTS
Falls back to Edge TTS without it
Without HF_TOKEN, the system uses a deterministic Telugu advisory based on ICAR lookup data. It still gives correct, safe answers — just not generative ones.
Fine-tuning
The training pipeline fine-tunes google/gemma-2-2b-it on Telugu agricultural Q&A using QLoRA (4-bit NF4, rank 16).