Empowering farmers with AI-driven crop predictions and data-backed farming insights.
AgroTech is an intelligent web platform built to modernize Indian agriculture. It combines a Django-powered backend, a curated ML crop predictor, and Google Gemini AI to deliver real-time, natural-language farming advice β putting the power of data science directly in the hands of farmers.
- β¨ Features
- ποΈ Project Structure
- π οΈ Tech Stack
- π€ Google Gemini AI Integration
- βοΈ Installation
- π Environment Configuration
- π Usage
- πΏ How the Predictor Works
- π Dataset Schema
- π€ Contributing
- π License
| Module | Description |
|---|---|
| πΎ Crop Predictor | ML-powered engine recommending the best crop based on soil & climate inputs |
| π€ Gemini AI Advisor | Google Gemini API provides natural-language farming tips, fertilizer advice, and pest control guidance |
| π Smart Datasets | Curated agricultural datasets covering soil nutrients, rainfall, temperature, and humidity |
| π₯οΈ Responsive Dashboard | Clean, mobile-friendly UI built with HTML5, SCSS, and vanilla JavaScript |
| βοΈ Django Backend | Robust server-side logic handling predictions, routing, and data processing |
| π Secure Architecture | Environment-based configuration, Django ORM, and modular app design |
AgroTech/
β
βββ Predictor/ # ML model logic β crop prediction engine
β βββ ... # Saved models (.pkl / .joblib), inference scripts
β
βββ backend/ # Django app β views, URLs, models, forms
β βββ ...
β
βββ datasets/ # Raw & processed agricultural datasets (.csv)
β βββ ...
β
βββ static/ # Static assets β CSS, SCSS, JavaScript, images
β βββ css/
β βββ js/
β βββ images/
β
βββ templates/ # Django HTML templates β pages and partials
β βββ ...
β
βββ manage.py # Django management entry point
βββ requirements.txt # Python dependencies
βββ .gitignore
βββ README.md
Backend
- Python 3.10+
- Django β web framework
- scikit-learn β ML crop predictor
- Pandas & NumPy β data processing
- Google Gemini API β generative AI farming advisor
Frontend
- HTML5, SCSS / CSS3, JavaScript (ES6+)
- Django Templating Engine
Data
- Custom curated CSV datasets (soil nutrients, weather parameters, crop labels)
AgroTech uses the Google Gemini API to provide farmers with intelligent, conversational farming advice β going beyond simple predictions.
- πΏ Fertilizer Recommendations β Based on soil nutrient levels (N, P, K), Gemini suggests organic and chemical fertilizer options in plain language
- π Pest & Disease Guidance β Farmers can describe symptoms and Gemini returns actionable pest control advice
- π¦οΈ Climate-Aware Tips β Seasonal and weather-aware crop care suggestions tailored to local conditions
- π¬ Natural Language Interface β Farmers interact with the platform conversationally, not just through forms
Farmer Input (soil data / question)
β
βΌ
Django Backend receives request
β
βΌ
Prompt constructed with farming context
β
βΌ
Google Gemini API call (gemini-pro model)
β
βΌ
AI-generated advice returned to UI
- Visit https://ai.google.dev/ and sign in with your Google account
- Click "Get API Key" β "Create API Key in new project"
- Copy the generated key
- Add it to your
.envfile as shown in the Environment Configuration section below
β οΈ Never commit your API key to version control. Always use environment variables.
- Python 3.10 or higher
- pip (Python package manager)
- Git
- A Google Gemini API key (get one free here)
git clone https://github.com/Lucky-939/AgroTech.git
cd AgroTech# Create virtual environment
python -m venv venv
# Activate on Linux / macOS
source venv/bin/activate
# Activate on Windows
venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root (see Environment Configuration below).
python manage.py makemigrations
python manage.py migratepython manage.py runserverVisit: http://127.0.0.1:8000/
Create a .env file in the root of the project with the following variables:
# Django
SECRET_KEY=your_django_secret_key_here
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhost
# Google Gemini AI
GEMINI_API_KEY=your_google_gemini_api_key_hereπ‘ Tip: Generate a Django secret key using:
python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
Make sure .env is listed in your .gitignore β never push API keys to GitHub.
- Open your browser and go to
http://127.0.0.1:8000/ - Enter your field parameters β nitrogen (N), phosphorus (P), potassium (K), temperature, humidity, pH, and rainfall
- Submit to get an instant ML-based crop recommendation
- Ask Gemini β use the AI advisor to get fertilizer tips, pest control advice, or farming guidance in natural language
- Explore the dashboard to understand why a specific crop is recommended for your local conditions
User Input (Soil + Climate Parameters)
β
βΌ
Feature Preprocessing
(Normalization / Encoding)
β
βΌ
Trained ML Model
(Random Forest / Decision Tree)
β
βΌ
Crop Recommendation Output
e.g., "Rice", "Wheat", "Cotton"
β
βΌ
Gemini AI adds natural-language advice
e.g., "Apply urea fertilizer before sowing..."
The Predictor/ module contains the pre-trained model, label encoders, and the Python inference script. The Django backend calls this module to serve predictions, then passes context to Gemini for enriched AI guidance.
The datasets/ folder contains curated agricultural data with the following feature columns:
| Column | Description | Unit |
|---|---|---|
N |
Nitrogen content in soil | mg/kg |
P |
Phosphorus content in soil | mg/kg |
K |
Potassium content in soil | mg/kg |
temperature |
Average ambient temperature | Β°C |
humidity |
Relative humidity | % |
ph |
Soil pH value | 0β14 scale |
rainfall |
Annual rainfall | mm |
label |
Recommended crop (target variable) | crop name |
Contributions are welcome! Here's how to get started:
# 1. Fork the repository on GitHub
# 2. Clone your fork
git clone https://github.com/YOUR-USERNAME/AgroTech.git
# 3. Create a new feature branch
git checkout -b feature/your-feature-name
# 4. Make your changes and commit
git add .
git commit -m "feat: describe your change here"
# 5. Push to your fork and open a Pull Request
git push origin feature/your-feature-namePlease follow PEP 8 for Python code and include comments where needed.
Found a bug or have a suggestion? Open an issue with:
- A clear description of the problem
- Steps to reproduce it
- Expected vs. actual behaviour
- Screenshots if applicable
This project is licensed under the MIT License β see the LICENSE file for details.
Made with β€οΈ for Indian Farmers β Lucky-939