From 8a6ad9d23269e6355c7a15e19703b74dfa01316e Mon Sep 17 00:00:00 2001 From: Mahesh Rajamani <99678631+maheshrajamani@users.noreply.github.com> Date: Mon, 9 Jun 2025 10:34:46 -0400 Subject: [PATCH] feat: NV-ingest high resolution extraction and infographics content extraction (#8315) * Added support for high resolution and extracting infographics content * [autofix.ci] apply automated fixes * Added validation for high resolution. Made image filter option value as false by default. * [autofix.ci] apply automated fixes * Fixed as per linters suggestion * [autofix.ci] apply automated fixes * Updated the file based on review for improved description * Update src/backend/base/langflow/components/nvidia/nvidia_ingest.py Accepted code change suggestion Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Addressed suggestion from coderabbitai * [autofix.ci] apply automated fixes * Addressed suggestion from Ruff * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Jordan Frazier <122494242+jordanrfrazier@users.noreply.github.com> --- .../components/nvidia/nvidia_ingest.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/components/nvidia/nvidia_ingest.py b/src/backend/base/langflow/components/nvidia/nvidia_ingest.py index a29ac1324..7ee8f2227 100644 --- a/src/backend/base/langflow/components/nvidia/nvidia_ingest.py +++ b/src/backend/base/langflow/components/nvidia/nvidia_ingest.py @@ -1,5 +1,7 @@ from urllib.parse import urlparse +from pypdf import PdfReader + from langflow.base.data import BaseFileComponent from langflow.io import ( BoolInput, @@ -67,6 +69,13 @@ class NvidiaIngestComponent(BaseFileComponent): info="Extract images from document", value=True, ), + BoolInput( + name="extract_infographics", + display_name="Extract Infographics", + info="Extract infographics from document", + value=False, + advanced=True, + ), DropdownInput( name="text_depth", display_name="Text Depth", @@ -104,7 +113,7 @@ class NvidiaIngestComponent(BaseFileComponent): display_name="Filter Images", info="Filter images (see advanced options for filtering criteria).", advanced=True, - value=True, + value=False, ), IntInput( name="min_image_size", @@ -141,6 +150,13 @@ class NvidiaIngestComponent(BaseFileComponent): advanced=True, value=True, ), + BoolInput( + name="high_resolution", + display_name="High Resolution (PDF only)", + info=("Process pdf in high-resolution mode for better quality extraction from scanned pdf."), + advanced=True, + value=False, + ), ] outputs = [ @@ -162,6 +178,17 @@ class NvidiaIngestComponent(BaseFileComponent): self.log(err_msg) raise ValueError(err_msg) + # Check if all files are PDFs when high resolution mode is enabled + if self.high_resolution: + for file in file_list: + try: + with file.path.open("rb") as f: + PdfReader(f) + except Exception as exc: + error_msg = "High-resolution mode only supports valid PDF files." + self.log(error_msg) + raise ValueError(error_msg) from exc + file_paths = [str(file.path) for file in file_list] self.base_url: str | None = self.base_url.strip() if self.base_url else None @@ -196,7 +223,9 @@ class NvidiaIngestComponent(BaseFileComponent): extract_tables=self.extract_tables, extract_charts=self.extract_charts, extract_images=self.extract_images, + extract_infographics=self.extract_infographics, text_depth=self.text_depth, + **({"extract_method": "nemoretriever_parse"} if self.high_resolution else {}), ) )