milwright commited on
Commit
55bd61c
·
1 Parent(s): 622c90f

Add ability to dismiss processed sample documents

Browse files

- Added close button to dismiss processed documents
- Enhanced sample document styling and indicators
- Added proper state management for active documents
- Improved logic for document processing flow
- Added helpful tooltips and styled buttons

Files changed (1) hide show
  1. app.py +67 -5
app.py CHANGED
@@ -1205,8 +1205,18 @@ with main_tab1:
1205
  if 'sample_document' in st.session_state and st.session_state.sample_document is not None:
1206
  # Use the sample document
1207
  uploaded_file = st.session_state.sample_document
1208
- # Add a notice about using sample document
1209
- st.success(f"Using sample document: {uploaded_file.name}")
 
 
 
 
 
 
 
 
 
 
1210
 
1211
  # Set auto-process flag in session state if this is a newly loaded sample
1212
  if st.session_state.sample_just_loaded:
@@ -1269,11 +1279,23 @@ with main_tab1:
1269
  # Container for success message (will be filled after processing)
1270
  # No extra spacing needed as it will be managed programmatically
1271
  metadata_placeholder = st.empty()
 
 
 
 
 
 
 
 
1272
 
1273
  # Check if we need to auto-process a sample document
1274
  if 'auto_process_sample' not in st.session_state:
1275
  st.session_state.auto_process_sample = False
1276
 
 
 
 
 
1277
  # Results section - process if button clicked or auto-process flag is set
1278
  process_now = process_button or st.session_state.auto_process_sample
1279
 
@@ -1281,7 +1303,12 @@ with main_tab1:
1281
  if st.session_state.auto_process_sample:
1282
  st.info("Automatically processing sample document...")
1283
 
1284
- if process_now:
 
 
 
 
 
1285
  # Reset auto-process flag to avoid processing on next rerun
1286
  if st.session_state.auto_process_sample:
1287
  st.session_state.auto_process_sample = False
@@ -2033,8 +2060,43 @@ with main_tab1:
2033
  # Close document content div
2034
  st.markdown('</div>', unsafe_allow_html=True)
2035
 
2036
- # Show a compact success message without extra container space
2037
- metadata_placeholder.success("**Document processed successfully**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2038
 
2039
  # Store the result in the previous results list
2040
  # Add timestamp to result for history tracking
 
1205
  if 'sample_document' in st.session_state and st.session_state.sample_document is not None:
1206
  # Use the sample document
1207
  uploaded_file = st.session_state.sample_document
1208
+ # Add a notice about using sample document with better style
1209
+ st.markdown(
1210
+ f"""
1211
+ <div style="background-color: #D4EDDA; color: #155724; padding: 10px;
1212
+ border-radius: 4px; border-left: 5px solid #155724; margin-bottom: 10px;">
1213
+ <div style="display: flex; justify-content: space-between; align-items: center;">
1214
+ <span style="font-weight: bold;">Sample Document: {uploaded_file.name}</span>
1215
+ </div>
1216
+ </div>
1217
+ """,
1218
+ unsafe_allow_html=True
1219
+ )
1220
 
1221
  # Set auto-process flag in session state if this is a newly loaded sample
1222
  if st.session_state.sample_just_loaded:
 
1279
  # Container for success message (will be filled after processing)
1280
  # No extra spacing needed as it will be managed programmatically
1281
  metadata_placeholder = st.empty()
1282
+
1283
+ # If there's a document already processed and active, show a button to close it
1284
+ if st.session_state.processed_document_active:
1285
+ if st.button("✕ Close Current Document", key="close_document_button_top", help="Clear current document and start over"):
1286
+ # Clear the processed document flag
1287
+ st.session_state.processed_document_active = False
1288
+ # Rerun to reset the page
1289
+ st.rerun()
1290
 
1291
  # Check if we need to auto-process a sample document
1292
  if 'auto_process_sample' not in st.session_state:
1293
  st.session_state.auto_process_sample = False
1294
 
1295
+ # Initialize processed_document_active if needed
1296
+ if 'processed_document_active' not in st.session_state:
1297
+ st.session_state.processed_document_active = False
1298
+
1299
  # Results section - process if button clicked or auto-process flag is set
1300
  process_now = process_button or st.session_state.auto_process_sample
1301
 
 
1303
  if st.session_state.auto_process_sample:
1304
  st.info("Automatically processing sample document...")
1305
 
1306
+ # Process if:
1307
+ # 1. Button is clicked (overrides active document flag)
1308
+ # 2. Auto processing is triggered and no active document is displayed
1309
+ should_process = process_button or (st.session_state.auto_process_sample and not st.session_state.processed_document_active)
1310
+
1311
+ if should_process:
1312
  # Reset auto-process flag to avoid processing on next rerun
1313
  if st.session_state.auto_process_sample:
1314
  st.session_state.auto_process_sample = False
 
2060
  # Close document content div
2061
  st.markdown('</div>', unsafe_allow_html=True)
2062
 
2063
+ # Initialize processed_document_active in session state if needed
2064
+ if 'processed_document_active' not in st.session_state:
2065
+ st.session_state.processed_document_active = True
2066
+ else:
2067
+ # Set to True when new document is processed
2068
+ st.session_state.processed_document_active = True
2069
+
2070
+ # Add CSS for styling close buttons
2071
+ st.markdown("""
2072
+ <style>
2073
+ .close-button {
2074
+ background-color: #e7e7e7;
2075
+ color: #666;
2076
+ border: none;
2077
+ border-radius: 4px;
2078
+ padding: 0.25rem 0.5rem;
2079
+ font-size: 0.8rem;
2080
+ cursor: pointer;
2081
+ transition: all 0.2s ease;
2082
+ }
2083
+ .close-button:hover {
2084
+ background-color: #d7d7d7;
2085
+ color: #333;
2086
+ }
2087
+ </style>
2088
+ """, unsafe_allow_html=True)
2089
+
2090
+ # Display success message with close button for dismissing processed documents
2091
+ success_cols = st.columns([5, 1])
2092
+ with success_cols[0]:
2093
+ metadata_placeholder.success("**Document processed successfully**")
2094
+ with success_cols[1]:
2095
+ if st.button("✕ Close", key="close_document_button", help="Clear current document and start over"):
2096
+ # Clear the session state
2097
+ st.session_state.processed_document_active = False
2098
+ # Rerun to reset the page
2099
+ st.rerun()
2100
 
2101
  # Store the result in the previous results list
2102
  # Add timestamp to result for history tracking