code: def sort_rotated_text(page_blocks, tolerance=1.25):
      vertical_groups = {}
      for block in page_blocks:
          group_key = round(block.bbox[1] / tolerance) * tolerance
          if group_key not in vertical_groups:
              vertical_groups[group_key] = []
          vertical_groups[group_key].append(block)
  
      # Sort each group horizontally and flatten the groups into a single list
      sorted_page_blocks = []
      for _, group in sorted(vertical_groups.items()):
          sorted_group = sorted(group, key=lambda x: x.bbox[0])
          sorted_page_blocks.extend(sorted_group)
  
      return sorted_page_blocks
  
file_path: pdf-to-markdown/marker/extract_text.py
imports: import os
  from typing import Tuple, List, Optional
  from spellchecker import SpellChecker
  from marker.bbox import correct_rotation
  from marker.ocr.page import ocr_entire_page
  from marker.ocr.utils import detect_bad_ocr, font_flags_decomposer
  from marker.settings import settings
  from marker.schema import Span, Line, Block, Page
  from concurrent.futures import ThreadPoolExecutor
label_desc: Use image node_id 1 for calling a global function with example usage: sort_rotated_text(page_blocks, tolerance) and returns: sorted_page_blocks