KushwanthK commited on
Commit
088c08e
·
verified ·
1 Parent(s): d827d39

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -489,14 +489,11 @@ def highlight_pdf(file_path, text_to_highlight, page_numbers):
489
  def pdf_to_images(pdf_path, page_numbers):
490
  doc = pymupdf.open(pdf_path)
491
  images = []
492
- for page_number in page_numbers:
493
  page = doc.load_page(page_number - 1)
494
  pix = page.get_pixmap()
495
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
496
- buf = io.BytesIO()
497
- img.save(buf, format="PNG")
498
- byte_im = buf.getvalue()
499
- images.append(byte_im)
500
  return images
501
 
502
  # Function to display PDF in Streamlit
@@ -517,7 +514,10 @@ def display_highlighted_pdf():
517
  images = pdf_to_images(highlighted_pdf_path, sources)
518
 
519
  for img in images:
520
- image_zoom(img)
 
 
 
521
 
522
  display_highlighted_pdf()
523
 
 
489
  def pdf_to_images(pdf_path, page_numbers):
490
  doc = pymupdf.open(pdf_path)
491
  images = []
492
+ for page_number in range(1, len(page_numbers)+1):
493
  page = doc.load_page(page_number - 1)
494
  pix = page.get_pixmap()
495
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
496
+ images.append(img)
 
 
 
497
  return images
498
 
499
  # Function to display PDF in Streamlit
 
514
  images = pdf_to_images(highlighted_pdf_path, sources)
515
 
516
  for img in images:
517
+ if isinstance(img, Image.Image): # Ensure img is a Pillow Image object
518
+ image_zoom(img)
519
+ else:
520
+ st.error("The provided image is not a valid Pillow Image object.")
521
 
522
  display_highlighted_pdf()
523