Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,50 +33,51 @@ def fill_nan_with_zero(value):
|
|
| 33 |
return value
|
| 34 |
|
| 35 |
# Creating tabs for the different features of the application
|
| 36 |
-
tab1,tab2
|
| 37 |
|
| 38 |
with tab1:
|
| 39 |
# Logging in to Hopsworks and loading the feature store
|
| 40 |
project = hopsworks.login(project = "annikaij", api_key_value=os.environ['HOPSWORKS_API_KEY'])
|
| 41 |
fs = project.get_feature_store()
|
| 42 |
|
| 43 |
-
col1, col2 = st.columns(2)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
st.subheader("Parking place near building:")
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
|
|
|
| 80 |
# Retrieving building data
|
| 81 |
building_new = retrieve_building()
|
| 82 |
|
|
@@ -91,6 +92,7 @@ with tab1:
|
|
| 91 |
building_mag_prediction_data = building_mag_prediction_data.set_index(['Time'])
|
| 92 |
st.dataframe(building_mag_prediction_data[['Status']].tail(3))
|
| 93 |
|
|
|
|
| 94 |
# Making the predictions and getting the latest data for radar data
|
| 95 |
building_rad_prediction_data = building_new[['time', 'radar_0', 'radar_1', 'radar_2', 'radar_3', 'radar_4', 'radar_5', 'radar_6', 'radar_7', 'temperature', 'et0_fao_evapotranspiration']]
|
| 96 |
building_rad_prediction_data['et0_fao_evapotranspiration'] = building_rad_prediction_data['et0_fao_evapotranspiration'].apply(fill_nan_with_zero)
|
|
@@ -102,45 +104,54 @@ with tab1:
|
|
| 102 |
building_rad_prediction_data = building_rad_prediction_data.set_index(['Time'])
|
| 103 |
st.dataframe(building_rad_prediction_data[['Status']].tail(3))
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
-
st.subheader("Parking place near bikelane:")
|
| 108 |
-
|
| 109 |
-
# Function to load the bikelane models
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
def retrieve_bikelane(feature_group=new_bikelane_fg):
|
| 137 |
-
new_bikelane_fg = feature_group.select_all()
|
| 138 |
-
df_bikelane_new = new_bikelane_fg.read(read_options={"use_hive": True})
|
| 139 |
-
return df_bikelane_new
|
| 140 |
|
| 141 |
-
|
| 142 |
-
bikelane_new = retrieve_bikelane()
|
| 143 |
|
|
|
|
| 144 |
# Making the predictions and getting the latest data for magnetic field data
|
| 145 |
bikelane_mag_prediction_data = bikelane_new[['time', 'x', 'y', 'z', 'temperature', 'et0_fao_evapotranspiration']]
|
| 146 |
bikelane_mag_prediction_data['et0_fao_evapotranspiration'] = bikelane_mag_prediction_data['et0_fao_evapotranspiration'].apply(fill_nan_with_zero)
|
|
@@ -152,6 +163,7 @@ with tab1:
|
|
| 152 |
bikelane_mag_prediction_data = bikelane_mag_prediction_data.set_index(['Time'])
|
| 153 |
st.dataframe(bikelane_mag_prediction_data[['Status']].tail(3))
|
| 154 |
|
|
|
|
| 155 |
# Making the predictions and getting the latest data for radar data
|
| 156 |
bikelane_rad_prediction_data = bikelane_new[['time', 'radar_0', 'radar_1', 'radar_2', 'radar_3', 'radar_4', 'radar_5', 'radar_6', 'radar_7', 'temperature', 'et0_fao_evapotranspiration']]
|
| 157 |
bikelane_rad_prediction_data['et0_fao_evapotranspiration'] = bikelane_rad_prediction_data['et0_fao_evapotranspiration'].apply(fill_nan_with_zero)
|
|
@@ -162,32 +174,5 @@ with tab1:
|
|
| 162 |
bikelane_rad_prediction_data = bikelane_rad_prediction_data.rename(columns={'time': 'Time'})
|
| 163 |
bikelane_rad_prediction_data = bikelane_rad_prediction_data.set_index(['Time'])
|
| 164 |
st.dataframe(bikelane_rad_prediction_data[['Status']].tail(3))
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
# Update button
|
| 168 |
-
if st.button("Update application"):
|
| 169 |
-
# Clear cached data
|
| 170 |
-
st.cache_data.clear()
|
| 171 |
-
# Immediately rerun the application
|
| 172 |
-
st.experimental_rerun()
|
| 173 |
-
|
| 174 |
-
with tab2:
|
| 175 |
-
st.subheader('...')
|
| 176 |
-
|
| 177 |
-
with tab3:
|
| 178 |
-
st.subheader('About the application:')
|
| 179 |
-
st.markdown('This application is made as part of the module "Data Engineering and Machine Learning Operations in Business - F2024" in Business Data Science 2nd Semester at Aalborg University Business School.')
|
| 180 |
-
st.markdown('The application is made by Annika and Mikkel and is divided into 5 tabs:')
|
| 181 |
-
st.markdown('* **Parking lot status:** The first tab includes the actual interface, where the goal has been to make a simple UI which shows if 2 parking spaces are occupied or available.')
|
| 182 |
-
st.markdown('* **Magnetic Field Explorer:** The second tabs is made for exploring the models, where the user can test different values for x, y and z and get a prediction')
|
| 183 |
-
st.markdown('* **About:** In the third tab (the current tab) you can get some information about the interface.')
|
| 184 |
-
st.markdown('* **Dataset and visualisations:** The fourth tab contains an overview of the training data and also includes EDAs for each individual parking space. The goal with these EDAs is to give you some information about when the parking spaces usually are occupied.')
|
| 185 |
-
st.markdown('* **Model Performance:** The fifth tab explains how the underlying Machine Learning Model performs and how the predictor works.')
|
| 186 |
-
|
| 187 |
-
with tab4:
|
| 188 |
-
st.subheader('...')
|
| 189 |
-
|
| 190 |
-
with tab5:
|
| 191 |
-
st.subheader('...')
|
| 192 |
-
|
| 193 |
|
|
|
|
| 33 |
return value
|
| 34 |
|
| 35 |
# Creating tabs for the different features of the application
|
| 36 |
+
tab1,tab2 = st.tabs(['Parking place near Building', 'Parking place near Bikelane'])
|
| 37 |
|
| 38 |
with tab1:
|
| 39 |
# Logging in to Hopsworks and loading the feature store
|
| 40 |
project = hopsworks.login(project = "annikaij", api_key_value=os.environ['HOPSWORKS_API_KEY'])
|
| 41 |
fs = project.get_feature_store()
|
| 42 |
|
|
|
|
| 43 |
|
| 44 |
+
st.subheader("Parking place near building:")
|
|
|
|
| 45 |
|
| 46 |
+
# Function to load the building models
|
| 47 |
|
| 48 |
+
@st.cache_data()
|
| 49 |
+
def get_building_mag_model(project=project):
|
| 50 |
+
mr = project.get_model_registry()
|
| 51 |
+
building_mag_model = mr.get_model("building_mag_hist_model", version = 2)
|
| 52 |
+
building_mag_model_dir = building_mag_model.download()
|
| 53 |
+
return joblib.load(building_mag_model_dir + "/building_mag_hist_model.pkl")
|
| 54 |
+
|
| 55 |
+
# Retrieving model
|
| 56 |
+
building_mag_hist_model = get_building_mag_model()
|
| 57 |
+
|
| 58 |
+
@st.cache_data()
|
| 59 |
+
def get_building_rad_model(project=project):
|
| 60 |
+
mr = project.get_model_registry()
|
| 61 |
+
building_rad_model = mr.get_model("building_rad_hist_model", version = 2)
|
| 62 |
+
building_rad_model_dir = building_rad_model.download()
|
| 63 |
+
return joblib.load(building_rad_model_dir + "/building_rad_hist_model.pkl")
|
| 64 |
+
|
| 65 |
+
# Retrieving model
|
| 66 |
+
building_rad_hist_model = get_building_rad_model()
|
| 67 |
|
| 68 |
+
# Loading the feature group with latest data for building
|
| 69 |
+
new_building_fg = fs.get_feature_group(name = 'new_building_fg', version = 1)
|
| 70 |
|
| 71 |
+
# Function to loading the feature group with latest data for building as a dataset
|
| 72 |
+
@st.cache_data()
|
| 73 |
+
def retrieve_building(feature_group=new_building_fg):
|
| 74 |
+
new_building_fg = feature_group.select_all()
|
| 75 |
+
df_building_new = new_building_fg.read(read_options={"use_hive": True})
|
| 76 |
+
return df_building_new
|
| 77 |
+
|
| 78 |
+
col1, col2 = st.columns(2)
|
| 79 |
|
| 80 |
+
with col1:
|
| 81 |
# Retrieving building data
|
| 82 |
building_new = retrieve_building()
|
| 83 |
|
|
|
|
| 92 |
building_mag_prediction_data = building_mag_prediction_data.set_index(['Time'])
|
| 93 |
st.dataframe(building_mag_prediction_data[['Status']].tail(3))
|
| 94 |
|
| 95 |
+
with col2:
|
| 96 |
# Making the predictions and getting the latest data for radar data
|
| 97 |
building_rad_prediction_data = building_new[['time', 'radar_0', 'radar_1', 'radar_2', 'radar_3', 'radar_4', 'radar_5', 'radar_6', 'radar_7', 'temperature', 'et0_fao_evapotranspiration']]
|
| 98 |
building_rad_prediction_data['et0_fao_evapotranspiration'] = building_rad_prediction_data['et0_fao_evapotranspiration'].apply(fill_nan_with_zero)
|
|
|
|
| 104 |
building_rad_prediction_data = building_rad_prediction_data.set_index(['Time'])
|
| 105 |
st.dataframe(building_rad_prediction_data[['Status']].tail(3))
|
| 106 |
|
| 107 |
+
# Update button
|
| 108 |
+
if st.button("Update application"):
|
| 109 |
+
# Clear cached data
|
| 110 |
+
st.cache_data.clear()
|
| 111 |
+
# Immediately rerun the application
|
| 112 |
+
st.experimental_rerun()
|
| 113 |
+
|
| 114 |
+
with tab2:
|
| 115 |
+
st.subheader("Parking place near bikelane:")
|
| 116 |
|
| 117 |
+
# Function to load the bikelane models
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
@st.cache_data()
|
| 120 |
+
def get_bikelane_mag_model(project=project):
|
| 121 |
+
mr = project.get_model_registry()
|
| 122 |
+
bikelane_mag_model = mr.get_model("bikelane_mag_hist_model", version = 2)
|
| 123 |
+
bikelane_mag_model_dir = bikelane_mag_model.download()
|
| 124 |
+
return joblib.load(bikelane_mag_model_dir + "/bikelane_mag_hist_model.pkl")
|
| 125 |
+
|
| 126 |
+
# Retrieving model
|
| 127 |
+
bikelane_mag_hist_model = get_bikelane_mag_model()
|
| 128 |
+
|
| 129 |
+
@st.cache_data()
|
| 130 |
+
def get_bikelane_rad_model(project=project):
|
| 131 |
+
mr = project.get_model_registry()
|
| 132 |
+
bikelane_rad_model = mr.get_model("bikelane_rad_hist_model", version = 2)
|
| 133 |
+
bikelane_rad_model_dir = bikelane_rad_model.download()
|
| 134 |
+
return joblib.load(bikelane_rad_model_dir + "/bikelane_rad_hist_model.pkl")
|
| 135 |
+
|
| 136 |
+
# Retrieving model
|
| 137 |
+
bikelane_rad_hist_model = get_bikelane_rad_model()
|
| 138 |
|
| 139 |
+
# Loading the feature group with latest data for bikelane
|
| 140 |
+
new_bikelane_fg = fs.get_feature_group(name = 'new_bikelane_fg', version = 1)
|
| 141 |
+
|
| 142 |
+
# Function to loading the feature group with latest data for bikelane as a dataset
|
| 143 |
+
@st.cache_data()
|
| 144 |
+
def retrieve_bikelane(feature_group=new_bikelane_fg):
|
| 145 |
+
new_bikelane_fg = feature_group.select_all()
|
| 146 |
+
df_bikelane_new = new_bikelane_fg.read(read_options={"use_hive": True})
|
| 147 |
+
return df_bikelane_new
|
| 148 |
|
| 149 |
+
# Retrieving bikelane data
|
| 150 |
+
bikelane_new = retrieve_bikelane()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
col1, col2 = st.columns(2)
|
|
|
|
| 153 |
|
| 154 |
+
with col1:
|
| 155 |
# Making the predictions and getting the latest data for magnetic field data
|
| 156 |
bikelane_mag_prediction_data = bikelane_new[['time', 'x', 'y', 'z', 'temperature', 'et0_fao_evapotranspiration']]
|
| 157 |
bikelane_mag_prediction_data['et0_fao_evapotranspiration'] = bikelane_mag_prediction_data['et0_fao_evapotranspiration'].apply(fill_nan_with_zero)
|
|
|
|
| 163 |
bikelane_mag_prediction_data = bikelane_mag_prediction_data.set_index(['Time'])
|
| 164 |
st.dataframe(bikelane_mag_prediction_data[['Status']].tail(3))
|
| 165 |
|
| 166 |
+
with col2:
|
| 167 |
# Making the predictions and getting the latest data for radar data
|
| 168 |
bikelane_rad_prediction_data = bikelane_new[['time', 'radar_0', 'radar_1', 'radar_2', 'radar_3', 'radar_4', 'radar_5', 'radar_6', 'radar_7', 'temperature', 'et0_fao_evapotranspiration']]
|
| 169 |
bikelane_rad_prediction_data['et0_fao_evapotranspiration'] = bikelane_rad_prediction_data['et0_fao_evapotranspiration'].apply(fill_nan_with_zero)
|
|
|
|
| 174 |
bikelane_rad_prediction_data = bikelane_rad_prediction_data.rename(columns={'time': 'Time'})
|
| 175 |
bikelane_rad_prediction_data = bikelane_rad_prediction_data.set_index(['Time'])
|
| 176 |
st.dataframe(bikelane_rad_prediction_data[['Status']].tail(3))
|
| 177 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|