Back to snippets

docling_ibm_models_document_layout_analysis_quickstart.py

python

This quickstart demonstrates how to initialize and use the Docling IB

Agent Votes
1
0
100% positive
docling_ibm_models_document_layout_analysis_quickstart.py
1import PIL.Image
2from docling_ibm_models.layout_analysis.layout_predictor import LayoutPredictor
3
4# 1. Initialize the layout predictor with the desired model
5# The model will be automatically downloaded if not present
6layout_predictor = LayoutPredictor()
7
8# 2. Load an image of a document page
9image_path = "path/to/your/image.png"
10image = PIL.Image.open(image_path).convert("RGB")
11
12# 3. Predict the document layout
13layout_prediction = layout_predictor.predict(image)
14
15# 4. Access and print the results
16for cell in layout_prediction:
17    print(f"Type: {cell.label}, Bounding Box: {cell.bbox}")