
'''simple docstring'''


import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
	from PIL import Image




class 						__snake_case (						unittest.TestCase				, _a  ):




		def   _snake_case  (     self				:List[Any])				-> List[Any]:






								'''simple docstring'''






								UpperCamelCase_    :  Any				    =    load_tool("""image-captioning""")
								self.tool.setup()
								UpperCamelCase_    :  Dict				    =    load_tool("""image-captioning""" ,						remote=_SCREAMING_SNAKE_CASE)




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






								'''simple docstring'''






								UpperCamelCase_    :  str				    =    Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO""")) / """000000039769.png""")
								UpperCamelCase_    :  List[Any]				    =    self.tool(_SCREAMING_SNAKE_CASE)
								self.assertEqual(_SCREAMING_SNAKE_CASE ,						"""two cats sleeping on a couch""")




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






								'''simple docstring'''






								UpperCamelCase_    :  int				    =    Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO""")) / """000000039769.png""")
								UpperCamelCase_    :  str				    =    self.remote_tool(_SCREAMING_SNAKE_CASE)
								self.assertEqual(_SCREAMING_SNAKE_CASE ,						"""two cats sleeping on a couch""")




		def   _snake_case  (     self				:Optional[int])				-> Tuple:






								'''simple docstring'''






								UpperCamelCase_    :  List[str]				    =    Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO""")) / """000000039769.png""")
								UpperCamelCase_    :  Dict				    =    self.tool(image=_SCREAMING_SNAKE_CASE)
								self.assertEqual(_SCREAMING_SNAKE_CASE ,						"""two cats sleeping on a couch""")





		def   _snake_case  (     self				:List[Any])				-> List[Any]:






								'''simple docstring'''






								UpperCamelCase_    :  Any				    =    Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO""")) / """000000039769.png""")
								UpperCamelCase_    :  Any				    =    self.remote_tool(image=_SCREAMING_SNAKE_CASE)
								self.assertEqual(_SCREAMING_SNAKE_CASE ,						"""two cats sleeping on a couch""")






'''simple docstring'''


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mpnet import MPNetTokenizer


