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'{text}' 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) fancy_header('\n Acquired data!') progress_bar.progress(60) st.write(36 * "-") fancy_header('\n Loading the XGBoost model from the Hopsworks Model Registry') 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") fancy_header('\n Model loaded. Let\'s make predictions!') 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 = [f"{(today + timedelta(days=d)).strftime('%Y-%m-%d')}, {(today + timedelta(days=d)).strftime('%A')}" for d in range(7)] df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week) st.write(df) progress_bar.progress(100) st.button("Re-run")