Skip to content

Commit 5907252

Browse files
committed
Speeded up pages loading regarding best practices
1 parent ece77c8 commit 5907252

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
21
import streamlit as st
32

3+
from test2text.pages.upload.annotations import show_annotations
4+
from test2text.pages.upload.requirements import show_requirements
5+
from test2text.services.embeddings.cache_distances import show_distances_histogram
6+
from test2text.pages.report import make_a_report
7+
from test2text.services.visualisation.visualize_vectors import visualize_vectors
8+
49

510
def add_logo():
611
st.markdown(
@@ -30,15 +35,15 @@ def add_logo():
3035
st.set_page_config(page_title="Test2Text App", layout="wide", initial_sidebar_state="auto")
3136
add_logo()
3237

33-
annotations = st.Page("test2text/pages/upload/annotations.py",
38+
annotations = st.Page(show_annotations,
3439
title="Annotations", icon=":material/database_upload:")
35-
requirements = st.Page("test2text/pages/upload/requirements.py",
40+
requirements = st.Page(show_requirements,
3641
title="Requirements", icon=":material/database_upload:")
37-
cache_distances = st.Page("test2text/services/embeddings/cache_distances.py",
42+
cache_distances = st.Page(show_distances_histogram,
3843
title="Cache Distances", icon=":material/cached:")
39-
report = st.Page("test2text/pages/report.py",
44+
report = st.Page(make_a_report,
4045
title="Report", icon=":material/publish:")
41-
visualization = st.Page("test2text/services/visualisation/visualize_vectors.py",
46+
visualization = st.Page(visualize_vectors,
4247
title="Visualize Vectors", icon=":material/dataset:")
4348
pages = {
4449
"Upload": [annotations, requirements],

test2text/pages/upload/annotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55

6-
def show():
6+
def show_annotations():
77
with st.form("Upload *.trace.csv file"):
88
st.header("Upload *.trace.csv file")
99

@@ -33,4 +33,4 @@ def show():
3333

3434

3535
if __name__ == "__main__":
36-
show()
36+
show_annotations()

test2text/pages/upload/requirements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import streamlit as st
22

33

4-
def show():
4+
def show_requirements():
55
st.title("Upload a file with requirements")
66

77
uploaded_files = st.file_uploader("Choose a file with requirements", type="csv", accept_multiple_files=True)
@@ -15,4 +15,4 @@ def show():
1515

1616

1717
if __name__ == "__main__":
18-
show()
18+
show_requirements()

test2text/services/embeddings/cache_distances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from test2text.services.db import DbClient
55

66

7-
def show_distances_histogram(db_path):
7+
def show_distances_histogram(db_path="./private/requirements.db"):
88
st.subheader("Distances between annotations and requirements")
99
db = DbClient(db_path)
1010
db.annos_to_reqs.recreate_table()

test2text/services/visualisation/visualize_vectors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def plot_2_sets_in_one_3d(first_set_of_vec, second_set_of_vec, first_title, seco
116116
st.plotly_chart(fig)
117117

118118

119-
if __name__ == "__main__":
119+
def visualize_vectors(db_path="./private/requirements.db"):
120120
st.header("Visualizing vectors")
121-
db = DbClient("./private/requirements.db")
121+
db = DbClient(db_path)
122122
Req_tab, Anno_tab, Req_Anno_tab = st.tabs(["Requirements", "Annotations", "Requirements vs Annotations"])
123123
with Req_tab:
124124
st.subheader("Requirements vectors")
@@ -154,7 +154,7 @@ def plot_2_sets_in_one_3d(first_set_of_vec, second_set_of_vec, first_title, seco
154154
# Show how these 2 groups of vectors are different
155155
st.subheader("Requirements vs Annotations")
156156
progress_bar = st.progress(40, "Extracted")
157-
plot_2_sets_in_one_2d(reqs_vectors_2d, anno_vectors_2d,"Requerements", "Annotations")
157+
plot_2_sets_in_one_2d(reqs_vectors_2d, anno_vectors_2d, "Requerements", "Annotations")
158158
progress_bar.progress(60, "Plotted in 2D")
159159

160160
plot_2_sets_in_one_3d(reqs_vectors_3d, anno_vectors_3d, "Requerements", "Annotations")
@@ -166,5 +166,7 @@ def plot_2_sets_in_one_3d(first_set_of_vec, second_set_of_vec, first_title, seco
166166
progress_bar.progress(100, "Minifolded and Plotted in 2D")
167167
db.conn.close()
168168

169+
if __name__ == "__main__":
170+
visualize_vectors("./private/requirements.db")
169171

170172

0 commit comments

Comments
 (0)