Agroculture is a context-aware, AI-powered agriculture assistant built for Indian farmers. It combines real-time market data (Agmarknet), live weather forecasting, a RAG-based knowledge engine, bilingual (Hindi/English) voice I/O, proactive smart alerts, and a clean web UI β all in a single deployable backend.
| Feature | Description |
|---|---|
| π§ Contextual Chat Agent | Multi-intent NLP pipeline routes queries to weather, market, agri-advisory, policy, logistics, and compliance handlers |
| π Live Market Prices | Real-time mandi prices via the Agmarknet / data.gov.in API with trend analysis and comparisons |
| π¦οΈ Weather Forecasting | Open-Meteo powered daily forecasts with farmer-specific summaries (rain probability, ETβ, wind gusts) |
| π Proactive Alerts | Hourly scheduled background job generates personalised weather alerts and government scheme updates per user |
| ποΈ Bilingual Voice I/O | Hindi-first ASR using OpenAI Whisper / faster-whisper; TTS via Microsoft Edge voices (hi-IN-SwaraNeural, en-IN-NeerjaNeural) |
| π RAG Knowledge Base | ChromaDB + sentence-transformers vector store built from agronomy PDFs, Wikipedia articles, and ICAR publications |
| π± Planting Decision Engine | Go/no-go planting advisor that fuses crop type, live weather, and LLM reasoning into a structured JSON decision |
| π€ Farmer Onboarding | Conversational profile builder (location, land size, budget, crops) for personalised recommendations |
| π Web UI | Single-file index.html frontend β no build step required |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β index.html (UI) β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β HTTP / REST
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β FastAPI (main.py) β
β ββββββββββββββββ βββββββββββββββββ βββββββββββββββββββββ β
β β Intent Routerβ β Scheduler β β Voice Endpoints β β
β β detect_intentβ β APScheduler β β /voice/transcribe β β
β β _nlp() β β (hourly jobs) β β /voice/ask /tts β β
β ββββββββ¬ββββββββ βββββββββββββββββ βββββββββββββββββββββ β
βββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ
β Core Modules β
β data_sources.py ββ Agmarknet + Open-Meteo APIs β
β qna.py ββ RAG query + Mistral LLM β
β rag.py ββ ChromaDB ingestion pipeline β
β ner_utils.py ββ spaCy location extractor β
β translator.py ββ Language detect + translate β
β url_checker.py ββ Source validation utilities β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
Agroculture/
βββ main.py # FastAPI application β all API endpoints & scheduler
βββ data_sources.py # Agmarknet market prices + Open-Meteo weather helpers
βββ qna.py # RAG query engine + Mistral LLM advisory generator
βββ rag.py # One-time script to build the ChromaDB vector store
βββ ner_utils.py # Named entity recognition (location extraction)
βββ translator.py # Language detection, translation & transliteration
βββ url_checker.py # URL validation and source management utilities
βββ index.html # Frontend single-page web UI
βββ requirements.txt # Python dependencies
βββ agri_db/ # Auto-generated ChromaDB vector store (after rag.py)
- Python 3.10 or 3.11 (recommended)
pipinstalled- Internet connectivity for API calls and model downloads
# Windows PowerShell
python -m venv .venv
.venv\Scripts\Activate.ps1
# macOS / Linux
python -m venv .venv
source .venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
AGMARKNET_API_KEY=your_data_gov_in_api_key
MISTRAL_API_KEY=your_mistral_api_key| Variable | Where to Get |
|---|---|
AGMARKNET_API_KEY |
data.gov.in β register for a free API key |
MISTRAL_API_KEY |
console.mistral.ai |
python rag.pyThis downloads and embeds agronomy PDFs and Wikipedia articles into a local ChromaDB store at agri_db/. Takes ~5β10 minutes on first run.
uvicorn main:app --host 127.0.0.1 --port 8000 --reload- π Interactive API docs:
http://127.0.0.1:8000/docs - π ReDoc:
http://127.0.0.1:8000/redoc
Open index.html directly in your browser, or serve it locally:
python -m http.server 5173
# Then visit: http://127.0.0.1:5173/index.html| Method | Endpoint | Description |
|---|---|---|
GET |
/status?user_id=<id> |
Check if user has completed onboarding |
POST |
/chat?user_id=<id> |
Step through the conversational onboarding flow |
| Method | Endpoint | Description |
|---|---|---|
POST |
/ask |
Context-aware Q&A (weather, market, policy, agri, logistics) |
GET |
/get-suggestion?user_id=<id>&category=<crop|land|budget> |
On-demand personalised suggestion |
POST |
/plan/plant |
Go/no-go planting decision based on live weather |
| Method | Endpoint | Description |
|---|---|---|
GET |
/alerts?user_id=<id> |
Fetch latest alerts and scheme suggestions |
POST |
/alerts/run-now?user_id=<id> |
Trigger alert generation immediately |
| Method | Endpoint | Description |
|---|---|---|
GET |
/weather_summary?location=<city> |
Compact dashboard weather metrics |
| Method | Endpoint | Description |
|---|---|---|
POST |
/voice/transcribe |
Upload audio β transcribed text (Whisper) |
POST |
/voice/ask |
Upload audio β answer text + base64 MP3 |
POST |
/tts |
Text β base64 MP3 (auto en-IN / hi-IN voice) |
Each /ask query is routed through detect_intent_nlp() which classifies it into one of:
weather β get_weather_forecast() + Mistral LLM
market β agmark_qna_answer() (Agmarknet API + fuzzy matching)
agriculture β get_answer_from_books() (RAG + LLM)
policy β get_answer_from_books() (RAG + LLM)
logistics / compliance / general β get_answer_from_books()
- Fetch β Downloads PDFs (via
PyMuPDF) and Wikipedia articles (viaBeautifulSoup) - Chunk β Splits into overlapping 1000-word chunks (200-word overlap)
- Embed β Uses
all-MiniLM-L6-v2viasentence-transformers - Store β Persists to ChromaDB with cosine similarity index
Every hour the scheduler calls check_for_personalized_alerts() for each registered user:
- Fetches live weather for the user's location
- Prompts Mistral to generate
ALERT:+ 3SUGGESTION:lines - Fetches applicable Indian government schemes for the farmer's profile
- Stores results in an in-memory list, served via
GET /alerts
| Layer | Technology |
|---|---|
| Backend | FastAPI 0.115, Uvicorn, APScheduler 3.10 |
| LLM | Mistral AI (mistralai SDK) |
| Vector DB | ChromaDB 0.5 + sentence-transformers (all-MiniLM-L6-v2) |
| ASR | OpenAI Whisper (fallback: faster-whisper on CPU, int8) |
| TTS | Microsoft Edge TTS (edge-tts) β Indian voices |
| Market Data | Agmarknet via data.gov.in API |
| Weather | Open-Meteo (free, no API key needed) |
| Geocoding | pgeocode + Open-Meteo geocoder |
| NER / NLP | rapidfuzz fuzzy matching, regex-based intent & commodity extractor |
| Frontend | Vanilla HTML/CSS/JS (index.html) |
- Hindi ASR: Voice input defaults to
lang=hito avoid Urdu auto-detection. Pass?lang=ento/voice/askfor English queries. - TTS Voices: English uses
en-IN-NeerjaNeural; Hindi/Devanagari text automatically switches tohi-IN-SwaraNeural. - Alerts frequency: Default is hourly. Use
POST /alerts/run-now?user_id=<id>to trigger on demand during development. - Whisper compatibility: If Whisper fails due to NumPy/Numba version mismatches, the system automatically falls back to
faster-whisper(CPU, int8). - RAG refresh: Re-run
python rag.pyanytime to add new knowledge sources by editingSOURCE_URLSinrag.py.
See requirements.txt for pinned versions. Key dependencies:
fastapi==0.115.0
uvicorn[standard]==0.30.6
apscheduler==3.10.4
mistralai==0.4.0
chromadb==0.5.5
sentence-transformers==2.6.1
torch>=2.2.0
edge-tts==6.1.9
faster-whisper==1.0.3
openai-whisper==20231117
rapidfuzz==3.9.6
pgeocode==0.5.0
- PostgreSQL / Redis persistence for user profiles and alerts
- Multi-language translation pipeline (Tamil, Telugu, Marathi)
- Mobile-responsive PWA frontend
- Real-time crop price push notifications
- Image-based pest/disease detection (vision LLM)
- Integration with e-NAM for direct market linkage
Contributions are welcome! Please open an issue first to discuss major changes.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m 'Add your feature' - Push and open a Pull Request
This project is licensed under the MIT License. See LICENSE for details.
Built with β€οΈ for Indian farmers | Powered by Mistral AI, Open-Meteo & Agmarknet