Annikaijak commited on
Commit
da7be76
·
verified ·
1 Parent(s): 925bf6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -76
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 Occupacy 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,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("EL123_model", version = 2)
45
  model_dir = model.download()
46
- return joblib.load(model_dir + "/EL123_model.pkl")
47
 
48
  # Retrieving model
49
- model = get_model()
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 loading the new parking detection feature view for el1 as a dataset
57
  @st.cache_data()
58
- def retrieve_el1(feature_view=new_el1_parking_detection_fv):
59
- el1 = feature_view.get_batch_data()
60
- return el1
 
 
61
 
62
- # Retrieving el1 data
63
- el1 = retrieve_el1()
64
-
65
- st.markdown('Parking Space 1:')
66
- el1_most_recent_prediction = el1[['x', 'y', 'z']]
67
- el1_most_recent_prediction = model.predict(el1_most_recent_prediction)
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 new parking detection feature view for el2 as a dataset
78
  @st.cache_data()
79
- def retrieve_el2(feature_view=new_el2_parking_detection_fv):
80
- el2 = feature_view.get_batch_data()
81
- return el2
82
 
83
  # Retrieving el1 data
84
- el2 = retrieve_el2()
85
-
86
- st.markdown('Parking Space 2:')
87
- el2_most_recent_prediction = el2[['x', 'y', 'z']]
88
- el2_most_recent_prediction = model.predict(el2_most_recent_prediction)
89
- el2['prediction'] = el2_most_recent_prediction
90
- el2 = el2.set_index(['time'])
91
- st.dataframe(el2[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
92
-
93
- # Loading the new parking detection feature view for el3
94
- new_el3_parking_detection_fv = fs.get_feature_view(
95
- name = 'new_el3_parking_detection_fv',
96
  version = 1)
97
 
98
- # Function to loading the new parking detection feature view for el3 as a dataset
99
  @st.cache_data()
100
- def retrieve_el3(feature_view=new_el3_parking_detection_fv):
101
- el3 = feature_view.get_batch_data()
102
- return el3
103
 
104
- # Retrieving el1 data
105
- el3 = retrieve_el3()
106
 
107
- st.markdown('Parking Space 3:')
108
- el3_most_recent_prediction = el3[['x', 'y', 'z']]
109
- el3_most_recent_prediction = model.predict(el3_most_recent_prediction)
110
- el3['prediction'] = el3_most_recent_prediction
111
- el3 = el3.set_index(['time'])
112
- st.dataframe(el3[['prediction']].tail(5).style.applymap(color_prediction, subset=['prediction']))
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
- name = 'parking_detection_fv',
131
- version = 1)
132
 
133
  # Function to loading the parking detection feature view as a dataset
134
- @st.cache_data()
135
- def retrieve_batch_data(feature_view=parking_detection_fv):
136
- batch_data = feature_view.get_batch_data()
137
- return batch_data
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")