Views
No views yet
Important: Make sure to include the--specialflag so that special tokens are properly returned. Example:llama-server -hf danchev/ibm-granite-docling-258m-GGUF --special
1# Serve the model with Docker
2docker run --rm -p 8080:8080 ghcr.io/danchev/llama.cpp:docling \
3 --server \
4 -hf danchev/ibm-granite-docling-258M-GGUF \
5 --host 0.0.0.0 \
6 --port 8080 \
7 --special # required for docling to work1# Build llama.cpp from source
2git clone git@github.com:ggml-org/llama.cpp.git
3cd llama.cpp
4cmake -B build
5cmake --build build --config Release -j $(nproc)
6
7# Serve the model
8./build/bin/llama-server -hf danchev/ibm-granite-docling-258M-GGUF --special1#!/usr/bin/env -S uv run --script
2# /// script
3# requires-python = ">=3.12"
4# dependencies = ["docling>=2.58.0", "requests>=2.32.5"]
5# ///
6
7import tempfile
8import requests
9from pydantic import AnyUrl
10from docling.datamodel.base_models import InputFormat
11from docling.datamodel.pipeline_options import VlmPipelineOptions
12from docling.datamodel.pipeline_options_vlm_model import ApiVlmOptions, ResponseFormat
13from docling.document_converter import DocumentConverter, PdfFormatOption
14from docling.pipeline.vlm_pipeline import VlmPipeline
15
16pdf_url = "https://arxiv.org/pdf/1706.03762.pdf"
17with tempfile.NamedTemporaryFile(suffix=".pdf") as f:
18 f.write(requests.get(pdf_url).content)
19 f.flush()
20
21 pipeline_options = VlmPipelineOptions(
22 enable_remote_services=True,
23 vlm_options=ApiVlmOptions(
24 url=AnyUrl("http://127.0.0.1:8080/v1/chat/completions"),
25 params={"model": "danchev/ibm-granite-docling-258m-GGUF"},
26 prompt="Convert this page to docling.",
27 temperature=0.0,
28 response_format=ResponseFormat.DOCTAGS,
29 ),
30 )
31
32 doc_converter = DocumentConverter(
33 format_options={
34 InputFormat.PDF: PdfFormatOption(
35 pipeline_options=pipeline_options, pipeline_cls=VlmPipeline
36 )
37 }
38 )
39
40 print(doc_converter.convert(f.name).document.export_to_markdown())1#!/usr/bin/env -S uv run --script
2# /// script
3# requires-python = ">=3.12"
4# dependencies = ["docling-core>=2.49.0", "Pillow>=11.3.0", "requests>=2.32.5"]
5# ///
6
7import base64
8from io import BytesIO
9from pathlib import Path
10
11import requests
12from docling_core.types.doc.base import ImageRefMode
13from docling_core.types.doc.document import DoclingDocument, DocTagsDocument
14from PIL import Image
15
16img_url = "https://ibm.biz/docling-page-with-list"
17img_bytes = requests.get(img_url).content
18img_b64 = base64.b64encode(img_bytes).decode()
19
20doctags = requests.post(
21 url="http://localhost:8080/v1/chat/completions",
22 json={
23 "model": "danchev/ibm-granite-docling-258M-GGUF",
24 "messages": [
25 {
26 "role": "user",
27 "content": [
28 {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{img_b64}"}},
29 {"type": "text", "text": "Convert this page to docling."},
30 ],
31 }
32 ],
33 }
34).json()["choices"][0]["message"]["content"]
35
36doc = DoclingDocument.load_from_doctags(
37 doctag_document=DocTagsDocument.from_doctags_and_image_pairs(
38 doctags=[doctags], images=[Image.open(BytesIO(img_bytes))]),
39)
40
41print(doc.export_to_markdown())
42
43doc.save_as_html(Path("output.html"), image_mode=ImageRefMode.EMBEDDED)