Skip to content

leninkumar1287/CropAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌾 CropAI - AI-Powered Crop Recommendation System

CropAI Logo Node.js React Express MongoDB License

Revolutionizing Agriculture with AI-Powered Crop Recommendations

πŸš€ Live Demo | πŸ“– Documentation | πŸ”§ Installation


🌟 Overview

CropAI is an intelligent agricultural platform that leverages artificial intelligence to provide personalized crop recommendations for farmers. By analyzing comprehensive farming data including soil health, climate conditions, historical yields, and government MSP (Minimum Support Price) data, CropAI helps farmers make data-driven decisions to maximize profitability and sustainability.

✨ Key Features

  • πŸ€– AI-Powered Recommendations: Uses advanced AI models (OpenAI GPT-4 or Together AI Mistral-7B)
  • πŸ“Š MSP Integration: Real-time integration with Government of India MSP data (2015-2026)
  • 🌱 Comprehensive Analysis: Considers soil health, climate, land details, and farmer profiles
  • πŸ’° Profit Optimization: Calculates expected profits, yields, and resource requirements
  • πŸ”„ Alternative Options: Provides multiple crop alternatives with detailed comparisons
  • πŸ“± Modern UI: Responsive React interface with intuitive farmer data collection
  • πŸ›‘οΈ Risk Assessment: Evaluates crop risks and provides mitigation strategies

πŸ—οΈ Architecture

CropAI/
β”œβ”€β”€ backend/                 # Node.js/Express API Server
β”‚   β”œβ”€β”€ server.js           # Main server file
β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   └── recommendation.js # AI recommendation endpoint
β”‚   β”œβ”€β”€ mspData.js         # Government MSP data
β”‚   └── package.json
β”œβ”€β”€ frontend/               # React Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx        # Main application component
β”‚   β”‚   β”œβ”€β”€ main.jsx       # React entry point
β”‚   β”‚   └── index.css      # Global styles
β”‚   └── package.json
└── README.md              # Project documentation

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Git for version control
  • API Keys for AI services (OpenAI or Together AI)

Installation

  1. Clone the repository

    git clone https://github.com/your-username/CropAI.git
    cd CropAI
  2. Backend Setup

    cd backend
    npm install
    cp .env.example .env  # Configure your API keys
    npm run dev
  3. Frontend Setup (in a new terminal)

    cd frontend
    npm install
    npm run dev
  4. Access the Application


πŸ”§ Configuration

Environment Variables

Create a .env file in the backend directory:

# Server Configuration
PORT=5000
NODE_ENV=development

# AI Service Configuration (choose one)
OPENAI_API_KEY=your_openai_api_key_here
TOGETHER_API_KEY=your_together_api_key_here

# Database (future use)
MONGODB_URI=mongodb://localhost:27017/cropai

AI Provider Selection

CropAI supports two AI providers:

  • OpenAI GPT-4: Higher accuracy, requires API key
  • Together AI Mistral-7B: Cost-effective, good performance

Configure the provider in the frontend or API request.


πŸ“– API Documentation

Base URL

http://localhost:5000/api

Authentication

Currently, no authentication required. Add API keys for production use.

Endpoints

POST /recommendations

Get AI-powered crop recommendations based on comprehensive farmer data.

Request Body:

{
  "soilType": "loam",
  "phLevel": 7.2,
  "rainfall": 1200,
  "temperature": 28,
  "currentCrop": "Rice",
  "yieldHistory": 3.5,
  "marketPrice": 25,
  "aiProvider": "together",
  "language": "en",
  "landDetails": {
    "state": "Andhra Pradesh",
    "district": "Chittoor",
    "subDistrict": "Kuppam",
    "village": "Kuppam Village",
    "surveyNumber": "789/B",
    "totalArea": 3.2,
    "extentAssignedArea": 2.8,
    "landSource": "Own Land"
  },
  "ownershipDetails": [{
    "ownerNumber": "001",
    "mainOwnerNumber": "001",
    "identifierName": "Farmer Name",
    "ownerType": "Individual",
    "ownerShareType": "Full Owner",
    "extent": 2.8
  }],
  "soilDetails": {
    "centreName": "Agricultural Research Center",
    "testId": "TEST-001",
    "testingDate": "2024-03-15",
    "validity": "2025-03-15",
    "surveyNo": "123/A",
    "plotSize": 2.3,
    "soilHealthParameters": {
      "nitrogen": 280,
      "phosphorus": 25,
      "potassium": 180,
      "ph": 7.2,
      "organicCarbon": 0.8,
      "sulphur": 15,
      "zinc": 1.2
    }
  },
  "cropDetailsEPanta": {
    "farmerName": "Farmer Name",
    "aadhaarNumber": "123456789012",
    "mobileNumber": "9876543210",
    "variety": "MTU 1010",
    "areaSown": 2.3,
    "dateOfSowing": "2024-07-15",
    "cropNature": "Kharif",
    "waterSource": "Canal",
    "methodOfIrrigation": "Drip Irrigation",
    "farmingType": "Organic"
  },
  "cropDetailsFarmer": {
    "investmentKharif": "β‚Ή85000",
    "cropYield": "4.2 tons/ha",
    "farmerAssets": ["Tractor", "Irrigation Pump"],
    "stages": {
      "preSowing": "Fertilizer application",
      "sowing": "Manual sowing",
      "germination": "70% germination",
      "vegetative": "Good growth",
      "flowering": "Dense flowering",
      "fruitingMaturity": "Grain filling",
      "harvesting": "Manual harvesting",
      "postHarvest": "Threshing and storage"
    }
  },
  "cropInsurance": {
    "insured": true,
    "sumInsured": "β‚Ή50000",
    "premiumPaid": "β‚Ή750",
    "coverageArea": 2.3,
    "riskCoverage": "Flood, Drought, Pest Attack"
  },
  "encumbrance": {
    "status": "Clear",
    "mortgageDetails": "Nil",
    "encumbranceIfAny": "No encumbrance"
  }
}

