Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ def color_prediction(val):
|
|
| 25 |
return f'background-color: {color}'
|
| 26 |
|
| 27 |
# Setting the title and adding text
|
| 28 |
-
st.title('Parking
|
| 29 |
|
| 30 |
# Creating tabs for the different features of the application
|
| 31 |
tab1,tab2,tab3,tab4 = st.tabs(['Parking lot status', 'About', 'Dataset and visualisations', 'Model performance'])
|
|
@@ -37,79 +37,69 @@ with tab1:
|
|
| 37 |
project = hopsworks.login(project = "miknie20", api_key_value=os.environ['HOPSWORKS_API_KEY'])
|
| 38 |
fs = project.get_feature_store()
|
| 39 |
|
| 40 |
-
# Function to load the model
|
| 41 |
@st.cache_data()
|
| 42 |
def get_model(project=project):
|
| 43 |
mr = project.get_model_registry()
|
| 44 |
-
model = mr.get_model("
|
| 45 |
model_dir = model.download()
|
| 46 |
-
return joblib.load(model_dir + "/
|
| 47 |
|
| 48 |
# Retrieving model
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
# Loading the new parking detection feature view for el1
|
| 52 |
-
new_el1_parking_detection_fv = fs.get_feature_view(
|
| 53 |
-
name = 'new_el1_parking_detection_fv',
|
| 54 |
-
version = 1)
|
| 55 |
|
| 56 |
-
# Function to
|
| 57 |
@st.cache_data()
|
| 58 |
-
def
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
# Retrieving
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
el1['prediction'] = el1_most_recent_prediction
|
| 69 |
-
el1 = el1.set_index(['time'])
|
| 70 |
-
st.dataframe(el1[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
|
| 71 |
-
|
| 72 |
-
# Loading the new parking detection feature view for el2
|
| 73 |
-
new_el2_parking_detection_fv = fs.get_feature_view(
|
| 74 |
-
name = 'new_el2_parking_detection_fv',
|
| 75 |
version = 1)
|
| 76 |
|
| 77 |
-
# Function to loading the
|
| 78 |
@st.cache_data()
|
| 79 |
-
def
|
| 80 |
-
|
| 81 |
-
return
|
| 82 |
|
| 83 |
# Retrieving el1 data
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
st.markdown('Parking Space
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
st.dataframe(
|
| 92 |
-
|
| 93 |
-
# Loading the
|
| 94 |
-
|
| 95 |
-
name = '
|
| 96 |
version = 1)
|
| 97 |
|
| 98 |
-
# Function to loading the
|
| 99 |
@st.cache_data()
|
| 100 |
-
def
|
| 101 |
-
|
| 102 |
-
return
|
| 103 |
|
| 104 |
-
# Retrieving
|
| 105 |
-
|
| 106 |
|
| 107 |
-
st.markdown('Parking Space
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
st.dataframe(
|
| 113 |
|
| 114 |
if st.button("Update status"):
|
| 115 |
st.rerun()
|
|
@@ -126,39 +116,39 @@ with tab3:
|
|
| 126 |
st.markdown('...')
|
| 127 |
|
| 128 |
# Loading the parking detection feature view
|
| 129 |
-
parking_detection_fv = fs.get_feature_view(
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
# Function to loading the parking detection feature view as a dataset
|
| 134 |
-
|
| 135 |
-
def retrieve_batch_data(feature_view=parking_detection_fv):
|
| 136 |
-
|
| 137 |
-
|
| 138 |
|
| 139 |
# Retrieving batch data
|
| 140 |
-
batch_data = retrieve_batch_data()
|
| 141 |
|
| 142 |
# Display dataset overview
|
| 143 |
-
st.subheader("Dataset Overview")
|
| 144 |
-
st.dataframe(batch_data.head())
|
| 145 |
|
| 146 |
with tab4:
|
| 147 |
st.markdown('The predictions are made on the basis of a KNearestNeighbours model.')
|
| 148 |
-
st.write(model)
|
| 149 |
|
| 150 |
|
| 151 |
# Making a countplot of the predictions
|
| 152 |
-
predictions = model.predict(batch_data)
|
| 153 |
-
df_test = batch_data.copy()
|
| 154 |
-
df_test['predictions'] = predictions
|
| 155 |
-
st.dataframe(df_test.head())
|
| 156 |
-
|
| 157 |
-
plt.figure(figsize=(10, 6))
|
| 158 |
-
sns.set_style("darkgrid")
|
| 159 |
-
sns.countplot(data=df_test, x="predictions")
|
| 160 |
-
plt.title('Distribution of Predictions')
|
| 161 |
-
st.pyplot(plt)
|
| 162 |
|
| 163 |
# Confusion Matrix
|
| 164 |
st.subheader("Confusion Matrix")
|
|
|
|
| 25 |
return f'background-color: {color}'
|
| 26 |
|
| 27 |
# Setting the title and adding text
|
| 28 |
+
st.title('Parking Occupancy Detection')
|
| 29 |
|
| 30 |
# Creating tabs for the different features of the application
|
| 31 |
tab1,tab2,tab3,tab4 = st.tabs(['Parking lot status', 'About', 'Dataset and visualisations', 'Model performance'])
|
|
|
|
| 37 |
project = hopsworks.login(project = "miknie20", api_key_value=os.environ['HOPSWORKS_API_KEY'])
|
| 38 |
fs = project.get_feature_store()
|
| 39 |
|
| 40 |
+
# Function to load the bikelane model
|
| 41 |
@st.cache_data()
|
| 42 |
def get_model(project=project):
|
| 43 |
mr = project.get_model_registry()
|
| 44 |
+
model = mr.get_model("bikelane_hist_model", version = 1)
|
| 45 |
model_dir = model.download()
|
| 46 |
+
return joblib.load(model_dir + "/bikelane_hist_model.pkl")
|
| 47 |
|
| 48 |
# Retrieving model
|
| 49 |
+
bikelane_hist_model = get_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Function to load the building model
|
| 52 |
@st.cache_data()
|
| 53 |
+
def get_model(project=project):
|
| 54 |
+
mr = project.get_model_registry()
|
| 55 |
+
model = mr.get_model("building_hist_model", version = 2)
|
| 56 |
+
model_dir = model.download()
|
| 57 |
+
return joblib.load(model_dir + "/building_hist_model.pkl")
|
| 58 |
|
| 59 |
+
# Retrieving model
|
| 60 |
+
building_hist_model = get_model()
|
| 61 |
+
|
| 62 |
+
# Loading the feature view with latest data for building
|
| 63 |
+
building_new_fv = fs.get_feature_view(
|
| 64 |
+
name = 'building_new_fv',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
version = 1)
|
| 66 |
|
| 67 |
+
# Function to loading the feature view with latest data for building as a dataset
|
| 68 |
@st.cache_data()
|
| 69 |
+
def retrieve_building(feature_view=building_new_fv):
|
| 70 |
+
building_new_fv = feature_view.get_batch_data()
|
| 71 |
+
return building_new_fv
|
| 72 |
|
| 73 |
# Retrieving el1 data
|
| 74 |
+
building_new = retrieve_building()
|
| 75 |
+
|
| 76 |
+
st.markdown('Parking Space near Building:')
|
| 77 |
+
building_most_recent_prediction = building[['x', 'y', 'z']]
|
| 78 |
+
building_most_recent_prediction = building_hist_model.predict(building_most_recent_prediction)
|
| 79 |
+
building_new['prediction'] = building_most_recent_prediction
|
| 80 |
+
building_new = building_new.set_index(['time'])
|
| 81 |
+
st.dataframe(building_new[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
|
| 82 |
+
|
| 83 |
+
# Loading the feature view with latest data for bikelane
|
| 84 |
+
bikelane_new_fv = fs.get_feature_view(
|
| 85 |
+
name = 'bikelane_new_fv',
|
| 86 |
version = 1)
|
| 87 |
|
| 88 |
+
# Function to loading the feature view with latest data for bikelane as a dataset
|
| 89 |
@st.cache_data()
|
| 90 |
+
def retrieve_bikelane(feature_view=bikelane_new_fv):
|
| 91 |
+
bikelane_new_fv = feature_view.get_batch_data()
|
| 92 |
+
return bikelane_new_fv
|
| 93 |
|
| 94 |
+
# Retrieving bikelane data
|
| 95 |
+
bikelane_new = retrieve_bikelane()
|
| 96 |
|
| 97 |
+
st.markdown('Parking Space near Bikelane:')
|
| 98 |
+
bikelane_most_recent_prediction = bikelane[['x', 'y', 'z']]
|
| 99 |
+
bikelane_most_recent_prediction = bikelane_hist_model.predict(bikelane_most_recent_prediction)
|
| 100 |
+
bikelane_new['prediction'] = bikelane_most_recent_prediction
|
| 101 |
+
bikelane_new = bikelane_new.set_index(['time'])
|
| 102 |
+
st.dataframe(bikelane_new[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
|
| 103 |
|
| 104 |
if st.button("Update status"):
|
| 105 |
st.rerun()
|
|
|
|
| 116 |
st.markdown('...')
|
| 117 |
|
| 118 |
# Loading the parking detection feature view
|
| 119 |
+
#parking_detection_fv = fs.get_feature_view(
|
| 120 |
+
# name = 'parking_detection_fv',
|
| 121 |
+
# version = 1)
|
| 122 |
|
| 123 |
# Function to loading the parking detection feature view as a dataset
|
| 124 |
+
#@st.cache_data()
|
| 125 |
+
#def retrieve_batch_data(feature_view=parking_detection_fv):
|
| 126 |
+
# batch_data = feature_view.get_batch_data()
|
| 127 |
+
# return batch_data
|
| 128 |
|
| 129 |
# Retrieving batch data
|
| 130 |
+
#batch_data = retrieve_batch_data()
|
| 131 |
|
| 132 |
# Display dataset overview
|
| 133 |
+
#st.subheader("Dataset Overview")
|
| 134 |
+
#st.dataframe(batch_data.head())
|
| 135 |
|
| 136 |
with tab4:
|
| 137 |
st.markdown('The predictions are made on the basis of a KNearestNeighbours model.')
|
| 138 |
+
#st.write(model)
|
| 139 |
|
| 140 |
|
| 141 |
# Making a countplot of the predictions
|
| 142 |
+
#predictions = model.predict(batch_data)
|
| 143 |
+
#df_test = batch_data.copy()
|
| 144 |
+
#df_test['predictions'] = predictions
|
| 145 |
+
#st.dataframe(df_test.head())
|
| 146 |
+
|
| 147 |
+
#plt.figure(figsize=(10, 6))
|
| 148 |
+
#sns.set_style("darkgrid")
|
| 149 |
+
#sns.countplot(data=df_test, x="predictions")
|
| 150 |
+
#plt.title('Distribution of Predictions')
|
| 151 |
+
#st.pyplot(plt)
|
| 152 |
|
| 153 |
# Confusion Matrix
|
| 154 |
st.subheader("Confusion Matrix")
|