St.textarea clear the content on click of the button

I have a code where onclick of submit button, the text in the text area should remain and onclick of clear button, the text in the text area shoul disappear.

I tried using SessionState as well, but sometimes on click of submit button the text in the text area disappears.

state = SessionState.get(key=0)
ta_placeholder = st.empty()

if st.button(‘Clear’):
# text in the text area should be empty
state.key += 1

x = ta_placeholder.text_area(’’,value=’’,height=120,key=state.key)
if st.button(‘Predict’):
#text in the text area should have that text
st.success(“print something”)

Python version :Python 3.7.0
Streamlit version: Streamlit, version 0.71.0
Please help me with this code as soon as possible. Thanks in advance!

1 Like