air_quality / app.py
Yasaman's picture
Create app.py
6380fd4
raw
history blame
1.11 kB
import streamlit as st
import hopsworks
import joblib
import pandas as pd
import datetime
from functions import get_weather_data_weekly, data_encoder, get_aplevel, get_color
today = datetime.date.today()
city = "Paris"
weekly_data = get_weather_data_weekly(city, today)
mr = project.get_model_registry()
model = mr.get_model("gradient_boost_model", version=1)
model_dir = model.download()
model = joblib.load(model_dir + "/model.pkl")
preds = model.predict(data_encoder(weekly_data)).astype(int)
air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
poll_level = get_aplevel(preds.T.reshape(-1, 1), air_pollution_level)
next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week_str)
st.write("Here they are!")
st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
st.button("Re-run")