code: def gen_public_api(
      output_dir: str,
      output_package: str,
      root_init_template: str,
      api_version: int,
      compat_api_versions: Sequence[int],
      compat_init_templates: Sequence[str],
      use_lazy_loading: bool,
      file_prefixes_to_strip: Sequence[str],
      mapping_files: Sequence[str],
      packages_to_ignore: Sequence[str],
      module_prefix: str,
      root_file_name: str,
      output_files: Set[str],
  ):
      """Generates the public API for tensorflow.
  
      Args:
        output_dir: The directory to output the files to.
        output_package: The package to use for the imports.
        root_init_template: The template for the root init file.
        api_version: The version of the API to generate.
        compat_api_versions: The versions of the compat APIs to generate.
        compat_init_templates: The templates for the compat init files.
        use_lazy_loading: Whether to use lazy loading or not.
        file_prefixes_to_strip: The prefixes to strip from the file names of the
          imports.
        mapping_files: The mapping files created by the API Extractor.
        packages_to_ignore: A list of python packages that should be ignored when
          searching for tf_exports.
        module_prefix: A prefix to add to the non-generated imports.
        root_file_name: The file name that should be generated for the top level
          API.
        output_files: List of files expected to generate.
      """
      public_api = get_public_api(
          mapping_files,
          file_prefixes_to_strip,
          packages_to_ignore,
          output_package,
          module_prefix,
      )
  
      root_entrypoints_by_module = public_api.v2_entrypoints_by_module
      root_generated_imports_by_module = (
          public_api.v2_generated_imports_by_module
      )
      if api_version == 1:
          root_entrypoints_by_module = (
              public_api.v1_entrypoints_by_module
          )
          root_generated_imports_by_module = (
              public_api.v1_generated_imports_by_module
          )
  
      for compat_version in compat_api_versions:
          compat_package = f"{output_package}.compat"
          compat_version_package = f"{compat_package}.v{compat_version}"
          public_api.v2_generated_imports_by_module[compat_package].add(
              compat_version_package
          )
          public_api.v1_generated_imports_by_module[compat_package].add(
              compat_version_package
          )
  
      _gen_init_files(
          output_dir,
          output_package,
          api_version,
          root_entrypoints_by_module,
          root_generated_imports_by_module,
          public_api.docs_by_module,
          root_init_template,
          file_prefixes_to_strip,
          use_lazy_loading,
          module_prefix,
          output_files,
          root_file_name=root_file_name,
      )
  
      for compat_index, compat_version in enumerate(
          compat_api_versions
      ):
          compat_output_dir = os.path.join(
              output_dir, "compat", f"v{compat_version}"
          )
          os.makedirs(compat_output_dir, exist_ok=True)
          compat_version = int(compat_version)
  
          compat_entrypoints_by_module = (
              public_api.v2_entrypoints_by_module
          )
          compat_generated_imports_by_module = (
              public_api.v2_generated_imports_by_module
          )
          if compat_version == 1:
              compat_entrypoints_by_module = (
                  public_api.v1_entrypoints_by_module
              )
              compat_generated_imports_by_module = (
                  public_api.v1_generated_imports_by_module
              )
  
          _gen_init_files(
              compat_output_dir,
              output_package,
              compat_version,
              compat_entrypoints_by_module,
              compat_generated_imports_by_module,
              public_api.docs_by_module,
              compat_init_templates[compat_index]
              if compat_init_templates
              else "",
              file_prefixes_to_strip,
              use_lazy_loading,
              module_prefix,
              output_files,
              subpackage_rewrite=f"{output_package}.compat.v{compat_version}",
          )
  
          for nested_compat_index, nested_compat_version in enumerate(
              compat_api_versions
          ):
              nested_compat_version = int(nested_compat_version)
              nested_compat_output_dir = os.path.join(
                  compat_output_dir,
                  "compat",
                  f"v{nested_compat_version}",
              )
              nested_compat_entrypoints_by_module = (
                  public_api.v2_entrypoints_by_module
              )
              nested_compat_generated_imports_by_module = (
                  public_api.v2_generated_imports_by_module
              )
              if nested_compat_version == 1:
                  nested_compat_entrypoints_by_module = (
                      public_api.v1_entrypoints_by_module
                  )
                  nested_compat_generated_imports_by_module = (
                      public_api.v1_generated_imports_by_module
                  )
              os.makedirs(nested_compat_output_dir, exist_ok=True)
              gen_nested_compat_files(
                  nested_compat_output_dir,
                  output_package,
                  nested_compat_version,
                  nested_compat_entrypoints_by_module,
                  nested_compat_generated_imports_by_module,
                  public_api.docs_by_module,
                  compat_init_templates[nested_compat_index]
                  if compat_init_templates
                  else "",
                  file_prefixes_to_strip,
                  use_lazy_loading,
                  compat_api_versions,
                  module_prefix,
                  output_files,
              )
  
imports: import collections
  from collections.abc import Mapping, Sequence, Set
  import dataclasses
  import os
  from typing import Optional
  from absl import app
  from absl import flags
  from tensorflow.python.tools.api.generator2.shared import exported_api
label_desc: Use image node_id 8 for calling a global function with example usage: gen_public_api(output_dir, output_package, root_init_template, api_version, compat_api_versions, compat_init_templates, use_lazy_loading, file_prefixes_to_strip, mapping_files, packages_to_ignore, module_prefix, root_file_name, output_files) without return types