Inspiration
Every harvest season across India, smallholder farmers load their tractors and trolleys to travel to the nearest APMC mandi completely blind. They have no reliable way to know whether prices crashed that morning, whether neighboring mandis are paying ₹400/quintal more for the same crop, or if sudden unseasonal rain will ruin the crop while waiting in the auction yard.
Middlemen exploit this information gap every day. While commodity traders in Mumbai and Delhi have access to live Bloomberg terminals and trading software, a farmer in Nashik or Punjab has to rely on word-of-mouth.
We built KisanGuard AI to bridge this gap. Our goal was simple: take raw commodity price records and live weather feeds, run them through real quantitative machine learning models, and deliver clear, honest advice straight to a farmer's phone via WhatsApp or SMS in less than 3 seconds.
What It Does
KisanGuard AI is a multi-channel agricultural intelligence platform that provides:
- 90-Day Mandi Price Forecasts: Predicts wholesale prices across major Indian APMC mandis (Azadpur, Vashi, Lasalgaon, Koyambedu, etc.) for key crops including Tomato, Onion, Potato, Wheat, and Rice.
- Honest Confidence Intervals: Instead of giving a misleading single number (e.g., "Price will be ₹2,450"), our engine outputs statistical bounds with 90% coverage guarantees using conformal prediction.
- Actionable Recommendations: Every forecast translates into a simple decision: SELL TODAY, HOLD, or STORE.
- Agrometeorological Risk Warnings: Ingests live temperature, precipitation, and soil moisture telemetry to alert farmers when upcoming rain or heat spikes threaten harvest transport or foliar spraying.
- Multi-Channel Accessibility:
- WhatsApp & SMS Simulator: Works on any basic phone with no app download or high-speed internet needed.
- Interactive Web Portal: Live charts, movers, and cross-mandi arbitrage comparisons built with Streamlit and Vite.
- Offline-First Mobile App: Flutter client with local SQLite caching for extension workers visiting rural dead zones.
- Lightweight Desktop Command Center: Native Tauri v2 station using under 15MB of RAM for cooperative managers.
How We Built It
We structured the project around a decoupled, high-performance architecture:
- Backend (
FastAPI): Asynchronous REST API serving/api/v1/predict,/forecasts,/markets, and/weatherendpoints. It handles background data sync using APScheduler and SQLite for local storage. - Machine Learning Core:
- Prophet: Models yearly seasonality, holiday demand spikes (festivals like Diwali), and long-term price trends.
- XGBoost: Ingests short-term momentum features, trailing 7/14/30-day price lags, rolling volatility, and weather signals.
- Conformal Prediction Intervals (
quant/intervals.py): Uses non-conformity scores on calibration data to guarantee honest prediction bounds: $$\Gamma_\alpha(X) = [\hat{y} - \hat{q}{1-\alpha}, \; \hat{y} + \hat{q}{1-\alpha}]$$
- Frontend & Interfaces:
- Streamlit (
frontend/Home.py): Interactive dashboard with custom CSS, dark-mode metrics, and real-time API health checks. - Vite + React (
desktop/): Clean, fast single-page app deployed on Vercel.
- Flutter (
mobile/): Offline-first mobile client with SQLite-backedLocalCache.Challenges We Ran Into
- Streamlit (
- Price Volatility Spikes: Horticultural crops like tomatoes and onions experience sudden 200% price swings when localized supply shocks hit. Traditional linear regression failed completely. We solved this by combining Prophet's baseline trend with gradient boosted trees (XGBoost) trained on multi-scale lag features.
- Preventing Future Data Leakage: In time-series forecasting, standard k-fold cross-validation accidentally trains on future prices to predict past prices. We engineered an expanding-window walk-forward validation split to ensure models were strictly evaluated on unseen future dates.
- Latency for Messaging Gateways: WhatsApp and SMS gateways timeout if a webhook takes more than 5 seconds. We pre-compute price features and cache encoders at startup so single-point inference resolves in under 80 milliseconds.
Accomplishments That We're Proud Of
- Zero-Friction Access: A farmer does not need a ₹20,000 smartphone or a 5G data pack. They can query mandi prices over basic messaging in under 3 seconds.
- Calibrated Risk Bounds: We refused to display uncalibrated point estimates. The conformal intervals give farmers realistic best-case and worst-case price ranges they can actually plan around.
- End-to-End Production: Complete, working pipeline from raw AGMARKNET ingestion to live web deployment on Vercel, native desktop build, and offline mobile client.
What We Learned
- Weather and Prices Cannot Be Separated: An unseasonal 30mm rainfall event in Maharashtra doesn't just wet the ground—it delays truck dispatches, spikes transit spoilage, and causes onion prices in Delhi to spike 48 hours later. Modeling price and climate together is essential.
- Simplicity Wins on the Ground: Complex charts are useful for researchers, but farmers need a clear, unequivocal verdict: "Mandi price expected to rise ₹150 this week. Hold your stock if you have dry storage."
What's Next for KisanGuard AI
- Multilingual Voice Calls (IVR via Bhashini): Adding automated voice queries in Hindi, Marathi, and Punjabi for farmers who cannot read text messages.
- Mandi Transport Cost Calculator: Factoring in diesel rates and truck freight costs so farmers can calculate if traveling to a further mandi with higher prices actually leaves more profit in their pocket.
- Field Pilot with Farmer Producer Organizations (FPOs): Rolling out a 100-farmer trial with local agricultural cooperatives to measure actual household revenue gains over a full crop cycle.
Built With
- conformal-prediction
- fastapi
- flutter
- machine-learning
- numpy
- open-meteo
- pandas
- prophet
- python
- react
- scikit-learn
- sqlalchemy
- sqlite
- streamlit
- tauri
- time-series
- typescript
- vite
- whatsapp-api
- xgboost
Log in or sign up for Devpost to join the conversation.