elisaklunder
commited on
Commit
•
94c13a3
1
Parent(s):
5c952a2
rvert
Browse files- app.py +2 -3
- predictions_history.csv +6 -0
- src/predict.py +20 -29
app.py
CHANGED
@@ -4,7 +4,7 @@ import plotly.graph_objects as go
|
|
4 |
import streamlit as st
|
5 |
|
6 |
from src.helper_functions import custom_metric_box, pollution_box
|
7 |
-
from src.predict import get_data_and_predictions
|
8 |
|
9 |
st.set_page_config(
|
10 |
page_title="Utrecht Pollution Dashboard",
|
@@ -15,8 +15,7 @@ st.set_page_config(
|
|
15 |
|
16 |
alt.themes.enable("dark")
|
17 |
|
18 |
-
|
19 |
-
week_data, predictions_O3, predictions_NO2 = get_data_and_predictions(model_NO2, model_O3)
|
20 |
|
21 |
today = week_data.iloc[-1]
|
22 |
previous_day = week_data.iloc[-2]
|
|
|
4 |
import streamlit as st
|
5 |
|
6 |
from src.helper_functions import custom_metric_box, pollution_box
|
7 |
+
from src.predict import get_data_and_predictions
|
8 |
|
9 |
st.set_page_config(
|
10 |
page_title="Utrecht Pollution Dashboard",
|
|
|
15 |
|
16 |
alt.themes.enable("dark")
|
17 |
|
18 |
+
week_data, predictions_O3, predictions_NO2 = get_data_and_predictions()
|
|
|
19 |
|
20 |
today = week_data.iloc[-1]
|
21 |
previous_day = week_data.iloc[-2]
|
predictions_history.csv
CHANGED
@@ -5,3 +5,9 @@ O3,2024-10-24,2024-10-26,16.000984317626852
|
|
5 |
NO2,2024-10-24,2024-10-26,25.760307451092384
|
6 |
O3,2024-10-24,2024-10-27,19.64377495640328
|
7 |
NO2,2024-10-24,2024-10-27,31.210576791105115
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
NO2,2024-10-24,2024-10-26,25.760307451092384
|
6 |
O3,2024-10-24,2024-10-27,19.64377495640328
|
7 |
NO2,2024-10-24,2024-10-27,31.210576791105115
|
8 |
+
O3,2024-10-24,2024-10-25,10.33808859423279
|
9 |
+
NO2,2024-10-24,2024-10-25,25.68519991558237
|
10 |
+
O3,2024-10-24,2024-10-26,16.000984317626852
|
11 |
+
NO2,2024-10-24,2024-10-26,25.760307451092384
|
12 |
+
O3,2024-10-24,2024-10-27,19.64377495640328
|
13 |
+
NO2,2024-10-24,2024-10-27,31.210576791105115
|
src/predict.py
CHANGED
@@ -3,53 +3,44 @@ from datetime import date, timedelta
|
|
3 |
|
4 |
import joblib
|
5 |
import pandas as pd
|
6 |
-
import streamlit as st
|
7 |
from dotenv import load_dotenv
|
8 |
from huggingface_hub import hf_hub_download, login
|
9 |
|
10 |
from src.data_api_calls import get_combined_data
|
11 |
from src.features_pipeline import create_features
|
12 |
|
13 |
-
load_dotenv()
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
def load_models():
|
18 |
login(token=os.getenv("HUGGINGFACE_DOWNLOAD_TOKEN"))
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
model_path = hf_hub_download(
|
26 |
-
repo_id="elisaklunder/Utrecht-NO2-Forecasting-Model",
|
27 |
-
filename="NO2_svr_model.pkl",
|
28 |
-
)
|
29 |
-
model_O3 = joblib.load(model_path)
|
30 |
-
return model_NO2, model_O3
|
31 |
|
|
|
|
|
|
|
32 |
|
33 |
-
def run_models(model_NO2, model_O3, data):
|
34 |
-
input_data = create_features(data=data, target_particle="NO2")
|
35 |
-
prediction = model_NO2.predict(input_data)
|
36 |
-
target_scaler = joblib.load("scalers/target_scaler_NO2.joblib")
|
37 |
-
prediction_NO2 = target_scaler.inverse_transform(prediction)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
return prediction_NO2, prediction_O3
|
45 |
|
46 |
-
|
47 |
-
def get_data_and_predictions(model_NO2, model_O3):
|
48 |
PREDICTIONS_FILE = "predictions_history.csv"
|
49 |
|
50 |
week_data = get_combined_data()
|
51 |
|
52 |
-
o3_predictions
|
|
|
53 |
|
54 |
prediction_data = []
|
55 |
for i in range(3):
|
|
|
3 |
|
4 |
import joblib
|
5 |
import pandas as pd
|
|
|
6 |
from dotenv import load_dotenv
|
7 |
from huggingface_hub import hf_hub_download, login
|
8 |
|
9 |
from src.data_api_calls import get_combined_data
|
10 |
from src.features_pipeline import create_features
|
11 |
|
|
|
12 |
|
13 |
+
def load_model(particle):
|
14 |
+
load_dotenv()
|
|
|
15 |
login(token=os.getenv("HUGGINGFACE_DOWNLOAD_TOKEN"))
|
16 |
|
17 |
+
repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
|
18 |
+
if particle == "O3":
|
19 |
+
file_name = "O3_svr_model.pkl"
|
20 |
+
elif particle == "NO2":
|
21 |
+
file_name = "NO2_svr_model.pkl"
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=file_name)
|
24 |
+
model = joblib.load(model_path)
|
25 |
+
return model
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
def run_model(particle, data):
|
29 |
+
input_data = create_features(data=data, target_particle=particle)
|
30 |
+
model = load_model(particle)
|
31 |
+
prediction = model.predict(input_data)
|
32 |
+
target_scaler = joblib.load(f"scalers/target_scaler_{particle}.joblib")
|
33 |
+
prediction = target_scaler.inverse_transform(prediction)
|
34 |
+
return prediction
|
35 |
|
|
|
36 |
|
37 |
+
def get_data_and_predictions():
|
|
|
38 |
PREDICTIONS_FILE = "predictions_history.csv"
|
39 |
|
40 |
week_data = get_combined_data()
|
41 |
|
42 |
+
o3_predictions = run_model("O3", data=week_data)
|
43 |
+
no2_predictions = run_model("NO2", data=week_data)
|
44 |
|
45 |
prediction_data = []
|
46 |
for i in range(3):
|