






"""simple docstring"""



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 				__SCREAMING_SNAKE_CASE    (					TensorFormatter[Mapping, np.ndarray, Mapping]		):


							def __init__(      self   :    List[str]      ,     snake_case   :    Tuple=None      ,     **snake_case   :    Tuple				):
													'''simple docstring'''





													super().__init__(features=snake_case				)
													A__    :	Tuple			=	np_array_kwargs


							def     _UpperCamelCase							(      self   :    Dict      ,     snake_case   :    Any				):
													'''simple docstring'''





													if isinstance(snake_case      ,     snake_case				):
																			if column and all(
																			    isinstance(snake_case      ,     np.ndarray				) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column				):
																									return np.stack(snake_case				)
																			else:
																									# don't use np.array(column, dtype=object)
																									# since it fails in certain cases
																									# see https://stackoverflow.com/q/51005699
																									A__    :	Union[str, Any]			=	np.empty(len(snake_case				)      ,     dtype=snake_case				)
																									A__    :	Tuple			=	column
																									return out
													return column


							def     _UpperCamelCase							(      self   :    int      ,     snake_case   :    Any				):
													'''simple docstring'''





													if isinstance(snake_case      ,     (str, bytes, type(snake_case				))				):
																			return value
													elif isinstance(snake_case      ,     (np.character, np.ndarray)				) and np.issubdtype(value.dtype      ,     np.character				):
																			return value
													elif isinstance(snake_case      ,     np.number				):
																			return value

													A__    :	Optional[Any]			=	{}

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

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

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


							def     _UpperCamelCase							(      self   :    Any      ,     snake_case   :    int				):
													'''simple docstring'''





													if config.TORCH_AVAILABLE and "torch" in sys.modules:
																			import torch

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


							def     _UpperCamelCase							(      self   :    List[str]      ,     snake_case   :    dict				):
													'''simple docstring'''





													return map_nested(self._recursive_tensorize      ,     snake_case      ,     map_list=snake_case				)


							def     _UpperCamelCase							(      self   :    List[Any]      ,     snake_case   :    pa.Table				):
													'''simple docstring'''





													A__    :	List[Any]			=	self.numpy_arrow_extractor().extract_row(snake_case				)
													A__    :	str			=	self.python_features_decoder.decode_row(snake_case				)
													return self.recursive_tensorize(snake_case				)


							def     _UpperCamelCase							(      self   :    List[Any]      ,     snake_case   :    pa.Table				):
													'''simple docstring'''





													A__    :	List[Any]			=	self.numpy_arrow_extractor().extract_column(snake_case				)
													A__    :	List[str]			=	self.python_features_decoder.decode_column(snake_case      ,     pa_table.column_names[0]				)
													A__    :	str			=	self.recursive_tensorize(snake_case				)
													A__    :	Union[str, Any]			=	self._consolidate(snake_case				)
													return column


							def     _UpperCamelCase							(      self   :    List[Any]      ,     snake_case   :    pa.Table				):
													'''simple docstring'''





													A__    :	Dict			=	self.numpy_arrow_extractor().extract_batch(snake_case				)
													A__    :	Tuple			=	self.python_features_decoder.decode_batch(snake_case				)
													A__    :	Any			=	self.recursive_tensorize(snake_case				)
													for column_name in batch:
																			A__    :	Optional[Any]			=	self._consolidate(batch[column_name]				)
													return batch














"""simple docstring"""



import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


A_     =				'''
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 				__SCREAMING_SNAKE_CASE    (					unittest.TestCase							,		UpperCamelCase		):


							def     _UpperCamelCase							(      self   :    int				):
													'''simple docstring'''





													A__    :	Any			=	load_tool("""summarization"""				)
													self.tool.setup()
													A__    :	List[Any]			=	load_tool("""summarization"""      ,     remote=snake_case				)


							def     _UpperCamelCase							(      self   :    Any				):
													'''simple docstring'''





													A__    :	List[Any]			=	self.tool(snake_case				)
													self.assertEqual(
													    snake_case      ,     """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     _UpperCamelCase							(      self   :    Optional[int]				):
													'''simple docstring'''





													A__    :	List[str]			=	self.remote_tool(snake_case				)
													self.assertEqual(
													    snake_case      ,     """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     _UpperCamelCase							(      self   :    Dict				):
													'''simple docstring'''





													A__    :	List[Any]			=	self.tool(text=snake_case				)
													self.assertEqual(
													    snake_case      ,     """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     _UpperCamelCase							(      self   :    Union[str, Any]				):
													'''simple docstring'''





													A__    :	Optional[int]			=	self.remote_tool(text=snake_case				)
													self.assertEqual(
													    snake_case      ,     """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."""      ,     )






