-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
140 lines (111 loc) · 4.18 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from flask import Flask, request
from flask_cors import CORS
import tensorflow as tf
import json
import pandas as pd
from funcs import sMAPE
from scrape import scrape
from predictARIMA import *
from predictSES import *
from predictNN import *
#Initialize App
scrp = scrape()
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['GET'])
def main():
scrp.getDaily()
scrp.getWeekly()
scrp.getMonthly()
dfDaily = pd.read_csv('./sih-2022/data/daily.csv')
dfSen = pd.read_csv('./sih-2022/data/dailySentiment.csv')
dfSen = dfSen.loc[:, ~dfSen.columns.str.contains('^Unnamed')]
if list(dfDaily.Day)[-1] != list(dfSen.Day)[-1]:
day = list(dfDaily.Day)[-1]
prevDay = list(dfDaily.Day)[-1]
price = list(dfDaily.Price)[-1]
s = sentimentData()
sen = s.getSentiment(str(prevDay))
dfSen = dfSen.append([{'Day':day, 'Price': price, 'Sentiment': sen}], ignore_index=True)
dfSen.to_csv('./sih-2022/data/dailySentiment.csv')
return json.dumps({'SiH-2022': 'Natural-Gas Price Prediction', 'Message': 'Updated all values'})
return json.dumps({'SiH-2022': 'Natural-Gas Price Prediction', 'Message': 'All data up-to-date'})
@app.route('/historical/daily', methods=['GET'])
def getDailyData():
dataHist = pd.read_csv('./sih-2022/data/daily.csv')
hist = {}
for i in range(len(dataHist)):
hist[int(dataHist['Day'][i])] = dataHist['Price'][i]
return json.dumps(hist)
@app.route('/historical/weekly', methods=['GET'])
def getWeeklyData():
dataHist = pd.read_csv('./sih-2022/data/weekly.csv')
hist = {}
for i in range(len(dataHist)):
hist[int(dataHist['Day'][i])] = dataHist['Price'][i]
return json.dumps(hist)
@app.route('/historical/monthly', methods=['GET'])
def getMonthlyData():
dataHist = pd.read_csv('./sih-2022/data/monthly.csv')
hist = {}
for i in range(len(dataHist)):
hist[int(dataHist['Day'][i])] = dataHist['Price'][i]
return json.dumps(hist)
@app.route('/predict/ARIMA/SS', methods=['GET'])
def predictARIMASS():
p = predictARIMA()
return json.dumps(p.getSS())
@app.route('/predict/ARIMA/MS', methods=['GET'])
def predictARIMAMS():
step = int(request.args.get('steps'))
p = predictARIMA()
j = {}
res = p.getMS(steps=step)
for i, item in enumerate(res):
j[i] = item
return json.dumps(j)
@app.route('/predict/SES/SS', methods=['GET'])
def predictSESSS():
p = predictSES()
return json.dumps(p.get())
@app.route('/predict/CNN/SS', methods=['GET'])
def predictCNNSS():
CNNModel = tf.keras.models.load_model('sih-2022\models\singleStepDailyCNN.h5', custom_objects={'smape': sMAPE})
p = predictNN(CNNModel)
return json.dumps(p)
@app.route('/predict/CNN/MS', methods=['GET'])
def predictCNNMS():
CNNModel = tf.keras.models.load_model('sih-2022\models\multiStepDailyCNN.h5', custom_objects={'smape': sMAPE})
p = predictNNMS(CNNModel)
j = {}
for i, item in enumerate(p):
j[i] = float(item)
return json.dumps(j)
@app.route('/predict/LSTM/SS', methods=['GET'])
def predictLSTMSS():
LSTMModel = tf.keras.models.load_model('sih-2022\models\singleStepDailyLSTM.h5', custom_objects={'smape': sMAPE})
p = predictNN(LSTMModel)
return json.dumps(p)
@app.route('/predict/LSTM/MS', methods=['GET'])
def predictLSTMMS():
LSTMModel = tf.keras.models.load_model('sih-2022\models\multiStepDailyLSTM.h5', custom_objects={'smape': sMAPE})
p = predictNNMS(LSTMModel)
j = {}
for i, item in enumerate(p):
j[i] = float(item)
return json.dumps(j)
@app.route('/predict/CNN-LSTM/SS', methods=['GET'])
def predictHybridSS():
hybridModel = tf.keras.models.load_model('sih-2022\models\singleStepDailyHybrid.h5', custom_objects={'smape': sMAPE})
p = predictNN(hybridModel)
return json.dumps(p)
@app.route('/predict/CNN-LSTM/MS', methods=['GET'])
def predictHybridMS():
hybridModel = tf.keras.models.load_model('sih-2022\models\multiStepDailyHybrid.h5', custom_objects={'smape': sMAPE})
p = predictNNMS(hybridModel)
j = {}
for i, item in enumerate(p):
j[i] = float(item)
return json.dumps(j)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=443, debug=True)