CsanadT commited on
Commit
60999f9
1 Parent(s): 6b4283a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -2,59 +2,49 @@ import streamlit as st
2
  import hopsworks
3
  import joblib
4
  import pandas as pd
5
- import numpy as np
6
  from datetime import timedelta, datetime
7
-
8
  from functions import *
9
 
 
10
  def fancy_header(text, font_size=24):
11
  res = f'<span style="color:#ff5f27; font-size: {font_size}px;">{text}</span>'
12
- st.markdown(res, unsafe_allow_html=True )
 
13
 
14
  st.title('Air Quality Prediction Project🌩')
15
 
16
- progress_bar = st.sidebar.header('Working Progress')
17
- progress_bar = st.sidebar.progress(0)
18
  st.write(36 * "-")
19
  fancy_header('\n Connecting to Hopsworks Feature Store...')
20
 
21
  project = hopsworks.login()
22
 
23
  st.write("Successfully connected!✔️")
24
- progress_bar.progress(20)
25
 
26
  st.write(36 * "-")
27
- fancy_header('\n Getting data from thee weather API...')
28
 
29
  today = datetime.date.today()
30
  city = "vienna"
31
  weekly_data = get_weather_data_weekly(city, today)
32
 
33
- fancy_header('\n Acquired data!')
34
- progress_bar.progress(60)
35
 
36
  st.write(36 * "-")
37
 
38
- fancy_header('\n Loading the XGBoost model from the Hopsworks Model Registry')
39
-
40
  mr = project.get_model_registry()
41
  model = mr.get_best_model("aqi_model", "rmse", "min")
42
  model_dir = model.download()
43
  model = joblib.load(model_dir + "/aqi_model.pkl")
44
 
45
- fancy_header('\n Model loaded. Let\'s make predictions!')
46
-
47
- progress_bar.progress(80)
48
-
49
  st.sidebar.write("-" * 36)
50
 
 
51
  preds = model.predict(data_encoder(weekly_data)).astype(int)
52
  poll_level = get_aplevel(preds.T.reshape(-1, 1))
53
 
54
- next_week = [f"{(today + timedelta(days=d)).strftime('%Y-%m-%d')}, {(today + timedelta(days=d)).strftime('%A')}" for d in range(7)]
55
 
56
- df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week)
57
 
58
  st.write(df)
59
- progress_bar.progress(100)
60
  st.button("Re-run")
 
2
  import hopsworks
3
  import joblib
4
  import pandas as pd
 
5
  from datetime import timedelta, datetime
 
6
  from functions import *
7
 
8
+
9
  def fancy_header(text, font_size=24):
10
  res = f'<span style="color:#ff5f27; font-size: {font_size}px;">{text}</span>'
11
+ st.markdown(res, unsafe_allow_html=True)
12
+
13
 
14
  st.title('Air Quality Prediction Project🌩')
15
 
 
 
16
  st.write(36 * "-")
17
  fancy_header('\n Connecting to Hopsworks Feature Store...')
18
 
19
  project = hopsworks.login()
20
 
21
  st.write("Successfully connected!✔️")
 
22
 
23
  st.write(36 * "-")
24
+ fancy_header('\n Getting data from Feature Store...')
25
 
26
  today = datetime.date.today()
27
  city = "vienna"
28
  weekly_data = get_weather_data_weekly(city, today)
29
 
 
 
30
 
31
  st.write(36 * "-")
32
 
 
 
33
  mr = project.get_model_registry()
34
  model = mr.get_best_model("aqi_model", "rmse", "min")
35
  model_dir = model.download()
36
  model = joblib.load(model_dir + "/aqi_model.pkl")
37
 
 
 
 
 
38
  st.sidebar.write("-" * 36)
39
 
40
+
41
  preds = model.predict(data_encoder(weekly_data)).astype(int)
42
  poll_level = get_aplevel(preds.T.reshape(-1, 1))
43
 
44
+ next_week = [[(today + timedelta(days=d)).strftime('%Y-%m-%d'),(today + timedelta(days=d)).strftime('%A')] for d in range(1, 7)]
45
 
46
+ df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=[f"AQI Predictions for {next_day}" for next_day in next_week])
47
 
48
  st.write(df)
49
+
50
  st.button("Re-run")