"""Credit to https://huggingface.co/spaces/lfqa/lfqa. This file is the framework for generating multiple Streamlit applications through an object oriented framework. """ # Import necessary libraries import streamlit as st from streamlit_option_menu import option_menu # Define the multipage class to manage the multiple apps in our program class Multipage: """Framework for combining multiple streamlit applications.""" def __init__(self) -> None: """Construct class to generate a list which will store all our applications as an instance variable.""" # noqa self.pages = [] def add_page(self, title, icon, func) -> None: """Class Method to Add pages to the project. Args: title ([str]): The title of page which we are adding to the list of apps icon: icon from streamlit-menu-option func: Python function to render this page in Streamlit """ self.pages.append({"title": title, "icon": icon, "function": func}) def run(self): """Dropdown to select the page to run.""" # Dropdown to select the page to run st.markdown( # 285/280/275/273 OK 270/272 NOK for Config """ """, unsafe_allow_html=True, ) selected = None with st.sidebar: selected = option_menu( None, [page["title"] for page in self.pages], icons=[page["icon"] for page in self.pages], menu_icon="cast", default_index=0, ) # Run the selected page for index, item in enumerate(self.pages): if item["title"] == selected: self.pages[index]["function"]() break