Vikrant26 commited on
Commit
c300ece
·
verified ·
1 Parent(s): baa4ffa

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +55 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from flask import Flask, request, render_template
3
+ import numpy as np
4
+ import pandas as pd
5
+ import sklearn
6
+ import pickle
7
+
8
+ # importing model
9
+ model = pickle.load(open('modelcr.pkl','rb'))
10
+ sc = pickle.load(open('standscalercr.pkl','rb'))
11
+ ms = pickle.load(open('minmaxscalercr.pkl','rb'))
12
+
13
+ # creating flask app
14
+ app = Flask(__name__, template_folder="template")
15
+
16
+
17
+ @app.route('/')
18
+ def index():
19
+ return render_template("index.html")
20
+
21
+ @app.route("/predict",methods=['POST'])
22
+ def predict():
23
+ N = request.form['Nitrogen']
24
+ P = request.form['Phosporus']
25
+ K = request.form['Potassium']
26
+ temp = request.form['Temperature']
27
+ humidity = request.form['Humidity']
28
+ ph = request.form['Ph']
29
+ rainfall = request.form['Rainfall']
30
+
31
+ feature_list = [N, P, K, temp, humidity, ph, rainfall]
32
+ single_pred = np.array(feature_list).reshape(1, -1)
33
+
34
+ scaled_features = ms.transform(single_pred)
35
+ final_features = sc.transform(scaled_features)
36
+ prediction = model.predict(final_features)
37
+
38
+ crop_dict = {1: "Rice", 2: "Maize", 3: "Jute", 4: "Cotton", 5: "Coconut", 6: "Papaya", 7: "Orange",
39
+ 8: "Apple", 9: "Muskmelon", 10: "Watermelon", 11: "Grapes", 12: "Mango", 13: "Banana",
40
+ 14: "Pomegranate", 15: "Lentil", 16: "Blackgram", 17: "Mungbean", 18: "Mothbeans",
41
+ 19: "Pigeonpeas", 20: "Kidneybeans", 21: "Chickpea", 22: "Coffee"}
42
+
43
+ if prediction[0] in crop_dict:
44
+ crop = crop_dict[prediction[0]]
45
+ result = "{} is the best crop to be cultivated right there".format(crop)
46
+ else:
47
+ result = "Sorry, we could not determine the best crop to be cultivated with the provided data."
48
+ return render_template('index.html',result = result)
49
+
50
+
51
+
52
+
53
+ # python main
54
+ if __name__ == "__main__":
55
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ numpy
3
+ sklearn