I am trying to save my input term and its column as label , but it is not saving


if "labels" not in st.session_state:
    st.session_state['labels'] = []

def cluster_page():
    st.title("Cluster Data")

    if 'uploaded_data' not in st.session_state or st.session_state['uploaded_data'] is None:
        st.warning("Please upload a file first.")
        return

    data = st.session_state['uploaded_data']

    st.write("Current Data:")
    st.write(data.head())

    search_column = st.selectbox("Select column to search", options=data.columns)

    search_term = st.text_input("Enter search term")
    if st.button("Search"):
        search_results = data[data[search_column].astype(str).str.contains(search_term, case=False, na=False)]
        
        if not search_results.empty:
            st.write(f"Search results for '{search_term}' in column '{search_column}':")
            st.write(search_results)

            # Print the search term and column
            st.write(f"Search term: {search_term}")
            st.write(f"Search column: {search_column}")

            # Save Label form
            with st.form("save_label_form"):
                label_name = st.text_input("Enter label name", value=f"{search_term} ({search_column})", key="label_name")
                submit_button = st.form_submit_button("Save Label")

                if submit_button:
                    st.session_state['labels'].append(label_name)
                    st.success(f"Label '{label_name}' saved successfully!")
                    st.write(f"Labels: {st.session_state['labels']}")

    st.write("---")
    st.subheader("Saved Labels")
    if st.session_state['labels']:
        for label in st.session_state['labels']:
            st.write(f"- {label}")
    else:
        st.info("No labels saved yet.")

    if st.button("Clear All Labels"):
        st.session_state['labels'] = []
        st.rerun()

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.