


'''simple docstring'''






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import GLPNImageProcessor






class        __snake_case	(       unittest.TestCase):







    """simple docstring"""



    def __init__(       self   :  List[Any]   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  Any=7   ,						lowerCamelCase   :  Optional[int]=3   ,						lowerCamelCase   :  Union[str, Any]=18   ,						lowerCamelCase   :  Tuple=30   ,						lowerCamelCase   :  List[Any]=4_00   ,						lowerCamelCase   :  str=True   ,						lowerCamelCase   :  List[str]=32   ,						lowerCamelCase   :  Optional[int]=True   ,						)       ->  List[Any]:
      lowerCAmelCase_      :				List[Any]      =       parent
      lowerCAmelCase_      :				int      =       batch_size
      lowerCAmelCase_      :				List[Any]      =       num_channels
      lowerCAmelCase_      :				Tuple      =       image_size
      lowerCAmelCase_      :				str      =       min_resolution
      lowerCAmelCase_      :				Tuple      =       max_resolution
      lowerCAmelCase_      :				Optional[Any]      =       do_resize
      lowerCAmelCase_      :				List[Any]      =       size_divisor
      lowerCAmelCase_      :				List[str]      =       do_rescale





    def __lowercase       (       self   :  int		)       ->  Union[str, Any]:
      return {
          "do_resize": self.do_resize,
          "size_divisor": self.size_divisor,
          "do_rescale": self.do_rescale,
      }







@require_torch
@require_vision
class        __snake_case	(       _SCREAMING_SNAKE_CASE     ,unittest.TestCase):







    """simple docstring"""



    lowercase       			= GLPNImageProcessor if is_vision_available() else None

    def __lowercase       (       self   :  int		)       ->  List[Any]:
      lowerCAmelCase_      :				Tuple      =       GLPNImageProcessingTester(self		)

    @property
    def __lowercase       (       self   :  Optional[int]		)       ->  int:
      return self.image_processor_tester.prepare_image_processor_dict()

    def __lowercase       (       self   :  Optional[Any]		)       ->  Optional[Any]:
      lowerCAmelCase_      :				Union[str, Any]      =       self.image_processing_class(**self.image_processor_dict		)
      self.assertTrue(hasattr(lowerCamelCase   ,						"""do_resize"""		)		)
      self.assertTrue(hasattr(lowerCamelCase   ,						"""size_divisor"""		)		)
      self.assertTrue(hasattr(lowerCamelCase   ,						"""resample"""		)		)
      self.assertTrue(hasattr(lowerCamelCase   ,						"""do_rescale"""		)		)

    def __lowercase       (       self   :  Union[str, Any]		)       ->  Any:
      pass

    def __lowercase       (       self   :  str		)       ->  Any:
      # Initialize image_processing
      lowerCAmelCase_      :				int      =       self.image_processing_class(**self.image_processor_dict		)
      # create random PIL images
      lowerCAmelCase_      :				int      =       prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=lowerCamelCase		)
      for image in image_inputs:
        self.assertIsInstance(lowerCamelCase   ,						Image.Image		)

      # Test not batched input (GLPNImageProcessor doesn't support batching)
      lowerCAmelCase_      :				Any      =       image_processing(image_inputs[0]   ,						return_tensors="""pt"""		).pixel_values
      self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0		)
      self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0		)

    def __lowercase       (       self   :  Tuple		)       ->  Union[str, Any]:
      # Initialize image_processing
      lowerCAmelCase_      :				Tuple      =       self.image_processing_class(**self.image_processor_dict		)
      # create random numpy tensors
      lowerCAmelCase_      :				Union[str, Any]      =       prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=lowerCamelCase   ,						numpify=lowerCamelCase		)
      for image in image_inputs:
        self.assertIsInstance(lowerCamelCase   ,						np.ndarray		)

      # Test not batched input (GLPNImageProcessor doesn't support batching)
      lowerCAmelCase_      :				Optional[int]      =       image_processing(image_inputs[0]   ,						return_tensors="""pt"""		).pixel_values
      self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0		)
      self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0		)





    def __lowercase       (       self   :  int		)       ->  Union[str, Any]:
      # Initialize image_processing
      lowerCAmelCase_      :				Dict      =       self.image_processing_class(**self.image_processor_dict		)
      # create random PyTorch tensors
      lowerCAmelCase_      :				Any      =       prepare_image_inputs(self.image_processor_tester   ,						equal_resolution=lowerCamelCase   ,						torchify=lowerCamelCase		)
      for image in image_inputs:
        self.assertIsInstance(lowerCamelCase   ,						torch.Tensor		)

      # Test not batched input (GLPNImageProcessor doesn't support batching)
      lowerCAmelCase_      :				Dict      =       image_processing(image_inputs[0]   ,						return_tensors="""pt"""		).pixel_values
      self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0		)
      self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0		)







'''simple docstring'''