__SCREAMING_SNAKE_CASE  =			logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE  =			{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

__SCREAMING_SNAKE_CASE  =			{
    "vocab_file": {
        "microsoft/mpnet-base": "https://huggingface.co/microsoft/mpnet-base/resolve/main/vocab.txt",
    },
    "tokenizer_file": {
        "microsoft/mpnet-base": "https://huggingface.co/microsoft/mpnet-base/resolve/main/tokenizer.json",
    },
}

__SCREAMING_SNAKE_CASE  =			{
    "microsoft/mpnet-base": 512,
}

__SCREAMING_SNAKE_CASE  =			{
    "microsoft/mpnet-base": {"do_lower_case": True},
}




class 						__snake_case (						_a  ):
		a_        =				VOCAB_FILES_NAMES
		a_        =				PRETRAINED_VOCAB_FILES_MAP
		a_        =				PRETRAINED_INIT_CONFIGURATION
		a_        =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		a_        =				MPNetTokenizer
		a_        =				["input_ids", "attention_mask"]




		def __init__(     self				:Tuple ,						_SCREAMING_SNAKE_CASE				:Dict=None ,						_SCREAMING_SNAKE_CASE				:List[Any]=None ,						_SCREAMING_SNAKE_CASE				:Optional[Any]=True ,						_SCREAMING_SNAKE_CASE				:Any="<s>" ,						_SCREAMING_SNAKE_CASE				:int="</s>" ,						_SCREAMING_SNAKE_CASE				:Optional[Any]="</s>" ,						_SCREAMING_SNAKE_CASE				:Any="<s>" ,						_SCREAMING_SNAKE_CASE				:Optional[int]="[UNK]" ,						_SCREAMING_SNAKE_CASE				:List[Any]="<pad>" ,						_SCREAMING_SNAKE_CASE				:int="<mask>" ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=True ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=None ,						**_SCREAMING_SNAKE_CASE				:Optional[int] ,						)				-> Optional[Any]:






								'''simple docstring'''






								super().__init__(
								    _SCREAMING_SNAKE_CASE ,						tokenizer_file=_SCREAMING_SNAKE_CASE ,						do_lower_case=_SCREAMING_SNAKE_CASE ,						bos_token=_SCREAMING_SNAKE_CASE ,						eos_token=_SCREAMING_SNAKE_CASE ,						sep_token=_SCREAMING_SNAKE_CASE ,						cls_token=_SCREAMING_SNAKE_CASE ,						unk_token=_SCREAMING_SNAKE_CASE ,						pad_token=_SCREAMING_SNAKE_CASE ,						mask_token=_SCREAMING_SNAKE_CASE ,						tokenize_chinese_chars=_SCREAMING_SNAKE_CASE ,						strip_accents=_SCREAMING_SNAKE_CASE ,						**_SCREAMING_SNAKE_CASE ,						)

								UpperCamelCase_    :  Dict				    =    json.loads(self.backend_tokenizer.normalizer.__getstate__())
								if (
								    pre_tok_state.get("""lowercase""" ,						_SCREAMING_SNAKE_CASE) != do_lower_case
								    or pre_tok_state.get("""strip_accents""" ,						_SCREAMING_SNAKE_CASE) != strip_accents
								):
														UpperCamelCase_    :  Any				    =    getattr(_SCREAMING_SNAKE_CASE ,						pre_tok_state.pop("""type"""))
														UpperCamelCase_    :  Optional[int]				    =    do_lower_case
														UpperCamelCase_    :  str				    =    strip_accents
														UpperCamelCase_    :  str				    =    pre_tok_class(**_SCREAMING_SNAKE_CASE)

								UpperCamelCase_    :  List[str]				    =    do_lower_case




		@property
		def   _snake_case  (     self				:Optional[int])				-> str:






								'''simple docstring'''






								if self._mask_token is None:
														if self.verbose:
																				logger.error("""Using mask_token, but it is not set yet.""")
														return None
								return str(self._mask_token)




		@mask_token.setter
		def   _snake_case  (     self				:Optional[Any] ,						_SCREAMING_SNAKE_CASE				:List[Any])				-> int:






								'''simple docstring'''






								UpperCamelCase_    :  Tuple				    =    AddedToken(_SCREAMING_SNAKE_CASE ,						lstrip=_SCREAMING_SNAKE_CASE ,						rstrip=_SCREAMING_SNAKE_CASE) if isinstance(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE) else value
								UpperCamelCase_    :  int				    =    value




		def   _snake_case  (     self				:str ,						_SCREAMING_SNAKE_CASE				:int ,						_SCREAMING_SNAKE_CASE				:Any=None)				-> str:






								'''simple docstring'''






								UpperCamelCase_    :  Tuple				    =    [self.bos_token_id] + token_ids_a + [self.eos_token_id]
								if token_ids_a is None:
														return output

								return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]




		def   _snake_case  (     self				:Optional[Any] ,						_SCREAMING_SNAKE_CASE				:List[int] ,						_SCREAMING_SNAKE_CASE				:Optional[List[int]] = None)				-> List[int]:






								'''simple docstring'''






								UpperCamelCase_    :  Optional[Any]				    =    [self.sep_token_id]
								UpperCamelCase_    :  Dict				    =    [self.cls_token_id]

								if token_ids_a is None:
														return len(cls + token_ids_a + sep) * [0]
								return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]





		def   _snake_case  (     self				:List[str] ,						_SCREAMING_SNAKE_CASE				:str ,						_SCREAMING_SNAKE_CASE				:Optional[str] = None)				-> Tuple[str]:






								'''simple docstring'''






								UpperCamelCase_    :  List[str]				    =    self._tokenizer.model.save(_SCREAMING_SNAKE_CASE ,						name=_SCREAMING_SNAKE_CASE)
								return tuple(_SCREAMING_SNAKE_CASE)




