code: import os
  import pathlib
  import tempfile
  import uuid
  
  import numpy as np
  
  from ..utils import is_soundfile_availble, is_torch_available, is_vision_available, logging
  
  
  _SCREAMING_SNAKE_CASE   						=    logging.get_logger(__name__)
  
  if is_vision_available():
       import PIL.Image
       from PIL import Image
       from PIL.Image import Image as ImageType
  else:
       _SCREAMING_SNAKE_CASE   						=    object
  
  if is_torch_available():
       import torch
  
  if is_soundfile_availble():
       import soundfile as sf
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				:
  
  
  
  
      def __init__(					self  :   Dict      ,      lowerCAmelCase  :   List[Any]   )	-> Optional[int]:
        a__     		=     value
  
  
  
  
      def __str__(					self  :   Optional[Any]   )	-> List[Any]:
        return self.to_string()
  
  
  
  
      def 						__lowerCamelCase (					self  :   Tuple   )	-> List[str]:
        logger.error(
            "This is a raw AgentType of unknown type. Display in notebooks and string conversion will be unreliable"   )
        return self._value
  
  
  
  
      def 						__lowerCamelCase (					self  :   List[str]   )	-> str:
        logger.error(
            "This is a raw AgentType of unknown type. Display in notebooks and string conversion will be unreliable"   )
        return str(self._value   )
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				(							_a     ,     _a    ):
  
  
  
  
      def 						__lowerCamelCase (					self  :   Union[str, Any]   )	-> str:
        return self._value
  
  
  
  
      def 						__lowerCamelCase (					self  :   int   )	-> str:
        return self._value
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				(							_a     ,     _a    ):
  
  
  
  
      def __init__(					self  :   List[str]      ,      lowerCAmelCase  :   List[str]   )	-> Optional[int]:
        super().__init__(lowerCAmelCase   )
  
        if not is_vision_available():
          raise ImportError("PIL must be installed in order to handle images."   )
  
        a__     		=     None
        a__     		=     None
        a__     		=     None
  
        if isinstance(lowerCAmelCase      ,      lowerCAmelCase   ):
          a__     		=     value
        elif isinstance(lowerCAmelCase      ,      (str, pathlib.Path)   ):
          a__     		=     value
        elif isinstance(lowerCAmelCase      ,      torch.Tensor   ):
          a__     		=     value
        else:
          raise ValueError(f"Unsupported type for {self.__class__.__name__}: {type(lowerCAmelCase   )}"   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   Tuple      ,      lowerCAmelCase  :   Tuple=None      ,      lowerCAmelCase  :   int=None   )	-> Dict:
        from IPython.display import Image, display
  
        display(Image(self.to_string()   )   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   Any   )	-> str:
        if self._raw is not None:
          return self._raw
  
        if self._path is not None:
          a__     		=     Image.open(self._path   )
          return self._raw
  
  
  
  
      def 						__lowerCamelCase (					self  :   Any   )	-> Union[str, Any]:
        if self._path is not None:
          return self._path
  
        if self._raw is not None:
          a__     		=     tempfile.mkdtemp()
          a__     		=     os.path.join(lowerCAmelCase      ,      str(uuid.uuida()   ) + ".png"   )
          self._raw.save(self._path   )
  
          return self._path
  
        if self._tensor is not None:
          a__     		=     self._tensor.cpu().detach().numpy()
  
          # There is likely simpler than load into image into save
          a__     		=     Image.fromarray((array * 255).astype(np.uinta   )   )
  
          a__     		=     tempfile.mkdtemp()
          a__     		=     os.path.join(lowerCAmelCase      ,      str(uuid.uuida()   ) + ".png"   )
  
          img.save(self._path   )
  
          return self._path
  
  
  
  
  
  
  
  class 					UpperCAmelCase_				(							_a    ):
  
  
  
  
      def __init__(					self  :   List[Any]      ,      lowerCAmelCase  :   int      ,      lowerCAmelCase  :   List[Any]=16000   )	-> str:
        super().__init__(lowerCAmelCase   )
  
        if not is_soundfile_availble():
          raise ImportError("soundfile must be installed in order to handle audio."   )
  
        a__     		=     None
        a__     		=     None
  
        a__     		=     samplerate
  
        if isinstance(lowerCAmelCase      ,      (str, pathlib.Path)   ):
          a__     		=     value
        elif isinstance(lowerCAmelCase      ,      torch.Tensor   ):
          a__     		=     value
        else:
          raise ValueError(f"Unsupported audio type: {type(lowerCAmelCase   )}"   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   List[str]      ,      lowerCAmelCase  :   Any=None      ,      lowerCAmelCase  :   Tuple=None   )	-> int:
        from IPython.display import Audio, display
  
        display(Audio(self.to_string()      ,      rate=self.samplerate   )   )
  
  
  
  
      def 						__lowerCamelCase (					self  :   Any   )	-> int:
        if self._tensor is not None:
          return self._tensor
  
        if self._path is not None:
          a__		,a__     		=     sf.read(self._path   )
          a__     		=     torch.tensor(lowerCAmelCase   )
          return self._tensor
  
  
  
  
      def 						__lowerCamelCase (					self  :   Union[str, Any]   )	-> Union[str, Any]:
        if self._path is not None:
          return self._path
  
        if self._tensor is not None:
          a__     		=     tempfile.mkdtemp()
          a__     		=     os.path.join(lowerCAmelCase      ,      str(uuid.uuida()   ) + ".wav"   )
          sf.write(self._path      ,      self._tensor      ,      samplerate=self.samplerate   )
          return self._path
  
  _SCREAMING_SNAKE_CASE   						=    {"""text""": AgentText, """image""": AgentImage, """audio""": AgentAudio}
  _SCREAMING_SNAKE_CASE   						=    {str: AgentText}
  
  if is_vision_available():
       _SCREAMING_SNAKE_CASE   						=    AgentImage
  def 				__lowercase	(						*lowerCamelCase__ ,				**lowerCamelCase__					)				->List[str]:
  
    '''simple docstring'''
  
  
  
  
    a__     		=     [(arg.to_raw() if isinstance(lowerCamelCase__ ,				lowerCamelCase__					) else arg) for arg in args]
    a__     		=     {k: (v.to_raw() if isinstance(lowerCamelCase__ ,				lowerCamelCase__					) else v) for k, v in kwargs.items()}
    return args, kwargs
  
  
  
  
  
  
  
  def 				__lowercase	(						lowerCamelCase__ ,				lowerCamelCase__=None					)				->Union[str, Any]:
  
    '''simple docstring'''
  
  
  
  
    if isinstance(lowerCamelCase__ ,				lowerCamelCase__					):
      a__     		=     {}
      for i, (k, v) in enumerate(outputs.items()					):
        if output_types is not None:
          # If the class has defined outputs, we can map directly according to the class definition
          if output_types[i] in AGENT_TYPE_MAPPING:
            a__     		=     AGENT_TYPE_MAPPING[output_types[i]](lowerCamelCase__					)
          else:
            a__     		=     AgentType(lowerCamelCase__					)
  
        else:
          # If the class does not have defined output, then we map according to the type
          for _k, _v in INSTANCE_TYPE_MAPPING.items():
            if isinstance(lowerCamelCase__ ,				_k					):
              a__     		=     _v(lowerCamelCase__					)
          if k not in decoded_outputs:
            a__     		=     AgentType[v]
  
    elif isinstance(lowerCamelCase__ ,				(list, tuple)					):
      a__     		=     type(lowerCamelCase__					)()
      for i, v in enumerate(lowerCamelCase__					):
        if output_types is not None:
          # If the class has defined outputs, we can map directly according to the class definition
          if output_types[i] in AGENT_TYPE_MAPPING:
            decoded_outputs.append(AGENT_TYPE_MAPPING[output_types[i]](lowerCamelCase__					)					)
          else:
            decoded_outputs.append(AgentType(lowerCamelCase__					)					)
        else:
          # If the class does not have defined output, then we map according to the type
          a__     		=     False
          for _k, _v in INSTANCE_TYPE_MAPPING.items():
            if isinstance(lowerCamelCase__ ,				_k					):
              decoded_outputs.append(_v(lowerCamelCase__					)					)
              a__     		=     True
  
          if not found:
            decoded_outputs.append(AgentType(lowerCamelCase__					)					)
  
    else:
      if output_types[0] in AGENT_TYPE_MAPPING:
        # If the class has defined outputs, we can map directly according to the class definition
        a__     		=     AGENT_TYPE_MAPPING[output_types[0]](lowerCamelCase__					)
  
      else:
        # If the class does not have defined output, then we map according to the type
        for _k, _v in INSTANCE_TYPE_MAPPING.items():
          if isinstance(lowerCamelCase__ ,				_k					):
            return _v(lowerCamelCase__					)
        return AgentType(lowerCamelCase__					)
  
    return decoded_outputs
  
  
style_context: from unittest.mock import patch
  
  import datasets
  from datasets import Dataset
  def 				__lowercase	(						)				->Union[str, Any]:
  
    '''simple docstring'''
  
  
  
  
    a__     		=     Dataset.from_dict({"col_1": [3, 2, 0, 1]}					)
  
    with patch("tqdm.auto.tqdm"					) as mock_tqdm:
      datasets.disable_progress_bar()
      dset.map(lambda lowerCamelCase__					: {"col_2": x["col_1"] + 1}					)
      mock_tqdm.assert_not_called()
  
      mock_tqdm.reset_mock()
  
      datasets.enable_progress_bar()
      dset.map(lambda lowerCamelCase__					: {"col_2": x["col_1"] + 1}					)
      mock_tqdm.assert_called()
  
  