CsanadT's picture
Update app.py
388226f
raw
history blame
1.51 kB
import streamlit as st
import hopsworks
import joblib
import pandas as pd
import numpy as np
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🌩')
progress_bar = st.sidebar.header('Working Progress')
progress_bar = st.sidebar.progress(0)
st.write(36 * "-")
fancy_header('\n Connecting to Hopsworks Feature Store...')
project = hopsworks.login()
st.write("Successfully connected!✔️")
progress_bar.progress(20)
st.write(36 * "-")
fancy_header('\n Getting data from thee weather API...')
today = datetime.date.today()
city = "vienna"
weekly_data = get_weather_data_weekly(city, today)
progress_bar.progress(50)
progress_bar.progress(60)
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")
progress_bar.progress(80)
st.sidebar.write("-" * 36)
preds = model.predict(data_encoder(weekly_data)).astype(int)
poll_level = get_aplevel(preds.T.reshape(-1, 1))
next_week = [(datetime.today() + timedelta(days=d)).strftime('%A') for d in range(1, 7)]
df = pd.DataFrame(data=preds, index=["eg"], columns=[f"AQI Predictions for {next_day}" for next_day in next_week], dtype=int)
st.sidebar.write(df)
progress_bar.progress(100)
st.button("Re-run")