air_quality_gb / app.py
Mei000's picture
Upload 3 files
557ecc6
raw history blame
No virus
1.91 kB
import streamlit as st
import hopsworks
import joblib
from datetime import date
import pandas as pd
from datetime import timedelta, datetime
from functions import *
import numpy as np
from sklearn.preprocessing import StandardScaler
import folium
from streamlit_folium import st_folium, folium_static
import json
import time
from branca.element import Figure
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(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 = 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)
df_weather_nn=np.array(df_weather_x)
scaler = StandardScaler()
scaler.fit(df_weather_x)
df_weather_use=scaler.transform(df_weather_x)
df_weather_use_1= pd.DataFrame(df_weather_use)
#preds_zzz = model.predict(df_weather_use_1).astype(int)
st.write(36 * "-")
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_use_1).astype(int)
pollution_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, pollution_level], index=["AQI", "Air pollution level"], columns=next_week)
st.write(df)
st.button("Re-run")