Hey @deepankar27 welcome to the forums
What happens here is when you press the second button "Submit report"
the script is rerun, and the first button hit "Find category"
will go back to None
since you hit the second one. So Streamlit won’t go inside the code block from the first button. You need to maintain the info that you pressed the first button somewhere to force Streamlit to go into the code block.
There’s a way to preserve this information inside a state that is preserved between runs, with the State hack. So if you put the State script near your file, you can then do the following :
import streamlit as st
import st_state_patch
def main():
st.title("Data Categorization")
txt = st.text_area("Paste your data here..")
s = st.State()
if not s:
s.pressed_first_button = False
if st.button("Find Category") or s.pressed_first_button:
s.pressed_first_button = True # preserve the info that you hit a button between runs
try:
if txt != '':
value = st.selectbox("Agree with result", ["Yes, I agree..", "Nah!! I don't"])
if st.button("Submit report"):
if value == "Yes, I agree..":
st.write('Do this ...')
elif value != "Nah!! I don't agree":
st.write('Do that ...')
else:
st.write('No content found')
except:
st.write('Looks like I am having problem connecting my backend')
if __name__ == '__main__':
main()