-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (38 loc) · 1.59 KB
/
main.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, render_template, redirect, url_for, request
from flask_restful import Api, Resource
import pickle
import requests
from lstm import df_to_windowed_df, windowed_df_to_date_X_y, recursive_predict, create_df
app = Flask(__name__)
api = Api(app)
@app.route('/')
def welcome():
return render_template('index.html')
@app.route('/predictions')
def predictions(result):
return render_template('result.html', result=result)
#class PredictFive(Resource):
#def get(self):
#if request.method=='POST':
#num = int(requests.form['preds'])
#df = create_df()
#windowed_df = df_to_windowed_df(df, '2021-03-25', '2022-03-23', n=5)
#dates, X, Y = windowed_df_to_date_X_y(windowed_df)
#with open('model.pkl', 'rb') as file:
#model = pickle.load(file)
#recursive_predictions = recursive_predict(num, X, model)
#return redirect(url_for('predictions', result = recursive_predictions))
@app.route("/predict", methods=['POST', "GET"])
def predict():
if request.method=='POST':
num = int(request.form['preds'])
df = create_df()
windowed_df = df_to_windowed_df(df, '2021-03-25', '2022-03-23', n=5)
dates, X, Y = windowed_df_to_date_X_y(windowed_df)
with open('model.pkl', 'rb') as file:
model = pickle.load(file)
recursive_predictions = recursive_predict(num, X, model)
return render_template('result.html', result=recursive_predictions)
#api.add_resource(PredictFive, "/predict")
if __name__ == "__main__":
app.run(debug=True)