
"""simple docstring"""

from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
   if not (is_transformers_available() and is_torch_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
   from .multicontrolnet import MultiControlNetModel
   from .pipeline_controlnet import StableDiffusionControlNetPipeline
   from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
   from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
   from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline





"""simple docstring"""

import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin
class      _UpperCAmelCase							(		SCREAMING_SNAKE_CASE_     ,			unittest.TestCase							):
      __SCREAMING_SNAKE_CASE   :							str							      =	CTRLTokenizer
      __SCREAMING_SNAKE_CASE   :							int							      =	False
      __SCREAMING_SNAKE_CASE   :							Optional[Any]							      =	False




      def     a_      (							self							)						->					Dict:
          super().setUp()

          # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
          UpperCAmelCase									=					['adapt', 're@@', 'a@@', 'apt', 'c@@', 't', '<unk>']
          UpperCAmelCase									=					dict(zip(lowercase_   ,       range(len(lowercase_							)							)							)							)
          UpperCAmelCase									=					['#version: 0.2', 'a p', 'ap t</w>', 'r e', 'a d', 'ad apt</w>', '']
          UpperCAmelCase									=					{'unk_token': '<unk>'}

          UpperCAmelCase									=					os.path.join(self.tmpdirname   ,       VOCAB_FILES_NAMES['vocab_file']							)
          UpperCAmelCase									=					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(lowercase_							) + '\n'							)
          with open(self.merges_file   ,       'w'   ,       encoding='utf-8'							) as fp:
              fp.write('\n'.join(lowercase_							)							)




      def     a_      (							self   ,       **lowercase_							)						->					Tuple:
          kwargs.update(self.special_tokens_map							)
          return CTRLTokenizer.from_pretrained(self.tmpdirname   ,       **lowercase_							)




      def     a_      (							self   ,       lowercase_							)						->					Tuple:
          UpperCAmelCase									=					'adapt react readapt apt'
          UpperCAmelCase									=					'adapt react readapt apt'
          return input_text, output_text




      def     a_      (							self							)						->					Union[str, Any]:
          UpperCAmelCase									=					CTRLTokenizer(self.vocab_file   ,       self.merges_file   ,       **self.special_tokens_map							)
          UpperCAmelCase									=					'adapt react readapt apt'
          UpperCAmelCase									=					'adapt re@@ a@@ c@@ t re@@ adapt apt'.split()
          UpperCAmelCase									=					tokenizer.tokenize(lowercase_							)
          self.assertListEqual(lowercase_   ,       lowercase_							)

          UpperCAmelCase									=					tokens + [tokenizer.unk_token]

          UpperCAmelCase									=					[0, 1, 2, 4, 5, 1, 0, 3, 6]
          self.assertListEqual(tokenizer.convert_tokens_to_ids(lowercase_							)   ,       lowercase_							)



