Wassup Guys,
I am working on an app for keyword prediction (table).
I have a multi select dropdown, where you can select the loaded words you want to replace, if they are inaccurate. I have a helper method (top_k), that returns me a frame of data containing name and ids.
However, when I want to load the new keys from the new table, when a user replaced a key, it works.
I tried to append the new keys into an existing array, that I use as the value for the dropdown, with success.
But the multi-select is not updating the new values I received and added to the word list (array).
Nevertheless I can see my new my session state keys including the old ones, when I print the values of the array.
What did I miss? (Below is a short screen cast where you can see, that the new loaded keys are not included in my multi select)
#checkbox if triggered
retrain = column_2.checkbox('๐ Retrain model')
#arr for values
wordList = []
#arr for sel val in multi sel
selectedWords = []
#save loaded keys in list
for key in top_k['name']:
wordList.append(key)
#if triggered retrain without sel keys
if retrain:
retrainKeys = column_2.checkbox('๐ Replace chosen keys')
if "options" not in st.session_state:
st.session_state['keys'] = wordList
#set session state for multi select using exisiting arr
if 'sel_key' in st.session_state:
column_2.write(
f'โ๏ธ Chosen Words: {st.session_state["sel_key"]}')
#print key
column_2.multiselect(
"", st.session_state['keys'], key='sel_key')
#appen session vals and keys for watcher
#if retrained
if retrainKeys:
with st.spinner('Reload model...'):
st.subheader('Iteration')
time.sleep(2)
for key in st.session_state["sel_key"]:
selectedWords.append(key)
print('SELECTED: ', selectedWords)
#new top k names
retrained_top_k = retrainModel(selectedWords,
input_text, label_embeddings, st.session_state.model, st.session_state.tokenizer, n_keywords)
for key in retrained_top_k['name']:
#add into wordList and sort
print('KEEEEEY: ', key)
wordList.append(key)
wordList.sort()
wordList = list(dict.fromkeys(wordList))
st.session_state["keys"] = wordList
column_1.dataframe(retrained_top_k, height=500)
st.write(st.session_state['keys'])