elisaklunder commited on
Commit
5c6dd58
1 Parent(s): ca76ce0

my last straw

Browse files
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .venv/
2
+ .env
3
+ __pycache__/
4
+ *.pyc
README.md CHANGED
@@ -11,4 +11,3 @@ short_description: 'Demo: Model to predict O3 and NO2 concentrations in Utrecht'
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
- hhhrhehheehehehe
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
app.py CHANGED
@@ -1,31 +1,28 @@
1
- import time
2
  import altair as alt
3
- import joblib
4
- import numpy as np
5
  import pandas as pd
6
- import streamlit as st
7
- from sklearn.linear_model import LinearRegression
8
- import matplotlib.pyplot as plt
9
  import plotly.graph_objects as go
10
- from helper_functions import custom_metric_box, pollution_box, run_model
 
 
11
 
12
  st.set_page_config(
13
  page_title="Utrecht Pollution Dashboard",
14
  page_icon="🏂��🌱",
15
  layout="wide",
16
- initial_sidebar_state="expanded")
 
17
 
18
  alt.themes.enable("dark")
19
 
20
- prediction = run_model() # Assuming you have a function run_model()
21
 
22
  # App Title
23
- st.title("Utrecht Pollution Dashboard 🌱")
24
 
25
- col1, col2 = st.columns((1,1))
26
  # Create a 3-column layout
27
  with col1:
28
- st.subheader('Current Weather')
29
  col1, col2, col3 = st.columns(3)
30
 
31
  # First column
@@ -43,10 +40,10 @@ with col1:
43
  custom_metric_box(label="Solar Radiation", value="200 W/m²", delta="-20 W/m²")
44
  custom_metric_box(label="Wind Speed", value="15 km/h", delta="-2 km/h")
45
 
46
- st.subheader('Current Pollution Levels')
47
- col1, col2 = st.columns((1,1))
48
  # Display the prediction
49
- #st.write(f'Predicted Pollution Level: {prediction[0]:.2f}')
50
  with col1:
51
  pollution_box(label="O<sub>3</sub>", value="37 µg/m³", delta="+2 µg/m³")
52
  with col2:
@@ -54,7 +51,9 @@ with col1:
54
 
55
  # Sample data (replace with your actual data)
56
  dates_past = pd.date_range(end=pd.Timestamp.today(), periods=7).to_list()
57
- dates_future = pd.date_range(start=pd.Timestamp.today() + pd.Timedelta(days=1), periods=3).to_list()
 
 
58
 
59
  # O3 and NO2 values for the past 7 days
60
  o3_past_values = [30, 32, 34, 33, 31, 35, 36]
@@ -70,61 +69,71 @@ o3_values = o3_past_values + o3_future_values
70
  no2_values = no2_past_values + no2_future_values
71
 
72
  # Create a DataFrame
73
- df = pd.DataFrame({
74
- 'Date': dates,
75
- 'O3': o3_values,
76
- 'NO2': no2_values
77
- })
78
 
79
- st.subheader('O3 and NO2 Prediction')
80
  # Create two columns for two separate graphs
81
  subcol1, subcol2 = st.columns(2)
82
  # Plot O3 in the first subcolumn
83
  with subcol1:
84
  fig_o3 = go.Figure()
85
- fig_o3.add_trace(go.Scatter(x=df['Date'], y=df['O3'],
86
- mode='lines+markers',
87
- name='O3',
88
- line=dict(color='rgb(0, 191, 255)', width=4))) # Bright blue
 
 
 
 
 
89
  # Add a vertical line for predictions (today's date)
90
  fig_o3.add_shape(
91
  dict(
92
  type="line",
93
- x0=pd.Timestamp.today(), x1=pd.Timestamp.today(),
94
- y0=min(o3_values), y1=max(o3_values),
 
 
95
  line=dict(color="White", width=3, dash="dash"),
96
  )
97
  )
98
  fig_o3.update_layout(
99
- plot_bgcolor='rgba(0, 0, 0, 0)', # Transparent background
100
- paper_bgcolor='rgba(0, 0, 0, 0)', # Transparent paper background
101
  yaxis_title="O3 Concentration (µg/m³)",
102
  font=dict(size=14),
103
- hovermode="x unified"
104
  )
105
  st.plotly_chart(fig_o3)
106
 
107
  # Plot NO2 in the second subcolumn
108
  with subcol2:
109
  fig_no2 = go.Figure()
