class_docstr: WIT widget for colab.
class_docstr_tok: ["WIT","widget","for","colab","."]
code: def infer(self):
      try:
          inferences = base.WitWidgetBase.infer_impl(self)
          # Parse out the inferences from the returned structure and empty the
          # structure of contents, keeping its nested structure.
          # Chunks of the inference results will be sent to the front-end and
          # re-assembled.
          indices = inferences["inferences"]["indices"][:]
          inferences["inferences"]["indices"] = []
          res2 = []
          extra = {}
          extra2 = {}
          model_inference = inferences["inferences"]["results"][0]
          if (
              "extra_outputs" in inferences
              and len(inferences["extra_outputs"])
              and inferences["extra_outputs"][0]
          ):
              for key in inferences["extra_outputs"][0]:
                  extra[key] = inferences["extra_outputs"][0][key][:]
                  inferences["extra_outputs"][0][key] = []
          if "classificationResult" in model_inference:
              res = model_inference["classificationResult"][
                  "classifications"
              ][:]
              model_inference["classificationResult"][
                  "classifications"
              ] = []
          else:
              res = model_inference["regressionResult"]["regressions"][
                  :
              ]
              model_inference["regressionResult"]["regressions"] = []
  
          if len(inferences["inferences"]["results"]) > 1:
              if (
                  "extra_outputs" in inferences
                  and len(inferences["extra_outputs"]) > 1
                  and inferences["extra_outputs"][1]
              ):
                  for key in inferences["extra_outputs"][1]:
                      extra2[key] = inferences["extra_outputs"][1][key][
                          :
                      ]
                      inferences["extra_outputs"][1][key] = []
              model_2_inference = inferences["inferences"]["results"][1]
              if "classificationResult" in model_2_inference:
                  res2 = model_2_inference["classificationResult"][
                      "classifications"
                  ][:]
                  model_2_inference["classificationResult"][
                      "classifications"
                  ] = []
              else:
                  res2 = model_2_inference["regressionResult"][
                      "regressions"
                  ][:]
                  model_2_inference["regressionResult"][
                      "regressions"
                  ] = []
  
          i = 0
          num_pieces = math.ceil(len(indices) / self.SLICE_SIZE)
  
          # Loop over each piece to send.
          while num_pieces > 0:
              num_pieces -= 1
              piece = [res[i : i + self.SLICE_SIZE]]
              extra_piece = [{}]
              for key in extra:
                  extra_piece[0][key] = extra[key][
                      i : i + self.SLICE_SIZE
                  ]
              if res2:
                  piece.append(res2[i : i + self.SLICE_SIZE])
                  extra_piece.append({})
                  for key in extra2:
                      extra_piece[1][key] = extra2[key][
                          i : i + self.SLICE_SIZE
                      ]
              ind_piece = indices[i : i + self.SLICE_SIZE]
              data = {
                  "results": piece,
                  "indices": ind_piece,
                  "extra": extra_piece,
                  "countdown": num_pieces,
              }
              # For the first segment to send, also send the blank inferences
              # structure to be filled in. This was cleared of contents above but is
              # used to maintain the nested structure of the results.
              if i == 0:
                  data["inferences"] = inferences
              output.eval_js(
                  """inferenceCallback({data})""".format(
                      data=json.dumps(data)
                  )
              )
              i += self.SLICE_SIZE
      except Exception as e:
          output.eval_js(
              """backendError({error})""".format(
                  error=json.dumps({"msg": repr(e)})
              )
          )
  
imports: import json
  import math
  import tensorflow
  from IPython import display
  from google.colab import output
  from witwidget.notebook import base
label_desc: Use image node_id 6 for calling the WitWidget obj's underlying member method code with example usage: obj.infer() without return types