code: def main(argv: Sequence[str]) -> Optional[dev_server.LitServerType]:
      if len(argv) > 1:
          raise app.UsageError("Too many command-line arguments.")
      ##
      # Load models. You can specify several here, if you want to compare different
      # models side-by-side, and can also include models of different types that use
      # different datasets.
      base_models = {}
      for model_string in _MODELS.value:
          # Only split on the first ':', because path may be a URL
          # containing 'https://'
          model_name, path = model_string.split(":", 1)
          if path.startswith("SavedModel"):
              saved_model_path = path.split(":", 1)[1]
              base_models[model_name] = t5.T5SavedModel(
                  saved_model_path
              )
          else:
              # TODO(lit-dev): attention is temporarily disabled, because O(n^2) between
              # tokens in a long document can get very, very large. Re-enable once we
              # can send this to the frontend more efficiently.
              base_models[model_name] = t5.T5HFModel(
                  model_name_or_path=path,
                  num_to_generate=_NUM_TO_GEN.value,
                  token_top_k=_TOKEN_TOP_K.value,
                  output_attention=False,
              )
  
      model_loaders: lit_app.ModelLoadersMap = {
          "T5 summarization": (
              t5.T5Summarization,
              t5.T5Summarization.init_spec(),
          ),
          "T5 translation": (
              t5.T5Translation,
              t5.T5Translation.init_spec(),
          ),
      }
  
      ##
      # Load eval sets and model wrappers for each task.
      # Model wrappers share the same in-memory T5 model, but add task-specific pre-
      # and post-processing code.
      models = {}
      datasets = {}
      dataset_loaders: lit_app.DatasetLoadersMap = {}
      if "summarization" in _TASKS.value:
          for k, m in base_models.items():
              models[k + "_summarization"] = t5.SummarizationWrapper(m)
          if _CNNDM_VALIDATION_HOSTED in _HOSTED_DATASETS.value:
              datasets["CNNDM"] = summarization.CNNDMData(
                  filepath=_CNNDM_VALIDATION_HOSTED_URL
              )
          else:
              datasets["CNNDM"] = summarization.CNNDMData(
                  split="validation", max_examples=_MAX_EXAMPLES.value
              )
  
          dataset_loaders["CNN DailyMail"] = (
              summarization.CNNDMData,
              summarization.CNNDMData.init_spec(),
          )
  
      if "mt" in _TASKS.value:
          for k, m in base_models.items():
              models[k + "_translation"] = t5.TranslationWrapper(m)
  
          if _WMT14_DE_EN_HOSTED in _HOSTED_DATASETS.value:
              datasets["wmt14_ende"] = mt.WMT14Data(
                  version="de-en",
                  reverse=True,
                  filepath=_WMT14_DE_EN_HOSTED_URL,
              )
          else:
              datasets["wmt14_ende"] = mt.WMT14Data(
                  version="de-en", reverse=True
              )
  
          if _WMT14_FR_EN_HOSTED in _HOSTED_DATASETS.value:
              datasets["wmt14_enfr"] = mt.WMT14Data(
                  version="fr-en",
                  reverse=True,
                  filepath=_WMT14_FR_EN_HOSTED_URL,
              )
          else:
              datasets["wmt14_enfr"] = mt.WMT14Data(
                  version="fr-en", reverse=True
              )
  
          dataset_loaders["WMT 14"] = (
              mt.WMT14Data,
              mt.WMT14Data.init_spec(),
          )
  
      # Truncate datasets if --max_examples is set.
      for name in datasets:
          logging.info(
              "Dataset: '%s' with %d examples",
              name,
              len(datasets[name]),
          )
          datasets[name] = datasets[name].slice[: _MAX_EXAMPLES.value]
          logging.info(
              "  truncated to %d examples", len(datasets[name])
          )
  
      ##
      # We can also add custom components. Generators are used to create new
      # examples by perturbing or modifying existing ones.
      generators = {
          # Word-substitution, like "great" -> "terrible"
          "word_replacer": word_replacer.WordReplacer(),
      }
  
      if _USE_INDEXER.value:
          indexer = build_indexer(models)
          # Wrap the indexer into a Generator component that we can query.
          generators[
              "similarity_searcher"
          ] = similarity_searcher.SimilaritySearcher(indexer=indexer)
  
      ##
      # Actually start the LIT server, using the models, datasets, and other
      # components constructed above.
      lit_demo = dev_server.Server(
          models,
          datasets,
          generators=generators,
          model_loaders=model_loaders,
          dataset_loaders=dataset_loaders,
          **server_flags.get_flags(),
      )
      return lit_demo.serve()
  
imports: from collections.abc import Sequence
  import sys
  from typing import Optional
  from absl import app
  from absl import flags
  from absl import logging
  from lit_nlp import app
  from lit_nlp import dev_server
  from lit_nlp import server_flags
  from lit_nlp.api import dataset
  from lit_nlp.components import index
  from lit_nlp.components import similarity_searcher
  from lit_nlp.components import word_replacer
  from lit_nlp.examples.datasets import mt
  from lit_nlp.examples.datasets import summarization
  from lit_nlp.examples.models import t5
  from lit_nlp.lib import caching
label_desc: Use image node_id 3 for calling a global function with example usage: main(argv) and returns: lit_demo