Spaces:
Running
Running
Fix session state initialization error
Browse files- Centralized session state initialization at the beginning of the app
- Fixed AttributeError with processed_document_active
- Removed redundant initialization code
- Streamlined state management for better reliability
app.py
CHANGED
@@ -1195,11 +1195,14 @@ with main_tab3:
|
|
1195 |
""")
|
1196 |
|
1197 |
with main_tab1:
|
1198 |
-
# Initialize session
|
|
|
1199 |
if 'auto_process_sample' not in st.session_state:
|
1200 |
st.session_state.auto_process_sample = False
|
1201 |
if 'sample_just_loaded' not in st.session_state:
|
1202 |
st.session_state.sample_just_loaded = False
|
|
|
|
|
1203 |
|
1204 |
# Use uploaded_file or sample_document if available
|
1205 |
if 'sample_document' in st.session_state and st.session_state.sample_document is not None:
|
@@ -1288,13 +1291,9 @@ with main_tab1:
|
|
1288 |
# Rerun to reset the page
|
1289 |
st.rerun()
|
1290 |
|
1291 |
-
#
|
1292 |
-
if 'auto_process_sample' not in st.session_state:
|
1293 |
-
st.session_state.auto_process_sample = False
|
1294 |
|
1295 |
-
#
|
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
|
@@ -2060,12 +2059,8 @@ with main_tab1:
|
|
2060 |
# Close document content div
|
2061 |
st.markdown('</div>', unsafe_allow_html=True)
|
2062 |
|
2063 |
-
#
|
2064 |
-
|
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("""
|
|
|
1195 |
""")
|
1196 |
|
1197 |
with main_tab1:
|
1198 |
+
# Initialize all session state variables in one place at the beginning
|
1199 |
+
# This ensures they exist before being accessed anywhere in the code
|
1200 |
if 'auto_process_sample' not in st.session_state:
|
1201 |
st.session_state.auto_process_sample = False
|
1202 |
if 'sample_just_loaded' not in st.session_state:
|
1203 |
st.session_state.sample_just_loaded = False
|
1204 |
+
if 'processed_document_active' not in st.session_state:
|
1205 |
+
st.session_state.processed_document_active = False
|
1206 |
|
1207 |
# Use uploaded_file or sample_document if available
|
1208 |
if 'sample_document' in st.session_state and st.session_state.sample_document is not None:
|
|
|
1291 |
# Rerun to reset the page
|
1292 |
st.rerun()
|
1293 |
|
1294 |
+
# auto_process_sample is already initialized at the top of the function
|
|
|
|
|
1295 |
|
1296 |
+
# processed_document_active is already initialized at the top of the function
|
|
|
|
|
1297 |
|
1298 |
# Results section - process if button clicked or auto-process flag is set
|
1299 |
process_now = process_button or st.session_state.auto_process_sample
|
|
|
2059 |
# Close document content div
|
2060 |
st.markdown('</div>', unsafe_allow_html=True)
|
2061 |
|
2062 |
+
# Set processed_document_active to True when a new document is processed
|
2063 |
+
st.session_state.processed_document_active = True
|
|
|
|
|
|
|
|
|
2064 |
|
2065 |
# Add CSS for styling close buttons
|
2066 |
st.markdown("""
|