Downloads · 30 days
2
7% of all-time downloads
asheesh07/krishivaani-gemma2-2b
krishivaani-gemma2-2b is a machine learning model from asheesh07. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
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.
Downloads · 30 days
2
7% of all-time downloads
All-time downloads
27
Public
Repo size
117 MB
Likes
0
Public
Click a slice to open those files.
.safetensors83.1 MB · 71%
From the Hugging Face model README
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.
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.
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
└─────┘
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%.
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% |
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.
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 "[email protected]" \
--output response.wav
| 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.
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.
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.
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.
# 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/.
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
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}
}
Built to close the agricultural information gap for low-literacy, low-bandwidth, low-income farmers in India.