Update my_model/utilities/ui_manager.py
Browse files- my_model/utilities/ui_manager.py +114 -26
my_model/utilities/ui_manager.py
CHANGED
@@ -8,11 +8,23 @@ from my_model.state_manager import StateManager
|
|
8 |
from my_model.tabs.dataset_analysis import run_dataset_analyzer
|
9 |
from my_model.tabs.model_arch import run_model_arch
|
10 |
|
11 |
-
class UIManager():
|
12 |
-
"""Manages the user interface for the Streamlit application."""
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
self.tabs = {
|
18 |
"Home": self.display_home,
|
@@ -28,13 +40,31 @@ class UIManager():
|
|
28 |
state_manager.initialize_state()
|
29 |
|
30 |
|
31 |
-
|
32 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
self.tabs[tab_name] = display_function
|
34 |
|
35 |
|
36 |
-
def display_sidebar(self):
|
37 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
st.sidebar.image("Files/logo.jpg")
|
39 |
st.sidebar.title("Navigation")
|
40 |
selection = st.sidebar.radio("Go to", list(self.tabs.keys()), disabled=st.session_state['loading_in_progress'])
|
@@ -51,20 +81,40 @@ class UIManager():
|
|
51 |
return selection
|
52 |
|
53 |
|
54 |
-
def display_selected_page(self, selection):
|
55 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
if selection in self.tabs:
|
58 |
self.tabs[selection]()
|
59 |
|
60 |
|
61 |
-
def display_home(self):
|
62 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
run_home()
|
65 |
|
66 |
-
def display_dataset_analysis(self):
|
67 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
st.title("Dataset Analysis")
|
70 |
st.write("""This page shows an overview of some of the KB-VQA datasets, and various analysis of
|
@@ -73,8 +123,15 @@ class UIManager():
|
|
73 |
run_dataset_analyzer()
|
74 |
|
75 |
|
76 |
-
def display_results(self):
|
77 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
st.title("Evaluation Results & Analyses")
|
80 |
st.write("This page demonstrates the model evaluation results and analyses in an interactive way.")
|
@@ -82,8 +139,15 @@ class UIManager():
|
|
82 |
|
83 |
run_demo()
|
84 |
|
85 |
-
def display_model_arch(self):
|
86 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
st.title("Model Architecture")
|
89 |
st.write("This page shows the detailed Model Architecture.")
|
@@ -92,8 +156,15 @@ class UIManager():
|
|
92 |
run_model_arch()
|
93 |
|
94 |
|
95 |
-
def display_run_inference(self):
|
96 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
st.title("Run Inference")
|
99 |
st.write("""Please note that this is not a general purpose model, it is specifically trained on
|
@@ -104,8 +175,15 @@ class UIManager():
|
|
104 |
inference_runner.run_inference()
|
105 |
|
106 |
|
107 |
-
def display_dissertation_report(self):
|
108 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
st.title("Dissertation Report")
|
111 |
st.write("Click the link below to view the PDF.")
|
@@ -118,16 +196,26 @@ class UIManager():
|
|
118 |
)
|
119 |
|
120 |
|
121 |
-
def display_code(self):
|
122 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
st.title("Code")
|
125 |
st.markdown("You can view the code for this project on HuggingFace Space files page.")
|
126 |
st.markdown("[View Code](https://huggingface.co/spaces/m7mdal7aj/Mohammed_Alhaj_KB-VQA/tree/main)", unsafe_allow_html=True)
|
127 |
|
128 |
|
129 |
-
def display_placeholder(self):
|
130 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
st.title("Stay Tuned")
|
133 |
st.write("This is a Place Holder until the contents are uploaded.")
|
|
|
8 |
from my_model.tabs.dataset_analysis import run_dataset_analyzer
|
9 |
from my_model.tabs.model_arch import run_model_arch
|
10 |
|
|
|
|
|
11 |
|
12 |
+
class UIManager():
|
13 |
+
"""
|
14 |
+
Manages the user interface for the Streamlit application.
|
15 |
+
|
16 |
+
This class handles the creation and navigation of various tabs in the Streamlit app. It provides methods to add new
|
17 |
+
tabs, display the sidebar, and render the content of the selected tab.
|
18 |
+
|
19 |
+
Attributes:
|
20 |
+
tabs (dict): A dictionary mapping tab names to their corresponding display functions.
|
21 |
+
"""
|
22 |
+
|
23 |
+
def __init__(self)-> None:
|
24 |
+
"""
|
25 |
+
Initializes the UIManager with predefined tabs.
|
26 |
+
This method sets up the initial tabs for the application and initializes the state manager.
|
27 |
+
"""
|
28 |
|
29 |
self.tabs = {
|
30 |
"Home": self.display_home,
|
|
|
40 |
state_manager.initialize_state()
|
41 |
|
42 |
|
43 |
+
def add_tab(self, tab_name: str, display_function: callable) -> None:
|
44 |
+
"""
|
45 |
+
Adds a new tab to the UI.
|
46 |
+
|
47 |
+
Args:
|
48 |
+
tab_name (str): The name of the new tab.
|
49 |
+
display_function (callable): The function to be called when the tab is selected.
|
50 |
+
|
51 |
+
Returns:
|
52 |
+
None
|
53 |
+
"""
|
54 |
+
|
55 |
self.tabs[tab_name] = display_function
|
56 |
|
57 |
|
58 |
+
def display_sidebar(self) -> str:
|
59 |
+
"""
|
60 |
+
Displays the sidebar for navigation.
|
61 |
+
|
62 |
+
This method creates a sidebar with navigation options and returns the user's selection.
|
63 |
+
|
64 |
+
Returns:
|
65 |
+
str: The name of the selected tab.
|
66 |
+
"""
|
67 |
+
|
68 |
st.sidebar.image("Files/logo.jpg")
|
69 |
st.sidebar.title("Navigation")
|
70 |
selection = st.sidebar.radio("Go to", list(self.tabs.keys()), disabled=st.session_state['loading_in_progress'])
|
|
|
81 |
return selection
|
82 |
|
83 |
|
84 |
+
def display_selected_page(self, selection: str) -> None:
|
85 |
+
"""
|
86 |
+
Displays the selected page based on the user's choice.
|
87 |
+
|
88 |
+
Args:
|
89 |
+
selection (str): The name of the selected tab.
|
90 |
+
|
91 |
+
Returns:
|
92 |
+
None
|
93 |
+
"""
|
94 |
|
95 |
if selection in self.tabs:
|
96 |
self.tabs[selection]()
|
97 |
|
98 |
|
99 |
+
def display_home(self) -> None:
|
100 |
+
"""
|
101 |
+
Displays the Home page of the application.
|
102 |
+
|
103 |
+
Returns:
|
104 |
+
None
|
105 |
+
"""
|
106 |
|
107 |
run_home()
|
108 |
|
109 |
+
def display_dataset_analysis(self) -> None:
|
110 |
+
"""
|
111 |
+
Displays the Dataset Analysis page.
|
112 |
+
|
113 |
+
This page provides an overview of various KB-VQA datasets and analyses of the OK-VQA dataset.
|
114 |
+
|
115 |
+
Returns:
|
116 |
+
None
|
117 |
+
"""
|
118 |
|
119 |
st.title("Dataset Analysis")
|
120 |
st.write("""This page shows an overview of some of the KB-VQA datasets, and various analysis of
|
|
|
123 |
run_dataset_analyzer()
|
124 |
|
125 |
|
126 |
+
def display_results(self) -> None:
|
127 |
+
"""
|
128 |
+
Displays the Evaluation Results page.
|
129 |
+
|
130 |
+
This page demonstrates the model evaluation results and analyses in an interactive way.
|
131 |
+
|
132 |
+
Returns:
|
133 |
+
None
|
134 |
+
"""
|
135 |
|
136 |
st.title("Evaluation Results & Analyses")
|
137 |
st.write("This page demonstrates the model evaluation results and analyses in an interactive way.")
|
|
|
139 |
|
140 |
run_demo()
|
141 |
|
142 |
+
def display_model_arch(self) -> None:
|
143 |
+
"""
|
144 |
+
Displays the Model Architecture page.
|
145 |
+
|
146 |
+
This page provides detailed information about the model architecture.
|
147 |
+
|
148 |
+
Returns:
|
149 |
+
None
|
150 |
+
"""
|
151 |
|
152 |
st.title("Model Architecture")
|
153 |
st.write("This page shows the detailed Model Architecture.")
|
|
|
156 |
run_model_arch()
|
157 |
|
158 |
|
159 |
+
def display_run_inference(self) -> None:
|
160 |
+
"""
|
161 |
+
Displays the Run Inference page.
|
162 |
+
|
163 |
+
This page allows users to run inference using the fine-tuned model on the OK-VQA dataset.
|
164 |
+
|
165 |
+
Returns:
|
166 |
+
None
|
167 |
+
"""
|
168 |
|
169 |
st.title("Run Inference")
|
170 |
st.write("""Please note that this is not a general purpose model, it is specifically trained on
|
|
|
175 |
inference_runner.run_inference()
|
176 |
|
177 |
|
178 |
+
def display_dissertation_report(self) -> None:
|
179 |
+
"""
|
180 |
+
Displays the Dissertation Report page.
|
181 |
+
|
182 |
+
This page provides a link to download the dissertation report PDF.
|
183 |
+
|
184 |
+
Returns:
|
185 |
+
None
|
186 |
+
"""
|
187 |
|
188 |
st.title("Dissertation Report")
|
189 |
st.write("Click the link below to view the PDF.")
|
|
|
196 |
)
|
197 |
|
198 |
|
199 |
+
def display_code(self) -> None:
|
200 |
+
"""
|
201 |
+
Displays the Code page with a link to the project's code repository.
|
202 |
+
|
203 |
+
Returns:
|
204 |
+
None
|
205 |
+
"""
|
206 |
|
207 |
st.title("Code")
|
208 |
st.markdown("You can view the code for this project on HuggingFace Space files page.")
|
209 |
st.markdown("[View Code](https://huggingface.co/spaces/m7mdal7aj/Mohammed_Alhaj_KB-VQA/tree/main)", unsafe_allow_html=True)
|
210 |
|
211 |
|
212 |
+
def display_placeholder(self) -> None:
|
213 |
+
"""
|
214 |
+
Displays a placeholder for future content.
|
215 |
+
|
216 |
+
Returns:
|
217 |
+
None
|
218 |
+
"""
|
219 |
|
220 |
st.title("Stay Tuned")
|
221 |
st.write("This is a Place Holder until the contents are uploaded.")
|