Inspiration
India has over 140 million farming households, yet most crop selection decisions are still made by tradition or guesswork. In rural Rajasthan, farmers face a critical knowledge gap — Soil Health Cards exist, but interpreting N, P, K values and translating them into actionable crop choices is beyond the reach of most small and marginal farmers.
We asked ourselves: what if a farmer could just answer 5 simple questions about their land — and get a scientifically-backed crop recommendation, in their own language, in under 30 seconds?
AgriSense is our answer to that question.
What it does
AgriSense is an AI-powered crop recommendation system designed specifically for Indian farmers with varying levels of technical literacy.
The app supports two input modes:
- With a Soil Health Card: The farmer enters N, P, K, pH, rainfall, temperature, and humidity directly for precise ML-based prediction.
- Without a Soil Health Card: The farmer answers 5 contextual questions (soil type, water availability, season, fertilizer history, temperature). AgriSense combines Google Gemini AI with live OpenWeatherMap data to estimate all 7 soil and climate parameters automatically.
The Random Forest ML model then returns the top 3 crop recommendations with confidence scores. Each recommendation is accompanied by a detailed report including:
- Nutrient gap analysis with visual bars (how far the farmer's soil is from each crop's requirement)
- Fertilizer prescription in practical units (50 kg bags of Urea, SSP, MOP)
- Revenue estimation based on current MSP and mandi market rates
- Full Hindi/English bilingual support with voice output for low-literacy users
Every prediction is stored per user in a database, and the report is fully printable.
How we built it
ML Pipeline: Trained a Random Forest classifier using scikit-learn on a custom-generated dataset of 8,800 rows with realistic variance across 22 crops. A StandardScaler pipeline ensures consistent feature normalization. Model artifacts are serialized with joblib.
Backend: Python + Flask REST API with two core routes — /estimate for AI-assisted parameter inference and /predict for direct ML inference. SQLAlchemy manages user profiles and prediction history in SQLite.
AI Integration: Google Gemini 2.5 Flash handles soil parameter estimation from farmer questionnaire inputs. A hybrid prompt architecture separates concerns — when live weather is available from OpenWeatherMap, Gemini is only asked for soil parameters (N, P, K, pH, rainfall), and real temperature and humidity are injected directly, improving accuracy.
Frontend: Bootstrap 5 with vanilla JavaScript, built mobile-first. Bilingual UI implemented via data-en / data-hi HTML attributes with a single applyLanguage() DOM traversal function. Voice input powered by the Web Speech API for accessibility.
Report Engine: Server-rendered Jinja2 HTML report with nutrient visualization, fertilizer prescriptions, economic projections, and comparative "why this crop ranked higher" analysis across alternatives.
Challenges we ran into
Live weather overwriting manual inputs: OpenWeatherMap data was silently overriding user-entered temperature and humidity values. We resolved this with a hybrid Gemini prompt strategy — when live weather is detected, only soil parameters are requested from AI, and real weather data is merged post-response.
Dataset quality vs. model reliability: The initial Kaggle synthetic dataset was too clean, producing an overconfident model that failed on real-world edge cases. We rebuilt the dataset with controlled statistical noise across all 22 crops, which brought accuracy to a defensible ~88% and significantly improved robustness.
Bilingual UI without a frontend framework: Maintaining Hindi/English parity across a dynamic multi-step interface without React or Vue required a disciplined attribute-based approach. Standardizing on data-en / data-hi across every UI element allowed a single function to handle all language switching cleanly.
AI output validation: Gemini occasionally returned agronomically invalid parameter values for obscure locations. We implemented post-response coercion and range validation for all 7 parameters before passing them to the ML model.
Accomplishments that we're proud of
- A complete end-to-end pipeline — from a farmer with no soil report → 5-question questionnaire → AI parameter estimation → ML prediction → detailed printable report — in under 30 seconds.
- Genuine accessibility: full Hindi/English toggle, voice input on the onboarding screen, and voice output on results — making the app usable for farmers with low digital or English literacy.
- A report that goes beyond "grow Rice." It explains why a crop was recommended, quantifies nutrient gaps, prescribes fertilizer in bags (not kg/ha abstractions), and estimates revenue using real MSP and mandi data.
- A production-grade hybrid AI + live data architecture with graceful degradation — the app functions correctly whether or not live weather, AI estimation, or the database layer is available.
What we learned
- Prompt engineering for structured outputs matters. Constraining Gemini to return only valid JSON with a strict schema — and parsing defensively — is the difference between a demo that works and one that crashes on stage.
- Farmer UX is not developer UX. Every additional step is a dropout point. Folding city input into onboarding instead of a separate flow, and replacing free-text fields with dropdowns, measurably reduced friction.
- Training data quality determines real-world performance. A synthetically clean dataset produces artificially high accuracy that collapses on real inputs. Injecting realistic variance into training data is not optional — it is the work.
- Graceful degradation is a feature. In rural deployment contexts, APIs fail. The system is designed so that if OpenWeatherMap is unreachable, Gemini estimates all 7 parameters. If Gemini fails, the user can still enter values manually. No single point of failure blocks the core use case.
What's next for Agri-Sense - Smart Crop Recommendation System
- KisanMind: A domain-specific agricultural AI assistant trained on the KCC (Kisan Call Centre) dataset from data.gov.in — over 1 million real farmer queries — capable of answering open-ended farming questions beyond crop prediction.
- Offline-capable mobile app built with Flutter, using a quantized ONNX version of the Random Forest model for on-device inference — targeting farmers in areas with no reliable internet connectivity.
- Real-time mandi price integration via the Agmarknet API to replace static MSP values with live market rates for more accurate revenue projections.
- Crop calendar generation: A month-by-month farming schedule — sowing dates, fertilizer application windows, irrigation guidance, and harvest timing — generated from the predicted crop and user location.
- Photo-based soil type detection using a lightweight CNN model, allowing farmers to point their phone camera at their soil and receive an automatic soil type classification — eliminating one more manual input step.
Built With
- bootstrap-5
- flask
- google-gemini-api
- openweathermap
- python
- scikit-learn
- sqlite
Log in or sign up for Devpost to join the conversation.