Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,42 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import hopsworks
|
3 |
import joblib
|
4 |
import pandas as pd
|
5 |
-
import
|
6 |
-
|
7 |
-
|
8 |
-
from
|
9 |
-
|
10 |
|
11 |
-
def fancy_header(text, font_size=24):
|
12 |
-
res = f'<p style="color:#ff5f27; font-size: {font_size}px;text-align:center">{text}</p>'
|
13 |
-
st.markdown(res, unsafe_allow_html=True)
|
14 |
|
15 |
-
|
16 |
-
st.title('Air Quality Prediction Project for Helsinki! 🌩')
|
17 |
|
18 |
-
fancy_header('\n Connecting to Hopsworks Feature Store...')
|
19 |
|
20 |
project = hopsworks.login()
|
|
|
|
|
21 |
|
22 |
-
st.write("Successfully connected!✔️")
|
23 |
-
|
24 |
-
st.write(36 * "-")
|
25 |
-
fancy_header('\n Collecting the weather data from Vienna...')
|
26 |
-
|
27 |
-
today = datetime.now()
|
28 |
-
city = "helsinki"
|
29 |
weather_df = pd.DataFrame()
|
30 |
for i in range(8):
|
31 |
weather_data = get_weather_df([get_weather_data((datetime.now() + timedelta(days=i)).strftime("%Y-%m-%d"))])
|
32 |
weather_df = weather_df.append(weather_data)
|
33 |
|
34 |
weather_df = weather_df.drop(columns=["precipprob", "uvindex", "date","city","conditions"]).fillna(0)
|
35 |
-
|
36 |
-
|
37 |
-
st.write(36 * "-")
|
38 |
-
|
39 |
-
fancy_header("Loading the fitted XGBoost model...")
|
40 |
mr = project.get_model_registry()
|
41 |
model = mr.get_model("lond_gradient_boost_model", version=1)
|
42 |
model_dir = model.download()
|
43 |
model = joblib.load(model_dir + "/lond_model.pkl")
|
44 |
-
|
45 |
-
st.write("Succesfully loaded!✔️")
|
46 |
-
st.sidebar.write("-" * 36)
|
47 |
-
|
48 |
-
fancy_header("Making AQI predictions for the next 7 days")
|
49 |
-
|
50 |
preds = model.predict(weather_df)
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
|
53 |
-
poll_level = get_aplevel(preds.T.reshape(-1, 1))
|
54 |
|
55 |
next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
|
56 |
next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
|
@@ -61,3 +47,4 @@ st.write("Here they are!")
|
|
61 |
st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
|
62 |
|
63 |
st.button("Re-run")
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import gradio as gr
|
3 |
import hopsworks
|
4 |
import joblib
|
5 |
import pandas as pd
|
6 |
+
import numpy as np
|
7 |
+
import json
|
8 |
+
import time
|
9 |
+
from datetime import timedelta, datetime
|
|
|
10 |
|
|
|
|
|
|
|
11 |
|
12 |
+
from functions import *
|
|
|
13 |
|
|
|
14 |
|
15 |
project = hopsworks.login()
|
16 |
+
fs = project.get_feature_store()
|
17 |
+
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
weather_df = pd.DataFrame()
|
20 |
for i in range(8):
|
21 |
weather_data = get_weather_df([get_weather_data((datetime.now() + timedelta(days=i)).strftime("%Y-%m-%d"))])
|
22 |
weather_df = weather_df.append(weather_data)
|
23 |
|
24 |
weather_df = weather_df.drop(columns=["precipprob", "uvindex", "date","city","conditions"]).fillna(0)
|
25 |
+
|
|
|
|
|
|
|
|
|
26 |
mr = project.get_model_registry()
|
27 |
model = mr.get_model("lond_gradient_boost_model", version=1)
|
28 |
model_dir = model.download()
|
29 |
model = joblib.load(model_dir + "/lond_model.pkl")
|
30 |
+
|
|
|
|
|
|
|
|
|
|
|
31 |
preds = model.predict(weather_df)
|
32 |
+
|
33 |
+
predictions = ''
|
34 |
+
for k in range(7):
|
35 |
+
predictions += "Predicted AQI on " + (datetime.now() + timedelta(days=k)).strftime('%Y-%m-%d') + ": " + str(int(preds[k]))+"\n"
|
36 |
+
|
37 |
|
38 |
air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
|
39 |
+
poll_level = get_aplevel(preds.T.reshape(-1, 1), air_pollution_level)
|
40 |
|
41 |
next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
|
42 |
next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
|
|
|
47 |
st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
|
48 |
|
49 |
st.button("Re-run")
|
50 |
+
|