Skip to content

Repository files navigation

AgriNex - Smart Agricultural Intelligence System 🌾

Python 3.8+ Streamlit TensorFlow scikit-learn License: MIT Status: Active

AgriNex is an end-to-end, multi-modal agricultural intelligence platform leveraging machine learning, deep neural networks, and interactive web tools to empower modern precision farming. The system brings predictive analytics directly to farmers and agricultural extension workers through intuitive dashboards and live deployed microservices.

🌾 Overview

AgriNex combines cutting-edge AI/ML technologies with user-friendly web interfaces to help farmers make data-driven decisions about crop selection, disease management, and fertilizer optimization. The platform integrates multiple machine learning models trained on agricultural datasets to provide accurate and actionable insights.

πŸ“Œ Table of Contents

πŸš€ Deployed Live Streamlit Applications

AgriNex trained machine learning models are deployed live on Streamlit Cloud:

πŸ—οΈ System Architecture & Workflow

graph TD
    User([Farmer / Agricultural Worker]) --> WebApp[AgriSens Web Application]
    
    subgraph Frontend Layer
        WebApp --> CropPage[Crop Recommendation UI]
        WebApp --> FertPage[Fertilizer Advisor UI]
        WebApp --> DiseasePage[Disease Detection UI]
        WebApp --> Chatbot[AI Kisan Chatbot Widget]
        WebApp --> Dashboard[Farm Dashboard & Mandi Ticker]
    end
    
    subgraph ML & Intelligence Layer
        CropPage --> |Soil & Climate Data| CropML[Random Forest Classifier]
        FertPage --> |Soil Nutrient Analysis| FertML[Fertilizer XGB/RF Classifier]
        DiseasePage --> |Leaf Image Upload| DiseaseCNN[TensorFlow 38-Class CNN Model]
        Chatbot --> |Natural Language Query| KisanEngine[Knowledge Engine & Mandi Data API]
    end

    subgraph External Cloud Deployments
        CropML --> StreamlitCloud[Streamlit Cloud Services]
        FertML --> StreamlitCloud
        DiseaseCNN --> StreamlitCloud
    end
Loading

✨ Features & Capabilities

  • Embedded Streamlit ML Apps: Real-time interactive model predictions seamlessly embedded inside responsive web interfaces (crop-prediction.html, fertilizer.html, disease-detection.html).
  • Universal AI Kisan Chatbot: Multi-lingual floating conversational assistant tailored for localized agricultural advice, weather alerts, disease remedies, and APMC market prices.
  • Precision Crop Recommendation Engine: High-accuracy crop selection powered by Random Forest algorithms analyzing Nitrogen (N), Phosphorus (P), Potassium (K), temperature, relative humidity, pH, and annual rainfall.
  • Computer Vision Plant Pathology: Deep convolutional neural network (CNN) capable of identifying 38 distinct crop diseases across 14 plant species with leaf image uploaded via web interface.
  • Soil-Specific Fertilizer Advisor: Automated fertilizer dosage calculation matching crop requirements against current NPK depletion metrics to avoid over-fertilization.
  • Live APMC Mandi Ticker & Government Schemes: Real-time wholesale commodity price ticker and curated catalog of PM-KISAN, KCC, and state agricultural subsidies.
  • Farm Management Telemetry Dashboard: Complete farm monitoring hub with 7-day weather forecasting, spray-window advisory, yield revenue estimate tools, and direct Krishi Vigyan Kendra (KVK) contacts.

πŸ› οΈ Tech Stack

Frontend

  • React.js - Interactive user interface
  • HTML/CSS/JavaScript - Web standards

Backend & ML Services

  • Python - Core language for ML/AI services
  • Streamlit - Framework for data apps and model serving
  • Flask - Web framework for APIs

Machine Learning & AI

  • TensorFlow - Deep learning framework
  • Keras - Neural network API for plant disease identification
  • scikit-learn - Machine learning algorithms for crop and fertilizer prediction
  • Random Forest Classifier - Ensemble learning for crop recommendation

Data Processing & Visualization

  • Pandas - Data manipulation and analysis
  • NumPy - Numerical computing
  • Matplotlib - 2D plotting and visualization
  • Seaborn - Statistical data visualization
  • OpenCV - Computer vision for image processing

Datasets

  • PlantVillage Dataset - 38 plant disease classes
  • Crop Recommendation Dataset - Soil and environmental parameters
  • Fertilizer Recommendation Dataset - Soil nutrient analysis

πŸ“ Project Structure

