Krishi Sakhi is a cross-platform solution for smart agriculture, featuring a Flutter mobile app and a Flask backend powered by machine learning models. The system provides crop recommendations, yield predictions, plant disease detection, and pest identification to assist farmers in making informed decisions.
Krishi Sakhi/
├── Flask Backend - ML Models/
│ ├── requirements.txt
│ ├── src/
│ │ ├── app.py
│ │ └── models/
│ │ └── ... (ML models and assets)
│ └── tests/
│ └── plant_disease_prediction_test_script.py
├── Flutter App/
│ ├── pubspec.yaml
│ ├── .env
│ ├── lib/
│ │ ├── main.dart
│ │ ├── l10n/ # Localization
│ │ ├── models/ # Data models
│ │ ├── providers/ # State management (provider)
│ │ ├── screens/ # UI screens (home, onboarding, crop recommendation, etc.)
│ │ ├── services/ # API and logic services
│ │ ├── utils/ # Utilities (env_keys, constants, theme)
│ │ └── widgets/ # Reusable widgets
│ └── ... (platform folders: android, ios, web, etc.)
└── README.md
- Crop Recommendation: Suggests optimal crops based on soil nutrients, weather, and rainfall using ML models and fallback logic.
- Yield Prediction: Estimates expected crop yield from user and weather data.
- Plant Disease Detection: Identifies plant diseases from leaf images using deep learning.
- Pest Detection: Detects and classifies pests from images.
- Fertilizer Recommendation: Recommends fertilizers based on soil and crop data.
- Weather Integration: Fetches real-time weather data for location-aware recommendations.
- Schemes & Loans: Provides information on government schemes and agricultural loans.
- Voice Assistant: Voice-based interaction for hands-free usage.
- Chatbot: In-app chatbot for agricultural queries and support.
- Multi-language Support: Localized UI for multiple Indian languages.
- Crop Recommendation: Predicts optimal crops using a trained ML model.
- Yield Prediction: Estimates crop yield based on area, production, rainfall, fertilizer, crop, season, and state.
- Plant Disease Detection: Classifies plant diseases from images using a PyTorch model and Gemini AI for enhanced accuracy.
- Pest Detection: Identifies pests from images using a deep learning model.
- Fertilizer Recommendation: Suggests fertilizers based on soil and crop type.
- API Endpoints: RESTful endpoints for all predictions, with JSON and image support.
- Environment Variables: Loads sensitive keys (e.g., Gemini API key) from
.env.
Flask Backend - ML Models/
├── requirements.txt # Python dependencies
├── .env # Environment variables (not committed)
├── src/
│ ├── app.py # Main Flask app and API endpoints
│ └── models/ # ML models and assets (joblib, pth files)
└── tests/
└── plant_disease_prediction_test_script.py
- Navigate to the backend folder:
cd "Flask Backend - ML Models"
- Create a Python virtual environment:
python -m venv venv
- Activate the environment:
- Windows:
.\venv\Scripts\activate
- macOS/Linux:
source venv/bin/activate
- Windows:
- Install dependencies:
pip install -r requirements.txt
- Create a
.envfile in the backend root. Example:GEMINI_API_KEY=your_api_key_here FLASK_ENV=development SECRET_KEY=your_secret_key # Add other keys as needed - Run the Flask server:
python src/app.py
- Navigate to the Flutter app folder:
cd "Flutter App"
- Get dependencies:
flutter pub get
- Create an environment file for API endpoints and keys:
- Create a
.envfile in theFlutter Appdirectory. Example:# Flutter App/.env API_BASE_URL=http://127.0.0.1:5000 OPENWEATHER_API_KEY=your_openweather_key GEMINI_API_KEY=your_gemini_key # Add other keys as needed - The app uses
flutter_dotenvto load environment variables at startup. Keys are accessed in code via theEnvKeysclass inlib/utils/env_keys.dart:import 'package:flutter_dotenv/flutter_dotenv.dart'; class EnvKeys { static String get openWeatherApiKey => dotenv.env['OPENWEATHER_API_KEY'] ?? ''; static String get geminiApiKey => dotenv.env['GEMINI_API_KEY'] ?? ''; // ... }
- Update the
.envfile as needed for your deployment.
- Create a
- Run the app:
flutter run
- State Management: Uses
providerfor app-wide state (authentication, language, crop recommendation, weather, etc.). - API Services: All backend and ML model communication is handled in
lib/services/(e.g.,crop_api_service.dart). - Screens: Each feature (crop recommendation, disease detection, etc.) has its own screen in
lib/screens/. - Localization: Multi-language support via
flutter_localizationsand customAppLocalizations. - Environment Variables: All sensitive keys and endpoints are loaded from
.envand never hardcoded. - UI: Custom themes and reusable widgets for a consistent look.
- Ensure both backend and frontend
.envfiles are not committed to version control. - Update API URLs in the Flutter
.envfile as per your backend deployment.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.