class_docstr: This class is a wrapper over the Dataset component and can be used to create Examples
  for Blocks / Interfaces. Populates the Dataset component with examples and
  assigns event listener so that clicking on an example populates the input/output
  components. Optionally handles example caching for fast inference.
  
  Demos: blocks_inputs, fake_gan
  Guides: more-on-examples-and-flagging, using-hugging-face-integrations, image-classification-in-pytorch, image-classification-in-tensorflow, image-classification-with-vision-transformers, create-your-own-friends-with-a-gan
docstr: Parameters:
      examples: example inputs that can be clicked to populate specific components. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided but it should be within the directory with the python file running the gradio app. If there are multiple input components and a directory is provided, a log.csv file must be present in the directory to link corresponding inputs.
      inputs: the component or list of components corresponding to the examples
      outputs: optionally, provide the component or list of components corresponding to the output of the examples. Required if `cache_examples` is True.
      fn: optionally, provide the function to run to generate the outputs corresponding to the examples. Required if `cache_examples` is True.
      cache_examples: if True, caches examples for fast runtime. If True, then `fn` and `outputs` must be provided. If `fn` is a generator function, then the last yielded value will be used as the output.
      examples_per_page: how many examples to show per page.
      label: the label to use for the examples component (by default, "Examples")
      elem_id: an optional string that is assigned as the id of this component in the HTML DOM.
      run_on_click: if cache_examples is False, clicking on an example does not run the function when an example is clicked. Set this to True to run the function when an example is clicked. Has no effect if cache_examples is True.
      preprocess: if True, preprocesses the example input before running the prediction function and caching the output. Only applies if `cache_examples` is True.
      postprocess: if True, postprocesses the example output after running the prediction function and before caching. Only applies if `cache_examples` is True.
      api_name: Defines how the event associated with clicking on the examples appears in the API docs. Can be a string or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use the example function.
      batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. Used only if cache_examples is True.
