code: def _pages_from_ranges(ranges: str) -> set[int]:
      pages: list[int] = []
      page_groups = ranges.replace(" ", "").split(",")
      for group in page_groups:
          if not group:
              continue
          try:
              start, end = group.split("-")
          except ValueError:
              pages.append(int(group) - 1)
          else:
              try:
                  new_pages = list(range(int(start) - 1, int(end)))
                  if not new_pages:
                      raise BadArgsError(
                          f"invalid page subrange '{start}-{end}'"
                      ) from None
                  pages.extend(new_pages)
              except ValueError:
                  raise BadArgsError(
                      f"invalid page subrange '{group}'"
                  ) from None
  
      if not pages:
          raise BadArgsError(
              f"The string of page ranges '{ranges}' did not contain any recognizable "
              f"page ranges."
          )
  
      if not monotonic(pages):
          log.warning(
              "List of pages to process contains duplicate pages, or pages that are "
              "out of order"
          )
      if any(page < 0 for page in pages):
          raise BadArgsError(
              "pages refers to a page number less than 1"
          )
  
      log.debug("OCRing only these pages: %s", pages)
      return set(pages)
  
imports: from __future__ import annotations
  import locale
  import logging
  import os
  import sys
  import unicodedata
  from argparse import Namespace
  from collections.abc import Sequence
  from pathlib import Path
  from shutil import copyfileobj
  import pikepdf
  import PIL
  from pluggy import PluginManager
  from ocrmypdf._exec import unpaper
  from ocrmypdf.exceptions import BadArgsError, InputFileError, MissingDependencyError, OutputFileAccessError
  from ocrmypdf.helpers import is_file_writable, monotonic, safe_symlink
  from ocrmypdf.subprocess import check_external_program
label_desc: Use image node_id 7 for calling a global function with example usage: _pages_from_ranges(ranges) and returns: set