Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -8
src/streamlit_app.py
CHANGED
|
@@ -539,14 +539,21 @@ if not st.session_state.is_processing_batch and len(st.session_state.batch_resul
|
|
| 539 |
st.warning(f"PDF {uploaded_file.name} has no pages.")
|
| 540 |
continue
|
| 541 |
except Exception as e:
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
|
| 551 |
if image is None:
|
| 552 |
continue
|
|
|
|
| 539 |
st.warning(f"PDF {uploaded_file.name} has no pages.")
|
| 540 |
continue
|
| 541 |
except Exception as e:
|
| 542 |
+
# log the real error (helps debug in Spaces logs)
|
| 543 |
+
st.warning(f"Could not render PDF {uploaded_file.name}. pdf2image/poppler may be missing. Error: {e}")
|
| 544 |
+
|
| 545 |
+
# Fallback: try PyMuPDF (pymupdf) which doesn't require poppler
|
| 546 |
+
try:
|
| 547 |
+
import fitz # pymupdf
|
| 548 |
+
doc = fitz.open(stream=uploaded_bytes, filetype="pdf")
|
| 549 |
+
page = doc.load_page(0)
|
| 550 |
+
pix = page.get_pixmap(dpi=200)
|
| 551 |
+
from PIL import Image
|
| 552 |
+
image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 553 |
+
except Exception as e2:
|
| 554 |
+
st.warning(f"Fallback rendering (PyMuPDF) also failed for {uploaded_file.name}: {e2}")
|
| 555 |
+
continue
|
| 556 |
+
|
| 557 |
|
| 558 |
if image is None:
|
| 559 |
continue
|