forked from rishabh-gurbani/Flood-Prediction-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (33 loc) · 1.2 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
from flask import Flask, request, jsonify
import pickle
import numpy as np
app = Flask(__name__)
@app.route('/')
def home():
return "hello world"
@app.route('/predict', methods=['GET', 'POST'])
def predict():
mon = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT',
'NOV', 'DEC']
months = [request.form.get(x) for x in mon]
modelType = [request.form.get('MODEL')]
input_query = np.array(months, dtype=float).reshape(1, 12)
pickle.load(open('LR.pkl', 'rb'))
model = pickle.load(open('LR.pkl', 'rb'))
if modelType == 'LR':
pickle.load(open('LR.pkl', 'rb'))
model = pickle.load(open('LR.pkl', 'rb'))
elif modelType == 'RF':
pickle.load(open('RF.pkl', 'rb'))
model = pickle.load(open('RF.pkl', 'rb'))
elif modelType == 'SVM':
pickle.load(open('SVM.pkl', 'rb'))
model = pickle.load(open('SVM.pkl', 'rb'))
elif modelType == 'XGB':
pickle.load(open('XGB.pkl', 'rb'))
model = pickle.load(open('XGB.pkl', 'rb'))
prediction = model.predict(input_query)[0]
print(modelType)
return jsonify({'prediction': str(prediction)})
if __name__ == '__main__':
app.run(debug=True)