class_docstr: LIT WSGI application.
class_docstr_tok: ["LIT","WSGI","application","."]
docstr: Convenience wrapper to handle args and serialization.
  
  This is a thin shim between server (handler, request, environ) and model
  logic (inputs, args, outputs).
  
  Args:
    fn: function (JsonDict, **kw) -> JsonDict
  
  Returns:
    fn wrapped as a request handler
code: def make_handler(self, fn):
      """Convenience wrapper to handle args and serialization.
  
      This is a thin shim between server (handler, request, environ) and model
      logic (inputs, args, outputs).
  
      Args:
        fn: function (JsonDict, **kw) -> JsonDict
  
      Returns:
        fn wrapped as a request handler
      """
  
      @functools.wraps(fn)
      def _handler(app: wsgi_app.App, request, environ):
          kw = request.args.to_dict()
          # The frontend needs "simple" data (e.g. NumPy arrays converted to lists),
          # but for requests from Python we may want to use the invertible encoding
          # so that datatypes from remote models are the same as local ones.
          response_simple_json = utils.coerce_bool(
              kw.pop("response_simple_json", True)
          )
          data = (
              serialize.from_json(request.data)
              if len(request.data)
              else None
          )
          # Special handling to dereference IDs.
          if (
              data
              and "inputs" in data.keys()
              and len(data.get("inputs"))
              and "dataset_name" in kw
          ):
              data["inputs"] = self._reconstitute_inputs(
                  data["inputs"], kw["dataset_name"]
              )
              # Validate that id and data._id match.
              # TODO(b/171513556): consider removing this if we can simplify the
              # data representation on the frontend so id and meta are not replicated.
              for ex in data["inputs"]:
                  if ex["id"] != ex["data"].get("_id"):
                      raise ValueError(
                          "Error: malformed example with inconsistent ids:"
                          f" {str(ex)}\nfrom request"
                          f" {request.path} {str(request.args.to_dict())}"
                      )
  
          outputs = fn(data, **kw)
          response_body = serialize.to_json(
              outputs, simple=response_simple_json
          )
          return app.respond(
              request, response_body, "application/json", 200
          )
  
      return _handler
  
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 23 for calling the LitApp obj's underlying member method code with example usage: obj.make_handler(fn) and returns: _handler, app