vlmparse 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vlmparse/build_doc.py +20 -19
- vlmparse/cli.py +439 -270
- vlmparse/clients/chandra.py +176 -60
- vlmparse/clients/deepseekocr.py +193 -12
- vlmparse/clients/docling.py +0 -1
- vlmparse/clients/dotsocr.py +34 -31
- vlmparse/clients/glmocr.py +243 -0
- vlmparse/clients/granite_docling.py +9 -36
- vlmparse/clients/hunyuanocr.py +5 -1
- vlmparse/clients/lightonocr.py +23 -1
- vlmparse/clients/mineru.py +0 -1
- vlmparse/clients/mistral_converter.py +85 -0
- vlmparse/clients/nanonetocr.py +5 -1
- vlmparse/clients/olmocr.py +6 -2
- vlmparse/clients/openai_converter.py +95 -60
- vlmparse/clients/paddleocrvl.py +195 -40
- vlmparse/converter.py +51 -11
- vlmparse/converter_with_server.py +92 -19
- vlmparse/registries.py +107 -89
- vlmparse/servers/base_server.py +127 -0
- vlmparse/servers/docker_compose_deployment.py +489 -0
- vlmparse/servers/docker_compose_server.py +39 -0
- vlmparse/servers/docker_run_deployment.py +226 -0
- vlmparse/servers/docker_server.py +17 -109
- vlmparse/servers/model_identity.py +48 -0
- vlmparse/servers/server_registry.py +42 -0
- vlmparse/servers/utils.py +83 -219
- vlmparse/st_viewer/st_viewer.py +1 -1
- vlmparse/utils.py +15 -2
- {vlmparse-0.1.7.dist-info → vlmparse-0.1.9.dist-info}/METADATA +13 -3
- vlmparse-0.1.9.dist-info/RECORD +44 -0
- {vlmparse-0.1.7.dist-info → vlmparse-0.1.9.dist-info}/WHEEL +1 -1
- vlmparse-0.1.7.dist-info/RECORD +0 -36
- {vlmparse-0.1.7.dist-info → vlmparse-0.1.9.dist-info}/entry_points.txt +0 -0
- {vlmparse-0.1.7.dist-info → vlmparse-0.1.9.dist-info}/licenses/LICENSE +0 -0
- {vlmparse-0.1.7.dist-info → vlmparse-0.1.9.dist-info}/top_level.txt +0 -0
vlmparse/build_doc.py
CHANGED
|
@@ -10,12 +10,10 @@ from .constants import PDF_EXTENSION
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def convert_pdfium(file_path, dpi):
|
|
13
|
-
pdf = pdfium.PdfDocument(file_path)
|
|
14
13
|
pil_images = []
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
pdf.close()
|
|
14
|
+
with pdfium.PdfDocument(file_path) as pdf:
|
|
15
|
+
for page in pdf:
|
|
16
|
+
pil_images.append(page.render(scale=dpi / 72).to_pil())
|
|
19
17
|
return pil_images
|
|
20
18
|
|
|
21
19
|
|
|
@@ -32,24 +30,29 @@ def convert_pdfium_to_images(file_path, dpi=175):
|
|
|
32
30
|
]
|
|
33
31
|
|
|
34
32
|
except PIL.Image.DecompressionBombError as e:
|
|
35
|
-
logger.exception(
|
|
33
|
+
logger.opt(exception=True).warning(
|
|
34
|
+
"Decompression bomb detected for {file_path}, reducing DPI",
|
|
35
|
+
file_path=str(file_path),
|
|
36
|
+
)
|
|
36
37
|
cur_size, limit_size = map(int, re.findall(r"\d+", str(e)))
|
|
37
38
|
factor = custom_ceil(cur_size / limit_size, precision=1)
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
new_dpi = dpi // factor
|
|
40
|
+
logger.info(
|
|
41
|
+
"Retrying {file_path} with reduced DPI: {old_dpi} -> {new_dpi}",
|
|
42
|
+
file_path=str(file_path),
|
|
43
|
+
old_dpi=dpi,
|
|
44
|
+
new_dpi=new_dpi,
|
|
40
45
|
)
|
|
41
|
-
|
|
42
|
-
images = convert_pdfium(file_path, dpi=dpi)
|
|
46
|
+
images = convert_pdfium(file_path, dpi=new_dpi)
|
|
43
47
|
|
|
44
48
|
return images
|
|
45
49
|
|
|
46
50
|
|
|
47
51
|
def convert_specific_page_to_image(file_path, page_number, dpi=175):
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
pdf.close()
|
|
52
|
+
with pdfium.PdfDocument(file_path) as pdf:
|
|
53
|
+
page = pdf.get_page(page_number)
|
|
54
|
+
image = page.render(scale=dpi / 72).to_pil()
|
|
55
|
+
image = image.convert("L").convert("RGB") if image.mode != "RGB" else image
|
|
53
56
|
return image
|
|
54
57
|
|
|
55
58
|
|
|
@@ -68,9 +71,7 @@ def resize_image(image, max_image_size):
|
|
|
68
71
|
|
|
69
72
|
def get_page_count(file_path):
|
|
70
73
|
if Path(file_path).suffix.lower() == PDF_EXTENSION:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
pdf.close()
|
|
74
|
-
return count
|
|
74
|
+
with pdfium.PdfDocument(file_path) as pdf:
|
|
75
|
+
return len(pdf)
|
|
75
76
|
else:
|
|
76
77
|
return 1
|