





import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter







class 						_lowerCAmelCase(						TensorFormatter[Mapping, np.ndarray, Mapping]):

  """simple docstring"""







  def __init__( self  ,    UpperCAmelCase=None  ,    **UpperCAmelCase     )-> int:
     super().__init__(features=UpperCAmelCase     )
     __A				 =       np_array_kwargs

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Dict:
     if isinstance(UpperCAmelCase  ,    UpperCAmelCase     ):
        if column and all(
            isinstance(UpperCAmelCase  ,    np.ndarray     ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column     ):
           return np.stack(UpperCAmelCase     )
        else:
           # don't use np.array(column, dtype=object)
           # since it fails in certain cases
           # see https://stackoverflow.com/q/51005699
           __A				 =       np.empty(len(UpperCAmelCase     )  ,    dtype=UpperCAmelCase     )
           __A				 =       column
           return out
     return column

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> List[str]:
     if isinstance(UpperCAmelCase  ,    (str, bytes, type(UpperCAmelCase     ))     ):
        return value
     elif isinstance(UpperCAmelCase  ,    (np.character, np.ndarray)     ) and np.issubdtype(value.dtype  ,    np.character     ):
        return value
     elif isinstance(UpperCAmelCase  ,    np.number     ):
        return value

     __A				 =       {}

     if isinstance(UpperCAmelCase  ,    np.ndarray     ) and np.issubdtype(value.dtype  ,    np.integer     ):
        __A				 =       {'''dtype''': np.intaa}
     elif isinstance(UpperCAmelCase  ,    np.ndarray     ) and np.issubdtype(value.dtype  ,    np.floating     ):
        __A				 =       {'''dtype''': np.floataa}
     elif config.PIL_AVAILABLE and "PIL" in sys.modules:
        import PIL.Image

        if isinstance(UpperCAmelCase  ,    PIL.Image.Image     ):
           return np.asarray(UpperCAmelCase  ,    **self.np_array_kwargs     )

     return np.asarray(UpperCAmelCase  ,    **{**default_dtype, **self.np_array_kwargs}     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Tuple:
     # support for torch, tf, jax etc.
     if config.TORCH_AVAILABLE and "torch" in sys.modules:
        import torch

        if isinstance(UpperCAmelCase  ,    torch.Tensor     ):
           return self._tensorize(data_struct.detach().cpu().numpy()[()]     )
     if hasattr(UpperCAmelCase  ,    '''__array__'''     ) and not isinstance(UpperCAmelCase  ,    (np.ndarray, np.character, np.number)     ):
        __A				 =       data_struct.__array__()
     # support for nested types like struct of list of struct
     if isinstance(UpperCAmelCase  ,    np.ndarray     ):
        if data_struct.dtype == object:
           return self._consolidate([self.recursive_tensorize(UpperCAmelCase     ) for substruct in data_struct]     )
     if isinstance(UpperCAmelCase  ,    (list, tuple)     ):
        return self._consolidate([self.recursive_tensorize(UpperCAmelCase     ) for substruct in data_struct]     )
     return self._tensorize(UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> List[Any]:
     return map_nested(self._recursive_tensorize  ,    UpperCAmelCase  ,    map_list=UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Mapping:
     __A				 =       self.numpy_arrow_extractor().extract_row(UpperCAmelCase     )
     __A				 =       self.python_features_decoder.decode_row(UpperCAmelCase     )
     return self.recursive_tensorize(UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> np.ndarray:
     __A				 =       self.numpy_arrow_extractor().extract_column(UpperCAmelCase     )
     __A				 =       self.python_features_decoder.decode_column(UpperCAmelCase  ,    pa_table.column_names[0]     )
     __A				 =       self.recursive_tensorize(UpperCAmelCase     )
     __A				 =       self._consolidate(UpperCAmelCase     )
     return column





  def 		SCREAMING_SNAKE_CASE__	( self  ,    UpperCAmelCase     )-> Mapping:
     __A				 =       self.numpy_arrow_extractor().extract_batch(UpperCAmelCase     )
     __A				 =       self.python_features_decoder.decode_batch(UpperCAmelCase     )
     __A				 =       self.recursive_tensorize(UpperCAmelCase     )
     for column_name in batch:
        __A				 =       self._consolidate(batch[column_name]     )
     return batch








import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_UpperCamelCase   :							str     =	"""
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
"""







class 						_lowerCAmelCase(						unittest.TestCase		,   _a):

  """simple docstring"""







  def 		SCREAMING_SNAKE_CASE__	( self     )-> int:
     __A				 =       load_tool('''summarization'''     )
     self.tool.setup()
     __A				 =       load_tool('''summarization'''  ,    remote=UpperCAmelCase     )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> List[str]:
     __A				 =       self.tool(UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Dict:
     __A				 =       self.remote_tool(UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )

  def 		SCREAMING_SNAKE_CASE__	( self     )-> Union[str, Any]:
     __A				 =       self.tool(text=UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )





  def 		SCREAMING_SNAKE_CASE__	( self     )-> Optional[Any]:
     __A				 =       self.remote_tool(text=UpperCAmelCase     )
     self.assertEqual(
         UpperCAmelCase  ,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''  ,    )