Response:

{
  "success": true,
  "recommendation": {
    "recommendedCrop": "Tur (Arhar)",
    "reason": "High MSP rates and suitable for loam soil conditions",
    "confidenceScore": 85,
    "expectedProfit": 80000,
    "expectedYield": 2.0,
    "waterRequirement": 2000,
    "laborRequirement": 100,
    "maturityTime": 110,
    "riskLevel": "Medium",
    "equipmentNeeded": ["Tractor", "Plough"],
    "effortDistribution": {
      "setup": 20,
      "maintenance": 50,
      "harvesting": 30
    },
    "resourceRequirements": {
      "waterNeeded": "2000 L/ha",
      "fertilizers": ["Urea", "DAP"],
      "pesticides": ["Generic Pesticide"]
    },
    "soilConditions": {
      "suitability": "Good",
      "analysis": "Tur is suitable for loam soil with pH 7.2"
    },
    "marketAnalysis": {
      "profitMargin": "25%",
      "marketDemand": "Medium"
    },
    "alternativeCrops": [
      {
        "crop": "Groundnut",
        "score": 75,
        "reason": "Alternative oilseed crop with stable market demand",
        "expectedProfit": 70000,
        "expectedYield": 1.8,
        "waterRequirement": 1800,
        "laborRequirement": 90,
        "maturityTime": 105,
        "riskLevel": "Medium",
        "equipmentNeeded": ["Tractor"],
        "resourceRequirements": {
          "waterNeeded": "1800 L/ha",
          "fertilizers": ["DAP"],
          "pesticides": ["Cypermethrin"]
        }
      }
    ]
  }
}

Error Response:

{
  "error": "All crop data fields are required",
  "details": "Missing required field: soilType"
}

🎯 Usage Examples

Basic Recommendation Request

const farmerData = {
  soilType: "loam",
  phLevel: 7.0,
  rainfall: 1000,
  temperature: 25,
  currentCrop: "Rice",
  yieldHistory: 3.0,
  marketPrice: 20,
  aiProvider: "together"
};

fetch('http://localhost:5000/api/recommendations', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(farmerData),
})
.then(response => response.json())
.then(data => console.log(data.recommendation));

Using with React Frontend

The frontend provides a comprehensive form interface for data collection. Sample farmer data is pre-loaded for testing.


πŸ“Š Data Sources

MSP (Minimum Support Price) Data

  • Source: Government of India, Ministry of Agriculture
  • Coverage: 2015-2026 for major crops
  • Update Frequency: Annual (Kharif & Rabi seasons)
  • Crops Covered: Paddy, Wheat, Tur, Moong, Urad, Cotton, and more

AI Models

  • OpenAI GPT-4: Advanced reasoning and analysis
  • Together AI Mistral-7B: Efficient and cost-effective

πŸ”’ Security & Privacy

  • Data Privacy: Farmer data is processed locally (no external storage)
  • API Security: Implement authentication for production use
  • Input Validation: Comprehensive validation of all input parameters
  • Error Handling: Secure error responses without data leakage

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

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

πŸ“„ License

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


πŸ™ Acknowledgments

  • Government of India for MSP data and agricultural support
  • OpenAI and Together AI for AI model access
  • React & Node.js communities for excellent frameworks
  • KADA (Kuppam Area Development Authority) for domain expertise

πŸ“ž Support


Made with ❀️ for farmers worldwide

⬆️ Back to Top

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published