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?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.