Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,35 @@
|
|
1 |
import streamlit as st
|
2 |
import hopsworks
|
3 |
import joblib
|
|
|
4 |
import pandas as pd
|
5 |
-
import datetime
|
6 |
-
from functions import
|
|
|
|
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
|
|
10 |
city = "Paris"
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
mr = project.get_model_registry()
|
14 |
model = mr.get_model("gradient_boost_model", version=1)
|
@@ -16,17 +37,14 @@ model_dir = model.download()
|
|
16 |
model = joblib.load(model_dir + "/model.pkl")
|
17 |
|
18 |
|
19 |
-
preds = model.predict(
|
|
|
20 |
|
21 |
-
|
22 |
-
poll_level = get_aplevel(preds.T.reshape(-1, 1), air_pollution_level)
|
23 |
|
24 |
-
|
25 |
-
next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
|
26 |
|
27 |
-
df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week_str)
|
28 |
|
29 |
-
st.write(
|
30 |
-
st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
|
31 |
|
32 |
st.button("Re-run")
|
|
|
1 |
import streamlit as st
|
2 |
import hopsworks
|
3 |
import joblib
|
4 |
+
from datetime import date
|
5 |
import pandas as pd
|
6 |
+
from datetime import timedelta, datetime
|
7 |
+
from functions import *
|
8 |
+
import numpy as np
|
9 |
+
from sklearn.preprocessing import StandardScaler
|
10 |
|
11 |
+
import folium
|
12 |
+
from streamlit_folium import st_folium, folium_static
|
13 |
+
import json
|
14 |
+
import time
|
15 |
+
from branca.element import Figure
|
16 |
|
17 |
+
|
18 |
+
project = hopsworks.login()
|
19 |
+
|
20 |
+
today = date.today()
|
21 |
city = "Paris"
|
22 |
+
df_weather = get_weather_data_weekly(city, today)
|
23 |
+
df_weather.date = df_weather.date.apply(timestamp_2_time)
|
24 |
+
df_weather_x = df_weather.drop(columns=["date"]).fillna(0)
|
25 |
+
df_weather_nn=np.array(df_weather_x)
|
26 |
+
scaler = StandardScaler()
|
27 |
+
scaler.fit(df_weather_x)
|
28 |
+
|
29 |
+
df_weather_use=scaler.transform(df_weather_x)
|
30 |
+
|
31 |
+
df_weather_use_1= pd.DataFrame(df_weather_use)
|
32 |
+
|
33 |
|
34 |
mr = project.get_model_registry()
|
35 |
model = mr.get_model("gradient_boost_model", version=1)
|
|
|
37 |
model = joblib.load(model_dir + "/model.pkl")
|
38 |
|
39 |
|
40 |
+
preds = model.predict(df_weather_use_1).astype(int)
|
41 |
+
pollution_level = get_aplevel(preds.T.reshape(-1, 1))
|
42 |
|
43 |
+
next_week = [f"{(today + timedelta(days=d)).strftime('%Y-%m-%d')},{(today + timedelta(days=d)).strftime('%A')}" for d in range(8)]
|
|
|
44 |
|
45 |
+
df = pd.DataFrame(data=[preds, pollution_level], index=["AQI", "Air pollution level"], columns=next_week)
|
|
|
46 |
|
|
|
47 |
|
48 |
+
st.write(df)
|
|
|
49 |
|
50 |
st.button("Re-run")
|