
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_splinter import SplinterTokenizer


__magic_name__  :  Tuple     			=   logging.get_logger(__name__)

__magic_name__  :  str     			=   {'vocab_file': 'vocab.txt'}

__magic_name__  :  Tuple     			=   {
    'vocab_file': {
        'tau/splinter-base': 'https://huggingface.co/tau/splinter-base/resolve/main/vocab.txt',
        'tau/splinter-base-qass': 'https://huggingface.co/tau/splinter-base-qass/resolve/main/vocab.txt',
        'tau/splinter-large': 'https://huggingface.co/tau/splinter-large/resolve/main/vocab.txt',
        'tau/splinter-large-qass': 'https://huggingface.co/tau/splinter-large-qass/resolve/main/vocab.txt',
    }
}

__magic_name__  :  Optional[int]     			=   {
    'tau/splinter-base': 5_1_2,
    'tau/splinter-base-qass': 5_1_2,
    'tau/splinter-large': 5_1_2,
    'tau/splinter-large-qass': 5_1_2,
}

__magic_name__  :  Tuple     			=   {
    'tau/splinter-base': {'do_lower_case': False},
    'tau/splinter-base-qass': {'do_lower_case': False},
    'tau/splinter-large': {'do_lower_case': False},
    'tau/splinter-large-qass': {'do_lower_case': False},
}


class 							lowerCamelCase       (		__snake_case					):



  """simple docstring"""





  lowerCAmelCase_								=		VOCAB_FILES_NAMES
  lowerCAmelCase_								=		PRETRAINED_VOCAB_FILES_MAP
  lowerCAmelCase_								=		PRETRAINED_INIT_CONFIGURATION
  lowerCAmelCase_								=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  lowerCAmelCase_								=		SplinterTokenizer

  def __init__(					self						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=True						,    __UpperCamelCase="[UNK]"						,    __UpperCamelCase="[SEP]"						,    __UpperCamelCase="[PAD]"						,    __UpperCamelCase="[CLS]"						,    __UpperCamelCase="[MASK]"						,    __UpperCamelCase="[QUESTION]"						,    __UpperCamelCase=True						,    __UpperCamelCase=None						,    **__UpperCamelCase						,    ):
      super().__init__(
          __UpperCamelCase						,    tokenizer_file=__UpperCamelCase						,    do_lower_case=__UpperCamelCase						,    unk_token=__UpperCamelCase						,    sep_token=__UpperCamelCase						,    pad_token=__UpperCamelCase						,    cls_token=__UpperCamelCase						,    mask_token=__UpperCamelCase						,    tokenize_chinese_chars=__UpperCamelCase						,    strip_accents=__UpperCamelCase						,    additional_special_tokens=(question_token,)						,    **__UpperCamelCase						,    )

      A_								=					json.loads(self.backend_tokenizer.normalizer.__getstate__()					)
      if (
          pre_tok_state.get("lowercase"						,    __UpperCamelCase					) != do_lower_case
          or pre_tok_state.get("strip_accents"						,    __UpperCamelCase					) != strip_accents
      ):
          A_								=					getattr(__UpperCamelCase						,    pre_tok_state.pop("type"					)					)
          A_								=					do_lower_case
          A_								=					strip_accents
          A_								=					pre_tok_class(**__UpperCamelCase					)

      A_								=					do_lower_case

  @property
  def 					lowercase_						(					self					):
      return self.convert_tokens_to_ids(self.question_token					)

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase = None					):
      if token_ids_a is None:
          return [self.cls_token_id] + token_ids_a + [self.sep_token_id]

      A_								=					[self.cls_token_id]
      A_								=					[self.sep_token_id]
      A_								=					[self.question_token_id] + [self.convert_tokens_to_ids("."					)]
      if self.padding_side == "right":
          # Input is question-then-context
          return cls + token_ids_a + question_suffix + sep + token_ids_a + sep
      else:
          # Input is context-then-question
          return cls + token_ids_a + sep + token_ids_a + question_suffix + sep

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase = None					):
      A_								=					[self.sep_token_id]
      A_								=					[self.cls_token_id]
      A_								=					[self.question_token_id] + [self.convert_tokens_to_ids("."					)]
      if token_ids_a is None:
          return len(cls + token_ids_a + sep					) * [0]

      if self.padding_side == "right":
          # Input is question-then-context
          return len(cls + token_ids_a + question_suffix + sep					) * [0] + len(token_ids_a + sep					) * [1]
      else:
          # Input is context-then-question
          return len(cls + token_ids_a + sep					) * [0] + len(token_ids_a + question_suffix + sep					) * [1]

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase = None					):
      A_								=					self._tokenizer.model.save(__UpperCamelCase						,    name=__UpperCamelCase					)
      return tuple(__UpperCamelCase					)








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 							lowerCamelCase       (		unittest.TestCase			,  __snake_case					):



  """simple docstring"""





  def 					lowercase_						(					self					):
      A_								=					load_tool("image-question-answering"					)
      self.tool.setup()
      A_								=					load_tool("image-question-answering"						,    remote=__UpperCamelCase					)

  def 					lowercase_						(					self					):
      A_								=					Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"					)					) / "000000039769.png"					)
      A_								=					self.tool(__UpperCamelCase						,    "How many cats are sleeping on the couch?"					)
      self.assertEqual(__UpperCamelCase						,    "2"					)

  def 					lowercase_						(					self					):
      A_								=					Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"					)					) / "000000039769.png"					)
      A_								=					self.remote_tool(__UpperCamelCase						,    "How many cats are sleeping on the couch?"					)
      self.assertEqual(__UpperCamelCase						,    "2"					)

  def 					lowercase_						(					self					):
      A_								=					Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"					)					) / "000000039769.png"					)
      A_								=					self.tool(image=__UpperCamelCase						,    question="How many cats are sleeping on the couch?"					)
      self.assertEqual(__UpperCamelCase						,    "2"					)

  def 					lowercase_						(					self					):
      A_								=					Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"					)					) / "000000039769.png"					)
      A_								=					self.remote_tool(image=__UpperCamelCase						,    question="How many cats are sleeping on the couch?"					)
      self.assertEqual(__UpperCamelCase						,    "2"					)






