CsanadT's picture
Update app.py
60999f9
raw
history blame
1.33 kB
import streamlit as st
import hopsworks
import joblib
import pandas as pd
from datetime import timedelta, datetime
from functions import *
def fancy_header(text, font_size=24):
res = f'<span style="color:#ff5f27; font-size: {font_size}px;">{text}</span>'
st.markdown(res, unsafe_allow_html=True)
st.title('Air Quality Prediction Project🌩')
st.write(36 * "-")
fancy_header('\n Connecting to Hopsworks Feature Store...')
project = hopsworks.login()
st.write("Successfully connected!✔️")
st.write(36 * "-")
fancy_header('\n Getting data from Feature Store...')
today = datetime.date.today()
city = "vienna"
weekly_data = get_weather_data_weekly(city, today)
st.write(36 * "-")
mr = project.get_model_registry()
model = mr.get_best_model("aqi_model", "rmse", "min")
model_dir = model.download()
model = joblib.load(model_dir + "/aqi_model.pkl")
st.sidebar.write("-" * 36)
preds = model.predict(data_encoder(weekly_data)).astype(int)
poll_level = get_aplevel(preds.T.reshape(-1, 1))
next_week = [[(today + timedelta(days=d)).strftime('%Y-%m-%d'),(today + timedelta(days=d)).strftime('%A')] for d in range(1, 7)]
df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=[f"AQI Predictions for {next_day}" for next_day in next_week])
st.write(df)
st.button("Re-run")