diff --git a/src/gui/pages/2_Text_Cleaner.py b/src/gui/pages/2_Text_Cleaner.py index c4315a0..4d7e667 100644 --- a/src/gui/pages/2_Text_Cleaner.py +++ b/src/gui/pages/2_Text_Cleaner.py @@ -101,18 +101,22 @@ except Exception as e: ) st.stop() -st.subheader(f"Preview: {uploaded.name}") -st.caption(f"{len(df)} rows, {len(df.columns)} columns") -preview_show_hidden = st.toggle( - "Show hidden characters in preview", - value=True, - help="Highlights NBSP, zero-width chars, smart quotes, and leading/trailing whitespace.", - key="textclean_preview_show_hidden", -) -if preview_show_hidden: - render_hidden_aware_preview(df, n_rows=10) -else: - st.dataframe(df.head(10), use_container_width=True) +# Collapse the input preview once the user has clicked Clean Text so +# the Results section below is the primary visual focus. The user can +# re-expand the expander to re-inspect the source rows. +_has_result = st.session_state.get("textclean_result") is not None +with st.expander(f"Preview: {uploaded.name}", expanded=not _has_result): + st.caption(f"{len(df)} rows, {len(df.columns)} columns") + preview_show_hidden = st.toggle( + "Show hidden characters in preview", + value=True, + help="Highlights NBSP, zero-width chars, smart quotes, and leading/trailing whitespace.", + key="textclean_preview_show_hidden", + ) + if preview_show_hidden: + render_hidden_aware_preview(df, n_rows=10) + else: + st.dataframe(df.head(10), use_container_width=True) st.divider() @@ -211,6 +215,11 @@ if st.button("Clean Text", type="primary", use_container_width=True): st.stop() st.session_state["textclean_result"] = result st.session_state["textclean_input_name"] = uploaded.name + # Force a second rerun so the preview-section expander above sees + # the new result on its NEXT script pass and collapses itself. + # Without this the preview stays expanded until the user touches + # any other widget. + st.rerun() result = st.session_state.get("textclean_result") if result is None: @@ -252,15 +261,19 @@ if result.cells_changed: if show_hidden: # Inject the badge CSS once, then render an HTML table so the # invisibles in old/new are actually visible to the user. + # ``mark_outer_whitespace=True`` matches the input preview's + # rendering so leading/trailing spaces show up as badges in the + # Before/After columns — without it, the examples table missed + # exactly the whitespace the cleaner is removing. st.markdown(hidden_char_css(), unsafe_allow_html=True) rows_html = [] for _, row in examples.iterrows(): rows_html.append( "
{visualize_hidden_html(str(row['column']))}{visualize_hidden_html(str(row['column']), mark_outer_whitespace=True)}{row['ops_applied']}