Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -9
src/streamlit_app.py
CHANGED
|
@@ -304,6 +304,21 @@ def find_actual_file(file_name):
|
|
| 304 |
if not file_name:
|
| 305 |
return None
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
# Try exact match
|
| 308 |
if file_name in st.session_state.images:
|
| 309 |
return file_name
|
|
@@ -319,15 +334,6 @@ def find_actual_file(file_name):
|
|
| 319 |
if uploaded_base == file_name:
|
| 320 |
return uploaded_name
|
| 321 |
|
| 322 |
-
# Try matching any filename in file_names list
|
| 323 |
-
if file_name.endswith('.png'):
|
| 324 |
-
base_name = os.path.splitext(file_name)[0]
|
| 325 |
-
# Check if this is a page from a multi-page PDF
|
| 326 |
-
if '_page' in base_name:
|
| 327 |
-
pdf_base = base_name.split('_page')[0]
|
| 328 |
-
if pdf_base + '.pdf' in st.session_state.images:
|
| 329 |
-
return pdf_base + '.pdf'
|
| 330 |
-
|
| 331 |
return None
|
| 332 |
|
| 333 |
# Initialize session state
|
|
|
|
| 304 |
if not file_name:
|
| 305 |
return None
|
| 306 |
|
| 307 |
+
# FIRST: Check if this is a generated filename from a multi-page PDF (e.g., "12_page1.png")
|
| 308 |
+
if file_name.endswith('.png') and '_page' in file_name:
|
| 309 |
+
base_name = os.path.splitext(file_name)[0] # Remove .png
|
| 310 |
+
# Extract the base name before _pageN
|
| 311 |
+
if '_page' in base_name:
|
| 312 |
+
pdf_base = base_name.split('_page')[0]
|
| 313 |
+
# Try to find the PDF file
|
| 314 |
+
if pdf_base + '.pdf' in st.session_state.images:
|
| 315 |
+
return pdf_base + '.pdf'
|
| 316 |
+
# Also try without any extension in case original didn't have it
|
| 317 |
+
for uploaded_name in st.session_state.images.keys():
|
| 318 |
+
uploaded_base = os.path.splitext(uploaded_name)[0]
|
| 319 |
+
if uploaded_base == pdf_base and uploaded_name.lower().endswith('.pdf'):
|
| 320 |
+
return uploaded_name
|
| 321 |
+
|
| 322 |
# Try exact match
|
| 323 |
if file_name in st.session_state.images:
|
| 324 |
return file_name
|
|
|
|
| 334 |
if uploaded_base == file_name:
|
| 335 |
return uploaded_name
|
| 336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
return None
|
| 338 |
|
| 339 |
# Initialize session state
|