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,270 +1,270 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
PaddleOCR-VL Configuration Wizard
|
|
4
|
-
|
|
5
|
-
Supports two modes:
|
|
6
|
-
1. Interactive mode (default): python configure.py
|
|
7
|
-
2. CLI mode: python configure.py --api-url URL --token TOKEN
|
|
8
|
-
|
|
9
|
-
Interactive configuration for PaddleOCR-VL API credentials.
|
|
10
|
-
Saves configuration to .env file in project root.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
import argparse
|
|
14
|
-
import os
|
|
15
|
-
import sys
|
|
16
|
-
from pathlib import Path
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def save_config(api_url: str, token: str, project_root: Path, quiet: bool = False) -> bool:
|
|
20
|
-
"""
|
|
21
|
-
Save configuration to .env file
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
api_url: VL API URL
|
|
25
|
-
token: VL access token
|
|
26
|
-
project_root: Project root directory
|
|
27
|
-
quiet: If True, suppress output messages
|
|
28
|
-
|
|
29
|
-
Returns:
|
|
30
|
-
True if successful, False otherwise
|
|
31
|
-
"""
|
|
32
|
-
env_file = project_root / ".env"
|
|
33
|
-
|
|
34
|
-
# Read existing .env if it exists
|
|
35
|
-
existing_config = {}
|
|
36
|
-
if env_file.exists():
|
|
37
|
-
if not quiet:
|
|
38
|
-
print(f"Found existing .env file: {env_file}")
|
|
39
|
-
overwrite = input("Overwrite? [Y/n]: ").strip().lower()
|
|
40
|
-
if overwrite == 'n':
|
|
41
|
-
print("Configuration cancelled")
|
|
42
|
-
return False
|
|
43
|
-
|
|
44
|
-
with open(env_file, 'r', encoding='utf-8') as f:
|
|
45
|
-
for line in f:
|
|
46
|
-
line = line.strip()
|
|
47
|
-
if line and not line.startswith('#') and '=' in line:
|
|
48
|
-
key, value = line.split('=', 1)
|
|
49
|
-
existing_config[key.strip()] = value.strip()
|
|
50
|
-
|
|
51
|
-
# Update configuration
|
|
52
|
-
existing_config['VL_API_URL'] = api_url
|
|
53
|
-
existing_config['VL_TOKEN'] = token
|
|
54
|
-
|
|
55
|
-
# Write to .env file
|
|
56
|
-
try:
|
|
57
|
-
with open(env_file, 'w', encoding='utf-8') as f:
|
|
58
|
-
# Write header
|
|
59
|
-
f.write("# PaddleOCR Skills Configuration\n")
|
|
60
|
-
f.write("# Generated by configuration wizard\n")
|
|
61
|
-
f.write("\n")
|
|
62
|
-
|
|
63
|
-
# Group PP-OCRv5 configs
|
|
64
|
-
if any(k.startswith('API_URL') or k.startswith('PADDLE_OCR_TOKEN') or k.startswith('PPOCRV5') for k in existing_config.keys()):
|
|
65
|
-
f.write("# ========================================\n")
|
|
66
|
-
f.write("# PP-OCRv5 Configuration\n")
|
|
67
|
-
f.write("# ========================================\n")
|
|
68
|
-
for key in ['API_URL', 'PADDLE_OCR_TOKEN', 'PPOCRV5_API_URL', 'PPOCRV5_TOKEN']:
|
|
69
|
-
if key in existing_config:
|
|
70
|
-
f.write(f"{key}={existing_config[key]}\n")
|
|
71
|
-
f.write("\n")
|
|
72
|
-
|
|
73
|
-
# Group PaddleOCR-VL configs
|
|
74
|
-
f.write("# ========================================\n")
|
|
75
|
-
f.write("# PaddleOCR-VL Configuration\n")
|
|
76
|
-
f.write("# ========================================\n")
|
|
77
|
-
f.write(f"VL_API_URL={existing_config['VL_API_URL']}\n")
|
|
78
|
-
f.write(f"VL_TOKEN={existing_config['VL_TOKEN']}\n")
|
|
79
|
-
f.write("\n")
|
|
80
|
-
|
|
81
|
-
# Write other configs
|
|
82
|
-
other_keys = [k for k in existing_config.keys()
|
|
83
|
-
if k not in ['API_URL', 'PADDLE_OCR_TOKEN', 'PPOCRV5_API_URL',
|
|
84
|
-
'PPOCRV5_TOKEN', 'VL_API_URL', 'VL_TOKEN']]
|
|
85
|
-
if other_keys:
|
|
86
|
-
f.write("# ========================================\n")
|
|
87
|
-
f.write("# Other Configuration\n")
|
|
88
|
-
f.write("# ========================================\n")
|
|
89
|
-
for key in other_keys:
|
|
90
|
-
f.write(f"{key}={existing_config[key]}\n")
|
|
91
|
-
|
|
92
|
-
if not quiet:
|
|
93
|
-
print(f"✓ Configuration saved to {env_file}")
|
|
94
|
-
return True
|
|
95
|
-
|
|
96
|
-
except Exception as e:
|
|
97
|
-
print(f"✗ Failed to save configuration: {e}")
|
|
98
|
-
return False
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def main():
|
|
102
|
-
# Parse command-line arguments
|
|
103
|
-
parser = argparse.ArgumentParser(
|
|
104
|
-
description='PaddleOCR-VL API Configuration Tool',
|
|
105
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
106
|
-
epilog="""
|
|
107
|
-
Examples:
|
|
108
|
-
# Interactive mode
|
|
109
|
-
python configure.py
|
|
110
|
-
|
|
111
|
-
# CLI mode (non-interactive)
|
|
112
|
-
python configure.py --api-url "https://your-service.com/v1" --token "your_token"
|
|
113
|
-
"""
|
|
114
|
-
)
|
|
115
|
-
parser.add_argument('--api-url', help='VL API URL (non-interactive mode)')
|
|
116
|
-
parser.add_argument('--token', help='VL access token (non-interactive mode)')
|
|
117
|
-
parser.add_argument('--quiet', action='store_true', help='Suppress output messages')
|
|
118
|
-
|
|
119
|
-
args = parser.parse_args()
|
|
120
|
-
|
|
121
|
-
# Find .env file location (project root, 2 levels up from script)
|
|
122
|
-
project_root = Path(__file__).parent.parent.parent
|
|
123
|
-
|
|
124
|
-
# ========================================
|
|
125
|
-
# CLI Mode (non-interactive)
|
|
126
|
-
# ========================================
|
|
127
|
-
if args.api_url and args.token:
|
|
128
|
-
try:
|
|
129
|
-
api_url = args.api_url.strip()
|
|
130
|
-
token = args.token.strip()
|
|
131
|
-
|
|
132
|
-
# Validate URL format
|
|
133
|
-
if not api_url.startswith(("http://", "https://")):
|
|
134
|
-
api_url = f"https://{api_url}"
|
|
135
|
-
|
|
136
|
-
# Validate token
|
|
137
|
-
if len(token) < 16:
|
|
138
|
-
print("Error: Token seems too short. Please check and try again.")
|
|
139
|
-
sys.exit(1)
|
|
140
|
-
|
|
141
|
-
# Save configuration
|
|
142
|
-
if save_config(api_url, token, project_root, quiet=args.quiet):
|
|
143
|
-
if not args.quiet:
|
|
144
|
-
masked_token = token[:8] + "..." + token[-4:] if len(token) > 12 else "***"
|
|
145
|
-
print("\n✓ Configuration complete!")
|
|
146
|
-
print(f" VL_API_URL: {api_url}")
|
|
147
|
-
print(f" VL_TOKEN: {masked_token}")
|
|
148
|
-
sys.exit(0)
|
|
149
|
-
else:
|
|
150
|
-
sys.exit(1)
|
|
151
|
-
|
|
152
|
-
except Exception as e:
|
|
153
|
-
print(f"Error: {e}")
|
|
154
|
-
sys.exit(1)
|
|
155
|
-
|
|
156
|
-
elif args.api_url or args.token:
|
|
157
|
-
print("Error: Both --api-url and --token are required for CLI mode")
|
|
158
|
-
print("Run without arguments for interactive mode")
|
|
159
|
-
sys.exit(1)
|
|
160
|
-
|
|
161
|
-
# ========================================
|
|
162
|
-
# Interactive Mode
|
|
163
|
-
# ========================================
|
|
164
|
-
print("=" * 60)
|
|
165
|
-
print("PaddleOCR-VL Configuration Wizard")
|
|
166
|
-
print("=" * 60)
|
|
167
|
-
print()
|
|
168
|
-
|
|
169
|
-
env_file = project_root / ".env"
|
|
170
|
-
print(f"Configuration will be saved to: {env_file}")
|
|
171
|
-
print()
|
|
172
|
-
|
|
173
|
-
# Read existing .env if it exists
|
|
174
|
-
existing_config = {}
|
|
175
|
-
if env_file.exists():
|
|
176
|
-
print("Found existing .env file, loading current values...")
|
|
177
|
-
with open(env_file, 'r', encoding='utf-8') as f:
|
|
178
|
-
for line in f:
|
|
179
|
-
line = line.strip()
|
|
180
|
-
if line and not line.startswith('#') and '=' in line:
|
|
181
|
-
key, value = line.split('=', 1)
|
|
182
|
-
existing_config[key.strip()] = value.strip()
|
|
183
|
-
print()
|
|
184
|
-
|
|
185
|
-
# Get current values
|
|
186
|
-
current_api_url = existing_config.get('VL_API_URL', '')
|
|
187
|
-
current_token = existing_config.get('VL_TOKEN', '')
|
|
188
|
-
|
|
189
|
-
print("Please provide your PaddleOCR-VL API credentials:")
|
|
190
|
-
print("(Press Enter to keep current value)")
|
|
191
|
-
print()
|
|
192
|
-
|
|
193
|
-
# Prompt for API URL
|
|
194
|
-
print("1. VL_API_URL - PaddleOCR-VL API endpoint")
|
|
195
|
-
print(" Example: https://your-service.com/v1")
|
|
196
|
-
if current_api_url:
|
|
197
|
-
print(f" Current: {current_api_url}")
|
|
198
|
-
|
|
199
|
-
api_url_input = input(" Enter VL_API_URL: ").strip()
|
|
200
|
-
new_api_url = api_url_input if api_url_input else current_api_url
|
|
201
|
-
|
|
202
|
-
if not new_api_url:
|
|
203
|
-
print()
|
|
204
|
-
print("ERROR: VL_API_URL is required.")
|
|
205
|
-
print("Please run this wizard again and provide a valid API URL.")
|
|
206
|
-
sys.exit(1)
|
|
207
|
-
|
|
208
|
-
print()
|
|
209
|
-
|
|
210
|
-
# Prompt for Token
|
|
211
|
-
print("2. VL_TOKEN - Your access token")
|
|
212
|
-
if current_token:
|
|
213
|
-
masked_token = current_token[:8] + "..." + current_token[-4:] if len(current_token) > 12 else "***"
|
|
214
|
-
print(f" Current: {masked_token}")
|
|
215
|
-
|
|
216
|
-
token_input = input(" Enter VL_TOKEN: ").strip()
|
|
217
|
-
new_token = token_input if token_input else current_token
|
|
218
|
-
|
|
219
|
-
if not new_token:
|
|
220
|
-
print()
|
|
221
|
-
print("ERROR: VL_TOKEN is required.")
|
|
222
|
-
print("Please run this wizard again and provide a valid token.")
|
|
223
|
-
sys.exit(1)
|
|
224
|
-
|
|
225
|
-
print()
|
|
226
|
-
|
|
227
|
-
# Save configuration
|
|
228
|
-
print("Saving configuration...")
|
|
229
|
-
|
|
230
|
-
if not save_config(new_api_url, new_token, project_root):
|
|
231
|
-
sys.exit(1)
|
|
232
|
-
|
|
233
|
-
print()
|
|
234
|
-
|
|
235
|
-
# Verify configuration
|
|
236
|
-
print("Verifying configuration...")
|
|
237
|
-
try:
|
|
238
|
-
sys.path.insert(0, str(Path(__file__).parent))
|
|
239
|
-
from _lib import Config
|
|
240
|
-
|
|
241
|
-
Config.load_env()
|
|
242
|
-
|
|
243
|
-
test_url = Config.get_vl_api_url()
|
|
244
|
-
test_token = Config.get_vl_token()
|
|
245
|
-
|
|
246
|
-
print("✓ VL_API_URL loaded successfully")
|
|
247
|
-
print("✓ VL_TOKEN loaded successfully")
|
|
248
|
-
print()
|
|
249
|
-
|
|
250
|
-
except Exception as e:
|
|
251
|
-
print(f"✗ Configuration verification failed: {e}")
|
|
252
|
-
print()
|
|
253
|
-
sys.exit(1)
|
|
254
|
-
|
|
255
|
-
# Next steps
|
|
256
|
-
print("=" * 60)
|
|
257
|
-
print("Configuration Complete!")
|
|
258
|
-
print("=" * 60)
|
|
259
|
-
print()
|
|
260
|
-
print("Next steps:")
|
|
261
|
-
print(" 1. Test the configuration:")
|
|
262
|
-
print(" python scripts/paddleocr-vl/smoke_test.py")
|
|
263
|
-
print()
|
|
264
|
-
print(" 2. Try parsing a document:")
|
|
265
|
-
print(" python scripts/paddleocr-vl/vl_caller.py --file-url \"URL\"")
|
|
266
|
-
print()
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if __name__ == '__main__':
|
|
270
|
-
main()
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
PaddleOCR-VL 1.5 Configuration Wizard
|
|
4
|
+
|
|
5
|
+
Supports two modes:
|
|
6
|
+
1. Interactive mode (default): python configure.py
|
|
7
|
+
2. CLI mode: python configure.py --api-url URL --token TOKEN
|
|
8
|
+
|
|
9
|
+
Interactive configuration for PaddleOCR-VL 1.5 API credentials.
|
|
10
|
+
Saves configuration to .env file in project root.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def save_config(api_url: str, token: str, project_root: Path, quiet: bool = False) -> bool:
|
|
20
|
+
"""
|
|
21
|
+
Save configuration to .env file
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
api_url: VL API URL
|
|
25
|
+
token: VL access token
|
|
26
|
+
project_root: Project root directory
|
|
27
|
+
quiet: If True, suppress output messages
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
True if successful, False otherwise
|
|
31
|
+
"""
|
|
32
|
+
env_file = project_root / ".env"
|
|
33
|
+
|
|
34
|
+
# Read existing .env if it exists
|
|
35
|
+
existing_config = {}
|
|
36
|
+
if env_file.exists():
|
|
37
|
+
if not quiet:
|
|
38
|
+
print(f"Found existing .env file: {env_file}")
|
|
39
|
+
overwrite = input("Overwrite? [Y/n]: ").strip().lower()
|
|
40
|
+
if overwrite == 'n':
|
|
41
|
+
print("Configuration cancelled")
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
with open(env_file, 'r', encoding='utf-8') as f:
|
|
45
|
+
for line in f:
|
|
46
|
+
line = line.strip()
|
|
47
|
+
if line and not line.startswith('#') and '=' in line:
|
|
48
|
+
key, value = line.split('=', 1)
|
|
49
|
+
existing_config[key.strip()] = value.strip()
|
|
50
|
+
|
|
51
|
+
# Update configuration
|
|
52
|
+
existing_config['VL_API_URL'] = api_url
|
|
53
|
+
existing_config['VL_TOKEN'] = token
|
|
54
|
+
|
|
55
|
+
# Write to .env file
|
|
56
|
+
try:
|
|
57
|
+
with open(env_file, 'w', encoding='utf-8') as f:
|
|
58
|
+
# Write header
|
|
59
|
+
f.write("# PaddleOCR Skills Configuration\n")
|
|
60
|
+
f.write("# Generated by configuration wizard\n")
|
|
61
|
+
f.write("\n")
|
|
62
|
+
|
|
63
|
+
# Group PP-OCRv5 configs
|
|
64
|
+
if any(k.startswith('API_URL') or k.startswith('PADDLE_OCR_TOKEN') or k.startswith('PPOCRV5') for k in existing_config.keys()):
|
|
65
|
+
f.write("# ========================================\n")
|
|
66
|
+
f.write("# PP-OCRv5 Configuration\n")
|
|
67
|
+
f.write("# ========================================\n")
|
|
68
|
+
for key in ['API_URL', 'PADDLE_OCR_TOKEN', 'PPOCRV5_API_URL', 'PPOCRV5_TOKEN']:
|
|
69
|
+
if key in existing_config:
|
|
70
|
+
f.write(f"{key}={existing_config[key]}\n")
|
|
71
|
+
f.write("\n")
|
|
72
|
+
|
|
73
|
+
# Group PaddleOCR-VL 1.5 configs
|
|
74
|
+
f.write("# ========================================\n")
|
|
75
|
+
f.write("# PaddleOCR-VL 1.5 Configuration\n")
|
|
76
|
+
f.write("# ========================================\n")
|
|
77
|
+
f.write(f"VL_API_URL={existing_config['VL_API_URL']}\n")
|
|
78
|
+
f.write(f"VL_TOKEN={existing_config['VL_TOKEN']}\n")
|
|
79
|
+
f.write("\n")
|
|
80
|
+
|
|
81
|
+
# Write other configs
|
|
82
|
+
other_keys = [k for k in existing_config.keys()
|
|
83
|
+
if k not in ['API_URL', 'PADDLE_OCR_TOKEN', 'PPOCRV5_API_URL',
|
|
84
|
+
'PPOCRV5_TOKEN', 'VL_API_URL', 'VL_TOKEN']]
|
|
85
|
+
if other_keys:
|
|
86
|
+
f.write("# ========================================\n")
|
|
87
|
+
f.write("# Other Configuration\n")
|
|
88
|
+
f.write("# ========================================\n")
|
|
89
|
+
for key in other_keys:
|
|
90
|
+
f.write(f"{key}={existing_config[key]}\n")
|
|
91
|
+
|
|
92
|
+
if not quiet:
|
|
93
|
+
print(f"✓ Configuration saved to {env_file}")
|
|
94
|
+
return True
|
|
95
|
+
|
|
96
|
+
except Exception as e:
|
|
97
|
+
print(f"✗ Failed to save configuration: {e}")
|
|
98
|
+
return False
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def main():
|
|
102
|
+
# Parse command-line arguments
|
|
103
|
+
parser = argparse.ArgumentParser(
|
|
104
|
+
description='PaddleOCR-VL 1.5 API Configuration Tool',
|
|
105
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
106
|
+
epilog="""
|
|
107
|
+
Examples:
|
|
108
|
+
# Interactive mode
|
|
109
|
+
python configure.py
|
|
110
|
+
|
|
111
|
+
# CLI mode (non-interactive)
|
|
112
|
+
python configure.py --api-url "https://your-service.com/v1" --token "your_token"
|
|
113
|
+
"""
|
|
114
|
+
)
|
|
115
|
+
parser.add_argument('--api-url', help='VL API URL (non-interactive mode)')
|
|
116
|
+
parser.add_argument('--token', help='VL access token (non-interactive mode)')
|
|
117
|
+
parser.add_argument('--quiet', action='store_true', help='Suppress output messages')
|
|
118
|
+
|
|
119
|
+
args = parser.parse_args()
|
|
120
|
+
|
|
121
|
+
# Find .env file location (project root, 2 levels up from script)
|
|
122
|
+
project_root = Path(__file__).parent.parent.parent
|
|
123
|
+
|
|
124
|
+
# ========================================
|
|
125
|
+
# CLI Mode (non-interactive)
|
|
126
|
+
# ========================================
|
|
127
|
+
if args.api_url and args.token:
|
|
128
|
+
try:
|
|
129
|
+
api_url = args.api_url.strip()
|
|
130
|
+
token = args.token.strip()
|
|
131
|
+
|
|
132
|
+
# Validate URL format
|
|
133
|
+
if not api_url.startswith(("http://", "https://")):
|
|
134
|
+
api_url = f"https://{api_url}"
|
|
135
|
+
|
|
136
|
+
# Validate token
|
|
137
|
+
if len(token) < 16:
|
|
138
|
+
print("Error: Token seems too short. Please check and try again.")
|
|
139
|
+
sys.exit(1)
|
|
140
|
+
|
|
141
|
+
# Save configuration
|
|
142
|
+
if save_config(api_url, token, project_root, quiet=args.quiet):
|
|
143
|
+
if not args.quiet:
|
|
144
|
+
masked_token = token[:8] + "..." + token[-4:] if len(token) > 12 else "***"
|
|
145
|
+
print("\n✓ Configuration complete!")
|
|
146
|
+
print(f" VL_API_URL: {api_url}")
|
|
147
|
+
print(f" VL_TOKEN: {masked_token}")
|
|
148
|
+
sys.exit(0)
|
|
149
|
+
else:
|
|
150
|
+
sys.exit(1)
|
|
151
|
+
|
|
152
|
+
except Exception as e:
|
|
153
|
+
print(f"Error: {e}")
|
|
154
|
+
sys.exit(1)
|
|
155
|
+
|
|
156
|
+
elif args.api_url or args.token:
|
|
157
|
+
print("Error: Both --api-url and --token are required for CLI mode")
|
|
158
|
+
print("Run without arguments for interactive mode")
|
|
159
|
+
sys.exit(1)
|
|
160
|
+
|
|
161
|
+
# ========================================
|
|
162
|
+
# Interactive Mode
|
|
163
|
+
# ========================================
|
|
164
|
+
print("=" * 60)
|
|
165
|
+
print("PaddleOCR-VL 1.5 Configuration Wizard")
|
|
166
|
+
print("=" * 60)
|
|
167
|
+
print()
|
|
168
|
+
|
|
169
|
+
env_file = project_root / ".env"
|
|
170
|
+
print(f"Configuration will be saved to: {env_file}")
|
|
171
|
+
print()
|
|
172
|
+
|
|
173
|
+
# Read existing .env if it exists
|
|
174
|
+
existing_config = {}
|
|
175
|
+
if env_file.exists():
|
|
176
|
+
print("Found existing .env file, loading current values...")
|
|
177
|
+
with open(env_file, 'r', encoding='utf-8') as f:
|
|
178
|
+
for line in f:
|
|
179
|
+
line = line.strip()
|
|
180
|
+
if line and not line.startswith('#') and '=' in line:
|
|
181
|
+
key, value = line.split('=', 1)
|
|
182
|
+
existing_config[key.strip()] = value.strip()
|
|
183
|
+
print()
|
|
184
|
+
|
|
185
|
+
# Get current values
|
|
186
|
+
current_api_url = existing_config.get('VL_API_URL', '')
|
|
187
|
+
current_token = existing_config.get('VL_TOKEN', '')
|
|
188
|
+
|
|
189
|
+
print("Please provide your PaddleOCR-VL 1.5 API credentials:")
|
|
190
|
+
print("(Press Enter to keep current value)")
|
|
191
|
+
print()
|
|
192
|
+
|
|
193
|
+
# Prompt for API URL
|
|
194
|
+
print("1. VL_API_URL - PaddleOCR-VL 1.5 API endpoint")
|
|
195
|
+
print(" Example: https://your-service.com/v1")
|
|
196
|
+
if current_api_url:
|
|
197
|
+
print(f" Current: {current_api_url}")
|
|
198
|
+
|
|
199
|
+
api_url_input = input(" Enter VL_API_URL: ").strip()
|
|
200
|
+
new_api_url = api_url_input if api_url_input else current_api_url
|
|
201
|
+
|
|
202
|
+
if not new_api_url:
|
|
203
|
+
print()
|
|
204
|
+
print("ERROR: VL_API_URL is required.")
|
|
205
|
+
print("Please run this wizard again and provide a valid API URL.")
|
|
206
|
+
sys.exit(1)
|
|
207
|
+
|
|
208
|
+
print()
|
|
209
|
+
|
|
210
|
+
# Prompt for Token
|
|
211
|
+
print("2. VL_TOKEN - Your access token")
|
|
212
|
+
if current_token:
|
|
213
|
+
masked_token = current_token[:8] + "..." + current_token[-4:] if len(current_token) > 12 else "***"
|
|
214
|
+
print(f" Current: {masked_token}")
|
|
215
|
+
|
|
216
|
+
token_input = input(" Enter VL_TOKEN: ").strip()
|
|
217
|
+
new_token = token_input if token_input else current_token
|
|
218
|
+
|
|
219
|
+
if not new_token:
|
|
220
|
+
print()
|
|
221
|
+
print("ERROR: VL_TOKEN is required.")
|
|
222
|
+
print("Please run this wizard again and provide a valid token.")
|
|
223
|
+
sys.exit(1)
|
|
224
|
+
|
|
225
|
+
print()
|
|
226
|
+
|
|
227
|
+
# Save configuration
|
|
228
|
+
print("Saving configuration...")
|
|
229
|
+
|
|
230
|
+
if not save_config(new_api_url, new_token, project_root):
|
|
231
|
+
sys.exit(1)
|
|
232
|
+
|
|
233
|
+
print()
|
|
234
|
+
|
|
235
|
+
# Verify configuration
|
|
236
|
+
print("Verifying configuration...")
|
|
237
|
+
try:
|
|
238
|
+
sys.path.insert(0, str(Path(__file__).parent))
|
|
239
|
+
from _lib import Config
|
|
240
|
+
|
|
241
|
+
Config.load_env()
|
|
242
|
+
|
|
243
|
+
test_url = Config.get_vl_api_url()
|
|
244
|
+
test_token = Config.get_vl_token()
|
|
245
|
+
|
|
246
|
+
print("✓ VL_API_URL loaded successfully")
|
|
247
|
+
print("✓ VL_TOKEN loaded successfully")
|
|
248
|
+
print()
|
|
249
|
+
|
|
250
|
+
except Exception as e:
|
|
251
|
+
print(f"✗ Configuration verification failed: {e}")
|
|
252
|
+
print()
|
|
253
|
+
sys.exit(1)
|
|
254
|
+
|
|
255
|
+
# Next steps
|
|
256
|
+
print("=" * 60)
|
|
257
|
+
print("Configuration Complete!")
|
|
258
|
+
print("=" * 60)
|
|
259
|
+
print()
|
|
260
|
+
print("Next steps:")
|
|
261
|
+
print(" 1. Test the configuration:")
|
|
262
|
+
print(" python scripts/paddleocr-vl-1.5/smoke_test.py")
|
|
263
|
+
print()
|
|
264
|
+
print(" 2. Try parsing a document:")
|
|
265
|
+
print(" python scripts/paddleocr-vl-1.5/vl_caller.py --file-url \"URL\"")
|
|
266
|
+
print()
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
if __name__ == '__main__':
|
|
270
|
+
main()
|