multimodalart HF Staff commited on
Commit
08a4d0e
·
verified ·
1 Parent(s): a16f61e

Upload pipeline.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pipeline.py +6 -1
pipeline.py CHANGED
@@ -152,7 +152,12 @@ class PageOCR:
152
  """PDF -> list of page texts."""
153
  pymupdf = importlib.import_module("pymupdf")
154
  doc = pymupdf.open(path)
155
- rng = pages if pages is not None else range(doc.page_count)
 
 
 
 
 
156
  out = []
157
  for i in rng:
158
  pix = doc[i].get_pixmap(dpi=dpi)
 
152
  """PDF -> list of page texts."""
153
  pymupdf = importlib.import_module("pymupdf")
154
  doc = pymupdf.open(path)
155
+ if pages is None:
156
+ rng = range(doc.page_count)
157
+ else:
158
+ # Clamp to the document: asking for 3 pages of a 1-page PDF
159
+ # must not IndexError.
160
+ rng = [p for p in pages if 0 <= p < doc.page_count]
161
  out = []
162
  for i in rng:
163
  pix = doc[i].get_pixmap(dpi=dpi)