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>
This commit is contained in:
parent
ed809d77e5
commit
8a6ad9d232
1 changed files with 30 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from pypdf import PdfReader
|
||||||
|
|
||||||
from langflow.base.data import BaseFileComponent
|
from langflow.base.data import BaseFileComponent
|
||||||
from langflow.io import (
|
from langflow.io import (
|
||||||
BoolInput,
|
BoolInput,
|
||||||
|
|
@ -67,6 +69,13 @@ class NvidiaIngestComponent(BaseFileComponent):
|
||||||
info="Extract images from document",
|
info="Extract images from document",
|
||||||
value=True,
|
value=True,
|
||||||
),
|
),
|
||||||
|
BoolInput(
|
||||||
|
name="extract_infographics",
|
||||||
|
display_name="Extract Infographics",
|
||||||
|
info="Extract infographics from document",
|
||||||
|
value=False,
|
||||||
|
advanced=True,
|
||||||
|
),
|
||||||
DropdownInput(
|
DropdownInput(
|
||||||
name="text_depth",
|
name="text_depth",
|
||||||
display_name="Text Depth",
|
display_name="Text Depth",
|
||||||
|
|
@ -104,7 +113,7 @@ class NvidiaIngestComponent(BaseFileComponent):
|
||||||
display_name="Filter Images",
|
display_name="Filter Images",
|
||||||
info="Filter images (see advanced options for filtering criteria).",
|
info="Filter images (see advanced options for filtering criteria).",
|
||||||
advanced=True,
|
advanced=True,
|
||||||
value=True,
|
value=False,
|
||||||
),
|
),
|
||||||
IntInput(
|
IntInput(
|
||||||
name="min_image_size",
|
name="min_image_size",
|
||||||
|
|
@ -141,6 +150,13 @@ class NvidiaIngestComponent(BaseFileComponent):
|
||||||
advanced=True,
|
advanced=True,
|
||||||
value=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 = [
|
outputs = [
|
||||||
|
|
@ -162,6 +178,17 @@ class NvidiaIngestComponent(BaseFileComponent):
|
||||||
self.log(err_msg)
|
self.log(err_msg)
|
||||||
raise ValueError(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]
|
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
|
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_tables=self.extract_tables,
|
||||||
extract_charts=self.extract_charts,
|
extract_charts=self.extract_charts,
|
||||||
extract_images=self.extract_images,
|
extract_images=self.extract_images,
|
||||||
|
extract_infographics=self.extract_infographics,
|
||||||
text_depth=self.text_depth,
|
text_depth=self.text_depth,
|
||||||
|
**({"extract_method": "nemoretriever_parse"} if self.high_resolution else {}),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue