code: def index_paper(directory: Path, args: argparse.Namespace):
      """
      Pack all image-text pairs into a single h5 file and save it at `args.out`
      """
      paper = directory.name
      markdowns = directory.glob("*.mmd")
      meta_file = directory / "meta.json"
      data_samples = []
      if not meta_file.exists():
          return
      # load meta info
      try:
          meta = read_metadata(
              json.load(meta_file.open("r", encoding="utf-8"))
          )
      except json.JSONDecodeError:
          return
  
      for md_path in markdowns:
          image = md_path.parent / (md_path.stem + ".png")
          i = int(image.stem) - 1
          if not image.exists():
              continue
          if i >= len(meta):
              continue
          data_sample = {}
          ocr_path = image.parent / (image.stem + "_OCR.txt")
          if args.tesseract and not ocr_path.exists():
              try:
                  pil = Image.open(image)
                  ocr = pytesseract.image_to_string(
                      pil, lang="eng", timeout=2
                  )
                  ocr = re.sub(
                      r"\n+\s+?([^\s])", r"\n\n\1", ocr
                  ).strip()
                  with ocr_path.open("w", encoding="utf-8") as f_ocr:
                      f_ocr.write(ocr)
              except RuntimeError:
                  logger.info(
                      "Page %s of paper %s timed out", image.stem, paper
                  )
                  pass
          if ocr_path.exists():
              data_sample["ocr"] = str(ocr_path.relative_to(args.root))
          data_sample["image"] = str(image.relative_to(args.root))
          data_sample["markdown"] = md_path.read_text(
              encoding="utf8"
          ).strip()
          data_sample["meta"] = meta[i]
          data_samples.append(data_sample)
      return data_samples
  
file_path: nougat/nougat/dataset/create_index.py
imports: import argparse
  import json
  from typing import Dict, List
  import numpy
  from pathlib import Path
  import multiprocessing
  from pebble import ProcessPool
  from PIL import Image
  import pytesseract
  import re
  import logging
  from tqdm import tqdm
label_desc: Use image node_id 3 for calling a global function with example usage: index_paper(directory, args) and returns: data_samples