code: def generate_local_files(
      num_shards: int,
      num_images_per_shard: Optional[int],
      shard_url: Optional[str],
      image_url: str,
      output_directory: str,
  ) -> None:
      if not os.path.exists(output_directory):
          os.makedirs(output_directory)
      for filename in os.listdir(output_directory):
          os.remove(os.path.join(output_directory, filename))
  
      print(
          f"Creating a tfrecord dataset with {num_shards} shards, {num_images_per_shard} images per shard, in the output directory {output_directory}"  # noqa: E501
      )
  
      def gen_filename(i: int, total: int) -> str:
          return os.path.join(
              output_directory,
              f"single-image-repeated-{i:05d}-of-{total:05d}",
          )
  
      filenames = [
          gen_filename(i, num_shards) for i in range(num_shards)
      ]
  
      if num_images_per_shard:
          single_example = create_single_example(
              image_url
          ).SerializeToString()
          write_shard(
              filenames[0], single_example, num_images_per_shard
          )
      elif shard_url:
          download_single_shard(shard_url, filenames[0])
  
      bcast_single_shard(filenames[0], filenames[1:])
  
imports: from typing import Union, Iterable, Tuple, Optional
  import os
  import requests
  import shutil
  import sys
  import tensorflow.compat.v1
  import time
  from ray.util.scheduling_strategies import NodeAffinitySchedulingStrategy
  import ray
label_desc: Use image node_id 2 for calling a global function with example usage: generate_local_files(num_shards, num_images_per_shard, shard_url, image_url, output_directory) and returns: os