AgriNex/
β”œβ”€β”€ CROP PREDICT/                          # React frontend + ML model training
β”‚   β”œβ”€β”€ frontend/                          # React application
β”‚   β”‚   β”œβ”€β”€ public/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.html
β”‚   β”‚   β”‚   └── manifest.json
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ App.js
β”‚   β”‚       β”œβ”€β”€ home.js
β”‚   β”‚       β”œβ”€β”€ index.js
β”‚   β”‚       └── index.css
β”‚   β”œβ”€β”€ saved_model/                       # Pre-trained crop prediction models
β”‚   β”‚   β”œβ”€β”€ model_v1.h5
β”‚   β”‚   β”œβ”€β”€ model_v2.h5
β”‚   β”‚   └── model_v3.h5
β”‚   └── training/
β”‚       β”œβ”€β”€ model.ipynb                    # Model training notebook
β”‚       └── PlantVillage/                  # Training dataset
β”‚
β”œβ”€β”€ CROP-RECOMMENDATION/                   # Streamlit crop recommendation app
β”‚   β”œβ”€β”€ webapp.py                          # Main Streamlit application
β”‚   β”œβ”€β”€ Crop_recommendation.csv            # Dataset
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── fgd.html
β”‚
β”œβ”€β”€ PLANT-DISEASE-IDENTIFICATION/          # Streamlit disease detection app
β”‚   β”œβ”€β”€ main.py                            # Main Streamlit application
β”‚   β”œβ”€β”€ trained_plant_disease_model.keras  # Trained Keras model
β”‚   β”œβ”€β”€ Train_plant_disease.ipynb          # Training notebook
β”‚   β”œβ”€β”€ Test_plant_disease.ipynb           # Testing notebook
β”‚   β”œβ”€β”€ training_hist.json                 # Training history
β”‚   β”œβ”€β”€ settings.json                      # Configuration
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── test/                              # Test images
β”‚
β”œβ”€β”€ fertilizer_prediction/                 # Fertilizer prediction module
β”‚   └── fertilizer_prediction/
β”‚       β”œβ”€β”€ fert.py                        # Fertilizer prediction script
β”‚       β”œβ”€β”€ p1.ipynb                       # Analysis notebook
β”‚       β”œβ”€β”€ data_core.csv                  # Dataset
β”‚       └── requirements.txt
β”‚
β”œβ”€β”€ Datasets/                              # Consolidated datasets
β”‚   β”œβ”€β”€ Crop_recommendation.csv
β”‚   β”œβ”€β”€ Fertilizer_recommendation.csv
β”‚   β”œβ”€β”€ README.md
β”‚   └── PlantVillage/                      # Plant disease images
β”‚       β”œβ”€β”€ Potato___healthy/
β”‚       β”œβ”€β”€ Potato___Late_blight/
β”‚       └── [38+ disease classes]
β”‚
└── AgriSens-web-app/                      # Integrated web application

πŸš€ Getting Started

Prerequisites

  • Python 3.8+
  • Node.js 14+ (for frontend web apps)
  • Docker & Docker Compose (optional for containerized setup)
  • pip / venv or conda for environment isolation
  • Git

Quick Setup with Virtual Environment

1. Clone the Repository

git clone https://github.com/SQUADRON-LEADER/AgriNex.git
cd AgriNex

2. Environment Setup (Recommended)

# Create and activate virtual environment
python -m venv venv

# On Windows
.\venv\Scripts\activate

# On Linux/macOS
source venv/bin/activate

3. Setup & Run Crop Recommendation Microservice

cd CROP-RECOMMENDATION
pip install -r requirements.txt
streamlit run webapp.py

Access interface at http://localhost:8501

4. Setup & Run Plant Disease Detection Microservice

cd ../PLANT-DISEASE-IDENTIFICATION
pip install -r requirements.txt
streamlit run main.py --server.port 8502

Access interface at http://localhost:8502

5. Setup & Run Fertilizer Advisor Microservice

cd ../fertilizer_prediction/fertilizer_prediction
pip install -r requirements.txt
python fert.py

6. Launch AgriSens Integrated Web Portal

cd ../AgriSens-web-app
# Open index.html directly in browser or serve via npx http-server
npx http-server -p 8080

🐳 Containerized Deployment (Docker)

# Build and run containers via Docker Compose
docker-compose up --build -d

πŸ“Š Model Details

Crop Recommendation Model

  • Algorithm: Random Forest Classifier
  • Features: N, P, K (soil nutrients), Temperature, Humidity, pH, Rainfall
  • Output Classes: 22 different crops (Rice, Maize, Chickpea, Kidney Beans, Pigeon Peas, Moth Beans, Mung Bean, Black Gram, Lentil, Pomegranate, Banana, Mango, Grapes, Watermelon, Muskmelon, Apple, Orange, Papaya, Coconut, Cotton, Jute, Coffee)
  • Accuracy: ~99% cross-validation accuracy
  • Training Data: 2,200+ soil & climate sample observations

πŸ§ͺ Input Parameter Specifications Table

