I am using the chat_input and chat_message functionality to create a chatbot. I have some suggestions in the sidebar as markdown. I was wondering, how I could make the suggestions clickable, so that they would populate the chat_input on click, and it wouldn’t look weird having each text wrapped as a button or something.
For each of the suggestion, you may assign it to the st.radio widget if you want only 1 to be selected or to st.checkbox in order to allow multiple selections. You could also look into using the component streamlit-pills as well.
Thanks for the suggestions. I’m now using streamlit-pills to give suggestions for the chatbot but I have an issue, once you click on a suggestion it remains selected in the next chat loop and then the chatbot keeps responding the same question. I would need to reset the pills widget then. I usually can do this with other widgets by defining an empty container like
empty_container = st.empty()
empty_container.selectbox()
... do stuff
#Reset selectbox
empty_container.selectbox()
How could I do this with pills or another way to deselect the clicked pill?
st.empty() would allow to reset the output display as for the value of variable using streamlit-pill we may have to try another way. Could you try assigning the values from streamlit-pill widget to a session state variable and use a callback function that resets the variable using the streamlit-pill widget to its default state once it is selected.
I tried something similar with setting the index on a session variable to None but it didn’t work. So I tried setting the list of query options in a session variable and each time the user chooses one option it is eliminated from the list and the pills widget is recreated. That’s the only way I could make it work.
# Get rid of the suggestion now that it was chosen
if predefined_prompt_selected:
index_to_eliminate = st.session_state.suggestions_list.index(predefined_prompt_selected)
st.session_state.suggestions_list.pop(index_to_eliminate)
st.session_state.suggestions_icons.pop(index_to_eliminate)
@Odrec@dataprofessor
I got the overall idea but how can I pass the selected predefined_prompt_selected to st.chat_input() as there is no value parameter to it? Please help me with this as soon as possible.