110
- fig_no2.add_trace(go.Scatter(x=df['Date'], y=df['NO2'],
111
- mode='lines+markers',
112
- name='NO2',
113
- line=dict(color='rgb(255, 20, 147)', width=4))) # Bright pink
 
 
 
 
 
114
  # Add a vertical line for predictions (today's date)
115
  fig_no2.add_shape(
116
  dict(
117
  type="line",
118
- x0=pd.Timestamp.today(), x1=pd.Timestamp.today(),
119
- y0=min(no2_values), y1=max(no2_values),
 
 
120
  line=dict(color="White", width=3, dash="dash"),
121
  )
122
  )
123
  fig_no2.update_layout(
124
- plot_bgcolor='rgba(0, 0, 0, 0)', # Transparent background
125
- paper_bgcolor='rgba(0, 0, 0, 0)', # Transparent paper background
126
  yaxis_title="NO2 Concentration (µg/m³)",
127
  font=dict(size=14),
128
- hovermode="x unified"
129
  )
130
- st.plotly_chart(fig_no2)
 
 
1
  import altair as alt
 
 
2
  import pandas as pd
 
 
 
3
  import plotly.graph_objects as go
4
+ import streamlit as st
5
+ from src.helper_functions import custom_metric_box, pollution_box
6
+ from src.models_loading import run_model
7
 
8
  st.set_page_config(
9
  page_title="Utrecht Pollution Dashboard",
10
  page_icon="🏂��🌱",
11
  layout="wide",
12
+ initial_sidebar_state="expanded",
13
+ )
14
 
15
  alt.themes.enable("dark")
16
 
17
+ test_predictions = run_model("O3")
18
 
19
  # App Title
20
+ st.title("Utrecht Pollution Dashboard🌱")
21
 
22
+ col1, col2 = st.columns((1, 1))
23
  # Create a 3-column layout
24
  with col1:
25
+ st.subheader("Current Weather")
26
  col1, col2, col3 = st.columns(3)
27
 
28
  # First column
 
40
  custom_metric_box(label="Solar Radiation", value="200 W/m²", delta="-20 W/m²")
41
  custom_metric_box(label="Wind Speed", value="15 km/h", delta="-2 km/h")
42
 
43
+ st.subheader("Current Pollution Levels")
44
+ col1, col2 = st.columns((1, 1))
45
  # Display the prediction
46
+ # st.write(f'Predicted Pollution Level: {prediction[0]:.2f}')
47
  with col1:
48
  pollution_box(label="O<sub>3</sub>", value="37 µg/m³", delta="+2 µg/m³")
49
  with col2:
 
51
 
52
  # Sample data (replace with your actual data)
53
  dates_past = pd.date_range(end=pd.Timestamp.today(), periods=7).to_list()
54
+ dates_future = pd.date_range(
55
+ start=pd.Timestamp.today() + pd.Timedelta(days=1), periods=3
56
+ ).to_list()
57
 
58
  # O3 and NO2 values for the past 7 days
59
  o3_past_values = [30, 32, 34, 33, 31, 35, 36]
 
69
  no2_values = no2_past_values + no2_future_values
70
 
71
  # Create a DataFrame
72
+ df = pd.DataFrame({"Date": dates, "O3": o3_values, "NO2": no2_values})
 
 
 
 
73
 
74
+ st.subheader("O3 and NO2 Prediction")
75
  # Create two columns for two separate graphs
76
  subcol1, subcol2 = st.columns(2)
77
  # Plot O3 in the first subcolumn
78
  with subcol1:
79
  fig_o3 = go.Figure()
80
+ fig_o3.add_trace(
81
+ go.Scatter(
82
+ x=df["Date"],
83
+ y=df["O3"],
84
+ mode="lines+markers",
85
+ name="O3",
86
+ line=dict(color="rgb(0, 191, 255)", width=4),
87
+ )
88
+ ) # Bright blue
89
  # Add a vertical line for predictions (today's date)
90
  fig_o3.add_shape(
91
  dict(
92
  type="line",
93
+ x0=pd.Timestamp.today(),
94
+ x1=pd.Timestamp.today(),
95
+ y0=min(o3_values),
96
+ y1=max(o3_values),
97
  line=dict(color="White", width=3, dash="dash"),
98
  )
99
  )
100
  fig_o3.update_layout(
101
+ plot_bgcolor="rgba(0, 0, 0, 0)", # Transparent background
102
+ paper_bgcolor="rgba(0, 0, 0, 0)", # Transparent paper background
103
  yaxis_title="O3 Concentration (µg/m³)",
104
  font=dict(size=14),
105
+ hovermode="x unified",
106
  )
