class_docstr: LIT WSGI application.
class_docstr_tok: ["LIT","WSGI","application","."]
docstr: Build metadata from model and dataset specs.
docstr_tok: ["Build","metadata","from","model","and","dataset","specs","."]
code: def _build_metadata(self):
      """Build metadata from model and dataset specs."""
      model_info = {}
      for name, model in self._models.items():
          info = {
              "description": model.description(),
              "spec": {
                  "input": model.input_spec(),
                  "output": model.output_spec(),
              },
          }
  
          # List compatible datasets.
          info["datasets"] = [
              name
              for name, dataset in self._datasets.items()
              if model.is_compatible_with_dataset(dataset)
          ]
          if (
              len(info["datasets"]) == 0
          ):  # pylint: disable=g-explicit-length-test
              logging.error(
                  "Error: model '%s' has no compatible datasets!", name
              )
  
          compat_gens: set[str] = set()
          compat_interps: set[str] = set()
          compat_metrics: set[str] = set()
  
          for d in info["datasets"]:
              dataset: lit_dataset.Dataset = self._datasets[d]
              compat_gens.update(
                  _get_compatible_names(
                      self._generators, model, dataset
                  )
              )
              compat_interps.update(
                  _get_compatible_names(
                      self._interpreters, model, dataset
                  )
              )
              compat_metrics.update(
                  _get_compatible_names(self._metrics, model, dataset)
              )
  
          info["generators"] = [
              name
              for name in self._generators.keys()
              if name in compat_gens
          ]
          info["interpreters"] = [
              name
              for name in self._interpreters.keys()
              if name in compat_interps
          ]
          info["metrics"] = [
              name
              for name in self._metrics.keys()
              if name in compat_metrics
          ]
          model_info[name] = info
  
      dataset_info = {}
      for name, ds in self._datasets.items():
          dataset_info[name] = {
              "spec": ds.spec(),
              "description": ds.description(),
              "size": len(ds),
          }
  
      generator_info: Mapping[str, ComponentInfo] = {
          name: _get_component_info(gen)
          for name, gen in self._generators.items()
      }
  
      interpreter_info: Mapping[str, ComponentInfo] = {
          name: _get_component_info(interp)
          for name, interp in self._interpreters.items()
      }
  
      metrics_info: Mapping[str, ComponentInfo] = {
          name: _get_component_info(metric)
          for name, metric in self._metrics.items()
      }
  
      init_specs = {
          "datasets": {
              n: s for n, (_, s) in self._dataset_loaders.items()
          },
          "models": {n: s for n, (_, s) in self._model_loaders.items()},
      }
  
      return {
          # Component info and specs
          "models": model_info,
          "datasets": dataset_info,
          "generators": generator_info,
          "interpreters": interpreter_info,
          "metrics": metrics_info,
          "layouts": self._layouts,
          # Global configuration
          "demoMode": self._demo_mode,
          "defaultLayout": self._default_layout,
          "canonicalURL": self._canonical_url,
          "pageTitle": self._page_title,
          "inlineDoc": self._inline_doc,
          "onboardStartDoc": self._onboard_start_doc,
          "onboardEndDoc": self._onboard_end_doc,
          "syncState": self.ui_state_tracker is not None,
          "initSpecs": init_specs,
      }
  
imports: from collections.abc import Callable, Iterable, Mapping, Sequence
  import functools
  import glob
  import math
  import os
  import random
  import threading
  import time
  from typing import Any, Optional, TypedDict, Union
  from absl import logging
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import layout
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.components import core
  from lit_nlp.lib import caching
  from lit_nlp.lib import flag_helpers
  from lit_nlp.lib import serialize
  from lit_nlp.lib import ui_state
  from lit_nlp.lib import utils
  from lit_nlp.lib import validation
  from lit_nlp.lib import wsgi_app
  import tqdm
label_desc: Use image node_id 1 for calling the LitApp obj's underlying member method code with example usage: obj._build_metadata() and returns: dict