-
Notifications
You must be signed in to change notification settings - Fork 1
/
application.py
42 lines (31 loc) · 1004 Bytes
/
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
from flask import Flask, request, jsonify
import numpy as np
import webbrowser
from threading import Timer
import pickle
model = pickle.load(open('RandomForest.pkl','rb'))
print(1)
app = Flask(__name__)
@app.route('/')
def index():
return "Try to use /predict endpoint"
@app.route('/predict',methods=['POST'])
def predict():
N = request.form.get('N')
P = request.form.get('P')
K = request.form.get('K')
temperature = request.form.get('temperature')
humidity = request.form.get('humidity')
ph = request.form.get('ph')
rainfall = request.form.get('rainfall')
input_query = np.array([[N,P,K,temperature,humidity,ph,rainfall]])
result = model.predict(input_query)[0]
return jsonify({'crop':str(result)})
if __name__ == '__app__':
app.run(debug=True)
# def open_browser():
# webbrowser.open_new("http://127.0.0.1:5000")
# if __name__ == "__main__":
# Timer(1, open_browser).start()
# app.run(port=2000)
# flask --app ml_backend run