class_docstr: Loader that extracts text from images
docstr: Helper function for getting the captions and metadata of an image
docstr_tok: ["Helper","function","for","getting","the","captions","and","metadata","of","an","image"]
code: def _get_captions_and_metadata(
      self, model: Any, document_path: str
  ) -> Tuple[list, dict]:
      """
      Helper function for getting the captions and metadata of an image
      """
      try:
          from doctr.io import DocumentFile
      except ImportError:
          raise ValueError(
              "`doctr` package not found, please install with "
              "`pip install git+https://github.com/h2oai/doctr.git`."
          )
      try:
          if document_path.lower().endswith(".pdf"):
              # load at roughly 300 dpi
              images = read_pdf(document_path)
          else:
              images = DocumentFile.from_images(document_path)
      except Exception:
          raise ValueError(
              f"Could not get image data for {document_path}"
          )
      document_words = []
      shapes = []
      for image in images:
          shape0 = str(image.shape)
          image = self.pad_resize_image(image)
          # debug, to see effect of pad-resize
          # import cv2
          # cv2.imwrite('new1.png', image)
          shape1 = str(image.shape)
  
          ocr_output = model([image])
          page_words = []
          page_boxes = []
          for block_num, block in enumerate(ocr_output.pages[0].blocks):
              for line_num, line in enumerate(block.lines):
                  for word_num, word in enumerate(line.words):
                      if not (word.value or "").strip():
                          continue
                      page_words.append(word.value)
                      page_boxes.append(
                          [
                              word.geometry[0][0],
                              word.geometry[0][1],
                              word.geometry[1][0],
                              word.geometry[1][1],
                          ]
                      )
          if self.layout_aware:
              ids = boxes_sort(page_boxes)
              texts = [page_words[i] for i in ids]
              text_boxes = [page_boxes[i] for i in ids]
              page_words = space_layout(texts=texts, boxes=text_boxes)
          else:
              page_words = " ".join(page_words)
          document_words.append(page_words)
          shapes.append(dict(shape0=shape0, shape1=shape1))
      metadata: dict = {
          "image_path": document_path,
          "shape": str(shapes),
      }
      return document_words, metadata
  
imports: from typing import List, Union, Any, Tuple, Optional
  import requests
  import torch
  from langchain.docstore.document import Document
  from langchain.document_loaders import ImageCaptionLoader
  import numpy
  from utils import get_device, clear_torch_cache, NullContext
  from doctr.utils.common_types import AbstractFile
label_desc: Use image node_id 8 for calling the H2OOCRLoader obj's underlying member method code with example usage: obj._get_captions_and_metadata(model, document_path) and returns: document_words,  metadata