




"""simple docstring"""
import enum
import warnings

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, is_tf_available, is_torch_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
					import tensorflow as tf

					from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

if is_torch_available():
					from ..models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

a_				:    Any										=     logging.get_logger(__name__)

class __lowercase(      enum.Enum				):




					'''simple docstring'''


					__a						:						str     		= 0
					__a						:						List[str]     		= 1



@add_end_docstrings(lowercase__				)
class __lowercase(      lowercase__				):




					'''simple docstring'''


					__a						:						Optional[Any]     		= 'generated'
					def __init__(    self						,	*__a						,	**__a     ):
								super().__init__(*__a						,	**__a     )

								self.check_model_type(
								    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
								    if self.framework == 'tf'
								    else MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING     )
					def     snake_case_				(    self						,	__a=None						,	__a=None						,	__a=None						,	__a=None						,	__a=None						,	__a=None						,	**__a						,	):
								__lowerCamelCase					:	Optional[int]	       =				{}
								if truncation is not None:
											__lowerCamelCase					:	Dict	       =				truncation

								__lowerCamelCase					:	Any	       =				generate_kwargs

								__lowerCamelCase					:	List[Any]	       =				{}
								if return_tensors is not None and return_type is None:
											__lowerCamelCase					:	List[Any]	       =				ReturnType.TENSORS if return_tensors else ReturnType.TEXT
								if return_type is not None:
											__lowerCamelCase					:	Dict	       =				return_type

								if clean_up_tokenization_spaces is not None:
											__lowerCamelCase					:	Optional[int]	       =				clean_up_tokenization_spaces

								if stop_sequence is not None:
											__lowerCamelCase					:	List[str]	       =				self.tokenizer.encode(__a						,	add_special_tokens=__a     )
											if len(__a     ) > 1:
														warnings.warn(
														    'Stopping on a multiple token sequence is not yet supported on transformers. The first token of'
														    ' the stop sequence will be used as the stop sequence string in the interim.'     )
											__lowerCamelCase					:	Dict	       =				stop_sequence_ids[0]

								return preprocess_params, forward_params, postprocess_params
					def     snake_case_				(    self						,	__a						,	__a						,	__a     ):
								return True
					def     snake_case_				(    self						,	*__a						,	__a     ):
								__lowerCamelCase					:	str	       =				self.model.config.prefix if self.model.config.prefix is not None else ''
								if isinstance(args[0]						,	__a     ):
											if self.tokenizer.pad_token_id is None:
														raise ValueError('Please make sure that the tokenizer has a pad_token_id when using a batch input'     )
											__lowerCamelCase					:	Optional[int]	       =				([prefix + arg for arg in args[0]],)
											__lowerCamelCase					:	Optional[Any]	       =				True

								elif isinstance(args[0]						,	__a     ):
											__lowerCamelCase					:	str	       =				(prefix + args[0],)
											__lowerCamelCase					:	int	       =				False
								else:
											raise ValueError(
											    f''' `args[0]`: {args[0]} have the wrong format. The should be either of type `str` or type `list`'''     )
								__lowerCamelCase					:	Optional[Any]	       =				self.tokenizer(*__a						,	padding=__a						,	truncation=__a						,	return_tensors=self.framework     )
								# This is produced by tokenizers but is an invalid generate kwargs
								if "token_type_ids" in inputs:
											del inputs["token_type_ids"]
								return inputs
					def __call__(    self						,	*__a						,	**__a     ):
								__lowerCamelCase					:	Any	       =				super().__call__(*__a						,	**__a     )
								if (
								    isinstance(args[0]						,	__a     )
								    and all(isinstance(__a						,	__a     ) for el in args[0]     )
								    and all(len(__a     ) == 1 for res in result     )
								):
											return [res[0] for res in result]
								return result
					def     snake_case_				(    self						,	__a						,	__a=TruncationStrategy.DO_NOT_TRUNCATE						,	**__a     ):
								__lowerCamelCase					:	Dict	       =				self._parse_and_tokenize(__a						,	truncation=__a						,	**__a     )
								return inputs
					def     snake_case_				(    self						,	__a						,	**__a     ):
								if self.framework == "pt":
											__lowerCamelCase       ,      __lowerCamelCase					:	Any	       =				model_inputs['input_ids'].shape
								elif self.framework == "tf":
											__lowerCamelCase       ,      __lowerCamelCase					:	Any	       =				tf.shape(model_inputs['input_ids']     ).numpy()

								__lowerCamelCase					:	Tuple	       =				generate_kwargs.get('min_length'						,	self.model.config.min_length     )
								__lowerCamelCase					:	int	       =				generate_kwargs.get('max_length'						,	self.model.config.max_length     )
								self.check_inputs(__a						,	generate_kwargs['min_length']						,	generate_kwargs['max_length']     )
								__lowerCamelCase					:	List[str]	       =				self.model.generate(**__a						,	**__a     )
								__lowerCamelCase					:	List[Any]	       =				output_ids.shape[0]
								if self.framework == "pt":
											__lowerCamelCase					:	str	       =				output_ids.reshape(__a						,	out_b // in_b						,	*output_ids.shape[1:]     )
								elif self.framework == "tf":
											__lowerCamelCase					:	Tuple	       =				tf.reshape(__a						,	(in_b, out_b // in_b, *output_ids.shape[1:])     )
								return {"output_ids": output_ids}





					def     snake_case_				(    self						,	__a						,	__a=ReturnType.TEXT						,	__a=False     ):
								__lowerCamelCase					:	List[str]	       =				[]
								for output_ids in model_outputs["output_ids"][0]:
											if return_type == ReturnType.TENSORS:
														__lowerCamelCase					:	Tuple	       =				{f'''{self.return_name}_token_ids''': output_ids}
											elif return_type == ReturnType.TEXT:
														__lowerCamelCase					:	List[Any]	       =				{
														    f'''{self.return_name}_text''': self.tokenizer.decode(
														        __a						,	skip_special_tokens=__a						,	clean_up_tokenization_spaces=__a						,	)
														}
											records.append(__a     )
								return records



@add_end_docstrings(lowercase__				)
class __lowercase(      lowercase__				):




					'''simple docstring'''


					__a						:						Tuple     		= 'summary'
					def __call__(    self						,	*__a						,	**__a     ):
								return super().__call__(*__a						,	**__a     )





					def     snake_case_				(    self						,	__a						,	__a						,	__a     ):
								if max_length < min_length:
											logger.warning(f'''Your min_length={min_length} must be inferior than your max_length={max_length}.'''     )

								if input_length < max_length:
											logger.warning(
											    f'''Your max_length is set to {max_length}, but your input_length is only {input_length}. Since this is '''
											    'a summarization task, where outputs shorter than the input are typically wanted, you might '
											    f'''consider decreasing max_length manually, e.g. summarizer(\'...\', max_length={input_length//2})'''     )



@add_end_docstrings(lowercase__				)
class __lowercase(      lowercase__				):




					'''simple docstring'''


					__a						:						Union[str, Any]     		= 'translation'
					def     snake_case_				(    self						,	__a						,	__a						,	__a     ):
								if input_length > 0.9 * max_length:
											logger.warning(
											    f'''Your input_length: {input_length} is bigger than 0.9 * max_length: {max_length}. You might consider '''
											    'increasing your max_length manually, e.g. translator(\'...\', max_length=400)'     )
								return True
					def     snake_case_				(    self						,	*__a						,	__a=TruncationStrategy.DO_NOT_TRUNCATE						,	__a=None						,	__a=None     ):
								if getattr(self.tokenizer						,	'_build_translation_inputs'						,	__a     ):
											return self.tokenizer._build_translation_inputs(
											    *__a						,	return_tensors=self.framework						,	truncation=__a						,	src_lang=__a						,	tgt_lang=__a     )
								else:
											return super()._parse_and_tokenize(*__a						,	truncation=__a     )
					def     snake_case_				(    self						,	__a=None						,	__a=None						,	**__a     ):
								__lowerCamelCase       ,      __lowerCamelCase       ,      __lowerCamelCase					:	Any	       =				super()._sanitize_parameters(**__a     )
								if src_lang is not None:
											__lowerCamelCase					:	int	       =				src_lang
								if tgt_lang is not None:
											__lowerCamelCase					:	Dict	       =				tgt_lang
								if src_lang is None and tgt_lang is None:
											# Backward compatibility, direct arguments use is preferred.
											__lowerCamelCase					:	int	       =				kwargs.get('task'						,	self.task     )
											__lowerCamelCase					:	Tuple	       =				task.split('_'     )
											if task and len(__a     ) == 4:
														# translation, XX, to YY
														__lowerCamelCase					:	Dict	       =				items[1]
														__lowerCamelCase					:	Union[str, Any]	       =				items[3]
								return preprocess_params, forward_params, postprocess_params





					def __call__(    self						,	*__a						,	**__a     ):
								return super().__call__(*__a						,	**__a     )









"""simple docstring"""
a_				:    Dict										=     {
    '''meter''': '''m''',
    '''kilometer''': '''km''',
    '''megametre''': '''Mm''',
    '''gigametre''': '''Gm''',
    '''terametre''': '''Tm''',
    '''petametre''': '''Pm''',
    '''exametre''': '''Em''',
    '''zettametre''': '''Zm''',
    '''yottametre''': '''Ym''',
}
# Exponent of the factor(meter)
a_				:    Optional[int]										=     {
    '''m''': 0,
    '''km''': 3,
    '''Mm''': 6,
    '''Gm''': 9,
    '''Tm''': 12,
    '''Pm''': 15,
    '''Em''': 18,
    '''Zm''': 21,
    '''Ym''': 24,
}





def 						UpperCAmelCase				(			A__:    float							,				A__:    str							,				A__:    str     )  ->     float:
			__lowerCamelCase					:	List[Any]	       =				from_type.lower().strip('s'     )
			__lowerCamelCase					:	Optional[int]	       =				to_type.lower().strip('s'     )

			__lowerCamelCase					:	int	       =				UNIT_SYMBOL.get(A__							,				A__     )
			__lowerCamelCase					:	Dict	       =				UNIT_SYMBOL.get(A__							,				A__     )

			if from_sanitized not in METRIC_CONVERSION:
						__lowerCamelCase					:	Dict	       =				(
						    f'''Invalid \'from_type\' value: {from_type!r}.\n'''
						    f'''Conversion abbreviations are: {", ".join(A__     )}'''
						)
						raise ValueError(A__     )
			if to_sanitized not in METRIC_CONVERSION:
						__lowerCamelCase					:	Any	       =				(
						    f'''Invalid \'to_type\' value: {to_type!r}.\n'''
						    f'''Conversion abbreviations are: {", ".join(A__     )}'''
						)
						raise ValueError(A__     )
			__lowerCamelCase					:	Any	       =				METRIC_CONVERSION[from_sanitized]
			__lowerCamelCase					:	Tuple	       =				METRIC_CONVERSION[to_sanitized]
			__lowerCamelCase					:	Any	       =				1

			if from_exponent > to_exponent:
						__lowerCamelCase					:	Union[str, Any]	       =				from_exponent - to_exponent
			else:
						__lowerCamelCase					:	List[Any]	       =				-(to_exponent - from_exponent)

			return value * pow(10							,				A__     )


if __name__ == "__main__":
					from doctest import testmod

					testmod()