Feature Parameter Symbol Measurement Unit Typical Value Range Description
Nitrogen N ratio / mg/kg 0 - 140 Soil ratio of Nitrogen content
Phosphorus P ratio / mg/kg 5 - 145 Soil ratio of Phosphorus content
Potassium K ratio / mg/kg 5 - 205 Soil ratio of Potassium content
Temperature temp Β°C 8.8 - 43.7 Ambient atmospheric temperature
Humidity humidity % 14.3 - 99.9 Relative air humidity percentage
pH Level ph pH scale 3.5 - 9.9 Acidity / alkalinity index of soil
Rainfall rainfall mm 20.2 - 298.6 Cumulative seasonal rainfall

Plant Disease Detection Model

  • Framework: TensorFlow / Keras 2.x
  • Architecture: Convolutional Neural Network (CNN) with Softmax classification layer
  • Input Dimensions: 128x128 pixel RGB tensor
  • Output Classes: 38 distinct plant pathology classes
  • Supported Crops: Apple, Blueberry, Cherry, Corn, Grape, Orange, Peach, Pepper, Potato, Raspberry, Soybean, Squash, Strawberry, Tomato

Fertilizer Prediction Model

  • Algorithm: Machine Learning Classifier (Random Forest / XGBoost hybrid)
  • Features: Soil NPK baseline, soil type, crop type, humidity, temperature
  • Output: Optimized target fertilizer blend (e.g., Urea, DAP, 14-35-14, 28-28, 17-17-17, 20-20, 10-26-26) with calculated application rate

πŸ’» Usage Examples

Crop Recommendation

Input: N=90, P=42, K=43, Temperature=20.87, Humidity=82.00, pH=6.5, Rainfall=202.9
Output: Recommendation for "Maize" crop

Disease Detection

Input: Plant leaf image
Output: Disease identified with confidence score
Example: "Potato___Late_blight - 95% confidence"

Fertilizer Recommendation

Input: Soil parameters and crop type
Output: Specific fertilizer recommendation with dosage

πŸ“ˆ Dataset Information

  • PlantVillage Dataset: 61,486 images across 38 disease classes
  • Crop Dataset: Features covering 22 different crops with environmental parameters
  • Fertilizer Dataset: Comprehensive soil and crop parameters with recommendations

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ Model Training & Evaluation

To retrain or evaluate models:

Crop Prediction

cd CROP\ PREDICT/training
jupyter notebook model.ipynb

Plant Disease Detection

cd PLANT-DISEASE-IDENTIFICATION
jupyter notebook Train_plant_disease.ipynb

πŸ”§ Configuration

Each service has a settings.json or configuration file for model parameters and settings. Modify these files to adjust:

  • Model paths
  • Input parameters
  • Output formats
  • Service ports

πŸ“¦ Dependencies

See individual requirements.txt files in each module directory for specific dependencies:

  • Core ML dependencies: TensorFlow, Keras, scikit-learn
  • Data processing: Pandas, NumPy
  • Visualization: Matplotlib, Seaborn
  • Web frameworks: Streamlit, Flask
  • Image processing: OpenCV, Pillow

πŸ› Troubleshooting

Model Loading Issues

  • Ensure model files (.keras, .h5) are in the correct directories
  • Verify TensorFlow and Keras versions match training environment

Streamlit Port Already in Use

streamlit run app.py --server.port 8503

Missing Dependencies

pip install --upgrade -r requirements.txt

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Team & Credits

AgriNex is developed as an agricultural AI solution combining expertise in:

  • Machine Learning & Deep Learning
  • Agricultural Science
  • Full-Stack Web Development

πŸ“ž Support

For issues, questions, or suggestions:

  1. Open an issue on GitHub
  2. Check existing documentation
  3. Review dataset README files for data-specific questions

🌱 Future Enhancements & Strategic Roadmap

  • Multi-modal Web Dashboard Integration: Unified interface for crop recommendation, disease detection, and fertilizer calculation.
  • Live Streamlit Cloud Deployment: Microservices published live for testing and remote inference.
  • Hyper-local Weather & Microclimate API: Integrate OpenWeatherMap API for live rainfall and moisture forecast alerts.
  • Real-time Commodity Price Forecasting: Time-series predictive models for APMC market trends.
  • Native Mobile Application (React Native): Offline-first mobile app for field operation with localized camera scan.
  • Regional Language Localization: Support for Hindi, Marathi, Punjabi, Tamil, Telugu, and Kannada.
  • IoT Sensor Grid Integration: Direct Bluetooth / LoRaWAN telemetry ingestion from soil NPK hardware probes.

AgriNex β€’ Empowering Sustainable Farming with Artificial Intelligence
Developed with ❀️ for farmers, agronomists, and precision agriculture worldwide.

About

AgriNex is a comprehensive agricultural intelligence platform that leverages machine learning and deep learning to provide intelligent solutions for modern farming. The system offers three core functionalities: crop recommendation, plant disease identification, and fertilizer prediction.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages