Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,123 +28,123 @@ fancy_header('\n📡 Connecting to Hopsworks Feature Store...')
|
|
28 |
project = hopsworks.login()
|
29 |
fs = project.get_feature_store()
|
30 |
feature_view = fs.get_feature_view(
|
31 |
-
name = '
|
32 |
version = 1
|
33 |
)
|
34 |
|
35 |
st.write("Successfully connected!✔️")
|
36 |
progress_bar.progress(20)
|
37 |
|
38 |
-
st.write(36 * "-")
|
39 |
-
fancy_header('\n☁️ Getting batch data from Feature Store...')
|
40 |
|
41 |
-
start_date = datetime.now() - timedelta(days=1)
|
42 |
-
start_time = int(start_date.timestamp()) * 1000
|
43 |
|
44 |
-
# X = feature_view.get_batch_data(start_time=start_time)
|
45 |
|
46 |
-
# 1662652800000
|
47 |
-
X = feature_view.get_batch_data(start_time=1662652800000)
|
48 |
-
progress_bar.progress(50)
|
49 |
|
50 |
-
print(X.date.values)
|
51 |
|
52 |
-
latest_date_unix = str(X.date.values[0])[:10]
|
53 |
-
latest_date = time.ctime(int(latest_date_unix))
|
54 |
|
55 |
-
st.write(f"⏱ Data for {latest_date}")
|
56 |
|
57 |
-
X = X.drop(columns=["date"]).fillna(0)
|
58 |
-
print("X is \n %s" % X)
|
59 |
|
60 |
-
data_to_display = decode_features(X, feature_view=feature_view)
|
61 |
|
62 |
-
progress_bar.progress(60)
|
63 |
|
64 |
-
st.write(36 * "-")
|
65 |
-
fancy_header(f"🗺 Processing the map...")
|
66 |
-
|
67 |
-
fig = Figure(width=550,height=350)
|
68 |
-
|
69 |
-
my_map = folium.Map(location=[58, 20], zoom_start=3.71)
|
70 |
-
fig.add_child(my_map)
|
71 |
-
folium.TileLayer('Stamen Terrain').add_to(my_map)
|
72 |
-
folium.TileLayer('Stamen Toner').add_to(my_map)
|
73 |
-
folium.TileLayer('Stamen Water Color').add_to(my_map)
|
74 |
-
folium.TileLayer('cartodbpositron').add_to(my_map)
|
75 |
-
folium.TileLayer('cartodbdark_matter').add_to(my_map)
|
76 |
-
folium.LayerControl().add_to(my_map)
|
77 |
-
|
78 |
-
data_to_display = data_to_display[["city", "temp", "humidity",
|
79 |
-
|
80 |
-
|
81 |
-
cities_coords = {("Sundsvall", "Sweden"): [62.390811, 17.306927],
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
# if "Kyiv" in data_to_display["city"]:
|
87 |
-
# cities_coords[("Kyiv", "Ukraine")]: [50.450001, 30.523333]
|
88 |
-
# pass
|
89 |
-
|
90 |
-
data_to_display = data_to_display.set_index("city")
|
91 |
-
|
92 |
-
cols_names_dict = {"temp": "Temperature",
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
data_to_display = data_to_display.rename(columns=cols_names_dict)
|
98 |
-
|
99 |
-
cols_ = ["Temperature", "Humidity", "AQI"]
|
100 |
-
data_to_display[cols_] = data_to_display[cols_].apply(lambda x: round(x, 1))
|
101 |
-
|
102 |
-
for city, country in cities_coords:
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
# call to render Folium map in Streamlit
|
127 |
-
folium_static(my_map)
|
128 |
-
progress_bar.progress(80)
|
129 |
-
st.sidebar.write("-" * 36)
|
130 |
-
|
131 |
-
|
132 |
-
model = get_model(project=project,
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
preds = model.predict(X)
|
138 |
-
|
139 |
-
cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
|
140 |
-
print("cities are %s" % cities)
|
141 |
-
|
142 |
-
next_day_date = datetime.today() + timedelta(days=1)
|
143 |
-
next_day = next_day_date.strftime ('%d/%m/%Y')
|
144 |
-
print("preds is %s" % preds)
|
145 |
-
df = pd.DataFrame(data=preds, index=cities, columns=[f"AQI Predictions for {next_day}"], dtype=int)
|
146 |
-
|
147 |
-
st.sidebar.write(df)
|
148 |
-
progress_bar.progress(100)
|
149 |
-
st.button("Re-run")
|
150 |
-
# hi
|
|
|
28 |
project = hopsworks.login()
|
29 |
fs = project.get_feature_store()
|
30 |
feature_view = fs.get_feature_view(
|
31 |
+
name = 'oslo_air_quality_fv',
|
32 |
version = 1
|
33 |
)
|
34 |
|
35 |
st.write("Successfully connected!✔️")
|
36 |
progress_bar.progress(20)
|
37 |
|
38 |
+
# st.write(36 * "-")
|
39 |
+
# fancy_header('\n☁️ Getting batch data from Feature Store...')
|
40 |
|
41 |
+
# start_date = datetime.now() - timedelta(days=1)
|
42 |
+
# start_time = int(start_date.timestamp()) * 1000
|
43 |
|
44 |
+
# # X = feature_view.get_batch_data(start_time=start_time)
|
45 |
|
46 |
+
# # 1662652800000
|
47 |
+
# X = feature_view.get_batch_data(start_time=1662652800000)
|
48 |
+
# progress_bar.progress(50)
|
49 |
|
50 |
+
# print(X.date.values)
|
51 |
|
52 |
+
# latest_date_unix = str(X.date.values[0])[:10]
|
53 |
+
# latest_date = time.ctime(int(latest_date_unix))
|
54 |
|
55 |
+
# st.write(f"⏱ Data for {latest_date}")
|
56 |
|
57 |
+
# X = X.drop(columns=["date"]).fillna(0)
|
58 |
+
# print("X is \n %s" % X)
|
59 |
|
60 |
+
# data_to_display = decode_features(X, feature_view=feature_view)
|
61 |
|
62 |
+
# progress_bar.progress(60)
|
63 |
|
64 |
+
# st.write(36 * "-")
|
65 |
+
# fancy_header(f"🗺 Processing the map...")
|
66 |
+
|
67 |
+
# fig = Figure(width=550,height=350)
|
68 |
+
|
69 |
+
# my_map = folium.Map(location=[58, 20], zoom_start=3.71)
|
70 |
+
# fig.add_child(my_map)
|
71 |
+
# folium.TileLayer('Stamen Terrain').add_to(my_map)
|
72 |
+
# folium.TileLayer('Stamen Toner').add_to(my_map)
|
73 |
+
# folium.TileLayer('Stamen Water Color').add_to(my_map)
|
74 |
+
# folium.TileLayer('cartodbpositron').add_to(my_map)
|
75 |
+
# folium.TileLayer('cartodbdark_matter').add_to(my_map)
|
76 |
+
# folium.LayerControl().add_to(my_map)
|
77 |
+
|
78 |
+
# data_to_display = data_to_display[["city", "temp", "humidity",
|
79 |
+
# "conditions", "aqi"]]
|
80 |
+
|
81 |
+
# cities_coords = {("Sundsvall", "Sweden"): [62.390811, 17.306927],
|
82 |
+
# ("Stockholm", "Sweden"): [59.334591, 18.063240],
|
83 |
+
# ("Malmo", "Sweden"): [55.604981, 13.003822],
|
84 |
+
# ("Kyiv", "Ukraine"): [50.450001, 30.523333]}
|
85 |
+
|
86 |
+
# # if "Kyiv" in data_to_display["city"]:
|
87 |
+
# # cities_coords[("Kyiv", "Ukraine")]: [50.450001, 30.523333]
|
88 |
+
# # pass
|
89 |
+
|
90 |
+
# data_to_display = data_to_display.set_index("city")
|
91 |
+
|
92 |
+
# cols_names_dict = {"temp": "Temperature",
|
93 |
+
# "humidity": "Humidity",
|
94 |
+
# "conditions": "Conditions",
|
95 |
+
# "aqi": "AQI"}
|
96 |
+
|
97 |
+
# data_to_display = data_to_display.rename(columns=cols_names_dict)
|
98 |
+
|
99 |
+
# cols_ = ["Temperature", "Humidity", "AQI"]
|
100 |
+
# data_to_display[cols_] = data_to_display[cols_].apply(lambda x: round(x, 1))
|
101 |
+
|
102 |
+
# for city, country in cities_coords:
|
103 |
+
# text = f"""
|
104 |
+
# <h4 style="color:green;">{city}</h4>
|
105 |
+
# <h5 style="color":"green">
|
106 |
+
# <table style="text-align: right;">
|
107 |
+
# <tr>
|
108 |
+
# <th>Country:</th>
|
109 |
+
# <td><b>{country}</b></td>
|
110 |
+
# </tr>
|
111 |
+
# """
|
112 |
+
# for column in data_to_display.columns:
|
113 |
+
# text += f"""
|
114 |
+
# <tr>
|
115 |
+
# <th>{column}:</th>
|
116 |
+
# <td>{data_to_display.loc[city][column]}</td>
|
117 |
+
# </tr>"""
|
118 |
+
# text += """</table>
|
119 |
+
# </h5>"""
|
120 |
+
|
121 |
+
# folium.Marker(
|
122 |
+
# cities_coords[(city, country)], popup=text, tooltip=f"<strong>{city}</strong>"
|
123 |
+
# ).add_to(my_map)
|
124 |
+
|
125 |
+
|
126 |
+
# # call to render Folium map in Streamlit
|
127 |
+
# folium_static(my_map)
|
128 |
+
# progress_bar.progress(80)
|
129 |
+
# st.sidebar.write("-" * 36)
|
130 |
+
|
131 |
+
|
132 |
+
# model = get_model(project=project,
|
133 |
+
# model_name="gradient_boost_model",
|
134 |
+
# evaluation_metric="f1_score",
|
135 |
+
# sort_metrics_by="max")
|
136 |
+
|
137 |
+
# preds = model.predict(X)
|
138 |
+
|
139 |
+
# cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
|
140 |
+
# print("cities are %s" % cities)
|
141 |
+
|
142 |
+
# next_day_date = datetime.today() + timedelta(days=1)
|
143 |
+
# next_day = next_day_date.strftime ('%d/%m/%Y')
|
144 |
+
# print("preds is %s" % preds)
|
145 |
+
# df = pd.DataFrame(data=preds, index=cities, columns=[f"AQI Predictions for {next_day}"], dtype=int)
|
146 |
+
|
147 |
+
# st.sidebar.write(df)
|
148 |
+
# progress_bar.progress(100)
|
149 |
+
# st.button("Re-run")
|
150 |
+
# # hi
|