


import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin







@skip_mps
class        __magic_name__  (					__lowerCamelCase						,		__lowerCamelCase						,		unittest.TestCase   ):

     """simple docstring"""






     lowerCamelCase__						=							IFSuperResolutionPipeline
     lowerCamelCase__						=							TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
     lowerCamelCase__						=							TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     lowerCamelCase__						=							PipelineTesterMixin.required_optional_params - {'latents'}


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          return self._get_superresolution_dummy_components()


     def lowerCAmelCase__     (      self ,    lowerCamelCase ,    lowerCamelCase=0		):


          '''simple docstring'''





          if str(lowerCamelCase		).startswith("mps"		):
               __A  :					Optional[int]						     =       torch.manual_seed(lowerCamelCase		)
          else:
               __A  :					Optional[Any]						     =       torch.Generator(device=lowerCamelCase		).manual_seed(lowerCamelCase		)

          __A  :					Any						     =       floats_tensor((1, 3, 32, 32) ,    rng=random.Random(lowerCamelCase		)		).to(lowerCamelCase		)

          __A  :					Union[str, Any]						     =       {
              "prompt": "A painting of a squirrel eating a burger",
              "image": image,
              "generator": generator,
              "num_inference_steps": 2,
              "output_type": "numpy",
          }

          return inputs


     @unittest.skipIf(
         torch_device != "cuda" or not is_xformers_available() ,    reason="XFormers attention is only available with CUDA and `xformers` installed" ,    )
     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_save_load_optional_components()


     @unittest.skipIf(torch_device != "cuda" ,    reason="float16 requires CUDA"		)
     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          super().test_save_load_floataa(expected_max_diff=1E-1		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_attention_slicing_forward_pass(expected_max_diff=1E-2		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_save_load_local()


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_inference_batch_single_identical(
              expected_max_diff=1E-2 ,    )





'''simple docstring'''


import os
from string import ascii_letters

_UpperCamelCase          =     ascii_letters + """ \t\n"""


def 		_lowercase   ():




     '''simple docstring'''





     __A  :					Any						     =       os.path.split(os.path.realpath(SCREAMING_SNAKE_CASE       )       )
     __A  :					dict[str, None]						     =       {}
     with open(path[0] + "/dictionary.txt"       ) as dictionary_file:
          for word in dictionary_file.read().split("\n"       ):
               __A  :					int						     =       None
     return english_words


_UpperCamelCase          =     load_dictionary()


def 		_lowercase   (SCREAMING_SNAKE_CASE       ):




     '''simple docstring'''





     __A  :					int						     =       message.upper()
     __A  :					int						     =       remove_non_letters(SCREAMING_SNAKE_CASE       )
     __A  :					str						     =       message.split()
     __A  :					Tuple						     =       len([word for word in possible_words if word in ENGLISH_WORDS]       )
     return float(SCREAMING_SNAKE_CASE       ) / len(SCREAMING_SNAKE_CASE       )


def 		_lowercase   (SCREAMING_SNAKE_CASE       ):




     '''simple docstring'''





     return "".join(symbol for symbol in message if symbol in LETTERS_AND_SPACE       )


def 		_lowercase   (SCREAMING_SNAKE_CASE					,				SCREAMING_SNAKE_CASE = 20					,				SCREAMING_SNAKE_CASE = 85       ):




     '''simple docstring'''





     __A  :					Optional[Any]						     =       get_english_count(SCREAMING_SNAKE_CASE       ) * 100 >= word_percentage
     __A  :					Optional[int]						     =       len(remove_non_letters(SCREAMING_SNAKE_CASE       )       )
     __A  :					Any						     =       (float(SCREAMING_SNAKE_CASE       ) / len(SCREAMING_SNAKE_CASE       )) * 100
     __A  :					int						     =       message_letters_percentage >= letter_percentage
     return words_match and letters_match


if __name__ == "__main__":
      import doctest

      doctest.testmod()