docstr_tok: ["Parameters",":","examples",":","example","inputs","that","can","be","clicked","to","populate","specific","components",".","Should","be","nested","list",",","in","which","the","outer","list","consists","of","samples","and","each","inner","list","consists","of","an","input","corresponding","to","each","input","component",".","A","string","path","to","a","directory","of","examples","can","also","be","provided","but","it","should","be","within","the","directory","with","the","python","file","running","the","gradio","app",".","If","there","are","multiple","input","components","and","a","directory","is","provided",",","a","log.csv","file","must","be","present","in","the","directory","to","link","corresponding","inputs",".","inputs",":","the","component","or","list","of","components","corresponding","to","the","examples","outputs",":","optionally",",","provide","the","component","or","list","of","components","corresponding","to","the","output","of","the","examples",".","Required","if","`","cache_examples","`","is","True",".","fn",":","optionally",",","provide","the","function","to","run","to","generate","the","outputs","corresponding","to","the","examples",".","Required","if","`","cache_examples","`","is","True",".","cache_examples",":","if","True",",","caches","examples","for","fast","runtime",".","If","True",",","then","`","fn","`","and","`","outputs","`","must","be","provided",".","If","`","fn","`","is","a","generator","function",",","then","the","last","yielded","value","will","be","used","as","the","output",".","examples_per_page",":","how","many","examples","to","show","per","page",".","label",":","the","label","to","use","for","the","examples","component","(","by","default",",","``","Examples","''",")","elem_id",":","an","optional","string","that","is","assigned","as","the","id","of","this","component","in","the","HTML","DOM",".","run_on_click",":","if","cache_examples","is","False",",","clicking","on","an","example","does","not","run","the","function","when","an","example","is","clicked",".","Set","this","to","True","to","run","the","function","when","an","example","is","clicked",".","Has","no","effect","if","cache_examples","is","True",".","preprocess",":","if","True",",","preprocesses","the","example","input","before","running","the","prediction","function","and","caching","the","output",".","Only","applies","if","`","cache_examples","`","is","True",".","postprocess",":","if","True",",","postprocesses","the","example","output","after","running","the","prediction","function","and","before","caching",".","Only","applies","if","`","cache_examples","`","is","True",".","api_name",":","Defines","how","the","event","associated","with","clicking","on","the","examples","appears","in","the","API","docs",".","Can","be","a","string","or","False",".","If","set","to","a","string",",","the","endpoint","will","be","exposed","in","the","API","docs","with","the","given","name",".","If","False",",","the","endpoint","will","not","be","exposed","in","the","API","docs","and","downstream","apps","(","including","those","that","`","gr.load","`","this","app",")","will","not","be","able","to","use","the","example","function",".","batch",":","If","True",",","then","the","function","should","process","a","batch","of","inputs",",","meaning","that","it","should","accept","a","list","of","input","values","for","each","parameter",".","Used","only","if","cache_examples","is","True","."]
code: def __init__(
      self,
      examples: list[Any] | list[list[Any]] | str,
      inputs: Component | list[Component],
      outputs: Component | list[Component] | None = None,
      fn: Callable | None = None,
      cache_examples: bool = False,
      examples_per_page: int = 10,
      _api_mode: bool = False,
      label: str | None = "Examples",
      elem_id: str | None = None,
      run_on_click: bool = False,
      preprocess: bool = True,
      postprocess: bool = True,
      api_name: str | Literal[False] = "load_example",
      batch: bool = False,
      _initiated_directly: bool = True,
  ):
      """
      Parameters:
          examples: example inputs that can be clicked to populate specific components. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided but it should be within the directory with the python file running the gradio app. If there are multiple input components and a directory is provided, a log.csv file must be present in the directory to link corresponding inputs.
          inputs: the component or list of components corresponding to the examples
          outputs: optionally, provide the component or list of components corresponding to the output of the examples. Required if `cache_examples` is True.
          fn: optionally, provide the function to run to generate the outputs corresponding to the examples. Required if `cache_examples` is True.
          cache_examples: if True, caches examples for fast runtime. If True, then `fn` and `outputs` must be provided. If `fn` is a generator function, then the last yielded value will be used as the output.
          examples_per_page: how many examples to show per page.
          label: the label to use for the examples component (by default, "Examples")
          elem_id: an optional string that is assigned as the id of this component in the HTML DOM.
          run_on_click: if cache_examples is False, clicking on an example does not run the function when an example is clicked. Set this to True to run the function when an example is clicked. Has no effect if cache_examples is True.
          preprocess: if True, preprocesses the example input before running the prediction function and caching the output. Only applies if `cache_examples` is True.
          postprocess: if True, postprocesses the example output after running the prediction function and before caching. Only applies if `cache_examples` is True.
          api_name: Defines how the event associated with clicking on the examples appears in the API docs. Can be a string or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use the example function.
          batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. Used only if cache_examples is True.
      """
      if _initiated_directly:
          warnings.warn(
              "Please use gr.Examples(...) instead of gr.examples.Examples(...) to create the Examples.",
          )
  
      if cache_examples and (fn is None or outputs is None):
          raise ValueError(
              "If caching examples, `fn` and `outputs` must be provided"
          )
  
      if not isinstance(inputs, list):
          inputs = [inputs]
      if outputs and not isinstance(outputs, list):
          outputs = [outputs]
  
      working_directory = Path().absolute()
  
      if examples is None:
          raise ValueError("The parameter `examples` cannot be None")
      elif isinstance(examples, list) and (
          len(examples) == 0 or isinstance(examples[0], list)
      ):
          pass
      elif (
          isinstance(examples, list) and len(inputs) == 1
      ):  # If there is only one input component, examples can be provided as a regular list instead of a list of lists
          examples = [[e] for e in examples]
      elif isinstance(examples, str):
          if not Path(examples).exists():
              raise FileNotFoundError(
                  f"Could not find examples directory: {examples}"
              )
          working_directory = examples
          if not (Path(examples) / LOG_FILE).exists():
              if len(inputs) == 1:
                  examples = [[e] for e in os.listdir(examples)]
              else:
                  raise FileNotFoundError(
                      "Could not find log file (required for multiple inputs): "
                      + LOG_FILE
                  )
          else:
              with open(Path(examples) / LOG_FILE) as logs:
                  examples = list(csv.reader(logs))
                  examples = [
                      examples[i][: len(inputs)]
                      for i in range(1, len(examples))
                  ]  # remove header and unnecessary columns
  
      else:
          raise ValueError(
              "The parameter `examples` must either be a string directory or a list"
              "(if there is only 1 input component) or (more generally), a nested "
              "list, where each sublist represents a set of inputs."
          )
  
      input_has_examples = [False] * len(inputs)
      for example in examples:
          for idx, example_for_input in enumerate(example):
              if example_for_input is not None:
                  try:
                      input_has_examples[idx] = True
                  except IndexError:
                      pass  # If there are more example components than inputs, ignore. This can sometimes be intentional (e.g. loading from a log file where outputs and timestamps are also logged)
  
      inputs_with_examples = [
          inp for (inp, keep) in zip(inputs, input_has_examples) if keep
      ]
      non_none_examples = [
          [
              ex
              for (ex, keep) in zip(example, input_has_examples)
              if keep
          ]
          for example in examples
      ]
  
      self.examples = examples
      self.non_none_examples = non_none_examples
      self.inputs = inputs
      self.inputs_with_examples = inputs_with_examples
      self.outputs = outputs or []
      self.fn = fn
      self.cache_examples = cache_examples
      self._api_mode = _api_mode
      self.preprocess = preprocess
      self.postprocess = postprocess
      self.api_name: str | Literal[False] = api_name
      self.batch = batch
  
      with utils.set_directory(working_directory):
          self.processed_examples = []
          for example in examples:
              sub = []
              for component, sample in zip(inputs, example):
                  prediction_value = component.postprocess(sample)
                  if isinstance(
                      prediction_value, (GradioRootModel, GradioModel)
                  ):
                      prediction_value = prediction_value.model_dump()
                  prediction_value = (
                      processing_utils.move_files_to_cache(
                          prediction_value, component, postprocess=True
                      )
                  )
                  sub.append(prediction_value)
              self.processed_examples.append(sub)
  
      self.non_none_processed_examples = [
          [
              ex
              for (ex, keep) in zip(example, input_has_examples)
              if keep
          ]
          for example in self.processed_examples
      ]
      if cache_examples:
          for example in self.examples:
              if len([ex for ex in example if ex is not None]) != len(
                  self.inputs
              ):
                  warnings.warn(
                      "Examples are being cached but not all input components have "
                      "example values. This may result in an exception being thrown by "
                      "your function. If you do get an error while caching examples, make "
                      "sure all of your inputs have example values for all of your examples "
                      "or you provide default values for those particular parameters in your function."
                  )
                  break
  
      from gradio import components
  
      with utils.set_directory(working_directory):
          self.dataset = components.Dataset(
              components=inputs_with_examples,
              samples=non_none_examples,
              type="index",
              label=label,
              samples_per_page=examples_per_page,
              elem_id=elem_id,
          )
  
      self.cached_folder = utils.get_cache_folder() / str(
          self.dataset._id
      )
      self.cached_file = Path(self.cached_folder) / "log.csv"
      self.cache_examples = cache_examples
      self.run_on_click = run_on_click
  
imports: from __future__ import annotations
  import ast
  import csv
  import inspect
  import os
  import shutil
  import subprocess
  import tempfile
  import warnings
  from functools import partial
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, Optional
  import matplotlib.pyplot
  import numpy
  import PIL
  import PIL.Image
  from gradio_client import utils
  from gradio_client.documentation import document, set_documentation_group
  from matplotlib import animation
  from gradio import components, oauth, processing_utils, routes, utils, wasm_utils
  from gradio.context import Context, LocalContext
  from gradio.data_classes import GradioModel, GradioRootModel
  from gradio.events import EventData
  from gradio.exceptions import Error
  from gradio.flagging import CSVLogger
label_desc: Use image node_id 1 to create a new Examples object  with example: obj = Examples(examples, inputs, outputs, fn, cache_examples, examples_per_page, _api_mode, label, elem_id, run_on_click, preprocess, postprocess, api_name, batch, _initiated_directly)