paddleocr-skills 1.0.0 → 1.1.0
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.
- package/README.md +220 -220
- package/bin/paddleocr-skills.js +33 -20
- package/lib/copy.js +39 -39
- package/lib/installer.js +76 -70
- package/lib/prompts.js +67 -67
- package/lib/python.js +75 -75
- package/lib/verify.js +121 -121
- package/package.json +42 -42
- package/templates/.env.example +12 -12
- package/templates/{paddleocr-vl/references/paddleocr-vl → paddleocr-vl-1.5/references/paddleocr-vl-1.5}/layout_schema.md +64 -64
- package/templates/{paddleocr-vl/references/paddleocr-vl → paddleocr-vl-1.5/references/paddleocr-vl-1.5}/output_format.md +154 -154
- package/templates/{paddleocr-vl/references/paddleocr-vl → paddleocr-vl-1.5/references/paddleocr-vl-1.5}/vl_model_spec.md +157 -157
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/_lib.py +780 -780
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/configure.py +270 -270
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/optimize_file.py +226 -226
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/requirements-optimize.txt +8 -8
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/requirements.txt +7 -7
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/smoke_test.py +199 -199
- package/templates/{paddleocr-vl/scripts/paddleocr-vl → paddleocr-vl-1.5/scripts/paddleocr-vl-1.5}/vl_caller.py +232 -232
- package/templates/{paddleocr-vl/skills/paddleocr-vl → paddleocr-vl-1.5/skills/paddleocr-vl-1.5}/SKILL.md +481 -481
- package/templates/ppocrv5/references/ppocrv5/agent_policy.md +258 -258
- package/templates/ppocrv5/references/ppocrv5/normalized_schema.md +257 -257
- package/templates/ppocrv5/references/ppocrv5/provider_api.md +140 -140
- package/templates/ppocrv5/scripts/ppocrv5/_lib.py +635 -635
- package/templates/ppocrv5/scripts/ppocrv5/configure.py +346 -346
- package/templates/ppocrv5/scripts/ppocrv5/ocr_caller.py +684 -684
- package/templates/ppocrv5/scripts/ppocrv5/requirements.txt +4 -4
- package/templates/ppocrv5/scripts/ppocrv5/smoke_test.py +139 -139
- package/templates/ppocrv5/skills/ppocrv5/SKILL.md +272 -272
|
@@ -1,226 +1,226 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
File Optimizer for PaddleOCR-VL
|
|
5
|
-
|
|
6
|
-
Compresses and optimizes large files to meet size requirements.
|
|
7
|
-
Supports images (PNG, JPG) and PDFs.
|
|
8
|
-
|
|
9
|
-
Usage:
|
|
10
|
-
python scripts/paddleocr-vl/optimize_file.py input.pdf output.pdf --target-size 15
|
|
11
|
-
python scripts/paddleocr-vl/optimize_file.py input.png output.png --quality 85
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
import argparse
|
|
15
|
-
import sys
|
|
16
|
-
from pathlib import Path
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def optimize_image(input_path: Path, output_path: Path, quality: int = 85, max_size_mb: float = 20):
|
|
20
|
-
"""
|
|
21
|
-
Optimize image file by reducing quality and/or resolution
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
input_path: Input image path
|
|
25
|
-
output_path: Output image path
|
|
26
|
-
quality: JPEG quality (1-100, lower = smaller file)
|
|
27
|
-
max_size_mb: Target max size in MB
|
|
28
|
-
"""
|
|
29
|
-
try:
|
|
30
|
-
from PIL import Image
|
|
31
|
-
except ImportError:
|
|
32
|
-
print("ERROR: Pillow not installed")
|
|
33
|
-
print("Install with: pip install Pillow")
|
|
34
|
-
sys.exit(1)
|
|
35
|
-
|
|
36
|
-
print(f"Optimizing image: {input_path}")
|
|
37
|
-
|
|
38
|
-
# Open image
|
|
39
|
-
img = Image.open(input_path)
|
|
40
|
-
original_size = input_path.stat().st_size / 1024 / 1024
|
|
41
|
-
|
|
42
|
-
print(f"Original size: {original_size:.2f}MB")
|
|
43
|
-
print(f"Original dimensions: {img.size[0]}x{img.size[1]}")
|
|
44
|
-
|
|
45
|
-
# Convert RGBA to RGB if needed (for JPEG)
|
|
46
|
-
if img.mode in ('RGBA', 'LA', 'P'):
|
|
47
|
-
# Create white background
|
|
48
|
-
background = Image.new('RGB', img.size, (255, 255, 255))
|
|
49
|
-
if img.mode == 'P':
|
|
50
|
-
img = img.convert('RGBA')
|
|
51
|
-
background.paste(img, mask=img.split()[-1] if img.mode in ('RGBA', 'LA') else None)
|
|
52
|
-
img = background
|
|
53
|
-
|
|
54
|
-
# Determine output format
|
|
55
|
-
output_format = output_path.suffix.lower()
|
|
56
|
-
if output_format in ['.jpg', '.jpeg']:
|
|
57
|
-
save_format = 'JPEG'
|
|
58
|
-
elif output_format == '.png':
|
|
59
|
-
save_format = 'PNG'
|
|
60
|
-
else:
|
|
61
|
-
save_format = 'JPEG'
|
|
62
|
-
output_path = output_path.with_suffix('.jpg')
|
|
63
|
-
|
|
64
|
-
# Try saving with specified quality
|
|
65
|
-
img.save(output_path, format=save_format, quality=quality, optimize=True)
|
|
66
|
-
new_size = output_path.stat().st_size / 1024 / 1024
|
|
67
|
-
|
|
68
|
-
# If still too large, reduce resolution
|
|
69
|
-
scale_factor = 0.9
|
|
70
|
-
while new_size > max_size_mb and scale_factor > 0.3:
|
|
71
|
-
new_width = int(img.size[0] * scale_factor)
|
|
72
|
-
new_height = int(img.size[1] * scale_factor)
|
|
73
|
-
|
|
74
|
-
print(f"Resizing to {new_width}x{new_height} (scale: {scale_factor:.2f})")
|
|
75
|
-
|
|
76
|
-
resized = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
|
77
|
-
resized.save(output_path, format=save_format, quality=quality, optimize=True)
|
|
78
|
-
new_size = output_path.stat().st_size / 1024 / 1024
|
|
79
|
-
|
|
80
|
-
scale_factor -= 0.1
|
|
81
|
-
|
|
82
|
-
print(f"Optimized size: {new_size:.2f}MB")
|
|
83
|
-
print(f"Reduction: {((original_size - new_size) / original_size * 100):.1f}%")
|
|
84
|
-
|
|
85
|
-
if new_size > max_size_mb:
|
|
86
|
-
print(f"\nWARNING: File still larger than {max_size_mb}MB")
|
|
87
|
-
print("Consider:")
|
|
88
|
-
print(" - Lower quality (--quality 70)")
|
|
89
|
-
print(" - Use --file-url instead of local file")
|
|
90
|
-
print(" - Split multi-page documents")
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def optimize_pdf(input_path: Path, output_path: Path, max_size_mb: float = 20):
|
|
94
|
-
"""
|
|
95
|
-
Optimize PDF by compressing images within it
|
|
96
|
-
|
|
97
|
-
Args:
|
|
98
|
-
input_path: Input PDF path
|
|
99
|
-
output_path: Output PDF path
|
|
100
|
-
max_size_mb: Target max size in MB
|
|
101
|
-
"""
|
|
102
|
-
try:
|
|
103
|
-
import fitz # PyMuPDF
|
|
104
|
-
except ImportError:
|
|
105
|
-
print("ERROR: PyMuPDF not installed")
|
|
106
|
-
print("Install with: pip install PyMuPDF")
|
|
107
|
-
sys.exit(1)
|
|
108
|
-
|
|
109
|
-
print(f"Optimizing PDF: {input_path}")
|
|
110
|
-
|
|
111
|
-
original_size = input_path.stat().st_size / 1024 / 1024
|
|
112
|
-
print(f"Original size: {original_size:.2f}MB")
|
|
113
|
-
|
|
114
|
-
# Open PDF
|
|
115
|
-
doc = fitz.open(input_path)
|
|
116
|
-
print(f"Pages: {len(doc)}")
|
|
117
|
-
|
|
118
|
-
# Create output PDF with compression
|
|
119
|
-
writer = fitz.open()
|
|
120
|
-
|
|
121
|
-
for page_num in range(len(doc)):
|
|
122
|
-
page = doc[page_num]
|
|
123
|
-
|
|
124
|
-
# Get page as pixmap with lower DPI if needed
|
|
125
|
-
dpi = 150 # Lower DPI for smaller file
|
|
126
|
-
mat = fitz.Matrix(dpi / 72, dpi / 72)
|
|
127
|
-
pix = page.get_pixmap(matrix=mat)
|
|
128
|
-
|
|
129
|
-
# Create new page
|
|
130
|
-
new_page = writer.new_page(width=page.rect.width, height=page.rect.height)
|
|
131
|
-
|
|
132
|
-
# Insert image with compression
|
|
133
|
-
new_page.insert_image(new_page.rect, pixmap=pix)
|
|
134
|
-
|
|
135
|
-
print(f"Processed page {page_num + 1}/{len(doc)}")
|
|
136
|
-
|
|
137
|
-
# Save with compression
|
|
138
|
-
writer.save(
|
|
139
|
-
output_path,
|
|
140
|
-
garbage=4, # Maximum compression
|
|
141
|
-
deflate=True,
|
|
142
|
-
clean=True
|
|
143
|
-
)
|
|
144
|
-
writer.close()
|
|
145
|
-
doc.close()
|
|
146
|
-
|
|
147
|
-
new_size = output_path.stat().st_size / 1024 / 1024
|
|
148
|
-
print(f"Optimized size: {new_size:.2f}MB")
|
|
149
|
-
print(f"Reduction: {((original_size - new_size) / original_size * 100):.1f}%")
|
|
150
|
-
|
|
151
|
-
if new_size > max_size_mb:
|
|
152
|
-
print(f"\nWARNING: PDF still larger than {max_size_mb}MB")
|
|
153
|
-
print("Consider:")
|
|
154
|
-
print(" - Split into multiple files")
|
|
155
|
-
print(" - Process specific pages only")
|
|
156
|
-
print(" - Use --file-url instead")
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def main():
|
|
160
|
-
parser = argparse.ArgumentParser(
|
|
161
|
-
description='Optimize files for PaddleOCR-VL processing',
|
|
162
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
163
|
-
epilog="""
|
|
164
|
-
Examples:
|
|
165
|
-
# Optimize image with default quality (85)
|
|
166
|
-
python scripts/paddleocr-vl/optimize_file.py input.png output.png
|
|
167
|
-
|
|
168
|
-
# Optimize with specific quality
|
|
169
|
-
python scripts/paddleocr-vl/optimize_file.py input.jpg output.jpg --quality 70
|
|
170
|
-
|
|
171
|
-
# Optimize PDF
|
|
172
|
-
python scripts/paddleocr-vl/optimize_file.py input.pdf output.pdf
|
|
173
|
-
|
|
174
|
-
# Target specific size
|
|
175
|
-
python scripts/paddleocr-vl/optimize_file.py input.pdf output.pdf --target-size 15
|
|
176
|
-
|
|
177
|
-
Supported formats:
|
|
178
|
-
- Images: PNG, JPG, JPEG, BMP, TIFF
|
|
179
|
-
- Documents: PDF
|
|
180
|
-
"""
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
parser.add_argument('input', help='Input file path')
|
|
184
|
-
parser.add_argument('output', help='Output file path')
|
|
185
|
-
parser.add_argument(
|
|
186
|
-
'--quality',
|
|
187
|
-
type=int,
|
|
188
|
-
default=85,
|
|
189
|
-
help='JPEG quality (1-100, default: 85)'
|
|
190
|
-
)
|
|
191
|
-
parser.add_argument(
|
|
192
|
-
'--target-size',
|
|
193
|
-
type=float,
|
|
194
|
-
default=20,
|
|
195
|
-
help='Target maximum size in MB (default: 20)'
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
args = parser.parse_args()
|
|
199
|
-
|
|
200
|
-
input_path = Path(args.input)
|
|
201
|
-
output_path = Path(args.output)
|
|
202
|
-
|
|
203
|
-
# Validate input
|
|
204
|
-
if not input_path.exists():
|
|
205
|
-
print(f"ERROR: Input file not found: {input_path}")
|
|
206
|
-
sys.exit(1)
|
|
207
|
-
|
|
208
|
-
# Determine file type
|
|
209
|
-
ext = input_path.suffix.lower()
|
|
210
|
-
|
|
211
|
-
if ext == '.pdf':
|
|
212
|
-
optimize_pdf(input_path, output_path, args.target_size)
|
|
213
|
-
elif ext in ['.png', '.jpg', '.jpeg', '.bmp', '.tiff', '.tif']:
|
|
214
|
-
optimize_image(input_path, output_path, args.quality, args.target_size)
|
|
215
|
-
else:
|
|
216
|
-
print(f"ERROR: Unsupported file format: {ext}")
|
|
217
|
-
print("Supported: PDF, PNG, JPG, JPEG, BMP, TIFF")
|
|
218
|
-
sys.exit(1)
|
|
219
|
-
|
|
220
|
-
print(f"\nOptimized file saved to: {output_path}")
|
|
221
|
-
print("\nYou can now process with:")
|
|
222
|
-
print(f' python scripts/paddleocr-vl/vl_caller.py --file-path "{output_path}" --pretty')
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if __name__ == '__main__':
|
|
226
|
-
main()
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
File Optimizer for PaddleOCR-VL 1.5
|
|
5
|
+
|
|
6
|
+
Compresses and optimizes large files to meet size requirements.
|
|
7
|
+
Supports images (PNG, JPG) and PDFs.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
python scripts/paddleocr-vl-1.5/optimize_file.py input.pdf output.pdf --target-size 15
|
|
11
|
+
python scripts/paddleocr-vl-1.5/optimize_file.py input.png output.png --quality 85
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def optimize_image(input_path: Path, output_path: Path, quality: int = 85, max_size_mb: float = 20):
|
|
20
|
+
"""
|
|
21
|
+
Optimize image file by reducing quality and/or resolution
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
input_path: Input image path
|
|
25
|
+
output_path: Output image path
|
|
26
|
+
quality: JPEG quality (1-100, lower = smaller file)
|
|
27
|
+
max_size_mb: Target max size in MB
|
|
28
|
+
"""
|
|
29
|
+
try:
|
|
30
|
+
from PIL import Image
|
|
31
|
+
except ImportError:
|
|
32
|
+
print("ERROR: Pillow not installed")
|
|
33
|
+
print("Install with: pip install Pillow")
|
|
34
|
+
sys.exit(1)
|
|
35
|
+
|
|
36
|
+
print(f"Optimizing image: {input_path}")
|
|
37
|
+
|
|
38
|
+
# Open image
|
|
39
|
+
img = Image.open(input_path)
|
|
40
|
+
original_size = input_path.stat().st_size / 1024 / 1024
|
|
41
|
+
|
|
42
|
+
print(f"Original size: {original_size:.2f}MB")
|
|
43
|
+
print(f"Original dimensions: {img.size[0]}x{img.size[1]}")
|
|
44
|
+
|
|
45
|
+
# Convert RGBA to RGB if needed (for JPEG)
|
|
46
|
+
if img.mode in ('RGBA', 'LA', 'P'):
|
|
47
|
+
# Create white background
|
|
48
|
+
background = Image.new('RGB', img.size, (255, 255, 255))
|
|
49
|
+
if img.mode == 'P':
|
|
50
|
+
img = img.convert('RGBA')
|
|
51
|
+
background.paste(img, mask=img.split()[-1] if img.mode in ('RGBA', 'LA') else None)
|
|
52
|
+
img = background
|
|
53
|
+
|
|
54
|
+
# Determine output format
|
|
55
|
+
output_format = output_path.suffix.lower()
|
|
56
|
+
if output_format in ['.jpg', '.jpeg']:
|
|
57
|
+
save_format = 'JPEG'
|
|
58
|
+
elif output_format == '.png':
|
|
59
|
+
save_format = 'PNG'
|
|
60
|
+
else:
|
|
61
|
+
save_format = 'JPEG'
|
|
62
|
+
output_path = output_path.with_suffix('.jpg')
|
|
63
|
+
|
|
64
|
+
# Try saving with specified quality
|
|
65
|
+
img.save(output_path, format=save_format, quality=quality, optimize=True)
|
|
66
|
+
new_size = output_path.stat().st_size / 1024 / 1024
|
|
67
|
+
|
|
68
|
+
# If still too large, reduce resolution
|
|
69
|
+
scale_factor = 0.9
|
|
70
|
+
while new_size > max_size_mb and scale_factor > 0.3:
|
|
71
|
+
new_width = int(img.size[0] * scale_factor)
|
|
72
|
+
new_height = int(img.size[1] * scale_factor)
|
|
73
|
+
|
|
74
|
+
print(f"Resizing to {new_width}x{new_height} (scale: {scale_factor:.2f})")
|
|
75
|
+
|
|
76
|
+
resized = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
|
77
|
+
resized.save(output_path, format=save_format, quality=quality, optimize=True)
|
|
78
|
+
new_size = output_path.stat().st_size / 1024 / 1024
|
|
79
|
+
|
|
80
|
+
scale_factor -= 0.1
|
|
81
|
+
|
|
82
|
+
print(f"Optimized size: {new_size:.2f}MB")
|
|
83
|
+
print(f"Reduction: {((original_size - new_size) / original_size * 100):.1f}%")
|
|
84
|
+
|
|
85
|
+
if new_size > max_size_mb:
|
|
86
|
+
print(f"\nWARNING: File still larger than {max_size_mb}MB")
|
|
87
|
+
print("Consider:")
|
|
88
|
+
print(" - Lower quality (--quality 70)")
|
|
89
|
+
print(" - Use --file-url instead of local file")
|
|
90
|
+
print(" - Split multi-page documents")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def optimize_pdf(input_path: Path, output_path: Path, max_size_mb: float = 20):
|
|
94
|
+
"""
|
|
95
|
+
Optimize PDF by compressing images within it
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
input_path: Input PDF path
|
|
99
|
+
output_path: Output PDF path
|
|
100
|
+
max_size_mb: Target max size in MB
|
|
101
|
+
"""
|
|
102
|
+
try:
|
|
103
|
+
import fitz # PyMuPDF
|
|
104
|
+
except ImportError:
|
|
105
|
+
print("ERROR: PyMuPDF not installed")
|
|
106
|
+
print("Install with: pip install PyMuPDF")
|
|
107
|
+
sys.exit(1)
|
|
108
|
+
|
|
109
|
+
print(f"Optimizing PDF: {input_path}")
|
|
110
|
+
|
|
111
|
+
original_size = input_path.stat().st_size / 1024 / 1024
|
|
112
|
+
print(f"Original size: {original_size:.2f}MB")
|
|
113
|
+
|
|
114
|
+
# Open PDF
|
|
115
|
+
doc = fitz.open(input_path)
|
|
116
|
+
print(f"Pages: {len(doc)}")
|
|
117
|
+
|
|
118
|
+
# Create output PDF with compression
|
|
119
|
+
writer = fitz.open()
|
|
120
|
+
|
|
121
|
+
for page_num in range(len(doc)):
|
|
122
|
+
page = doc[page_num]
|
|
123
|
+
|
|
124
|
+
# Get page as pixmap with lower DPI if needed
|
|
125
|
+
dpi = 150 # Lower DPI for smaller file
|
|
126
|
+
mat = fitz.Matrix(dpi / 72, dpi / 72)
|
|
127
|
+
pix = page.get_pixmap(matrix=mat)
|
|
128
|
+
|
|
129
|
+
# Create new page
|
|
130
|
+
new_page = writer.new_page(width=page.rect.width, height=page.rect.height)
|
|
131
|
+
|
|
132
|
+
# Insert image with compression
|
|
133
|
+
new_page.insert_image(new_page.rect, pixmap=pix)
|
|
134
|
+
|
|
135
|
+
print(f"Processed page {page_num + 1}/{len(doc)}")
|
|
136
|
+
|
|
137
|
+
# Save with compression
|
|
138
|
+
writer.save(
|
|
139
|
+
output_path,
|
|
140
|
+
garbage=4, # Maximum compression
|
|
141
|
+
deflate=True,
|
|
142
|
+
clean=True
|
|
143
|
+
)
|
|
144
|
+
writer.close()
|
|
145
|
+
doc.close()
|
|
146
|
+
|
|
147
|
+
new_size = output_path.stat().st_size / 1024 / 1024
|
|
148
|
+
print(f"Optimized size: {new_size:.2f}MB")
|
|
149
|
+
print(f"Reduction: {((original_size - new_size) / original_size * 100):.1f}%")
|
|
150
|
+
|
|
151
|
+
if new_size > max_size_mb:
|
|
152
|
+
print(f"\nWARNING: PDF still larger than {max_size_mb}MB")
|
|
153
|
+
print("Consider:")
|
|
154
|
+
print(" - Split into multiple files")
|
|
155
|
+
print(" - Process specific pages only")
|
|
156
|
+
print(" - Use --file-url instead")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def main():
|
|
160
|
+
parser = argparse.ArgumentParser(
|
|
161
|
+
description='Optimize files for PaddleOCR-VL 1.5 processing',
|
|
162
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
163
|
+
epilog="""
|
|
164
|
+
Examples:
|
|
165
|
+
# Optimize image with default quality (85)
|
|
166
|
+
python scripts/paddleocr-vl-1.5/optimize_file.py input.png output.png
|
|
167
|
+
|
|
168
|
+
# Optimize with specific quality
|
|
169
|
+
python scripts/paddleocr-vl-1.5/optimize_file.py input.jpg output.jpg --quality 70
|
|
170
|
+
|
|
171
|
+
# Optimize PDF
|
|
172
|
+
python scripts/paddleocr-vl-1.5/optimize_file.py input.pdf output.pdf
|
|
173
|
+
|
|
174
|
+
# Target specific size
|
|
175
|
+
python scripts/paddleocr-vl-1.5/optimize_file.py input.pdf output.pdf --target-size 15
|
|
176
|
+
|
|
177
|
+
Supported formats:
|
|
178
|
+
- Images: PNG, JPG, JPEG, BMP, TIFF
|
|
179
|
+
- Documents: PDF
|
|
180
|
+
"""
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
parser.add_argument('input', help='Input file path')
|
|
184
|
+
parser.add_argument('output', help='Output file path')
|
|
185
|
+
parser.add_argument(
|
|
186
|
+
'--quality',
|
|
187
|
+
type=int,
|
|
188
|
+
default=85,
|
|
189
|
+
help='JPEG quality (1-100, default: 85)'
|
|
190
|
+
)
|
|
191
|
+
parser.add_argument(
|
|
192
|
+
'--target-size',
|
|
193
|
+
type=float,
|
|
194
|
+
default=20,
|
|
195
|
+
help='Target maximum size in MB (default: 20)'
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
args = parser.parse_args()
|
|
199
|
+
|
|
200
|
+
input_path = Path(args.input)
|
|
201
|
+
output_path = Path(args.output)
|
|
202
|
+
|
|
203
|
+
# Validate input
|
|
204
|
+
if not input_path.exists():
|
|
205
|
+
print(f"ERROR: Input file not found: {input_path}")
|
|
206
|
+
sys.exit(1)
|
|
207
|
+
|
|
208
|
+
# Determine file type
|
|
209
|
+
ext = input_path.suffix.lower()
|
|
210
|
+
|
|
211
|
+
if ext == '.pdf':
|
|
212
|
+
optimize_pdf(input_path, output_path, args.target_size)
|
|
213
|
+
elif ext in ['.png', '.jpg', '.jpeg', '.bmp', '.tiff', '.tif']:
|
|
214
|
+
optimize_image(input_path, output_path, args.quality, args.target_size)
|
|
215
|
+
else:
|
|
216
|
+
print(f"ERROR: Unsupported file format: {ext}")
|
|
217
|
+
print("Supported: PDF, PNG, JPG, JPEG, BMP, TIFF")
|
|
218
|
+
sys.exit(1)
|
|
219
|
+
|
|
220
|
+
print(f"\nOptimized file saved to: {output_path}")
|
|
221
|
+
print("\nYou can now process with:")
|
|
222
|
+
print(f' python scripts/paddleocr-vl-1.5/vl_caller.py --file-path "{output_path}" --pretty')
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if __name__ == '__main__':
|
|
226
|
+
main()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# File Optimization Dependencies
|
|
2
|
-
# Install with: pip install -r scripts/paddleocr-vl/requirements-optimize.txt
|
|
3
|
-
|
|
4
|
-
# Image processing
|
|
5
|
-
Pillow>=10.0.0
|
|
6
|
-
|
|
7
|
-
# PDF processing
|
|
8
|
-
PyMuPDF>=1.23.0
|
|
1
|
+
# File Optimization Dependencies
|
|
2
|
+
# Install with: pip install -r scripts/paddleocr-vl-1.5/requirements-optimize.txt
|
|
3
|
+
|
|
4
|
+
# Image processing
|
|
5
|
+
Pillow>=10.0.0
|
|
6
|
+
|
|
7
|
+
# PDF processing
|
|
8
|
+
PyMuPDF>=1.23.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# PaddleOCR-VL Dependencies
|
|
2
|
-
|
|
3
|
-
# HTTP client
|
|
4
|
-
httpx>=0.24.0
|
|
5
|
-
|
|
6
|
-
# Environment variables
|
|
7
|
-
python-dotenv>=1.0.0
|
|
1
|
+
# PaddleOCR-VL 1.5 Dependencies
|
|
2
|
+
|
|
3
|
+
# HTTP client
|
|
4
|
+
httpx>=0.24.0
|
|
5
|
+
|
|
6
|
+
# Environment variables
|
|
7
|
+
python-dotenv>=1.0.0
|