Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import hopsworks
|
3 |
+
import joblib
|
4 |
+
import pandas as pd
|
5 |
+
import datetime
|
6 |
+
from functions import get_weather_data_weekly, data_encoder, get_aplevel, get_color
|
7 |
+
|
8 |
+
|
9 |
+
today = datetime.date.today()
|
10 |
+
city = "Paris"
|
11 |
+
weekly_data = get_weather_data_weekly(city, today)
|
12 |
+
|
13 |
+
mr = project.get_model_registry()
|
14 |
+
model = mr.get_model("gradient_boost_model", version=1)
|
15 |
+
model_dir = model.download()
|
16 |
+
model = joblib.load(model_dir + "/model.pkl")
|
17 |
+
|
18 |
+
|
19 |
+
preds = model.predict(data_encoder(weekly_data)).astype(int)
|
20 |
+
|
21 |
+
air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
|
22 |
+
poll_level = get_aplevel(preds.T.reshape(-1, 1), air_pollution_level)
|
23 |
+
|
24 |
+
next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
|
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("Here they are!")
|
30 |
+
st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
|
31 |
+
|
32 |
+
st.button("Re-run")
|