Spaces:
Runtime error
Runtime error
Refactored pages to make the functions smaller and clearer
Browse files- pages/003_Dissertation.py +18 -8
- pages/010_LLM_Architectures.py +48 -20
pages/003_Dissertation.py
CHANGED
@@ -1,15 +1,17 @@
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import base64
|
3 |
|
4 |
from src.st_helpers import st_setup
|
5 |
|
6 |
-
if st_setup('Dissertation'):
|
7 |
-
st.write("# Dissertation")
|
8 |
-
st.write("The dissertation is delivered as a PDF dcoument. In addition, the submission is supported by a short video giving an overview of the project for orientation.")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
with open("img/dissertation.pdf", "rb") as f:
|
14 |
pdf_bytes = f.read()
|
15 |
st.download_button(label="Download dissertation",
|
@@ -17,8 +19,16 @@ if st_setup('Dissertation'):
|
|
17 |
file_name="dissertation.pdf",
|
18 |
mime='application/octet-stream')
|
19 |
|
20 |
-
|
|
|
21 |
with open("img/dissertation.pdf", "rb") as f:
|
22 |
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
|
23 |
-
pdf_display =
|
24 |
st.markdown(pdf_display, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Page which shows the dissertation download button and the dissertation inline in a frame
|
3 |
+
"""
|
4 |
+
|
5 |
import streamlit as st
|
6 |
import base64
|
7 |
|
8 |
from src.st_helpers import st_setup
|
9 |
|
|
|
|
|
|
|
10 |
|
11 |
+
def show_download_button() -> None:
|
12 |
+
"""
|
13 |
+
Displays a button on the page which will download the dissertation PDF
|
14 |
+
"""
|
15 |
with open("img/dissertation.pdf", "rb") as f:
|
16 |
pdf_bytes = f.read()
|
17 |
st.download_button(label="Download dissertation",
|
|
|
19 |
file_name="dissertation.pdf",
|
20 |
mime='application/octet-stream')
|
21 |
|
22 |
+
|
23 |
+
def show_dissertation_inline() -> None:
|
24 |
with open("img/dissertation.pdf", "rb") as f:
|
25 |
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
|
26 |
+
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="1000" height="1500" type="application/pdf"></iframe>'
|
27 |
st.markdown(pdf_display, unsafe_allow_html=True)
|
28 |
+
|
29 |
+
|
30 |
+
if st_setup('Dissertation'):
|
31 |
+
st.write("# Dissertation")
|
32 |
+
st.write("The dissertation is delivered as a PDF document.")
|
33 |
+
show_download_button()
|
34 |
+
show_dissertation_inline()
|
pages/010_LLM_Architectures.py
CHANGED
@@ -9,6 +9,9 @@ from src.common import img_dir, escape_dollars, generate_group_tag
|
|
9 |
from src.architectures import *
|
10 |
|
11 |
|
|
|
|
|
|
|
12 |
def show_side_by_side() -> None:
|
13 |
"""
|
14 |
Streamlit render a prompt and the boxes to show each architecture
|
@@ -68,18 +71,7 @@ def show_side_by_side() -> None:
|
|
68 |
st.write(f'#### {a}')
|
69 |
|
70 |
|
71 |
-
def
|
72 |
-
"""
|
73 |
-
Streamlit render an architecture details and the
|
74 |
-
ability to interact with the architecture
|
75 |
-
:param architecture: the name of the architecture to output
|
76 |
-
"""
|
77 |
-
arch = Architecture.get_architecture(architecture)
|
78 |
-
|
79 |
-
# Segment into two containers for organisation
|
80 |
-
arch_container = st.container()
|
81 |
-
chat_container = st.container()
|
82 |
-
|
83 |
with arch_container:
|
84 |
st.divider()
|
85 |
st.write(f'### {arch.name}')
|
@@ -97,6 +89,8 @@ def show_architecture(architecture: str) -> None:
|
|
97 |
st.write('#### Architecture pipeline steps')
|
98 |
st.table(pd.DataFrame(table_data, columns=table_cols))
|
99 |
|
|
|
|
|
100 |
with chat_container:
|
101 |
st.write(f"### Chat with {arch.name}")
|
102 |
st.write("Note this is a simple single query through the relevant architecture. This is just a sample so you can interact with it and does not manage a chat session history.")
|
@@ -127,27 +121,61 @@ def show_architecture(architecture: str) -> None:
|
|
127 |
st.markdown(request.as_markdown())
|
128 |
|
129 |
|
130 |
-
if st_setup('LLM Arch'):
|
131 |
-
st.write("# LLM Architectures")
|
132 |
-
Architecture.load_architectures()
|
133 |
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
arch_count = len(Architecture.architectures)
|
136 |
if arch_count == 1:
|
137 |
st.write('### 1 Architecture available')
|
138 |
else:
|
139 |
st.write(f'### {arch_count} Architectures available')
|
140 |
|
|
|
|
|
|
|
|
|
|
|
141 |
if st.button("Force reload of architecture configs"):
|
142 |
Architecture.load_architectures(force_reload=True)
|
143 |
|
|
|
|
|
|
|
|
|
|
|
144 |
arch_names = [a.name for a in Architecture.architectures]
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
if selected_arch is None:
|
149 |
st.info('Select an architecture from above to see details and interact with it')
|
150 |
-
elif selected_arch ==
|
151 |
show_side_by_side()
|
152 |
else:
|
153 |
show_architecture(selected_arch)
|
|
|
9 |
from src.architectures import *
|
10 |
|
11 |
|
12 |
+
COMPARE = "Side by side compare" # Constant value to use for the UI to select a side by side architecture comparison
|
13 |
+
|
14 |
+
|
15 |
def show_side_by_side() -> None:
|
16 |
"""
|
17 |
Streamlit render a prompt and the boxes to show each architecture
|
|
|
71 |
st.write(f'#### {a}')
|
72 |
|
73 |
|
74 |
+
def display_architecture_in_container(arch, arch_container) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
with arch_container:
|
76 |
st.divider()
|
77 |
st.write(f'### {arch.name}')
|
|
|
89 |
st.write('#### Architecture pipeline steps')
|
90 |
st.table(pd.DataFrame(table_data, columns=table_cols))
|
91 |
|
92 |
+
|
93 |
+
def display_architecture_chat_in_container(arch, chat_container) -> None:
|
94 |
with chat_container:
|
95 |
st.write(f"### Chat with {arch.name}")
|
96 |
st.write("Note this is a simple single query through the relevant architecture. This is just a sample so you can interact with it and does not manage a chat session history.")
|
|
|
121 |
st.markdown(request.as_markdown())
|
122 |
|
123 |
|
|
|
|
|
|
|
124 |
|
125 |
+
def show_architecture(architecture: str) -> None:
|
126 |
+
"""
|
127 |
+
Streamlit render an architecture details and the
|
128 |
+
ability to interact with the architecture
|
129 |
+
:param architecture: the name of the architecture to output
|
130 |
+
"""
|
131 |
+
arch = Architecture.get_architecture(architecture)
|
132 |
+
|
133 |
+
# Segment into two containers for organisation
|
134 |
+
arch_container = st.container()
|
135 |
+
chat_container = st.container()
|
136 |
+
|
137 |
+
display_architecture_in_container(arch, arch_container)
|
138 |
+
display_architecture_chat_in_container(arch, chat_container)
|
139 |
+
|
140 |
+
|
141 |
+
def show_sub_header() -> None:
|
142 |
+
"""
|
143 |
+
Write a subheader to the page depending on how many architectures are configured
|
144 |
+
"""
|
145 |
arch_count = len(Architecture.architectures)
|
146 |
if arch_count == 1:
|
147 |
st.write('### 1 Architecture available')
|
148 |
else:
|
149 |
st.write(f'### {arch_count} Architectures available')
|
150 |
|
151 |
+
|
152 |
+
def show_reload_button() -> None:
|
153 |
+
"""
|
154 |
+
Shows a button to reload the architectures and force them to reload if clicked
|
155 |
+
"""
|
156 |
if st.button("Force reload of architecture configs"):
|
157 |
Architecture.load_architectures(force_reload=True)
|
158 |
|
159 |
+
|
160 |
+
def get_user_selected_architecture() -> Optional[str]:
|
161 |
+
"""
|
162 |
+
Display a picker of all the architectures plus the option to do a side by side compare
|
163 |
+
"""
|
164 |
arch_names = [a.name for a in Architecture.architectures]
|
165 |
+
arch_names.append(COMPARE)
|
166 |
+
return st.radio(label="Available architectures", label_visibility="hidden", options=arch_names, index=None)
|
167 |
+
|
168 |
+
|
169 |
+
if st_setup('LLM Arch'):
|
170 |
+
st.write("# LLM Architectures")
|
171 |
+
Architecture.load_architectures()
|
172 |
+
show_sub_header()
|
173 |
+
show_reload_button()
|
174 |
+
|
175 |
+
selected_arch = get_user_selected_architecture()
|
176 |
if selected_arch is None:
|
177 |
st.info('Select an architecture from above to see details and interact with it')
|
178 |
+
elif selected_arch == COMPARE:
|
179 |
show_side_by_side()
|
180 |
else:
|
181 |
show_architecture(selected_arch)
|