code: def create_index(args):
      if not args.dir.exists() and not args.dir.is_dir():
          logger.error("%s does not exist or is no dir.", args.dir)
          return
      papers = []
      depth = 0
      p = args.dir
      while True:
          p = next(p.iterdir())
          if p.is_file():
              break
          else:
              depth += 1
      papers = args.dir.glob("*/" * depth)
      index = []
      with ProcessPool(max_workers=args.workers) as pool:
          tasks = {}
          for j, paper in enumerate(papers):
              fname = paper.name
              tasks[fname] = pool.schedule(
                  index_paper,
                  args=[paper, args],
                  timeout=args.timeout,
              )
  
          for fname in tqdm(tasks):
              try:
                  res = tasks[fname].result()
                  if res is None:
                      logger.info("%s is faulty", fname)
                      continue
                  index.append(res)
              except TimeoutError:
                  logger.info("%s timed out", fname)
  
          with args.out.open("w", encoding="utf-8") as f:
              for item in index:
                  for page in item:
                      if len(page) == 0:
                          continue
                      f.write(json.dumps(page) + "\n")
  
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 4 for calling a global function with example usage: create_index(args) without return types