I have a large number of components in my sidebar which is kind of like a config. Every time the user changes one component, the app re-runs. The run time process involves a heavy dict object with word embeddings. Even though I cache the dict, but it still takes time on the hashing process!
Coming to the question - is there some way of enforcing the app to rerun once user has made all selections and not every time?
Using a button to trigger the dict generation could work in your case? If it doesn’t, could you share what you have so far to get a better idea on how we could fix your issue?
Hi @okld: the dict is needed in the backend for processing user query so cannot be part of the user interface.
This is the function to load the dict:
@st.cache(suppress_st_warning = True)
def build_dicts():
st.write(“building dicts”)
embeddings_dict = {}
with open(“glove.6B.300d.txt”, ‘r’, encoding=“utf8”) as f:
for line in f:
values = line.split()
word = values[0]
vector = np.asarray(values[1:], “float32”)
embeddings_dict[word] = vector
print(“dicts over”)
As per my earlier msg, it does get cached but as it is such a large object even checking the hash takes a long time. And this happens every time a sidebar component is selected. Any inputs on how I can avoid this?