Mark7549 commited on
Commit
aa5c198
·
1 Parent(s): b720441

used caching to improve speed when switching tabs

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -12,24 +12,39 @@ from streamlit_tags import st_tags, st_tags_sidebar
12
 
13
  st.set_page_config(page_title="Ancient Greek Word2Vec", layout="centered")
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # Horizontal menu
16
  active_tab = option_menu(None, ["Nearest neighbours", "Cosine similarity", "3D graph", 'Dictionary'],
17
  menu_icon="cast", default_index=0, orientation="horizontal")
18
 
19
- # Prepare dictionary
20
- lemma_dict = json.load(open('lsj_dict.json', 'r'))
21
 
22
  # Nearest neighbours tab
23
  if active_tab == "Nearest neighbours":
24
 
25
  # Load the compressed word list
26
- compressed_word_list_filename = 'corpora/compass_filtered.pkl.gz'
27
- all_words = load_compressed_word_list(compressed_word_list_filename)
28
  eligible_models = ["Archaic", "Classical", "Hellenistic", "Early Roman", "Late Roman"]
29
 
30
  with st.form("nn_form"):
31
  st.markdown("## Nearest Neighbours")
32
- target_word = st.multiselect("Enter a word", all_words, max_selections=1)
33
  if len(target_word) > 0:
34
  target_word = target_word[0]
35
 
@@ -113,12 +128,11 @@ elif active_tab == "3D graph":
113
  col1, col2 = st.columns(2)
114
 
115
  # Load compressed word list
116
- compressed_word_list_filename = 'corpora/compass_filtered.pkl.gz'
117
- all_words = load_compressed_word_list(compressed_word_list_filename)
118
 
119
  with st.container():
120
  with col1:
121
- word = st.multiselect("Enter a word", all_words, max_selections=1)
122
  if len(word) > 0:
123
  word = word[0]
124
 
 
12
 
13
  st.set_page_config(page_title="Ancient Greek Word2Vec", layout="centered")
14
 
15
+ # Cache data
16
+ @st.cache_data
17
+ def load_lsj_dict():
18
+ return json.load(open('lsj_dict.json', 'r'))
19
+
20
+ @st.cache_data
21
+ def load_all_models_words():
22
+ return load_compressed_word_list('all_lemmas.pkl.gz')
23
+
24
+
25
+ # Load compressed word list
26
+ all_models_words = load_all_models_words()
27
+
28
+
29
+ # Prepare lsj dictionary
30
+ lemma_dict = load_lsj_dict()
31
+
32
+
33
  # Horizontal menu
34
  active_tab = option_menu(None, ["Nearest neighbours", "Cosine similarity", "3D graph", 'Dictionary'],
35
  menu_icon="cast", default_index=0, orientation="horizontal")
36
 
 
 
37
 
38
  # Nearest neighbours tab
39
  if active_tab == "Nearest neighbours":
40
 
41
  # Load the compressed word list
42
+
 
43
  eligible_models = ["Archaic", "Classical", "Hellenistic", "Early Roman", "Late Roman"]
44
 
45
  with st.form("nn_form"):
46
  st.markdown("## Nearest Neighbours")
47
+ target_word = st.multiselect("Enter a word", all_models_words, max_selections=1)
48
  if len(target_word) > 0:
49
  target_word = target_word[0]
50
 
 
128
  col1, col2 = st.columns(2)
129
 
130
  # Load compressed word list
131
+ all_models_words = load_all_models_words()
 
132
 
133
  with st.container():
134
  with col1:
135
+ word = st.multiselect("Enter a word", all_models_words, max_selections=1)
136
  if len(word) > 0:
137
  word = word[0]
138