Spaces:
Runtime error
Runtime error
File size: 1,909 Bytes
557ecc6 |
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 61 62 63 64 65 66 67 68 69 70 71 |
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") |