


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


if is_torch_available():
	import torch

if is_vision_available():
	from PIL import Image

	from transformers import TvltImageProcessor







def  _lowerCamelCase(			lowercase__     ,				lowercase__=1_0     ,				lowercase__=1_0     ,				lowercase__=False     ,				lowercase__=False			)		->			List[str]:

		'''simple docstring'''







		__lowercase=    []
		for i in range(image_processor_tester.num_frames			):
				video.append(np.random.randint(2_5_5     ,				size=(image_processor_tester.num_channels, width, height)     ,				dtype=np.uinta			)			)

		if not numpify and not torchify:
				# PIL expects the channel dimension as last dimension
				__lowercase=    [Image.fromarray(np.moveaxis(lowercase__     ,				0     ,				-1			)			) for frame in video]

		if torchify:
				__lowercase=    [torch.from_numpy(lowercase__			) for frame in video]

		return video







def  _lowerCamelCase(			lowercase__     ,				lowercase__=False     ,				lowercase__=False     ,				lowercase__=False			)		->			List[Any]:

		'''simple docstring'''







		assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

		__lowercase=    []
		for i in range(image_processor_tester.batch_size			):
				if equal_resolution:
						__lowercase=    __lowercase=    image_processor_tester.max_resolution
				else:
						__lowercase,							__lowercase=    np.random.choice(
						    np.arange(image_processor_tester.min_resolution     ,				image_processor_tester.max_resolution			)     ,				2			)
						__lowercase=    prepare_video(
						    image_processor_tester=lowercase__     ,				width=lowercase__     ,				height=lowercase__     ,				numpify=lowercase__     ,				torchify=lowercase__     ,				)
				video_inputs.append(lowercase__			)

		return video_inputs





class    A					(     unittest.TestCase				):


							def __init__(self   ,       lowerCAmelCase   ,       lowerCAmelCase=7   ,       lowerCAmelCase=3   ,       lowerCAmelCase=4   ,       lowerCAmelCase=1_8   ,       lowerCAmelCase=3_0   ,       lowerCAmelCase=4_0_0   ,       lowerCAmelCase=True   ,       lowerCAmelCase=None   ,       lowerCAmelCase=True   ,       lowerCAmelCase=[0.5, 0.5, 0.5]   ,       lowerCAmelCase=[0.5, 0.5, 0.5]   ,       lowerCAmelCase=True   ,       lowerCAmelCase=None   ,       ):
									__lowercase=    size if size is not None else {'shortest_edge': 1_8}
									__lowercase=    crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}

									__lowercase=    parent
									__lowercase=    batch_size
									__lowercase=    num_channels
									__lowercase=    num_frames
									__lowercase=    image_size
									__lowercase=    min_resolution
									__lowercase=    max_resolution
									__lowercase=    do_resize
									__lowercase=    size
									__lowercase=    do_normalize
									__lowercase=    image_mean
									__lowercase=    image_std
									__lowercase=    do_center_crop
									__lowercase=    crop_size







							def     _A (self      ):
									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "size": self.size,
									    "do_center_crop": self.do_center_crop,
									    "crop_size": self.crop_size,
									}





