Bhuvi13 commited on
Commit
212ebee
·
verified ·
1 Parent(s): 8f855cb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- st.warning(f"Could not render PDF {uploaded_file.name}. Ensure 'pdf2image' and poppler are installed.")
543
- continue
544
- else:
545
- try:
546
- image = Image.open(BytesIO(uploaded_bytes)).convert("RGB")
547
- except Exception as e:
548
- st.warning(f"Failed to open {uploaded_file.name}.")
549
- continue
 
 
 
 
 
 
 
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