
"""simple docstring"""



import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
	from PIL import Image

	from transformers import OwlViTImageProcessor, OwlViTProcessor
@require_vision
class        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				def 				__lowerCamelCase	(					self	:			int  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			tempfile.mkdtemp()

											# fmt: off
											_lowerCAmelCase  	=			['', 'l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
											# fmt: on
											_lowerCAmelCase  	=			dict(zip(UpperCAmelCase_				,     range(len(UpperCAmelCase_  )  )  )  )
											_lowerCAmelCase  	=			['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>', '']
											_lowerCAmelCase  	=			{'unk_token': '<unk>'}

											_lowerCAmelCase  	=			os.path.join(self.tmpdirname				,     VOCAB_FILES_NAMES['vocab_file']  )
											_lowerCAmelCase  	=			os.path.join(self.tmpdirname				,     VOCAB_FILES_NAMES['merges_file']  )
											with open(self.vocab_file				,     'w'				,     encoding='utf-8'  ) as fp:
																		fp.write(json.dumps(UpperCAmelCase_  ) + '\n'  )
											with open(self.merges_file				,     'w'				,     encoding='utf-8'  ) as fp:
																		fp.write('\n'.join(UpperCAmelCase_  )  )

											_lowerCAmelCase  	=			{
											    'do_resize': True,
											    'size': 20,
											    'do_center_crop': True,
											    'crop_size': 18,
											    'do_normalize': True,
											    'image_mean': [0.48145466, 0.4578275, 0.40821073],
											    'image_std': [0.26862954, 0.26130258, 0.27577711],
											}
											_lowerCAmelCase  	=			os.path.join(self.tmpdirname				,     UpperCAmelCase_  )
											with open(self.image_processor_file				,     'w'				,     encoding='utf-8'  ) as fp:
																		json.dump(UpperCAmelCase_				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]				,     **UpperCAmelCase_	:			Optional[int]  )		->  List[str]:







											"""simple docstring"""




											return CLIPTokenizer.from_pretrained(self.tmpdirname				,     pad_token='!'				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[Any]				,     **UpperCAmelCase_	:			List[str]  )		->  Union[str, Any]:







											"""simple docstring"""




											return CLIPTokenizerFast.from_pretrained(self.tmpdirname				,     pad_token='!'				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Union[str, Any]				,     **UpperCAmelCase_	:			Dict  )		->  List[Any]:







											"""simple docstring"""




											return OwlViTImageProcessor.from_pretrained(self.tmpdirname				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[Any]:







											"""simple docstring"""




											shutil.rmtree(self.tmpdirname  )


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase  	=			[np.random.randint(255				,     size=(3, 30, 400)				,     dtype=np.uinta  )]

											_lowerCAmelCase  	=			[Image.fromarray(np.moveaxis(UpperCAmelCase_				,     0				,     -1  )  ) for x in image_inputs]

											return image_inputs


				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.get_tokenizer()
											_lowerCAmelCase  	=			self.get_rust_tokenizer()
											_lowerCAmelCase  	=			self.get_image_processor()

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )
											processor_slow.save_pretrained(self.tmpdirname  )
											_lowerCAmelCase  	=			OwlViTProcessor.from_pretrained(self.tmpdirname				,     use_fast=UpperCAmelCase_  )

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )
											processor_fast.save_pretrained(self.tmpdirname  )
											_lowerCAmelCase  	=			OwlViTProcessor.from_pretrained(self.tmpdirname  )

											self.assertEqual(processor_slow.tokenizer.get_vocab()				,     tokenizer_slow.get_vocab()  )
											self.assertEqual(processor_fast.tokenizer.get_vocab()				,     tokenizer_fast.get_vocab()  )
											self.assertEqual(tokenizer_slow.get_vocab()				,     tokenizer_fast.get_vocab()  )
											self.assertIsInstance(processor_slow.tokenizer				,     UpperCAmelCase_  )
											self.assertIsInstance(processor_fast.tokenizer				,     UpperCAmelCase_  )

											self.assertEqual(processor_slow.image_processor.to_json_string()				,     image_processor.to_json_string()  )
											self.assertEqual(processor_fast.image_processor.to_json_string()				,     image_processor.to_json_string()  )
											self.assertIsInstance(processor_slow.image_processor				,     UpperCAmelCase_  )
											self.assertIsInstance(processor_fast.image_processor				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=self.get_tokenizer()				,     image_processor=self.get_image_processor()  )
											processor.save_pretrained(self.tmpdirname  )

											_lowerCAmelCase  	=			self.get_tokenizer(bos_token='(BOS)'				,     eos_token='(EOS)'  )
											_lowerCAmelCase  	=			self.get_image_processor(do_normalize=UpperCAmelCase_  )

											_lowerCAmelCase  	=			OwlViTProcessor.from_pretrained(
											    self.tmpdirname				,     bos_token='(BOS)'				,     eos_token='(EOS)'				,     do_normalize=UpperCAmelCase_  )

											self.assertEqual(processor.tokenizer.get_vocab()				,     tokenizer_add_kwargs.get_vocab()  )
											self.assertIsInstance(processor.tokenizer				,     UpperCAmelCase_  )

											self.assertEqual(processor.image_processor.to_json_string()				,     image_processor_add_kwargs.to_json_string()  )
											self.assertIsInstance(processor.image_processor				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Any  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.get_image_processor()
											_lowerCAmelCase  	=			self.get_tokenizer()

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase  	=			self.prepare_image_inputs()

											_lowerCAmelCase  	=			image_processor(UpperCAmelCase_				,     return_tensors='np'  )
											_lowerCAmelCase  	=			processor(images=UpperCAmelCase_				,     return_tensors='np'  )

											for key in input_image_proc.keys():
																		self.assertAlmostEqual(input_image_proc[key].sum()				,     input_processor[key].sum()				,     delta=1E-2  )


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.get_image_processor()
											_lowerCAmelCase  	=			self.get_tokenizer()

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase  	=			'lower newer'

											_lowerCAmelCase  	=			processor(text=UpperCAmelCase_				,     return_tensors='np'  )

											_lowerCAmelCase  	=			tokenizer(UpperCAmelCase_				,     return_tensors='np'  )

											for key in encoded_tok.keys():
																		self.assertListEqual(encoded_tok[key][0].tolist()				,     encoded_processor[key][0].tolist()  )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  Any:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.get_image_processor()
											_lowerCAmelCase  	=			self.get_tokenizer()

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase  	=			'lower newer'
											_lowerCAmelCase  	=			self.prepare_image_inputs()

											_lowerCAmelCase  	=			processor(text=UpperCAmelCase_				,     images=UpperCAmelCase_  )

											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask', 'pixel_values']  )

											# test if it raises when no input is passed
											with pytest.raises(UpperCAmelCase_  ):
																		processor()


				def 				__lowerCamelCase	(					self	:			str  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			'google/owlvit-base-patch32'
											_lowerCAmelCase  	=			OwlViTProcessor.from_pretrained(UpperCAmelCase_  )

											_lowerCAmelCase  	=			['cat', 'nasa badge']
											_lowerCAmelCase  	=			processor(text=UpperCAmelCase_  )

											_lowerCAmelCase  	=			16
											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask']  )
											self.assertEqual(inputs['input_ids'].shape				,     (2, seq_length)  )

											# test if it raises when no input is passed
											with pytest.raises(UpperCAmelCase_  ):
																		processor()


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			'google/owlvit-base-patch32'
											_lowerCAmelCase  	=			OwlViTProcessor.from_pretrained(UpperCAmelCase_  )

											_lowerCAmelCase  	=			[['cat', 'nasa badge'], ['person']]
											_lowerCAmelCase  	=			processor(text=UpperCAmelCase_  )

											_lowerCAmelCase  	=			16
											_lowerCAmelCase  	=			len(UpperCAmelCase_  )
											_lowerCAmelCase  	=			max([len(UpperCAmelCase_  ) for texts in input_texts]  )

											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask']  )
											self.assertEqual(inputs['input_ids'].shape				,     (batch_size * num_max_text_queries, seq_length)  )

											# test if it raises when no input is passed
											with pytest.raises(UpperCAmelCase_  ):
																		processor()


				def 				__lowerCamelCase	(					self	:			Any  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			'google/owlvit-base-patch32'
											_lowerCAmelCase  	=			OwlViTProcessor.from_pretrained(UpperCAmelCase_  )

											_lowerCAmelCase  	=			['cat', 'nasa badge']
											_lowerCAmelCase  	=			processor(text=UpperCAmelCase_  )

											_lowerCAmelCase  	=			16
											_lowerCAmelCase  	=			inputs['input_ids']
											_lowerCAmelCase  	=			[
											    [49_406, 2_368, 49_407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
											    [49_406, 6_841, 11_301, 49_407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
											]

											self.assertListEqual(list(inputs.keys()  )				,     ['input_ids', 'attention_mask']  )
											self.assertEqual(inputs['input_ids'].shape				,     (2, seq_length)  )
											self.assertListEqual(list(input_ids[0]  )				,     predicted_ids[0]  )
											self.assertListEqual(list(input_ids[1]  )				,     predicted_ids[1]  )


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.get_image_processor()
											_lowerCAmelCase  	=			self.get_tokenizer()

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase  	=			self.prepare_image_inputs()
											_lowerCAmelCase  	=			self.prepare_image_inputs()

											_lowerCAmelCase  	=			processor(images=UpperCAmelCase_				,     query_images=UpperCAmelCase_  )

											self.assertListEqual(list(inputs.keys()  )				,     ['query_pixel_values', 'pixel_values']  )

											# test if it raises when no input is passed
											with pytest.raises(UpperCAmelCase_  ):
																		processor()







				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.get_image_processor()
											_lowerCAmelCase  	=			self.get_tokenizer()

											_lowerCAmelCase  	=			OwlViTProcessor(tokenizer=UpperCAmelCase_				,     image_processor=UpperCAmelCase_  )

											_lowerCAmelCase  	=			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

											_lowerCAmelCase  	=			processor.batch_decode(UpperCAmelCase_  )
											_lowerCAmelCase  	=			tokenizer.batch_decode(UpperCAmelCase_  )

											self.assertListEqual(UpperCAmelCase_				,     UpperCAmelCase_  )








"""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

_snake_case          =						logging.get_logger(__name__)
class        _SCREAMING_SNAKE_CASE  (  enum.Enum							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Any							=					0
				SCREAMING_SNAKE_CASE_:							str							=					1






@add_end_docstrings(UpperCAmelCase							)
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							int							=					"generated"


				def __init__(					self	:			Optional[Any]				,     *UpperCAmelCase_	:			Dict				,     **UpperCAmelCase_	:			Union[str, Any]  )		->  Optional[Any]:







											"""simple docstring"""




											super().__init__(*UpperCAmelCase_				,     **UpperCAmelCase_  )

											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 				__lowerCamelCase	(					self	:			List[str]				,     UpperCAmelCase_	:			Any=None				,     UpperCAmelCase_	:			List[str]=None				,     UpperCAmelCase_	:			Union[str, Any]=None				,     UpperCAmelCase_	:			List[str]=None				,     UpperCAmelCase_	:			Tuple=None				,     UpperCAmelCase_	:			Optional[Any]=None				,     **UpperCAmelCase_	:			Union[str, Any]				,     )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			{}
											if truncation is not None:
																		_lowerCAmelCase  	=			truncation

											_lowerCAmelCase  	=			generate_kwargs

											_lowerCAmelCase  	=			{}
											if return_tensors is not None and return_type is None:
																		_lowerCAmelCase  	=			ReturnType.TENSORS if return_tensors else ReturnType.TEXT
											if return_type is not None:
																		_lowerCAmelCase  	=			return_type

											if clean_up_tokenization_spaces is not None:
																		_lowerCAmelCase  	=			clean_up_tokenization_spaces

											if stop_sequence is not None:
																		_lowerCAmelCase  	=			self.tokenizer.encode(UpperCAmelCase_				,     add_special_tokens=UpperCAmelCase_  )
																		if len(UpperCAmelCase_  ) > 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  	=			stop_sequence_ids[0]

											return preprocess_params, forward_params, postprocess_params


				def 				__lowerCamelCase	(					self	:			List[Any]				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			int  )		->  Optional[Any]:







											"""simple docstring"""




											return True


				def 				__lowerCamelCase	(					self	:			Union[str, Any]				,     *UpperCAmelCase_	:			str				,     UpperCAmelCase_	:			int  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.model.config.prefix if self.model.config.prefix is not None else ''
											if isinstance(args[0]				,     UpperCAmelCase_  ):
																		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  	=			([prefix + arg for arg in args[0]],)
																		_lowerCAmelCase  	=			True

											elif isinstance(args[0]				,     UpperCAmelCase_  ):
																		_lowerCAmelCase  	=			(prefix + args[0],)
																		_lowerCAmelCase  	=			False
											else:
																		raise ValueError(
																		    F""" `args[0]`: {args[0]} have the wrong format. The should be either of type `str` or type `list`"""  )
											_lowerCAmelCase  	=			self.tokenizer(*UpperCAmelCase_				,     padding=UpperCAmelCase_				,     truncation=UpperCAmelCase_				,     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	:			Union[str, Any]				,     *UpperCAmelCase_	:			Optional[Any]				,     **UpperCAmelCase_	:			Tuple  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			super().__call__(*UpperCAmelCase_				,     **UpperCAmelCase_  )
											if (
											    isinstance(args[0]				,     UpperCAmelCase_  )
											    and all(isinstance(UpperCAmelCase_				,     UpperCAmelCase_  ) for el in args[0]  )
											    and all(len(UpperCAmelCase_  ) == 1 for res in result  )
											):
																		return [res[0] for res in result]
											return result


				def 				__lowerCamelCase	(					self	:			int				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			Dict=TruncationStrategy.DO_NOT_TRUNCATE				,     **UpperCAmelCase_	:			Tuple  )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase  	=			self._parse_and_tokenize(UpperCAmelCase_				,     truncation=UpperCAmelCase_				,     **UpperCAmelCase_  )
											return inputs


				def 				__lowerCamelCase	(					self	:			Optional[Any]				,     UpperCAmelCase_	:			List[Any]				,     **UpperCAmelCase_	:			List[str]  )		->  Any:







											"""simple docstring"""




											if self.framework == "pt":
																		_lowerCAmelCase	,		_lowerCAmelCase  	=			model_inputs['input_ids'].shape
											elif self.framework == "tf":
																		_lowerCAmelCase	,		_lowerCAmelCase  	=			tf.shape(model_inputs['input_ids']  ).numpy()

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







				def 				__lowerCamelCase	(					self	:			Dict				,     UpperCAmelCase_	:			Tuple				,     UpperCAmelCase_	:			Union[str, Any]=ReturnType.TEXT				,     UpperCAmelCase_	:			Optional[Any]=False  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			[]
											for output_ids in model_outputs["output_ids"][0]:
																		if return_type == ReturnType.TENSORS:
																									_lowerCAmelCase  	=			{F"""{self.return_name}_token_ids""": output_ids}
																		elif return_type == ReturnType.TEXT:
																									_lowerCAmelCase  	=			{
																									    F"""{self.return_name}_text""": self.tokenizer.decode(
																									        UpperCAmelCase_				,     skip_special_tokens=UpperCAmelCase_				,     clean_up_tokenization_spaces=UpperCAmelCase_				,     )
																									}
																		records.append(UpperCAmelCase_  )
											return records






@add_end_docstrings(UpperCAmelCase							)
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Optional[Any]							=					"summary"


				def __call__(					self	:			Optional[int]				,     *UpperCAmelCase_	:			Optional[Any]				,     **UpperCAmelCase_	:			Dict  )		->  int:







											"""simple docstring"""




											return super().__call__(*UpperCAmelCase_				,     **UpperCAmelCase_  )







				def 				__lowerCamelCase	(					self	:			Dict				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			int  )		->  bool:







											"""simple docstring"""




											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(UpperCAmelCase							)
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Optional[int]							=					"translation"


				def 				__lowerCamelCase	(					self	:			str				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			int  )		->  Any:







											"""simple docstring"""




											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 				__lowerCamelCase	(					self	:			Optional[Any]				,     *UpperCAmelCase_	:			List[Any]				,     UpperCAmelCase_	:			Optional[int]=TruncationStrategy.DO_NOT_TRUNCATE				,     UpperCAmelCase_	:			Tuple=None				,     UpperCAmelCase_	:			Dict=None  )		->  Optional[int]:







											"""simple docstring"""




											if getattr(self.tokenizer				,     '_build_translation_inputs'				,     UpperCAmelCase_  ):
																		return self.tokenizer._build_translation_inputs(
																		    *UpperCAmelCase_				,     return_tensors=self.framework				,     truncation=UpperCAmelCase_				,     src_lang=UpperCAmelCase_				,     tgt_lang=UpperCAmelCase_  )
											else:
																		return super()._parse_and_tokenize(*UpperCAmelCase_				,     truncation=UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Union[str, Any]				,     UpperCAmelCase_	:			Tuple=None				,     UpperCAmelCase_	:			Union[str, Any]=None				,     **UpperCAmelCase_	:			Optional[int]  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase	,		_lowerCAmelCase	,		_lowerCAmelCase  	=			super()._sanitize_parameters(**UpperCAmelCase_  )
											if src_lang is not None:
																		_lowerCAmelCase  	=			src_lang
											if tgt_lang is not None:
																		_lowerCAmelCase  	=			tgt_lang
											if src_lang is None and tgt_lang is None:
																		# Backward compatibility, direct arguments use is preferred.
																		_lowerCAmelCase  	=			kwargs.get('task'				,     self.task  )
																		_lowerCAmelCase  	=			task.split('_'  )
																		if task and len(UpperCAmelCase_  ) == 4:
																									# translation, XX, to YY
																									_lowerCAmelCase  	=			items[1]
																									_lowerCAmelCase  	=			items[3]
											return preprocess_params, forward_params, postprocess_params







				def __call__(					self	:			Optional[int]				,     *UpperCAmelCase_	:			int				,     **UpperCAmelCase_	:			Optional[int]  )		->  Union[str, Any]:







											"""simple docstring"""




											return super().__call__(*UpperCAmelCase_				,     **UpperCAmelCase_  )






