code: def replace_bidirectional(
      texts: Union[str, List[str]],
      granularity: str = "all",
      split_word: bool = False,
      metadata: Optional[List[Dict[str, Any]]] = None,
  ) -> Union[str, List[str]]:
      """
      Reverses each word (or part of the word) in each input text and uses
      bidirectional marks to render the text in its original order. It reverses
      each word separately which keeps the word order even when a line wraps
  
      @param texts: a string or a list of text documents to be augmented
  
      @param granularity: the level at which the font is applied; this must be either
          'word' or 'all'
  
      @param split_word: if true and granularity is 'word', reverses only the second
          half of each word
  
      @param metadata: if set to be a list, metadata about the function execution
          including its name, the source & dest length, etc. will be appended to
          the inputted list. If set to None, no metadata will be appended or returned
  
      @returns: the list of augmented texts
      """
      func_kwargs = txtutils.get_func_kwargs(metadata, locals())
  
      bidirectional_aug = a.BidirectionalAugmenter(
          granularity, split_word
      )
      aug_texts = bidirectional_aug.augment(texts)
  
      txtutils.get_metadata(
          metadata=metadata,
          function_name="replace_bidirectional",
          aug_texts=aug_texts,
          **func_kwargs,
      )
  
      return aug_texts
  
imports: from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Union
  from augly.text import augmenters, utils
  from augly.utils import CONTRACTIONS_MAPPING, FUN_FONTS_PATH, GENDERED_WORDS_MAPPING, MISSPELLING_DICTIONARY_PATH, UNICODE_MAPPING_PATH
label_desc: Use image node_id 10 for calling a global function with example usage: replace_bidirectional(texts, granularity, split_word, metadata) and returns: aug_texts