import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class        __snake_case	(       unittest.TestCase):







    """simple docstring"""



    def __lowercase       (       self   :  Tuple		)       ->  Dict:
      lowerCAmelCase_      :				str      =       [
          """safety_checker/pytorch_model.bin""",
          """safety_checker/model.safetensors""",
          """vae/diffusion_pytorch_model.bin""",
          """vae/diffusion_pytorch_model.safetensors""",
          """text_encoder/pytorch_model.bin""",
          """text_encoder/model.safetensors""",
          """unet/diffusion_pytorch_model.bin""",
          """unet/diffusion_pytorch_model.safetensors""",
      ]
      self.assertTrue(is_safetensors_compatible(lowerCamelCase		)		)

    def __lowercase       (       self   :  List[Any]		)       ->  int:
      lowerCAmelCase_      :				Tuple      =       [
          """unet/diffusion_pytorch_model.bin""",
          """unet/diffusion_pytorch_model.safetensors""",
      ]
      self.assertTrue(is_safetensors_compatible(lowerCamelCase		)		)

    def __lowercase       (       self   :  Optional[int]		)       ->  Optional[Any]:
      lowerCAmelCase_      :				int      =       [
          """safety_checker/pytorch_model.bin""",
          """safety_checker/model.safetensors""",
          """vae/diffusion_pytorch_model.bin""",
          """vae/diffusion_pytorch_model.safetensors""",
          """text_encoder/pytorch_model.bin""",
          """text_encoder/model.safetensors""",
          """unet/diffusion_pytorch_model.bin""",
          # Removed: 'unet/diffusion_pytorch_model.safetensors',
      ]
      self.assertFalse(is_safetensors_compatible(lowerCamelCase		)		)

    def __lowercase       (       self   :  int		)       ->  List[Any]:
      lowerCAmelCase_      :				Dict      =       [
          """text_encoder/pytorch_model.bin""",
          """text_encoder/model.safetensors""",
      ]
      self.assertTrue(is_safetensors_compatible(lowerCamelCase		)		)

    def __lowercase       (       self   :  str		)       ->  List[str]:
      lowerCAmelCase_      :				Union[str, Any]      =       [
          """safety_checker/pytorch_model.bin""",
          """safety_checker/model.safetensors""",
          """vae/diffusion_pytorch_model.bin""",
          """vae/diffusion_pytorch_model.safetensors""",
          """text_encoder/pytorch_model.bin""",
          # Removed: 'text_encoder/model.safetensors',
          """unet/diffusion_pytorch_model.bin""",
          """unet/diffusion_pytorch_model.safetensors""",
      ]
      self.assertFalse(is_safetensors_compatible(lowerCamelCase		)		)

    def __lowercase       (       self   :  List[Any]		)       ->  Tuple:
      lowerCAmelCase_      :				Union[str, Any]      =       [
          """safety_checker/pytorch_model.fp16.bin""",
          """safety_checker/model.fp16.safetensors""",
          """vae/diffusion_pytorch_model.fp16.bin""",
          """vae/diffusion_pytorch_model.fp16.safetensors""",
          """text_encoder/pytorch_model.fp16.bin""",
          """text_encoder/model.fp16.safetensors""",
          """unet/diffusion_pytorch_model.fp16.bin""",
          """unet/diffusion_pytorch_model.fp16.safetensors""",
      ]
      lowerCAmelCase_      :				Union[str, Any]      =       """fp16"""
      self.assertTrue(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)

    def __lowercase       (       self   :  Optional[Any]		)       ->  List[str]:
      lowerCAmelCase_      :				str      =       [
          """unet/diffusion_pytorch_model.fp16.bin""",
          """unet/diffusion_pytorch_model.fp16.safetensors""",
      ]
      lowerCAmelCase_      :				Optional[int]      =       """fp16"""
      self.assertTrue(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)

    def __lowercase       (       self   :  Tuple		)       ->  Optional[Any]:
      # pass variant but use the non-variant filenames
      lowerCAmelCase_      :				Dict      =       [
          """unet/diffusion_pytorch_model.bin""",
          """unet/diffusion_pytorch_model.safetensors""",
      ]
      lowerCAmelCase_      :				str      =       """fp16"""
      self.assertTrue(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)

    def __lowercase       (       self   :  Optional[int]		)       ->  List[str]:
      lowerCAmelCase_      :				str      =       [
          """safety_checker/pytorch_model.fp16.bin""",
          """safety_checker/model.fp16.safetensors""",
          """vae/diffusion_pytorch_model.fp16.bin""",
          """vae/diffusion_pytorch_model.fp16.safetensors""",
          """text_encoder/pytorch_model.fp16.bin""",
          """text_encoder/model.fp16.safetensors""",
          """unet/diffusion_pytorch_model.fp16.bin""",
          # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
      ]
      lowerCAmelCase_      :				List[str]      =       """fp16"""
      self.assertFalse(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)

    def __lowercase       (       self   :  Union[str, Any]		)       ->  Optional[int]:
      lowerCAmelCase_      :				str      =       [
          """text_encoder/pytorch_model.fp16.bin""",
          """text_encoder/model.fp16.safetensors""",
      ]
      lowerCAmelCase_      :				Optional[Any]      =       """fp16"""
      self.assertTrue(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)

    def __lowercase       (       self   :  List[Any]		)       ->  List[Any]:
      # pass variant but use the non-variant filenames
      lowerCAmelCase_      :				Dict      =       [
          """text_encoder/pytorch_model.bin""",
          """text_encoder/model.safetensors""",
      ]
      lowerCAmelCase_      :				Any      =       """fp16"""
      self.assertTrue(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)





    def __lowercase       (       self   :  Dict		)       ->  Any:
      lowerCAmelCase_      :				Optional[int]      =       [
          """safety_checker/pytorch_model.fp16.bin""",
          """safety_checker/model.fp16.safetensors""",
          """vae/diffusion_pytorch_model.fp16.bin""",
          """vae/diffusion_pytorch_model.fp16.safetensors""",
          """text_encoder/pytorch_model.fp16.bin""",
          # 'text_encoder/model.fp16.safetensors',
          """unet/diffusion_pytorch_model.fp16.bin""",
          """unet/diffusion_pytorch_model.fp16.safetensors""",
      ]
      lowerCAmelCase_      :				int      =       """fp16"""
      self.assertFalse(is_safetensors_compatible(lowerCamelCase   ,						variant=lowerCamelCase		)		)



