File size: 1,667 Bytes
1ae03dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388226f
1ae03dd
 
 
 
 
bb98c8a
1ae03dd
 
 
 
bb98c8a
 
1ae03dd
 
 
 
 
4b84daf
bb98c8a
1ae03dd
 
bb98c8a
1ae03dd
 
 
 
6b4283a
1ae03dd
7af8d8e
1ae03dd
bb98c8a
1ae03dd
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)

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")