Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import streamlit.components.v1 as components | |
| import pandas as pd | |
| from my_model.tabs.run_inference import InferenceRunner | |
| from my_model.tabs.results import run_demo | |
| from my_model.tabs.home import run_home | |
| from my_model.state_manager import StateManager | |
| from my_model.tabs.dataset_analysis import run_dataset_analyzer | |
| class UIManager(): | |
| """Manages the user interface for the Streamlit application.""" | |
| def __init__(self): | |
| """Initializes the UIManager with predefined tabs.""" | |
| self.tabs = { | |
| "Home": self.display_home, | |
| "Dataset Analysis": self.display_dataset_analysis, | |
| "Results": self.display_results, | |
| "Run Inference": self.display_run_inference, | |
| "Dissertation Report": self.display_dissertation_report, | |
| "Code": self.display_code | |
| } | |
| state_manager = StateManager() | |
| state_manager.initialize_state() | |
| def add_tab(self, tab_name, display_function): | |
| """Adds a new tab to the UI.""" | |
| self.tabs[tab_name] = display_function | |
| def display_sidebar(self): | |
| """Displays the sidebar for navigation.""" | |
| st.sidebar.image("Files/logo.jpg") | |
| st.sidebar.title("Navigation") | |
| selection = st.sidebar.radio("Go to", list(self.tabs.keys()), disabled=st.session_state['loading_in_progress']) | |
| st.sidebar.image("Files/mm.jpeg", use_column_width=True) | |
| st.sidebar.markdown( | |
| """ | |
| <div style="text-align: center;"> | |
| <a href="https://www.linkedin.com/in/m7mdal7aj" style="font-weight: bold; text-decoration: none;">Mohammed H AlHaj</a> | |
| </div> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| return selection | |
| def display_selected_page(self, selection): | |
| """Displays the selected page based on user's choice.""" | |
| if selection in self.tabs: | |
| self.tabs[selection]() | |
| def display_home(self): | |
| """Displays the Home page of the application.""" | |
| run_home() | |
| def display_dataset_analysis(self): | |
| """Displays the Dataset Analysis page.""" | |
| st.title("Dataset Analysis") | |
| st.write("""This page shows an overview of some of the KB-VQA datasets, and various analysis of | |
| the [OK-VQA Dataset](https://okvqa.allenai.org/) that this KB-VQA model was fine-tuned | |
| and evaluated on.""") | |
| run_dataset_analyzer() | |
| def display_results(self): | |
| """Displays Evaluation Results page.""" | |
| st.title("Evaluation Results & Analyses") | |
| st.write("This page demonstrates the model evaluation results and analyses in an interactive way.") | |
| st.write("\n") | |
| run_demo() | |
| def display_run_inference(self): | |
| """Displays the Run Inference page.""" | |
| st.title("Run Inference") | |
| st.write("""Please note that this is not a general purpose model, it is specifically trained on | |
| [OK-VQA Dataset](https://okvqa.allenai.org/) and desgined to give short and direct answers to the | |
| given questions about the given image.\n""") | |
| inference_runner = InferenceRunner() | |
| inference_runner.run_inference() | |
| def display_dissertation_report(self): | |
| """Displays the Dissertation Report page.""" | |
| st.title("Dissertation Report") | |
| st.write("Click the link below to view the PDF.") | |
| # Error handling for file access should be considered here | |
| st.download_button( | |
| label="Download PDF", | |
| data=open("Files/Dissertation Report.pdf", "rb"), | |
| file_name="example.pdf", | |
| mime="application/octet-stream" | |
| ) | |
| def display_code(self): | |
| """Displays the Code page with a link to the project's code repository.""" | |
| st.title("Code") | |
| st.markdown("You can view the code for this project on HuggingFace Space files page.") | |
| st.markdown("[View Code](https://huggingface.co/spaces/m7mdal7aj/Mohammed_Alhaj_KB-VQA/tree/main)", unsafe_allow_html=True) | |
| def display_placeholder(self): | |
| """Displays a placeholder for future content.""" | |
| st.title("Stay Tuned") | |
| st.write("This is a Place Holder until the contents are uploaded.") | |