Spaces:
Runtime error
Runtime error
Commit
•
7657c22
1
Parent(s):
af5cec1
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import hopsworks
|
3 |
+
import joblib
|
4 |
+
from datetime import date
|
5 |
+
import pandas as pd
|
6 |
+
from datetime import timedelta, datetime
|
7 |
+
from functions import *
|
8 |
+
import numpy as np
|
9 |
+
from sklearn.preprocessing import StandardScaler
|
10 |
+
|
11 |
+
import folium
|
12 |
+
from streamlit_folium import st_folium, folium_static
|
13 |
+
import json
|
14 |
+
import time
|
15 |
+
from branca.element import Figure
|
16 |
+
|
17 |
+
|
18 |
+
def fancy_header(text, font_size=24):
|
19 |
+
res = f'<p style="color:#ff5f72; font-size: {font_size}px; text-align:center;">{text}</p>'
|
20 |
+
st.markdown(res, unsafe_allow_html=True)
|
21 |
+
|
22 |
+
st.set_page_config(layout="wide")
|
23 |
+
|
24 |
+
st.title('Air Quality Prediction Project🌩')
|
25 |
+
|
26 |
+
st.write(36 * "-")
|
27 |
+
fancy_header('\n Connecting to Hopsworks Feature Store...')
|
28 |
+
|
29 |
+
project = hopsworks.login()
|
30 |
+
|
31 |
+
st.write("Successfully connected!✔️")
|
32 |
+
|
33 |
+
st.write(36 * "-")
|
34 |
+
fancy_header('\n Getting data from Feature Store...')
|
35 |
+
|
36 |
+
today = date.today()
|
37 |
+
##########################城市####################
|
38 |
+
city = "Guangzhou"
|
39 |
+
df_weather = get_weather_data_weekly(city, today)
|
40 |
+
df_weather.date = df_weather.date.apply(timestamp_2_time)
|
41 |
+
df_weather_x = df_weather.drop(columns=["date"]).fillna(0)
|
42 |
+
df_weather_nn=np.array(df_weather_x)
|
43 |
+
scaler = StandardScaler()
|
44 |
+
scaler.fit(df_weather_x)
|
45 |
+
|
46 |
+
df_weather_use=scaler.transform(df_weather_x)
|
47 |
+
|
48 |
+
df_weather_use_1= pd.DataFrame(df_weather_use)
|
49 |
+
|
50 |
+
#preds_zzz = model.predict(df_weather_use_1).astype(int)
|
51 |
+
|
52 |
+
st.write(36 * "-")
|
53 |
+
|
54 |
+
########################根据模型名称进行修改#####################
|
55 |
+
mr = project.get_model_registry()
|
56 |
+
model = mr.get_model("AIR_Forecast_Model", version=9)
|
57 |
+
model_dir = model.download()
|
58 |
+
model = joblib.load(model_dir + "/AIR_Forecast_Model.pkl")
|
59 |
+
|
60 |
+
st.write("-" * 36)
|
61 |
+
|
62 |
+
|
63 |
+
preds = model.predict(df_weather_use_1).astype(int)
|
64 |
+
pollution_level = get_aplevel(preds.T.reshape(-1, 1))
|
65 |
+
|
66 |
+
next_week = [f"{(today + timedelta(days=d)).strftime('%Y-%m-%d')},{(today + timedelta(days=d)).strftime('%A')}" for d in range(8)]
|
67 |
+
|
68 |
+
df = pd.DataFrame(data=[preds, pollution_level], index=["AQI", "Air pollution level"], columns=next_week)
|
69 |
+
###########如果报错AQI这个修改成preds的标签##################
|
70 |
+
|
71 |
+
st.write(df)
|
72 |
+
|
73 |
+
st.button("Re-run")
|
74 |
+
|
75 |
+
|