from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_clip import CLIPTokenizer


_lowerCAmelCase        =       logging.get_logger(__name__)

_lowerCAmelCase        =       {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

_lowerCAmelCase        =       {
    'vocab_file': {
        'openai/clip-vit-base-patch32': 'https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json',
    },
    'merges_file': {
        'openai/clip-vit-base-patch32': 'https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt',
    },
    'tokenizer_file': {
        'openai/clip-vit-base-patch32': (
            'https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/tokenizer.json'
        ),
    },
}

_lowerCAmelCase        =       {
    'openai/clip-vit-base-patch32': 7_7,
}






class     __UpperCAmelCase(    A__				):






 """simple docstring"""




 __magic_name__          =   VOCAB_FILES_NAMES
 __magic_name__          =   PRETRAINED_VOCAB_FILES_MAP
 __magic_name__          =   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 __magic_name__          =   ["""input_ids""", """attention_mask"""]
 __magic_name__          =   CLIPTokenizer
 def __init__(    self ,       __magic_name__=None ,       __magic_name__=None ,       __magic_name__=None ,       __magic_name__="<|endoftext|>" ,       __magic_name__="<|startoftext|>" ,       __magic_name__="<|endoftext|>" ,       __magic_name__="<|endoftext|>" ,       **__magic_name__ ,       ):

        """simple docstring"""

        super().__init__(
            __magic_name__ ,       __magic_name__ ,       tokenizer_file=__magic_name__ ,       unk_token=__magic_name__ ,       bos_token=__magic_name__ ,       eos_token=__magic_name__ ,       pad_token=__magic_name__ ,       **__magic_name__ ,       )

        if not isinstance(self.backend_tokenizer.pre_tokenizer ,       pre_tokenizers.Sequence      ):
               raise ValueError(
                   '''The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been'''
                   ''' heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using'''
                   ''' to be compatible with this version.The easiest way to do so is'''
                   ''' `CLIPTokenizerFast.from_pretrained("path_to_local_folder_or_hub_repo, from_slow=True)`. If you want'''
                   ''' to use your existing tokenizer, you will have to revert to a version prior to 4.17.0 of'''
                   ''' transformers.'''      )

        self._wrap_decode_method_backend_tokenizer()
 def  UpperCAmelCase   (    self      ):

        """simple docstring"""

        A_							:       Optional[int]	      =				self.backend_tokenizer.decode

        def new_decode_method(*__magic_name__ ,       **__magic_name__      ):
               A_							:       Tuple	      =				orig_decode_method(*__magic_name__ ,       **__magic_name__      )
               A_							:       Optional[int]	      =				text.replace(self.backend_tokenizer.model.end_of_word_suffix ,       ''' '''      ).strip()
               return text

        A_							:       int	      =				new_decode_method
 def  UpperCAmelCase   (    self ,       __magic_name__ ,       __magic_name__ = None      ):

        """simple docstring"""

        A_							:       Any	      =				[self.bos_token_id]
        A_							:       Dict	      =				[self.eos_token_id]

        if token_ids_a is None:
               return bos_token + token_ids_a + eos_token
        return bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token
 def  UpperCAmelCase   (    self ,       __magic_name__ ,       __magic_name__ = None      ):

        """simple docstring"""

        A_							:       str	      =				[self.bos_token_id]
        A_							:       Any	      =				[self.eos_token_id]

        if token_ids_a is None:
               return len(bos_token + token_ids_a + eos_token      ) * [0]
        return len(bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token      ) * [0]
 def  UpperCAmelCase   (    self ,       __magic_name__ ,       __magic_name__ = None      ):

        """simple docstring"""

        A_							:       str	      =				self._tokenizer.model.save(__magic_name__ ,       name=__magic_name__      )
        return tuple(__magic_name__      )



import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard






class     __UpperCAmelCase(    unittest.TestCase				):






 """simple docstring"""




 def  UpperCAmelCase   (    self      ):

        """simple docstring"""

        A_							:       Optional[int]	      =				{
            '''model_details''': {
                '''Organization''': '''testing''',
                '''Model date''': '''today''',
                '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
                '''Architecture''': '''Convolutional Neural Network.''',
            },
            '''metrics''': '''BLEU and ROUGE-1''',
            '''evaluation_data''': {
                '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
                '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
            },
            '''training_data''': {
                '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
                '''Preprocessing''': (
                    '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
                    ''' https://arxiv.org/pdf/1810.03993.pdf'''
                ),
            },
            '''quantitative_analyses''': {'''BLEU''': 55.1, '''ROUGE-1''': 76},
        }
 def  UpperCAmelCase   (    self      ):

        """simple docstring"""

        A_							:       Tuple	      =				ModelCard.from_dict(self.inputs_dict      )
        self.assertTrue(hasattr(__magic_name__ ,       '''model_details'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''intended_use'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''factors'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''metrics'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''evaluation_data'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''training_data'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''quantitative_analyses'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''ethical_considerations'''      )      )
        self.assertTrue(hasattr(__magic_name__ ,       '''caveats_and_recommendations'''      )      )
 def  UpperCAmelCase   (    self      ):

        """simple docstring"""

        A_							:       Optional[Any]	      =				ModelCard.from_dict(self.inputs_dict      )
        A_							:       List[Any]	      =				json.loads(modelcard.to_json_string()      )
        for key, value in self.inputs_dict.items():
               self.assertEqual(obj[key] ,       __magic_name__      )
 def  UpperCAmelCase   (    self      ):

        """simple docstring"""

        A_							:       Dict	      =				ModelCard.from_dict(self.inputs_dict      )

        with tempfile.TemporaryDirectory() as tmpdirname:
               A_							:       str	      =				os.path.join(__magic_name__ ,       '''modelcard.json'''      )
               model_card_first.to_json_file(__magic_name__      )
               A_							:       str	      =				ModelCard.from_json_file(__magic_name__      )

        self.assertEqual(model_card_second.to_dict() ,       model_card_first.to_dict()      )
 def  UpperCAmelCase   (    self      ):

        """simple docstring"""

        A_							:       List[str]	      =				ModelCard.from_dict(self.inputs_dict      )

        with tempfile.TemporaryDirectory() as tmpdirname:
               model_card_first.save_pretrained(__magic_name__      )
               A_							:       Optional[int]	      =				ModelCard.from_pretrained(__magic_name__      )

        self.assertEqual(model_card_second.to_dict() ,       model_card_first.to_dict()      )