107
  st.plotly_chart(fig_o3)
108
 
109
  # Plot NO2 in the second subcolumn
110
  with subcol2:
111
  fig_no2 = go.Figure()
112
+ fig_no2.add_trace(
113
+ go.Scatter(
114
+ x=df["Date"],
115
+ y=df["NO2"],
116
+ mode="lines+markers",
117
+ name="NO2",
118
+ line=dict(color="rgb(255, 20, 147)", width=4),
119
+ )
120
+ ) # Bright pink
121
  # Add a vertical line for predictions (today's date)
122
  fig_no2.add_shape(
123
  dict(
124
  type="line",
125
+ x0=pd.Timestamp.today(),
126
+ x1=pd.Timestamp.today(),
127
+ y0=min(no2_values),
128
+ y1=max(no2_values),
129
  line=dict(color="White", width=3, dash="dash"),
130
  )
131
  )
132
  fig_no2.update_layout(
133
+ plot_bgcolor="rgba(0, 0, 0, 0)", # Transparent background
134
+ paper_bgcolor="rgba(0, 0, 0, 0)", # Transparent paper background
135
  yaxis_title="NO2 Concentration (µg/m³)",
136
  font=dict(size=14),
137
+ hovermode="x unified",
138
  )
139
+ st.plotly_chart(fig_no2)
requirements.txt CHANGED
@@ -5,4 +5,5 @@ joblib # or pickle if you're using that to load the model
5
  scikit-learn # for mock model
6
  altair
7
  matplotlib
8
- plotly
 
 
5
  scikit-learn # for mock model
6
  altair
7
  matplotlib
8
+ plotly
9
+ huggingface-hub
scalers/target_scaler_NO2.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:255a0d1dd1d8673ce03e838e9fc1a7df4dab1248ca70f6cb73b66aea83ed6316
3
+ size 1023
scalers/target_scaler_O3.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ad485897b59228f1c1efd8c76cc2fa771d10efd379297f163ceba32dbacbab6
3
+ size 1023
daily_api__pollution.py → src/daily_api__pollution.py RENAMED
File without changes
data_loading.py → src/data_loading.py RENAMED
File without changes
helper_functions.py → src/helper_functions.py RENAMED
@@ -1,22 +1,4 @@
1
  import streamlit as st
2
- import joblib
3
- import pandas as pd
4
-
5
- @st.cache_resource(ttl=6*300) # Reruns every 6 hours
6
- def run_model():
7
- # Load or train your model (pretrained model in this case)
8
- model = joblib.load("linear_regression_model.pkl")
9
-
10
- # Static input values
11
- input_data = pd.DataFrame({
12
- 'Temperature': [20.0],
13
- 'Wind Speed': [10.0],
14
- 'Humidity': [50.0]
15
- })
16
-
17
- # Run the model with static input
18
- prediction = model.predict(input_data)
19
- return prediction
20
 
21
  # Custom function to create styled metric boxes with subscripts, smaller label, and larger metric
22
  def custom_metric_box(label, value, delta):
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Custom function to create styled metric boxes with subscripts, smaller label, and larger metric
4
  def custom_metric_box(label, value, delta):
src/models_loading.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import joblib
4
+ import pandas as pd
5
+ import streamlit as st
6
+ from dotenv import load_dotenv
7
+ from huggingface_hub import hf_hub_download, login
8
+
9
+
10
+ def load_model(particle):
11
+ load_dotenv()
12
+ login(token=os.getenv("HUGGINGFACE_DOWNLOAD_TOKEN"))
13
+
14
+ repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
15
+ if particle == "O3":
16
+ file_name = "O3_svr_model.pkl"
17
+ elif particle == "NO2":
18
+ file_name == "hehehe"
19
+
20
+ model_path = hf_hub_download(repo_id=repo_id, filename=file_name)
21
+ model = joblib.load(model_path)
22
+
23
+ return model
24
+
25
+
26
+ @st.cache_resource(ttl=6 * 300) # Reruns every 6 hours
27
+ def run_model(particle):
28
+ model = load_model(particle)
29
+
30
+ # Static input values
31
+ input_data = pd.DataFrame(
32
+ {"Temperature": [20.0], "Wind Speed": [10.0], "Humidity": [50.0]}
33
+ )
34
+
35
+ # Run the model with static input
36
+ prediction = model.predict(input_data)
37
+ return prediction