|
import streamlit as st |
|
import hopsworks |
|
import joblib |
|
from datetime import date |
|
import pandas as pd |
|
from datetime import timedelta, datetime |
|
from functions import * |
|
|
|
|
|
def fancy_header(text, font_size=24): |
|
res = f'<p style="color:#ff5f72; font-size: {font_size}px; text-align:center;">{text}</p>' |
|
st.markdown(res, unsafe_allow_html=True) |
|
|
|
st.set_page_config(layout="wide") |
|
|
|
st.title('Air Quality Prediction Project🌩') |
|
|
|
st.write(9 * "-") |
|
fancy_header('\n Connecting to Hopsworks Feature Store...') |
|
|
|
project = hopsworks.login() |
|
|
|
st.write("Successfully connected!✔️") |
|
|
|
st.write(18 * "-") |
|
fancy_header('\n Getting data from Feature Store...') |
|
|
|
today = date.today() |
|
city = "Beijing" |
|
df_weather = get_weather_data_weekly(city, today) |
|
df_weather.date = df_weather.date.apply(timestamp_2_time) |
|
df_weather_x = df_weather.drop(columns=["date"]).fillna(0) |
|
|
|
|
|
st.write(27 * "-") |
|
|
|
mr = project.get_model_registry() |
|
model = mr.get_model("air_quality_modal_choosed", version=1) |
|
model_dir = model.download() |
|
model = joblib.load(model_dir + "/air_quality_model_choosed.pkl") |
|
|
|
st.write("-" * 36) |
|
|
|
|
|
preds = model.predict(df_weather_x).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(8)] |
|
|
|
df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week) |
|
|
|
st.write(df) |
|
|
|
st.button("Re-run") |