The Crop Prediction Web Application is a tool designed to predict the best crop to grow based on various environmental factors. The application is built using a React front-end and a Flask back-end, leveraging a machine learning model for the prediction.
Visit the live website : https://next-crop.onrender.com
- User-friendly Interface: Intuitive and easy-to-use interface built with React.
- Machine Learning Predictions: Utilizes a trained machine learning model to predict the optimal crop.
- RESTful API: Backend API developed with Flask to handle predictions and data processing.
- Cross-Origin Resource Sharing (CORS): Enabled to allow the front-end and back-end to communicate seamlessly.
- Front-end: React,JavaScript
- Back-end: Flask, Python
- Machine Learning: Pandas, Scikit-learn, Pickle , xgboost
- Other: Flask-CORS for handling cross-origin requests
- Node.js
- Python 3.x
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/yourusername/crop-prediction.git cd crop-prediction/backend -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Run the Flask server:
python app.py
-
Navigate to the frontend directory:
cd ../client -
Install dependencies:
npm install
-
Start the React development server:
npm run dev
- Ensure the Flask server is running on port 5000.
- Ensure the React development server is running on port 3000.
- Open your browser and navigate to
http://localhost:3000. - Enter the required environmental parameters (Nitrogen, Phosphorus, Potassium, Temperature, Humidity, pH Value, Rainfall).
- Click on the "Predict" button to get the crop prediction.
- Description: Check if the API is running.
- Response:
{"message": "API is Running"}
- Description: Predict the optimal crop based on input parameters.
- Request Body: JSON object containing the following fields:
Nitrogen(int)Phosphorus(int)Potassium(int)Temperature(float)Humidity(float)pH_Value(float)Rainfall(float)
- Response: JSON object containing the prediction:
{"prediction": ["CropName"]}
Request:
{
"Nitrogen": 90,
"Phosphorus": 42,
"Potassium": 43,
"Temperature": 20.8,
"Humidity": 82,
"pH_Value": 6.5,
"Rainfall": 202
}
