YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
KrishiVaani β ΰ°ΰ±ΰ°·ΰ°Ώ ΰ°΅ΰ°Ύΰ°£ΰ°Ώ
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.
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.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β KrishiVaani Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
WAV upload (2G)
β
βΌ
βββββββββββ low confidence βββββββββββββββββ
β ASR β ββββββββββββββββββΊ β Clarification ββββΊ TTS βββΊ WAV out
β Whisper β βββββββββββββββββ
βββββββββββ
β ok
βΌ
βββββββββββββββ
β Memory Load β (SQLite, last 6 turns)
βββββββββββββββ
β
βΌ
ββββββββββ OUT_OF_DOMAIN βββββββββββββββββββββββββββββββββββΊ TTS
β Router β WEATHER / MARKET βββΊ βββββββββββββ
β β β MCP Tools ββββΊ OpenWeatherMap
ββββββββββ β ββββΊ Agmarknet API
β DISEASE / FERTILIZER / βββββββββββββ
β IRRIGATION / GENERAL β
ββββββββββββββββββββββββββββββββββ
βΌ
ββββββββββββββββββββ
β LLM β Gemma-2-2B (QLoRA fine-tune, served via HF/Groq)
β + local Telugu β β deterministic fallback when model unavailable
β advisory β
ββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ICAR Verification β the novel part β
β β
β β’ banned chemical in response? β block, replace β
β β’ mentioned dose > ICAR max? β correct in-place β
β β’ pesticide + near-harvest? β append PHI warningβ
β β
β runs only on DISEASE + FERTILIZER (no false alarms) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββ
β Memory Save β
βββββββββββββββ
β
βΌ
βββββββ Edge TTS (te-IN-ShrutiNeural) β 8kHz WAV βββΊ farmer
β TTS β gTTS fallback
β β pyttsx3 offline fallback
βββββββ
Evaluation
Safety (ICAR Verification Layer)
Test set: 30 hand-labelled cases β 10 banned chemicals, 8 overdose responses, 3 near-harvest, 9 safe queries.
| Metric | Result |
|---|---|
| Banned chemical block rate | 100% |
| Dosage correction rate | 100% |
| PHI near-harvest warning rate | 100% |
| False positive rate on safe queries | 0% |
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
git clone https://github.com/asheesh07/krishivaani.git
cd krishivaani
pip install -r requirements.txt
cp .env.example .env
# fill in HF_TOKEN at minimum
uvicorn main:app --reload
Check what's configured:
GET /ready
Send a text query (no audio needed to test):
curl -X POST http://localhost:8000/chat/text \
-H "Content-Type: application/json" \
-d '{"user_input": "ΰ°΅ΰ°°ΰ°Ώΰ°ΰ°Ώ ΰ°―ΰ±ΰ°°ΰ°Ώΰ°―ΰ°Ύ ΰ°ΰ°ΰ°€ ΰ°΅ΰ±ΰ°―ΰ°Ύΰ°²ΰ°Ώ?"}'
Send a voice query:
curl -X POST http://localhost:8000/chat/voice \
-F "file=@query.wav" \
--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).
# Build dataset (ICAR-derived + synthetic, ~260 pairs default)
python -m training.dataset
# Add Claude-synthesised pairs (needs ANTHROPIC_API_KEY)
python -m training.dataset --claude-n 500
# Fine-tune (needs GPU β A100 recommended)
python training/finetune.py --hf-repo your-username/krishivaani-gemma2-2b
After training, set HF_MODEL_ID=your-username/krishivaani-gemma2-2b in .env.
Evaluation
# Run all evals
python -m eval.run_all
# Individual
python -m eval.safety_eval
python -m eval.latency_eval --runs 10
python -m eval.accuracy_eval
Results land in eval/results/.
Project Structure
krishivaani/
βββ agent/
β βββ asr_node.py # Whisper ASR, confidence-gated
β βββ router_node.py # Keyword intent classifier (7 intents)
β βββ mcp_tools_node.py # Weather + mandi price live tools
β βββ llm_node.py # Gemma-2-2B + deterministic fallback
β βββ icar_verification_node.py # Safety layer β the key contribution
β βββ memory_node.py # SQLite session memory
β βββ tts_node.py # Edge TTS β gTTS β pyttsx3 fallback chain
β βββ graph.py # LangGraph 8-node pipeline
β βββ state.py # AgentState TypedDict
βββ data/
β βββ icar_lookup.json # 20 chemicals, ICAR dosages, banned list
β βββ telangana_districts.json # District β lat/lon for weather
βββ training/
β βββ dataset.py # Dataset builder (ICAR + synthetic + Claude)
β βββ finetune.py # QLoRA training script
β βββ data/ # train.jsonl, eval.jsonl
βββ eval/
β βββ safety_eval.py # ICAR verification accuracy
β βββ latency_eval.py # End-to-end pipeline latency
β βββ accuracy_eval.py # ROUGE-L against held-out set
β βββ results/ # Saved JSON + summary
βββ web/index.html # Browser test UI
βββ main.py # FastAPI app, 5 endpoints
βββ config.py # All settings via env vars
βββ paper/outline.md # ACL/EMNLP system paper draft
Limitations
- ICAR lookup covers 20 chemicals. CIB&RC registers 800+. Coverage is narrow.
- ASR confidence scoring is heuristic, not derived from Whisper token probabilities.
- No real field deployment yet β evaluation is on curated test sets.
- Fine-tuned model not yet published. Current LLM path is rule-based.
- Telangana districts only for weather geolocation.
Roadmap
- Replace heuristic ASR confidence with IndicWhisper + real logprobs
- Publish fine-tuned Gemma-2-2B to HuggingFace Hub
- Expand ICAR lookup to 200+ chemicals
- Telephony integration (Exotel) for actual 2G voice calls
- Cross-session farmer profile (crop, location, disease history)
- Field study with Telangana farmer groups
Citation
If you use KrishiVaani in research, please cite:
@misc{krishivaani2026,
title = {KrishiVaani: A Safety-Grounded Voice AI Agent for Telugu-Speaking Farmers},
author = {Dhamacharla, Asheesh},
year = {2026},
url = {https://github.com/asheesh07/krishivaani}
}
Acknowledgements
- AI4Bharat for IndicWhisper and Bhashini TTS
- ICAR-NIPHM for chemical safety advisories
- LangGraph for the pipeline framework
- Bhashini / MeitY for the Indic language AI infrastructure
Built to close the agricultural information gap for low-literacy, low-bandwidth, low-income farmers in India.