This commit is contained in:
29
docs/snippets/python/cli/cli_with_config.py
Normal file
29
docs/snippets/python/cli/cli_with_config.py
Normal file
@@ -0,0 +1,29 @@
|
||||
```python title="cli_with_config.py"
|
||||
import subprocess
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def extract_with_config(file_path: str, config_path: str) -> dict:
|
||||
result = subprocess.run(
|
||||
["kreuzberg", "extract", file_path, "--config", config_path, "--format", "json"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"Error: {result.stderr}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return json.loads(result.stdout)
|
||||
|
||||
config_file = Path("kreuzberg.toml")
|
||||
document = "document.pdf"
|
||||
|
||||
print(f"Extracting {document} with config {config_file}")
|
||||
result = extract_with_config(str(document), str(config_file))
|
||||
|
||||
print(f"Content length: {len(result.get('content', ''))}")
|
||||
print(f"Format: {result.get('format')}")
|
||||
print(f"Languages: {result.get('languages')}")
|
||||
```
|
||||
Reference in New Issue
Block a user