Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
#%%
|
3 |
from matplotlib.pyplot import title
|
4 |
import tensorflow as tf
|
@@ -9,57 +8,20 @@ import matplotlib.pyplot as plt
|
|
9 |
import streamlit as st
|
10 |
from zipfile import ZipFile
|
11 |
import os
|
12 |
-
import datetime
|
13 |
-
from io import StringIO
|
14 |
|
15 |
import warnings
|
16 |
warnings.filterwarnings("ignore")
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
uri = "https://storage.googleapis.com/tensorflow/tf-keras-datasets/jena_climate_2009_2016.csv.zip"
|
29 |
-
zip_path = keras.utils.get_file(origin=uri, fname="jena_climate_2009_2016.csv.zip")
|
30 |
-
zip_file = ZipFile(zip_path)
|
31 |
-
zip_file.extractall()
|
32 |
-
csv_path = "jena_climate_2009_2016.csv"
|
33 |
-
df = pd.read_csv(csv_path)
|
34 |
-
st.dataframe(df)
|
35 |
-
|
36 |
-
if ("0" != ""):
|
37 |
-
today = datetime.date.today()
|
38 |
-
|
39 |
-
ayear = int(today.strftime("%Y"))-0
|
40 |
-
amonth = int(today.strftime("%m"))
|
41 |
-
amonthday = int(today.strftime("%d"))
|
42 |
-
|
43 |
-
csvString = ""
|
44 |
-
csvString += (",").join(mytitles)
|
45 |
-
adf = pd.DataFrame(columns=mytitles)
|
46 |
-
for i in range((ayear-mybacklogmax),ayear,1):
|
47 |
-
alink = ("https://data.weather.gov.hk/weatherAPI/opendata/opendata.php?dataType=CLMTEMP&year={}&rformat=csv&station=HKO").format(str(i))
|
48 |
-
df = pd.read_csv(alink, skiprows=[0,1,2], skipfooter=3, engine='python', on_bad_lines='skip')
|
49 |
-
|
50 |
-
df = df.reset_index() # make sure indexes pair with number of rows
|
51 |
-
for index, row in df.iterrows():
|
52 |
-
if (row[2]!=amonth) or (row[3]!=amonthday):
|
53 |
-
continue
|
54 |
-
|
55 |
-
adate = ("{:02d}.{:02d}.{} 00:00:00").format(row[3], row[2], row[1])
|
56 |
-
csvString += '\n'+(",").join([adate,"",str(row[4]),"","","","","","","","","","","",""])
|
57 |
-
st.write(row[0],adate)
|
58 |
-
adf = adf.append({"Date Time":adate,"T (degC)":(row[4]),}, ignore_index=True)
|
59 |
-
break
|
60 |
-
adf = pd.read_csv(StringIO(csvString), sep=",")
|
61 |
-
df = adf
|
62 |
-
st.dataframe(df)
|
63 |
|
64 |
#%%
|
65 |
|
@@ -127,9 +89,9 @@ def normalize(data, train_split):
|
|
127 |
|
128 |
print(
|
129 |
"The selected parameters are:",
|
130 |
-
", ".join([titles[i] for i in
|
131 |
)
|
132 |
-
selected_features = [feature_keys[i] for i in
|
133 |
features = df[selected_features]
|
134 |
features.index = df[date_time_key]
|
135 |
features.head()
|
@@ -159,9 +121,9 @@ def normalize(data, train_split):
|
|
159 |
return (data - data_mean) / data_std
|
160 |
print(
|
161 |
"The selected parameters are:",
|
162 |
-
", ".join([titles[i] for i in
|
163 |
)
|
164 |
-
selected_features = [feature_keys[i] for i in
|
165 |
features = df[selected_features]
|
166 |
features.index = df[date_time_key]
|
167 |
features.head()
|
@@ -175,48 +137,16 @@ val_data = features.loc[train_split:]
|
|
175 |
start = past + future
|
176 |
end = start + train_split
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
st.dataframe(val_data)
|
181 |
-
|
182 |
-
myrangeend = int(split_fraction*mybacklogmax)
|
183 |
-
#mycolumns = df[date_time_key]
|
184 |
-
mycolumns = pd.RangeIndex(0, myrangeend).to_series()
|
185 |
-
#train_data = train_data.reindex(columns=mycolumns)
|
186 |
-
|
187 |
-
st.write(val_data.to_numpy())
|
188 |
-
|
189 |
-
#x_train = train_data[[i for i in range(myrangeend)]].values
|
190 |
-
x_train = train_data.to_numpy()
|
191 |
-
#y_train = features.iloc[start:end][[1]]
|
192 |
-
#y_train = features.reindex(columns=mycolumns).iloc[start:end][[1]]
|
193 |
-
|
194 |
-
|
195 |
-
y_train = df[date_time_key].loc[0 : train_split - 1].to_numpy()
|
196 |
-
|
197 |
-
st.write(x_train)
|
198 |
-
st.write(y_train)
|
199 |
-
|
200 |
|
201 |
sequence_length = int(past / step)
|
202 |
x_end = len(val_data) - past - future
|
203 |
|
204 |
label_start = train_split + past + future
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
x_val = val_data.iloc[:x_end].to_numpy()
|
210 |
-
y_val = df[date_time_key].iloc[label_start:].to_numpy()
|
211 |
-
|
212 |
-
#x_val = val_data.reindex(columns=mycolumns)
|
213 |
-
#x_val = x_val.iloc[:x_end][[i for i in range(myrangeend)]].values
|
214 |
-
#y_val = features.reindex(columns=mycolumns)
|
215 |
-
#y_val = y_val.iloc[label_start:][[1]]
|
216 |
-
|
217 |
-
st.write(x_val,x_end)
|
218 |
-
st.write(y_val,label_start)
|
219 |
-
|
220 |
|
221 |
dataset_val = keras.preprocessing.timeseries_dataset_from_array(
|
222 |
x_val,
|
@@ -266,4 +196,3 @@ fig = plot()
|
|
266 |
st.pyplot(fig)
|
267 |
|
268 |
# %%
|
269 |
-
|
|
|
|
|
1 |
#%%
|
2 |
from matplotlib.pyplot import title
|
3 |
import tensorflow as tf
|
|
|
8 |
import streamlit as st
|
9 |
from zipfile import ZipFile
|
10 |
import os
|
|
|
|
|
11 |
|
12 |
import warnings
|
13 |
warnings.filterwarnings("ignore")
|
14 |
|
15 |
+
if ("0" == "mycustom"):
|
16 |
+
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
|
17 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
18 |
+
|
19 |
+
uri = "https://storage.googleapis.com/tensorflow/tf-keras-datasets/jena_climate_2009_2016.csv.zip"
|
20 |
+
zip_path = keras.utils.get_file(origin=uri, fname="jena_climate_2009_2016.csv.zip")
|
21 |
+
zip_file = ZipFile(zip_path)
|
22 |
+
zip_file.extractall()
|
23 |
+
csv_path = "jena_climate_2009_2016.csv"
|
24 |
+
df = pd.read_csv(csv_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
#%%
|
27 |
|
|
|
89 |
|
90 |
print(
|
91 |
"The selected parameters are:",
|
92 |
+
", ".join([titles[i] for i in [0, 1, 5, 7, 8, 10, 11]]),
|
93 |
)
|
94 |
+
selected_features = [feature_keys[i] for i in [0, 1, 5, 7, 8, 10, 11]]
|
95 |
features = df[selected_features]
|
96 |
features.index = df[date_time_key]
|
97 |
features.head()
|
|
|
121 |
return (data - data_mean) / data_std
|
122 |
print(
|
123 |
"The selected parameters are:",
|
124 |
+
", ".join([titles[i] for i in [0, 1, 5, 7, 8, 10, 11]]),
|
125 |
)
|
126 |
+
selected_features = [feature_keys[i] for i in [0, 1, 5, 7, 8, 10, 11]]
|
127 |
features = df[selected_features]
|
128 |
features.index = df[date_time_key]
|
129 |
features.head()
|
|
|
137 |
start = past + future
|
138 |
end = start + train_split
|
139 |
|
140 |
+
x_train = train_data[[i for i in range(7)]].values
|
141 |
+
y_train = features.iloc[start:end][[1]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
sequence_length = int(past / step)
|
144 |
x_end = len(val_data) - past - future
|
145 |
|
146 |
label_start = train_split + past + future
|
147 |
|
148 |
+
x_val = val_data.iloc[:x_end][[i for i in range(7)]].values
|
149 |
+
y_val = features.iloc[label_start:][[1]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
dataset_val = keras.preprocessing.timeseries_dataset_from_array(
|
152 |
x_val,
|
|
|
196 |
st.pyplot(fig)
|
197 |
|
198 |
# %%
|
|