-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
61 lines (52 loc) · 1.68 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask, render_template, request, jsonify
import pickle
import numpy as np
import json
app = Flask(__name__)
model = pickle.load(open('classifier.pkl', 'rb'))
@app.route("/")
def home():
return render_template('index.html')
@app.route("/predict", methods=["POST"])
def predict():
data = request.form.values()
float_features = [float(x) for x in data]
final_features = [np.array(float_features)]
predictions = model.predict(final_features)
if predictions == 0:
predictions = "NPK 10-26-26"
elif predictions == 1:
predictions = "NPK 14-35-14"
elif predictions == 2:
predictions = "NPK 17-17-17"
elif predictions == 3:
predictions = "NPK 20-20"
elif predictions == 4:
predictions = "NPK 28-28"
elif predictions == 5:
predictions = "NPK DAP"
else:
predictions = "NPK Urea"
return jsonify({"predictions": predictions})
@app.route("/predict-web", methods=["POST"])
def predictWeb():
float_features = [float(x) for x in request.form.values()]
final_features = [np.array(float_features)]
predictions = model.predict(final_features)
if predictions == 0:
predictions = "NPK 10-26-26"
elif predictions == 1:
predictions = "NPK 14-35-14"
elif predictions == 2:
predictions = "NPK 17-17-17"
elif predictions == 3:
predictions = "NPK 20-20"
elif predictions == 4:
predictions = "NPK 28-28"
elif predictions == 5:
predictions = "NPK DAP"
else:
predictions = "NPK Urea"
return render_template("index.html", prediction_text="{}".format(predictions))
if __name__ == "__main__":
app.run(debug=True)