class_docstr: Displays text that contains spans that are highlighted by category or numerical value.
  Preprocessing: passes a list of tuples as a {List[Tuple[str, float | str | None]]]} into the function. If no labels are provided, the text will be displayed as a single span.
  Postprocessing: expects a {List[Tuple[str, float | str]]]} consisting of spans of text and their associated labels, or a {Dict} with two keys: (1) "text" whose value is the complete text, and (2) "entities", which is a list of dictionaries, each of which have the keys: "entity" (consisting of the entity label, can alternatively be called "entity_group"), "start" (the character index where the label starts), and "end" (the character index where the label ends). Entities should not overlap.
  
  Demos: diff_texts, text_analysis
  Guides: named-entity-recognition
class_docstr_tok: ["Displays","text","that","contains","spans","that","are","highlighted","by","category","or","numerical","value",".","Preprocessing",":","passes","a","list","of","tuples","as","a","{","List","[","Tuple","[","str",",","float","|","str","|","None","]","]","]","}","into","the","function",".","If","no","labels","are","provided",",","the","text","will","be","displayed","as","a","single","span",".","Postprocessing",":","expects","a","{","List","[","Tuple","[","str",",","float","|","str","]","]","]","}","consisting","of","spans","of","text","and","their","associated","labels",",","or","a","{","Dict","}","with","two","keys",":","(","1",")","``","text","''","whose","value","is","the","complete","text",",","and","(","2",")","``","entities","''",",","which","is","a","list","of","dictionaries",",","each","of","which","have","the","keys",":","``","entity","''","(","consisting","of","the","entity","label",",","can","alternatively","be","called","``","entity_group","''",")",",","``","start","''","(","the","character","index","where","the","label","starts",")",",","and","``","end","''","(","the","character","index","where","the","label","ends",")",".","Entities","should","not","overlap",".","Demos",":","diff_texts",",","text_analysis","Guides",":","named-entity-recognition"]
docstr: Parameters:
      value: List of (word, category) tuples, or a dictionary of two keys: "text", and "entities", which itself is a list of dictionaries, each of which have the keys: "entity" (or "entity_group"), "start", and "end"
  Returns:
      List of (word, category) tuples
docstr_tok: ["Parameters",":","value",":","List","of","(","word",",","category",")","tuples",",","or","a","dictionary","of","two","keys",":","``","text","''",",","and","``","entities","''",",","which","itself","is","a","list","of","dictionaries",",","each","of","which","have","the","keys",":","``","entity","''","(","or","``","entity_group","''",")",",","``","start","''",",","and","``","end","''","Returns",":","List","of","(","word",",","category",")","tuples"]
code: def postprocess(
      self, value: list[tuple[str, str | float | None]] | dict | None
  ) -> HighlightedTextData | None:
      """
      Parameters:
          value: List of (word, category) tuples, or a dictionary of two keys: "text", and "entities", which itself is a list of dictionaries, each of which have the keys: "entity" (or "entity_group"), "start", and "end"
      Returns:
          List of (word, category) tuples
      """
      if value is None:
          return None
      if isinstance(value, dict):
          try:
              text = value["text"]
              entities = value["entities"]
          except KeyError as ke:
              raise ValueError(
                  "Expected a dictionary with keys 'text' and 'entities' "
                  "for the value of the HighlightedText component."
              ) from ke
          if len(entities) == 0:
              value = [(text, None)]
          else:
              list_format = []
              index = 0
              entities = sorted(entities, key=lambda x: x["start"])
              for entity in entities:
                  list_format.append(
                      (text[index : entity["start"]], None)
                  )
                  entity_category = entity.get("entity") or entity.get(
                      "entity_group"
                  )
                  list_format.append(
                      (
                          text[entity["start"] : entity["end"]],
                          entity_category,
                      )
                  )
                  index = entity["end"]
              list_format.append((text[index:], None))
              value = list_format
      if self.combine_adjacent:
          output = []
          running_text, running_category = None, None
          for text, category in value:
              if running_text is None:
                  running_text = text
                  running_category = category
              elif category == running_category:
                  running_text += self.adjacent_separator + text
              elif not text:
                  # Skip fully empty item, these get added in processing
                  # of dictionaries.
                  pass
              else:
                  output.append((running_text, running_category))
                  running_text = text
                  running_category = category
          if running_text is not None:
              output.append((running_text, running_category))
          return HighlightedTextData(
              root=[
                  HighlightedToken(token=o[0], class_or_confidence=o[1])
                  for o in output
              ]
          )
      else:
          return HighlightedTextData(
              root=[
                  HighlightedToken(token=o[0], class_or_confidence=o[1])
                  for o in value
              ]
          )
  
file_path: gradio/gradio/components/highlighted_text.py
imports: from __future__ import annotations
  from typing import Any, Callable, List, Union
  from gradio_client.documentation import document, set_documentation_group
  from gradio.components.base import Component
  from gradio.data_classes import GradioModel, GradioRootModel
  from gradio.events import Events
label_desc: Use image node_id 3 for calling the HighlightedText obj's underlying member method code with example usage: obj.postprocess(value) and returns: None, HighlightedTextData, HighlightedTextData