File size: 4,456 Bytes
1eb130f
e94bd1c
1eb130f
a93f397
4117bed
 
 
 
 
 
 
 
 
 
 
 
 
a93f397
4117bed
a93f397
4117bed
 
 
 
 
 
 
a93f397
4117bed
a93f397
4117bed
 
 
 
 
 
 
 
 
 
 
 
 
 
a93f397
 
 
 
4117bed
 
 
 
 
 
a93f397
4117bed
 
 
 
a93f397
4117bed
 
a93f397
 
 
 
 
1eb130f
4117bed
 
 
 
 
1eb130f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import streamlit as st
from my_model.tabs.run_inference import run_inference

class UIManager:
    def __init__(self):
        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):
        self.tabs[tab_name] = display_function

    def display_sidebar(self):
        st.sidebar.title("Navigation")
        selection = st.sidebar.radio("Go to", list(self.tabs.keys()))
        st.sidebar.write("More Pages will follow .. ")
        return selection

    def display_selected_page(self, selection):
        if selection in self.tabs:
            self.tabs[selection]()

    def display_home(self):
        st.title("MultiModal Learning for Knowledge-Based Visual Question Answering")
        st.write("""This application is an interactive element of the project and prepared by Mohammed Alhaj as part of the dissertation for Masters degree in Artificial Intelligence at the University of Bath. 
                    Further details will be updated later""")

    def display_dataset_analysis(self):
        st.title("OK-VQA Dataset Analysis")
        st.write("This is a Place Holder until the contents are uploaded.")

    def display_finetuning_evaluation(self):
        st.title("Finetuning and Evaluation Results")
        st.write("This is a Place Holder until the contents are uploaded.")

    def display_run_inference(self):
        
        run_inference()

    def display_dissertation_report(self):
        st.title("Dissertation Report")
        st.write("Click the link below to view the PDF.")
        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):
        st.title("Code")
        st.markdown("You can view the code for this project on the Hugging Face Space file page.")
        st.markdown("[View Code](https://huggingface.co/spaces/m7mdal7aj/Mohammed_Alhaj_PlayGround/tree/main)", unsafe_allow_html=True)

    def display_placeholder(self):
        st.title("Stay Tuned")
        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.")