Spaces:
Runtime error
Runtime error
Commit
·
699f5e3
1
Parent(s):
92e0d15
Update app.py
Browse files
app.py
CHANGED
@@ -11,42 +11,22 @@ import numpy as np
|
|
11 |
import cpi
|
12 |
from sklearn.preprocessing import MinMaxScaler
|
13 |
from huggingface_hub import hf_hub_download
|
14 |
-
|
15 |
-
#cpi.update()
|
16 |
-
|
17 |
import gradio as gr
|
18 |
-
|
19 |
from huggingface_hub import notebook_login
|
20 |
notebook_login()
|
21 |
import hopsworks
|
22 |
|
23 |
-
# from huggingface_hub import hf_hub_download
|
24 |
-
# m = hf_hub_download(repo_id="marvmk/model-test", filename="model.pkl")
|
25 |
-
|
26 |
-
project = hopsworks.login(api_key_value="4CY1rwa8iz8Yu6gG.TwayrYmsX4GQfhSp3LNKYTLvyFMfqAvnzNUQp5ae9K5HhfYxb5mcnLAutm1K18zV")
|
27 |
-
fs = project.get_feature_store()
|
28 |
-
|
29 |
-
mr = project.get_model_registry()
|
30 |
-
#model = mr.get_model("stock_price_modal")
|
31 |
-
#model_dir = model.download()
|
32 |
-
#model = joblib.load(model_dir + "/stock_price_model.pkl")
|
33 |
-
model = keras.models.load_model('model_stock_prices.h5')
|
34 |
-
|
35 |
-
|
36 |
-
#from huggingface_hub import hf_hub_download
|
37 |
-
#m = hf_hub_download(repo_id="marvmk/model-test", filename="model.pkl")
|
38 |
-
#model = pickle.load(open(m, 'rb'))
|
39 |
|
40 |
|
41 |
-
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
|
|
|
46 |
|
47 |
|
48 |
|
49 |
-
#model = pickle.load(open(m, 'rb'))
|
50 |
|
51 |
# downloading the last 10 days to make the prediction
|
52 |
from datetime import date
|
@@ -82,37 +62,8 @@ for x in hist.index:
|
|
82 |
|
83 |
hist['Inflation'] = inflation
|
84 |
hist['CPI'] = cpi_col
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
hist['Quarter_end'] = np.where(hist.index.month%3==0,1,0)
|
89 |
|
90 |
-
# def build_sequences(nump, target_labels=['Close'], window=10, stride=1, telescope=1):
|
91 |
-
# # Sanity check to avoid runtime errors
|
92 |
-
# df = pd.DataFrame(nump, columns = ['Open','High','Low','Close','Volume','Inflation', 'CPI', 'Quarter_end'])
|
93 |
-
# assert window % stride == 0
|
94 |
-
# dataset = []
|
95 |
-
# labels = []
|
96 |
-
# temp_df = df.copy().values
|
97 |
-
# temp_label = df[target_labels].copy().values
|
98 |
-
# padding_len = len(df)%window
|
99 |
-
|
100 |
-
# if(padding_len != 0):
|
101 |
-
# # Compute padding length
|
102 |
-
# padding_len = window - len(df)%window
|
103 |
-
# padding = np.zeros((padding_len,temp_df.shape[1]), dtype='float64')
|
104 |
-
# temp_df = np.concatenate((padding,df))
|
105 |
-
# padding = np.zeros((padding_len,temp_label.shape[1]), dtype='float64')
|
106 |
-
# temp_label = np.concatenate((padding,temp_label))
|
107 |
-
# assert len(temp_df) % window == 0
|
108 |
-
|
109 |
-
# for idx in np.arange(0,len(temp_df)-window-telescope,stride):
|
110 |
-
# dataset.append(temp_df[idx:idx+window])
|
111 |
-
# labels.append(temp_label[idx+window:idx+window+telescope])
|
112 |
-
|
113 |
-
# dataset = np.array(dataset)
|
114 |
-
# labels = np.array(labels)
|
115 |
-
# return dataset, labels
|
116 |
|
117 |
|
118 |
|
@@ -120,7 +71,6 @@ s = hf_hub_download(repo_id="marvmk/scalable_project", filename="scaler.save", r
|
|
120 |
scaler = joblib.load(s)
|
121 |
|
122 |
inp = scaler.transform(hist.to_numpy())
|
123 |
-
#inp = scaler.inverse_transform(inp)
|
124 |
|
125 |
df = inp
|
126 |
temp_df = pd.DataFrame(inp, columns = ['Open','High','Low','Close','Volume','Inflation', 'CPI', 'Quarter_end'])
|
@@ -134,12 +84,8 @@ predictions = model.predict(ds)
|
|
134 |
predictions
|
135 |
p = predictions[0][0][0]
|
136 |
p = float(p)
|
137 |
-
p
|
138 |
-
#print(p)
|
139 |
a = np.array([0,0,0,p,0,0,0,0])
|
140 |
-
a
|
141 |
a = scaler.inverse_transform(a.reshape(1,-1))
|
142 |
-
a
|
143 |
|
144 |
|
145 |
final_prediction = a[-1][3]
|
|
|
11 |
import cpi
|
12 |
from sklearn.preprocessing import MinMaxScaler
|
13 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
14 |
import gradio as gr
|
|
|
15 |
from huggingface_hub import notebook_login
|
16 |
notebook_login()
|
17 |
import hopsworks
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
+
st.write("""
|
22 |
+
# Stock Price Prediction
|
23 |
+
Shown is the stock prediction of the next working day taking into account the last 10 working days
|
24 |
+
""")
|
25 |
|
26 |
+
model = keras.models.load_model('model_stock_prices.h5')
|
27 |
|
28 |
|
29 |
|
|
|
30 |
|
31 |
# downloading the last 10 days to make the prediction
|
32 |
from datetime import date
|
|
|
62 |
|
63 |
hist['Inflation'] = inflation
|
64 |
hist['CPI'] = cpi_col
|
|
|
|
|
|
|
65 |
hist['Quarter_end'] = np.where(hist.index.month%3==0,1,0)
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
|
69 |
|
|
|
71 |
scaler = joblib.load(s)
|
72 |
|
73 |
inp = scaler.transform(hist.to_numpy())
|
|
|
74 |
|
75 |
df = inp
|
76 |
temp_df = pd.DataFrame(inp, columns = ['Open','High','Low','Close','Volume','Inflation', 'CPI', 'Quarter_end'])
|
|
|
84 |
predictions
|
85 |
p = predictions[0][0][0]
|
86 |
p = float(p)
|
|
|
|
|
87 |
a = np.array([0,0,0,p,0,0,0,0])
|
|
|
88 |
a = scaler.inverse_transform(a.reshape(1,-1))
|
|
|
89 |
|
90 |
|
91 |
final_prediction = a[-1][3]
|