|
import streamlit as st |
|
|
|
class UIManager: |
|
def __init__(self, state_manager): |
|
self.state_manager = state_manager |
|
|
|
def display_sidebar_navigation(self): |
|
st.sidebar.title("Navigation") |
|
return st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "Evaluation Results", "Run Inference", "Dissertation Report"]) |
|
|
|
def display_home_page(self): |
|
st.title("MultiModal Learning for Knowledge-Based Visual Question Answering") |
|
st.write("Home page content goes here...") |
|
|
|
def display_dissertation_report(self): |
|
st.title("Dissertation Report") |
|
st.write("Click the link below to view the PDF.") |
|
with open("Files/Dissertation Report.pdf", "rb") as file: |
|
st.download_button(label="Download PDF", data=file, file_name="Dissertation_Report.pdf", mime="application/octet-stream") |
|
|
|
def display_evaluation_results(self): |
|
st.title("Evaluation Results") |
|
st.write("This is a Place Holder until the contents are uploaded.") |
|
|
|
def display_dataset_analysis(self): |
|
st.title("OK-VQA Dataset Analysis") |
|
st.write("This is a Place Holder until the contents are uploaded.") |
|
|
|
|
|
|
|
|
|
|
|
class StateManager: |
|
def __init__(self): |
|
self.reset_state() |
|
|
|
def reset_state(self): |
|
"""Resets the state to its initial values.""" |
|
self.current_image = None |
|
self.qa_history = [] |
|
self.analysis_done = False |
|
self.answer_in_progress = False |
|
self.caption = "" |
|
self.detected_objects_str = "" |
|
|
|
def set_current_image(self, image): |
|
"""Sets the current image and resets relevant state variables.""" |
|
try: |
|
self.current_image = image |
|
self.qa_history = [] |
|
self.analysis_done = False |
|
self.answer_in_progress = False |
|
self.caption = "" |
|
self.detected_objects_str = "" |
|
except Exception as e: |
|
print(f"Error setting current image: {e}") |
|
|
|
def add_to_qa_history(self, question, answer): |
|
"""Adds a question-answer pair to the history.""" |
|
if question and answer: |
|
self.qa_history.append((question, answer)) |
|
else: |
|
print("Invalid question or answer. Cannot add to history.") |
|
|
|
def set_analysis_done(self, status=True): |
|
"""Sets the analysis status.""" |
|
self.analysis_done = status |
|
|
|
def set_answer_in_progress(self, status=True): |
|
"""Sets the answer in progress status.""" |
|
self.answer_in_progress = status |
|
|
|
def set_caption(self, caption): |
|
"""Sets the image caption.""" |
|
if caption: |
|
self.caption = caption |
|
else: |
|
print("Invalid caption. Cannot set caption.") |
|
|
|
def set_detected_objects_str(self, detected_objects_str): |
|
"""Sets the detected objects string.""" |
|
if detected_objects_str: |
|
self.detected_objects_str = detected_objects_str |
|
else: |
|
print("Invalid detected objects string. Cannot set detected objects.") |
|
|
|
|