Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add poppler_path Argument to zerox Function #127

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions py_zerox/pyzerox/core/zerox.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,15 @@ async def zerox(
"save_directory":temp_directory, "suffix":"_selected_pages"}
local_path = await asyncio.to_thread(create_selected_pages_pdf,
**subset_pdf_create_kwargs)

# explicitly pass poppler path via kwargs
if "poppler_path" in kwargs:
poppler_path = kwargs["poppler_path"]
else:
poppler_path = None

# Convert the file to a series of images, below function returns a list of image paths in page order
images = await convert_pdf_to_images(image_density=image_density, image_height=image_height, local_path=local_path, temp_dir=temp_directory)
images = await convert_pdf_to_images(image_density=image_density, image_height=image_height, local_path=local_path, temp_dir=temp_directory, poppler_path=poppler_path)

if maintain_format:
for image in images:
Expand Down Expand Up @@ -199,4 +205,4 @@ async def zerox(
input_tokens=input_token_count,
output_tokens=output_token_count,
pages=formatted_pages,
)
)
3 changes: 2 additions & 1 deletion py_zerox/pyzerox/processor/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..models import litellmmodel


async def convert_pdf_to_images(image_density: int, image_height: tuple[Optional[int], int], local_path: str, temp_dir: str) -> List[str]:
async def convert_pdf_to_images(image_density: int, image_height: tuple[Optional[int], int], local_path: str, temp_dir: str, poppler_path: str = None) -> List[str]:
"""Converts a PDF file to a series of images in the temp_dir. Returns a list of image paths in page order."""
options = {
"pdf_path": local_path,
Expand All @@ -22,6 +22,7 @@ async def convert_pdf_to_images(image_density: int, image_height: tuple[Optional
"thread_count": PDFConversionDefaultOptions.THREAD_COUNT,
"use_pdftocairo": PDFConversionDefaultOptions.USE_PDFTOCAIRO,
"paths_only": True,
"poppler_path": poppler_path
}

try:
Expand Down