Bhuvi13 commited on
Commit
e77e890
·
verified ·
1 Parent(s): ceca5e4

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -14
src/streamlit_app.py CHANGED
@@ -539,20 +539,14 @@ 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
- # 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:
 
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
 
552
  if image is None: