put run_model function into helpers
Browse files- app.py +4 -23
- helper_functions.py +17 -0
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import time
|
2 |
-
|
3 |
import altair as alt
|
4 |
import joblib
|
5 |
import numpy as np
|
@@ -8,11 +7,7 @@ import streamlit as st
|
|
8 |
from sklearn.linear_model import LinearRegression
|
9 |
import matplotlib.pyplot as plt
|
10 |
import plotly.graph_objects as go
|
11 |
-
from helper_functions import custom_metric_box, pollution_box
|
12 |
-
import plotly.graph_objects as go
|
13 |
-
import streamlit as st
|
14 |
-
import pandas as pd
|
15 |
-
import numpy as np
|
16 |
|
17 |
st.set_page_config(
|
18 |
page_title="Utrecht Pollution Dashboard",
|
@@ -21,24 +16,12 @@ st.set_page_config(
|
|
21 |
initial_sidebar_state="expanded")
|
22 |
|
23 |
alt.themes.enable("dark")
|
|
|
|
|
|
|
24 |
# App Title
|
25 |
st.title("Utrecht Pollution Dashboard 🌱")
|
26 |
|
27 |
-
@st.cache_resource(ttl=6*300) # Reruns every 6 hours
|
28 |
-
def run_model():
|
29 |
-
# Load or train your model (pretrained model in this case)
|
30 |
-
model = joblib.load("linear_regression_model.pkl")
|
31 |
-
|
32 |
-
# Static input values
|
33 |
-
input_data = pd.DataFrame({
|
34 |
-
'Temperature': [20.0],
|
35 |
-
'Wind Speed': [10.0],
|
36 |
-
'Humidity': [50.0]
|
37 |
-
})
|
38 |
-
|
39 |
-
# Run the model with static input
|
40 |
-
prediction = model.predict(input_data)
|
41 |
-
return prediction
|
42 |
col1, col2 = st.columns((1,1))
|
43 |
# Create a 3-column layout
|
44 |
with col1:
|
@@ -69,8 +52,6 @@ with col1:
|
|
69 |
with col2:
|
70 |
pollution_box(label="NO<sub>2</sub>", value="28 µg/m³", delta="+3 µg/m³")
|
71 |
|
72 |
-
|
73 |
-
prediction = run_model() # Assuming you have a function run_model()
|
74 |
# Sample data (replace with your actual data)
|
75 |
dates_past = pd.date_range(end=pd.Timestamp.today(), periods=7).to_list()
|
76 |
dates_future = pd.date_range(start=pd.Timestamp.today() + pd.Timedelta(days=1), periods=3).to_list()
|
|
|
1 |
import time
|
|
|
2 |
import altair as alt
|
3 |
import joblib
|
4 |
import numpy as np
|
|
|
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",
|
|
|
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:
|
|
|
52 |
with col2:
|
53 |
pollution_box(label="NO<sub>2</sub>", value="28 µg/m³", delta="+3 µg/m³")
|
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()
|
helper_functions.py
CHANGED
@@ -1,5 +1,22 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Custom function to create styled metric boxes with subscripts, smaller label, and larger metric
|
5 |
def custom_metric_box(label, value, delta):
|
|
|
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):
|