Oprydning og opdeling i programfiler og datafiler - og datafiler i input og output.

This commit is contained in:
anders committed 2026-10-28 20:03:47 +01:00
1 parent 00697527f6
commit b859d67ac2
87 files changed
+22278 -61575

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
from pathlib import Path
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import (
VlmConvertOptions,
VlmPipelineOptions,
)
from docling.datamodel.stage_model_specs import ApiModelConfig
from docling.datamodel.vlm_engine_options import (
ApiVlmEngineOptions,
VlmEngineType,
)
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.pipeline.vlm_pipeline import VlmPipeline
INPUT_FILE = Path("Skemaer_2026_2027.pdf")
OUTPUT_FILE = INPUT_FILE.with_suffix(".json")
OLLAMA_MODEL = "ibm-granite/granite-vision-4.1-4b:latest"
OLLAMA_URL = "http://localhost:11434/v1/chat/completions"
def main():
if not INPUT_FILE.is_file():
raise FileNotFoundError(f"PDF not found: {INPUT_FILE}")
# Start with the Granite Vision preset to retain its prompt
# and expected response format.
vlm_options = VlmConvertOptions.from_preset(
"granite_vision",
engine_options=ApiVlmEngineOptions(
engine_type=VlmEngineType.API_OLLAMA,
url=OLLAMA_URL,
timeout=300,
),
)
# Override the model selected by the preset.
vlm_options.model_spec.api_overrides[
VlmEngineType.API_OLLAMA
] = ApiModelConfig(
params={"model": OLLAMA_MODEL}
)
pipeline_options = VlmPipelineOptions(
vlm_options=vlm_options,
enable_remote_services=True,
)
converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(
pipeline_cls=VlmPipeline,
pipeline_options=pipeline_options,
)
}
)
print(f"Input: {INPUT_FILE}")
print(f"Engine: {vlm_options.engine_options.engine_type}")
print(f"Model: {OLLAMA_MODEL}")
print(f"Output: {OUTPUT_FILE}")
result = converter.convert(INPUT_FILE)
result.document.save_as_json(OUTPUT_FILE)
print(f"Conversion complete: {OUTPUT_FILE}")
if __name__ == "__main__":
main()