-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.py
47 lines (37 loc) · 1.56 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Flask, request, jsonify
import numpy as np
import sklearn
import pickle
model = pickle.load(open('model.pkl', 'rb'))
sc = pickle.load(open('standscaler.pkl', 'rb'))
ms = pickle.load(open('minmaxscaler.pkl', 'rb'))
application = Flask(__name__)
@application.route('/')
def ok():
return "Running!"
@application.route('/pred', methods=['POST'])
def predict():
N = request.form['Nitrogen']
P = request.form['Phosphorus']
K = request.form['Potassium']
temp = request.form['Temperature']
humidity = request.form['Humidity']
ph = request.form['Ph']
rainfall = request.form['Rainfall']
feature_list = [N, P, K, temp, humidity, ph, rainfall]
single_pred = np.array(feature_list).reshape(1, -1)
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"}
if prediction[0] in crop_dict:
crop = crop_dict[prediction[0]]
else:
crop = 'NOT able to recommend'
return jsonify(crop)
# python main
if __name__ == "__main__":
application.run(host='0.0.0.0', port=5000, debug=True)