@require_torch
@require_vision
class    A					(     A_      ,       unittest.TestCase				):
							UpperCamelCase_     :							Optional[int] =TvltImageProcessor if is_vision_available() else None


							def     _A (self      ):
									__lowercase=    TvltImageProcessorTester(self      )


							@property
							def     _A (self      ):
									return self.image_processor_tester.prepare_image_processor_dict()


							def     _A (self      ):
									__lowercase=    self.image_processing_class(**self.image_processor_dict      )
									self.assertTrue(hasattr(lowerCAmelCase   ,       'image_mean'      )      )
									self.assertTrue(hasattr(lowerCAmelCase   ,       'image_std'      )      )
									self.assertTrue(hasattr(lowerCAmelCase   ,       'do_normalize'      )      )
									self.assertTrue(hasattr(lowerCAmelCase   ,       'do_resize'      )      )
									self.assertTrue(hasattr(lowerCAmelCase   ,       'do_center_crop'      )      )
									self.assertTrue(hasattr(lowerCAmelCase   ,       'size'      )      )


							def     _A (self      ):
									# Initialize image_processor
									__lowercase=    self.image_processing_class(**self.image_processor_dict      )
									# create random PIL videos
									__lowercase=    prepare_video_inputs(self.image_processor_tester   ,       equal_resolution=lowerCAmelCase      )
									for video in video_inputs:
											self.assertIsInstance(lowerCAmelCase   ,       lowerCAmelCase      )
											self.assertIsInstance(video[0]   ,       Image.Image      )

									# Test not batched input
									__lowercase=    image_processor(video_inputs[0]   ,       return_tensors='pt'      ).pixel_values
									self.assertEqual(
									    encoded_videos.shape   ,       (
									        1,
									        self.image_processor_tester.num_frames,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size['height'],
									        self.image_processor_tester.crop_size['width'],
									    )   ,       )

									# Test batched
									__lowercase=    image_processor(lowerCAmelCase   ,       return_tensors='pt'      ).pixel_values
									self.assertEqual(
									    encoded_videos.shape   ,       (
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_frames,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size['height'],
									        self.image_processor_tester.crop_size['width'],
									    )   ,       )


							def     _A (self      ):
									# Initialize image_processor
									__lowercase=    self.image_processing_class(**self.image_processor_dict      )
									# create random numpy tensors
									__lowercase=    prepare_video_inputs(self.image_processor_tester   ,       equal_resolution=lowerCAmelCase   ,       numpify=lowerCAmelCase      )
									for video in video_inputs:
											self.assertIsInstance(lowerCAmelCase   ,       lowerCAmelCase      )
											self.assertIsInstance(video[0]   ,       np.ndarray      )

									# Test not batched input
									__lowercase=    image_processor(video_inputs[0]   ,       return_tensors='pt'      ).pixel_values
									self.assertEqual(
									    encoded_videos.shape   ,       (
									        1,
									        self.image_processor_tester.num_frames,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size['height'],
									        self.image_processor_tester.crop_size['width'],
									    )   ,       )

									# Test batched
									__lowercase=    image_processor(lowerCAmelCase   ,       return_tensors='pt'      ).pixel_values
									self.assertEqual(
									    encoded_videos.shape   ,       (
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_frames,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size['height'],
									        self.image_processor_tester.crop_size['width'],
									    )   ,       )







							def     _A (self      ):
									# Initialize image_processor
									__lowercase=    self.image_processing_class(**self.image_processor_dict      )
									# create random PyTorch tensors
									__lowercase=    prepare_video_inputs(self.image_processor_tester   ,       equal_resolution=lowerCAmelCase   ,       torchify=lowerCAmelCase      )
									for video in video_inputs:
											self.assertIsInstance(lowerCAmelCase   ,       lowerCAmelCase      )
											self.assertIsInstance(video[0]   ,       torch.Tensor      )

									# Test not batched input
									__lowercase=    image_processor(video_inputs[0]   ,       return_tensors='pt'      ).pixel_values
									self.assertEqual(
									    encoded_videos.shape   ,       (
									        1,
									        self.image_processor_tester.num_frames,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size['height'],
									        self.image_processor_tester.crop_size['width'],
									    )   ,       )

									# Test batched
									__lowercase=    image_processor(lowerCAmelCase   ,       return_tensors='pt'      ).pixel_values
									self.assertEqual(
									    encoded_videos.shape   ,       (
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_frames,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size['height'],
									        self.image_processor_tester.crop_size['width'],
									    )   ,       )










from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available





@dataclass
class    A					(     A_				):
							UpperCamelCase_     :							Optional[int] ={
							    '''sld_warmup_steps''': 15,
							    '''sld_guidance_scale''': 20,
							    '''sld_threshold''': 0.0,
							    '''sld_momentum_scale''': 0.0,
							    '''sld_mom_beta''': 0.0,
							}
							UpperCamelCase_     :							Tuple ={
							    '''sld_warmup_steps''': 10,
							    '''sld_guidance_scale''': 1_000,
							    '''sld_threshold''': 0.01,
							    '''sld_momentum_scale''': 0.3,
							    '''sld_mom_beta''': 0.4,
							}
							UpperCamelCase_     :							Union[str, Any] ={
							    '''sld_warmup_steps''': 7,
							    '''sld_guidance_scale''': 2_000,
							    '''sld_threshold''': 0.025,
							    '''sld_momentum_scale''': 0.5,
							    '''sld_mom_beta''': 0.7,
							}
							UpperCamelCase_     :							List[Any] ={
							    '''sld_warmup_steps''': 0,
							    '''sld_guidance_scale''': 5_000,
							    '''sld_threshold''': 1.0,
							    '''sld_momentum_scale''': 0.5,
							    '''sld_mom_beta''': 0.7,
							}





@dataclass
class    A					(     A_				):
							UpperCamelCase_     :							Union[List[PIL.Image.Image], np.ndarray]
							UpperCamelCase_     :							Optional[List[bool]]
							UpperCamelCase_     :							Optional[Union[List[PIL.Image.Image], np.ndarray]]
							UpperCamelCase_     :							Optional[str]


if is_transformers_available() and is_torch_available():
	from .pipeline_stable_diffusion_safe import StableDiffusionPipelineSafe
	from .safety_checker import SafeStableDiffusionSafetyChecker






