Spaces:
Sleeping
Sleeping
| # Loading packages | |
| import datetime | |
| import joblib | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import warnings | |
| import hopsworks | |
| import streamlit as st | |
| import json | |
| import os | |
| import seaborn as sns | |
| import time | |
| import random | |
| # Configuring the web page and setting the page title and icon | |
| st.set_page_config( | |
| page_title='Parking Occupacy Detection System', | |
| page_icon='🅿️', | |
| initial_sidebar_state='expanded') | |
| # Ignoring filtering warnings | |
| warnings.filterwarnings("ignore") | |
| # Setting the title and adding text | |
| st.title('Parking Occupancy Detection System') | |
| # Creating tabs for the different features of the application | |
| tab1,tab2,tab3,tab4, tab5 = st.tabs(['Parking lot status', 'Magnetic Field Explorer', 'About', 'Dataset and visualisations', 'Model performance']) | |
| with tab1: | |
| # Logging in to Hopsworks and loading the feature store | |
| project = hopsworks.login(project = "annikaij", api_key_value=os.environ['HOPSWORKS_API_KEY']) | |
| fs = project.get_feature_store() | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("Parking place near building:") | |
| # Function to load the building models | |
| def get_building_mag_model(project=project): | |
| mr = project.get_model_registry() | |
| building_mag_model = mr.get_model("building_mag_hist_model", version = 2) | |
| building_mag_model_dir = building_mag_model.download() | |
| return joblib.load(building_mag_model_dir + "/building_mag_hist_model.pkl") | |
| # Retrieving model | |
| building_mag_hist_model = get_building_mag_model() | |
| def get_building_rad_model(project=project): | |
| mr = project.get_model_registry() | |
| building_rad_model = mr.get_model("building_rad_hist_model", version = 2) | |
| building_rad_model_dir = building_rad_model.download() | |
| return joblib.load(building_rad_model_dir + "/building_rad_hist_model.pkl") | |
| # Retrieving model | |
| building_rad_hist_model = get_building_rad_model() | |
| # Loading the feature group with latest data for building | |
| new_building_fg = fs.get_feature_group(name = 'new_building_fg', version = 1) | |
| # Function to loading the feature group with latest data for building as a dataset | |
| def retrieve_building(feature_group=new_building_fg): | |
| new_building_fg = feature_group.select_all() | |
| df_building_new = new_building_fg.read(read_options={"use_hive": True}) | |
| return df_building_new | |
| # Retrieving building data | |
| building_new = retrieve_building() | |
| building_mag_prediction_data = building_new[['time', 'x', 'y', 'z', 'temperature', 'et0_fao_evapotranspiration']] | |
| def add_small_value_if_zero(value): | |
| if value == 0.000000: | |
| return value + 0.000001 | |
| else: | |
| return value | |
| building_mag_prediction_data['et0_fao_evapotranspiration'] = building_mag_prediction_data['et0_fao_evapotranspiration'].apply(add_small_value_if_zero) | |
| st.dataframe(building_mag_prediction_data) | |
| # Making the predictions and getting the latest data | |
| #building_mag_most_recent_prediction = building_new[['x', 'y', 'z', 'temperature', 'et0_fao_evapotranspiration']] | |
| #building_mag_most_recent_prediction_mag = building_mag_hist_model.predict(building_mag_most_recent_prediction) | |
| #building_new['Status'] = building_mag_most_recent_prediction | |
| #building_new['Status'].replace(['detection', 'no_detection'], ['Vehicle detected', 'No vehicle detected'], inplace=True) | |
| #building_new = building_new.rename(columns={'time': 'Time'}) | |
| #building_new = building_new.set_index(['Time']) | |
| #st.dataframe(building_new[['Status']].tail(3)) | |
| with col2: | |
| st.subheader("Parking place near bikelane:") | |
| # Update button | |
| if st.button("Update application"): | |
| # Clear cached data | |
| st.cache_data.clear() | |
| # Immediately rerun the application | |
| st.experimental_rerun() | |
| with tab2: | |
| st.subheader('...') | |
| with tab3: | |
| st.subheader('About the application:') | |
| 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.') | |
| st.markdown('The application is made by Annika and Mikkel and is divided into 5 tabs:') | |
| 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.') | |
| 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') | |
| st.markdown('* **About:** In the third tab (the current tab) you can get some information about the interface.') | |
| 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.') | |
| st.markdown('* **Model Performance:** The fifth tab explains how the underlying Machine Learning Model performs and how the predictor works.') | |
| with tab4: | |
| st.subheader('...') | |
| with tab5: | |
| st.subheader('...') | |