AgriSmart: AI-Powered Crop Yield Prediction and Agricultural Advisory System
Back to ProjectFollow the steps below to set up AgriSmart on your local machine. The entire process takes approximately 10 to 15 minutes depending on your internet speed and system configuration.
Download the project ZIP from CodeAj Marketplace and extract it, or clone the repository using the command below. Navigate into the project folder after extraction.
git clone <repository_url>
cd "Crop Yield Prediction"
The dataset files are hosted externally due to their size. Click the button below to download the dataset from Google Drive. Once downloaded, extract the contents and place all CSV files inside the dataset/ folder in the project root.
Dataset folder should contain:
dataset/
├── pesticides.csv
├── rainfall.csv
├── temp.csv
├── yield_df.csv
└── yield.csv
It is strongly recommended to create an isolated virtual environment before installing dependencies. This prevents conflicts with other Python projects on your system.
python -m venv venv
Activate the virtual environment based on your operating system before proceeding to install dependencies.
.\venv\Scripts\activate
source venv/bin/activate
Once activated, you will see (venv) appear at the beginning of your terminal prompt, confirming the environment is active.
Run the following command to install all required Python libraries including Flask, scikit-learn, Keras, TensorFlow, NumPy, Pandas, Matplotlib, and Seaborn in one step.
pip install -r requirements.txt
This step may take 3 to 8 minutes depending on your internet connection as it downloads TensorFlow and other large libraries.
The pre-trained machine learning models are included in the models/ directory and are ready to use without any additional training. Verify that the following files are present.
models/
├── yield_prediction_model.pkl (Random Forest — crop yield)
├── yield_scaler.pkl (scaler for yield inputs)
├── disease_prediction_model.pkl (CNN — plant disease detection)
├── disease_scaler.pkl (scaler for disease inputs)
├── disease_encoder.pkl (label encoder for diseases)
└── weather_model.pkl (Linear Regression — rainfall)
The fertilizer_recommender.pkl file is optional. If not present, the system automatically falls back to a built-in rule-based recommendation engine. This is expected behavior and does not affect functionality.
If you want to retrain the models from scratch or explore the training process for your project presentation, open the Jupyter Notebook and execute all cells in order.
jupyter notebook training.ipynb
Running the full training notebook will overwrite the existing model files in the models/ directory with newly trained versions. Skip this step if you want to use the pre-trained models.
Start the AgriSmart web server using the command below. The application will launch on your local machine and be accessible through your browser.
python app.py
Once running, open your browser and go to:
http://127.0.0.1:5000/
Use the following URLs to access each module of AgriSmart directly from your browser.
| Module | URL |
|---|---|
| Home Dashboard | http://127.0.0.1:5000/ |
| Crop Yield Prediction | http://127.0.0.1:5000/yield-prediction |
| Disease Detection | http://127.0.0.1:5000/disease-prediction |
| Fertilizer Recommendation | http://127.0.0.1:5000/fertilizer-recommendation |
| Weather Prediction | http://127.0.0.1:5000/weather-prediction |
| About | http://127.0.0.1:5000/about |
AgriSmart also exposes REST API endpoints that accept POST requests, allowing programmatic access to all four AI modules. Refer to app.py for the exact request payload and response structure for each endpoint.
POST /api/predict-yield
POST /api/predict-disease
POST /api/recommend-fertilizer
POST /api/predict-weather
Make sure you are using Python 3.8 to 3.11. TensorFlow does not officially support Python 3.12 and above on some platforms. Consider using Python 3.10 for best compatibility.
This is not an error. The system automatically uses the built-in rule-based fallback engine if this file is absent. All fertilizer recommendations will still work correctly.
Ensure all five CSV files from the Google Drive download are placed inside the dataset/ folder. The folder must be in the same directory as app.py.
Another application is using port 5000. You can run Flask on a different port using: python app.py --port 5001 or change the port inside app.py.
CodeAj offers a dedicated Project Setup and Source Code Explanation service. Our team will guide you through the complete installation process, walk you through every module of the code, and ensure you are fully prepared for your final year project submission and viva. Visit our services page to know more.
Our team is here to assist you with installation and setup.