KB-VQA / my_model /utilities /ui_manager.py
m7mdal7aj's picture
Update my_model/utilities/ui_manager.py
8a5ab3e verified
raw
history blame
4.01 kB
import pandas as pd
import streamlit as st
from my_model.tabs.run_inference import InferenceRunner
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,
"Finetuning and Evaluation Results": self.display_finetuning_evaluation,
"Run Inference": self.display_run_inference,
"Dissertation Report": self.display_dissertation_report,
"Code": self.display_code,
"More Pages will follow .. ": self.display_placeholder
}
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.title("Navigation")
selection = st.sidebar.radio("Go to", list(self.tabs.keys()))
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."""
st.markdown("<h1 style='text-align: center;'>MultiModal Learning for Visual Question Answering using World Knowledge</h1>", unsafe_allow_html=True)
st.write(" ")
st.markdown("<h2 style='text-align: center;'>(Knowledge-Based Visual Question Answering)</h2>", unsafe_allow_html=True)
st.write("""\n\nThis application is an interactive element of the project as part of the dissertation for Masters degree in Artificial Intelligence at the [University of Bath](https://www.bath.ac.uk/).
\n\n\n
Developed by: [Mohammed H AlHaj](https://www.linkedin.com/in/m7mdal7aj)
\n\n
Dissertation Supervisor: [Andreas Theophilou](https://researchportal.bath.ac.uk/en/persons/andreas-theophilou)
Further details will be updated later""")
def display_dataset_analysis(self):
"""Displays the Dataset Analysis page."""
st.title("OK-VQA Dataset Analysis")
st.write("This is a Place Holder until the contents are uploaded.")
def display_finetuning_evaluation(self):
"""Displays the Finetuning and Evaluation Results page."""
st.title("Finetuning and Evaluation Results")
st.write("This is a Place Holder until the contents are uploaded.")
def display_run_inference(self):
"""Displays the Run Inference page."""
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_PlayGround/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.")