diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4994c67 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +chromium \ No newline at end of file diff --git a/app.py b/app.py index d8f05ac..b8221c3 100644 --- a/app.py +++ b/app.py @@ -1,23 +1,24 @@ -from flask import Flask,request,render_template +from flask import Flask, request, render_template import numpy as np import pandas import sklearn import pickle -# importing model -model = pickle.load(open('model.pkl','rb')) -sc = pickle.load(open('standscaler.pkl','rb')) -ms = pickle.load(open('minmaxscaler.pkl','rb')) +# Create the Flask app instance with the template and static folder set to the project root +app = Flask(__name__, template_folder='.', static_folder='.') -# creating flask app -app = Flask(__name__) +# Importing the model and scalers +model = pickle.load(open('model.pkl', 'rb')) +sc = pickle.load(open('standscaler.pkl', 'rb')) +ms = pickle.load(open('minmaxscaler.pkl', 'rb')) @app.route('/') def index(): return render_template("index.html") -@app.route("/predict",methods=['POST']) +@app.route("/predict", methods=['POST']) def predict(): + # Retrieve form data N = request.form['Nitrogen'] P = request.form['Phosporus'] K = request.form['Potassium'] @@ -26,28 +27,30 @@ def predict(): ph = request.form['Ph'] rainfall = request.form['Rainfall'] + # Prepare features for prediction feature_list = [N, P, K, temp, humidity, ph, rainfall] single_pred = np.array(feature_list).reshape(1, -1) + # Scaling features scaled_features = ms.transform(single_pred) final_features = sc.transform(scaled_features) prediction = model.predict(final_features) - crop_dict = {1: "Rice", 2: "Maize", 3: "Jute", 4: "Cotton", 5: "Coconut", 6: "Papaya", 7: "Orange", - 8: "Apple", 9: "Muskmelon", 10: "Watermelon", 11: "Grapes", 12: "Mango", 13: "Banana", - 14: "Pomegranate", 15: "Lentil", 16: "Blackgram", 17: "Mungbean", 18: "Mothbeans", - 19: "Pigeonpeas", 20: "Kidneybeans", 21: "Chickpea", 22: "Coffee"} + # Crop recommendation based on prediction output + crop_dict = { + 1: "Rice", 2: "Maize", 3: "Jute", 4: "Cotton", 5: "Coconut", 6: "Papaya", 7: "Orange", + 8: "Apple", 9: "Muskmelon", 10: "Watermelon", 11: "Grapes", 12: "Mango", 13: "Banana", + 14: "Pomegranate", 15: "Lentil", 16: "Blackgram", 17: "Mungbean", 18: "Mothbeans", + 19: "Pigeonpeas", 20: "Kidneybeans", 21: "Chickpea", 22: "Coffee" + } if prediction[0] in crop_dict: crop = crop_dict[prediction[0]] result = "{} is the best crop to be cultivated right there".format(crop) else: result = "Sorry, we could not determine the best crop to be cultivated with the provided data." - return render_template('index.html',result = result) + + return render_template("index.html", result=result) - - - -# python main if __name__ == "__main__": app.run(debug=True) \ No newline at end of file diff --git a/index.html b/index.html index 78ecc5e..b929840 100644 --- a/index.html +++ b/index.html @@ -3,130 +3,135 @@ - Bootstrap demo - + Crop Recommendation System + + - - - - - - - - - - -
-

Crop Recommendation System 🌱

- - + + + + + +
+

Crop Recommendation System 🌱

+
-
-
- - -
-
- - -
-
- - -
+
+
+ +
+
+ + +
+
+ + +
+
-
-
- - -
-
- - -
-
- - -
-
- -
-
- - -
-
- - +
+
+ + +
+
+ + +
+
+ + +
+
-
+
+
+ + +
+
-
- -
-
+
+
+ +
+
+ + {% if result %} +
+ Crop Image +
+
Recommended Crop for Cultivation:
+

{{ result }}

+
+
+ {% endif %} +
- - {% if result %} -
- ... -
-
Recommend Crop for cultivation is:
-

{{ result }}

-
-
- {% endif %} -
- - + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d1d305f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Flask==3.1.0 +numpy==2.2.3 +pandas==2.2.3 +scikit_learn==1.6.1