code: def ocr(  # noqa: D417
      input_file: PathOrIO,
      output_file: PathOrIO,
      *,
      language: Iterable[str] | None = None,
      image_dpi: int | None = None,
      output_type: str | None = None,
      sidecar: StrPath | None = None,
      jobs: int | None = None,
      use_threads: bool | None = None,
      title: str | None = None,
      author: str | None = None,
      subject: str | None = None,
      keywords: str | None = None,
      rotate_pages: bool | None = None,
      remove_background: bool | None = None,
      deskew: bool | None = None,
      clean: bool | None = None,
      clean_final: bool | None = None,
      unpaper_args: str | None = None,
      oversample: int | None = None,
      remove_vectors: bool | None = None,
      force_ocr: bool | None = None,
      skip_text: bool | None = None,
      redo_ocr: bool | None = None,
      skip_big: float | None = None,
      optimize: int | None = None,
      jpg_quality: int | None = None,
      png_quality: int | None = None,
      jbig2_lossy: bool | None = None,
      jbig2_page_group_size: int | None = None,
      jbig2_threshold: float | None = None,
      pages: str | None = None,
      max_image_mpixels: float | None = None,
      tesseract_config: Iterable[str] | None = None,
      tesseract_pagesegmode: int | None = None,
      tesseract_oem: int | None = None,
      tesseract_thresholding: int | None = None,
      pdf_renderer: str | None = None,
      tesseract_timeout: float | None = None,
      tesseract_non_ocr_timeout: float | None = None,
      tesseract_downsample_above: int | None = None,
      tesseract_downsample_large_images: bool | None = None,
      rotate_pages_threshold: float | None = None,
      pdfa_image_compression: str | None = None,
      color_conversion_strategy: str | None = None,
      user_words: os.PathLike | None = None,
      user_patterns: os.PathLike | None = None,
      fast_web_view: float | None = None,
      continue_on_soft_render_error: bool | None = None,
      invalidate_digital_signatures: bool | None = None,
      plugins: Iterable[StrPath] | None = None,
      plugin_manager=None,
      keep_temporary_files: bool | None = None,
      progress_bar: bool | None = None,
      **kwargs,
  ):
      """Run OCRmyPDF on one PDF or image.
  
      For most arguments, see documentation for the equivalent command line parameter.
  
      This API takes a threading lock, because OCRmyPDF uses global state in particular
      for the plugin system. The jobs parameter will be used to create a pool of
      worker threads or processes at different times, subject to change. A Python
      process can only run one OCRmyPDF task at a time.
  
      To run parallelize instances OCRmyPDF, use separate Python processes to scale
      horizontally. Generally speaking you should set jobs=sqrt(cpu_count) and run
      sqrt(cpu_count) processes as a starting point. If you have files with a high page
      count, run fewer processes and more jobs per process. If you have a lot of short
      files, run more processes and fewer jobs per process.
  
      A few specific arguments are discussed here:
  
      Args:
          use_threads: Use worker threads instead of processes. This reduces
              performance but may make debugging easier since it is easier to set
              breakpoints.
          input_file: If a :class:`pathlib.Path`, ``str`` or ``bytes``, this is
              interpreted as file system path to the input file. If the object
              appears to be a readable stream (with methods such as ``.read()``
              and ``.seek()``), the object will be read in its entirety and saved to
              a temporary file. If ``input_file`` is  ``"-"``, standard input will be
              read.
          output_file: If a :class:`pathlib.Path`, ``str`` or ``bytes``, this is
              interpreted as file system path to the output file. If the object
              appears to be a writable stream (with methods such as ``.write()`` and
              ``.seek()``), the output will be written to this stream. If
              ``output_file`` is ``"-"``, the output will be written to ``sys.stdout``
              (provided that standard output does not seem to be a terminal device).
              When a stream is used as output, whether via a writable object or
              ``"-"``, some final validation steps are not performed (we do not read
              back the stream after it is written).
  
      Raises:
          ocrmypdf.MissingDependencyError: If a required dependency program is missing or
              was not found on PATH.
          ocrmypdf.UnsupportedImageFormatError: If the input file type was an image that
              could not be read, or some other file type that is not a PDF.
          ocrmypdf.DpiError: If the input file is an image, but the resolution of the
              image is not credible (allowing it to proceed would cause poor OCR).
          ocrmypdf.OutputFileAccessError: If an attempt to write to the intended output
              file failed.
          ocrmypdf.PriorOcrFoundError: If the input PDF seems to have OCR or digital
              text already, and settings did not tell us to proceed.
          ocrmypdf.InputFileError: Any other problem with the input file.
          ocrmypdf.SubprocessOutputError: Any error related to executing a subprocess.
          ocrmypdf.EncryptedPdfError: If the input PDF is encrypted (password protected).
              OCRmyPDF does not remove passwords.
          ocrmypdf.TesseractConfigError: If Tesseract reported its configuration was not
              valid.
  
      Returns:
          :class:`ocrmypdf.ExitCode`
      """
      if plugins and plugin_manager:
          raise ValueError(
              "plugins= and plugin_manager are mutually exclusive"
          )
  
      if not plugins:
          plugins = []
      elif isinstance(plugins, (str, Path)):
          plugins = [plugins]
      else:
          plugins = list(plugins)
  
      # No new variable names should be assigned until these two steps are run
      create_options_kwargs = {
          k: v
          for k, v in locals().items()
          if k not in {"input_file", "output_file", "kwargs"}
      }
      create_options_kwargs.update(kwargs)
  
      parser = get_parser()
      with _api_lock:
          if not plugin_manager:
              plugin_manager = get_plugin_manager(plugins)
          plugin_manager.hook.add_options(
              parser=parser
          )  # pylint: disable=no-member
  
          if "verbose" in kwargs:
              warn(
                  "ocrmypdf.ocr(verbose=) is ignored. Use ocrmypdf.configure_logging()."
              )
  
          options = create_options(
              input_file=input_file,
              output_file=output_file,
              parser=parser,
              **create_options_kwargs,
          )
          check_options(options, plugin_manager)
          return run_pipeline(
              options=options, plugin_manager=plugin_manager
          )
  
imports: from __future__ import annotations
  import logging
  import os
  import sys
  import threading
  from argparse import Namespace
  from collections.abc import Iterable, Sequence
  from enum import IntEnum
  from io import IOBase
  from pathlib import Path
  from typing import AnyStr, BinaryIO, Union
  from warnings import warn
  import pluggy
  from ocrmypdf._logging import PageNumberFilter
  from ocrmypdf._pipelines.hocr_to_ocr_pdf import run_hocr_to_ocr_pdf_pipeline
  from ocrmypdf._pipelines.ocr import run_pipeline, run_pipeline_cli
  from ocrmypdf._pipelines.pdf_to_hocr import run_hocr_pipeline
  from ocrmypdf._plugin_manager import get_plugin_manager
  from ocrmypdf._validation import check_options
  from ocrmypdf.cli import ArgumentParser, get_parser
  from ocrmypdf.helpers import is_iterable_notstr
label_desc: Use image node_id 4 for calling a global function with example usage: ocr(input_file, output_file) and returns: run_pipeline