code: def get_page_encoding(page, page_blocks: Page):
      if len(page_blocks.get_all_lines()) == 0:
          return [], []
  
      page_box = page_blocks.bbox
      pwidth = page_blocks.width
      pheight = page_blocks.height
  
      pix = page.get_pixmap(
          dpi=settings.LAYOUT_DPI, annots=False, clip=page_blocks.bbox
      )
      png = pix.pil_tobytes(format="PNG")
      png_image = Image.open(io.BytesIO(png))
      # If it is too large, make it smaller for the model
      rgb_image = png_image.convert("RGB")
      rgb_width, rgb_height = rgb_image.size
  
      # Image is correct size wrt the pdf page
      assert isclose(
          rgb_width / pwidth, rgb_height / pheight, abs_tol=2e-2
      )
  
      lines = page_blocks.get_all_lines()
  
      boxes = []
      text = []
      for line in lines:
          box = line.bbox
          # Bounding boxes sometimes overflow
          if box[0] < page_box[0]:
              box[0] = page_box[0]
          if box[1] < page_box[1]:
              box[1] = page_box[1]
          if box[2] > page_box[2]:
              box[2] = page_box[2]
          if box[3] > page_box[3]:
              box[3] = page_box[3]
  
          # Handle case when boxes are 0 or less width or height
          if box[2] <= box[0]:
              print("Zero width box found, cannot convert properly")
              raise ValueError
          if box[3] <= box[1]:
              print("Zero height box found, cannot convert properly")
              raise ValueError
          boxes.append(box)
          text.append(line.prelim_text)
  
      # Normalize boxes for model (scale to 1000x1000)
      boxes = [normalize_box(box, pwidth, pheight) for box in boxes]
      for box in boxes:
          # Verify that boxes are all valid
          assert len(box) == 4
          assert (max(box)) <= 1000
          assert (min(box)) >= 0
  
      encoding = processor(
          rgb_image,
          text=text,
          boxes=boxes,
          return_offsets_mapping=True,
          truncation=True,
          return_tensors="pt",
          stride=settings.LAYOUT_CHUNK_OVERLAP,
          padding="max_length",
          max_length=settings.LAYOUT_MODEL_MAX,
          return_overflowing_tokens=True,
      )
      offset_mapping = encoding.pop("offset_mapping")
      overflow_to_sample_mapping = encoding.pop(
          "overflow_to_sample_mapping"
      )
      bbox = list(encoding["bbox"])
      input_ids = list(encoding["input_ids"])
      attention_mask = list(encoding["attention_mask"])
      pixel_values = list(encoding["pixel_values"])
  
      assert (
          len(bbox)
          == len(input_ids)
          == len(attention_mask)
          == len(pixel_values)
          == len(offset_mapping)
      )
  
      list_encoding = []
      for i in range(len(bbox)):
          list_encoding.append(
              {
                  "bbox": bbox[i],
                  "input_ids": input_ids[i],
                  "attention_mask": attention_mask[i],
                  "pixel_values": pixel_values[i],
                  "offset_mapping": offset_mapping[i],
              }
          )
  
      other_data = {
          "original_bbox": boxes,
          "pwidth": pwidth,
          "pheight": pheight,
      }
      return list_encoding, other_data
  
imports: from concurrent.futures import ThreadPoolExecutor
  from typing import List
  from transformers import LayoutLMv3ForTokenClassification
  from marker.bbox import unnormalize_box
  from transformers.models.layoutlmv3.image_processing_layoutlmv3 import normalize_box
  import io
  from PIL import Image
  from transformers import LayoutLMv3Processor
  import numpy
  from marker.settings import settings
  from marker.schema import Page, BlockType
  import torch
  from math import isclose
label_desc: Use image node_id 4 for calling a global function with example usage: get_page_encoding(page, page_blocks) and returns: list_encoding,  other_data, list,  list