


"""simple docstring"""






from ...processing_utils import ProcessorMixin
class        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				"WhisperFeatureExtractor"
					snake_case__       					=				"WhisperTokenizer"







					def __init__(       self     :			Optional[int]					,lowerCamelCase__     :			str					,lowerCamelCase__     :			Optional[int]    ):
									super().__init__(__UpperCamelCase					,__UpperCamelCase    )
									UpperCAmelCase__    =							self.feature_extractor
									UpperCAmelCase__    =							False







					def 	__lowerCAmelCase		(       self     :			Dict					,lowerCamelCase__     :			Optional[int]=None					,lowerCamelCase__     :			int=None					,lowerCamelCase__     :			Optional[int]=True    ):
									return self.tokenizer.get_decoder_prompt_ids(task=__UpperCamelCase					,language=__UpperCamelCase					,no_timestamps=__UpperCamelCase    )







					def __call__(       self     :			Optional[int]					,*lowerCamelCase__     :			Optional[Any]					,**lowerCamelCase__     :			List[str]    ):
									# For backward compatibility
									if self._in_target_context_manager:
													return self.current_processor(*__UpperCamelCase					,**__UpperCamelCase    )

									UpperCAmelCase__    =							kwargs.pop('audio'					,__UpperCamelCase    )
									UpperCAmelCase__    =							kwargs.pop('sampling_rate'					,__UpperCamelCase    )
									UpperCAmelCase__    =							kwargs.pop('text'					,__UpperCamelCase    )
									if len(__UpperCamelCase    ) > 0:
													UpperCAmelCase__    =							args[0]
													UpperCAmelCase__    =							args[1:]

									if audio is None and text is None:
													raise ValueError('You need to specify either an `audio` or `text` input to process.'    )

									if audio is not None:
													UpperCAmelCase__    =							self.feature_extractor(__UpperCamelCase					,*__UpperCamelCase					,sampling_rate=__UpperCamelCase					,**__UpperCamelCase    )
									if text is not None:
													UpperCAmelCase__    =							self.tokenizer(__UpperCamelCase					,**__UpperCamelCase    )

									if text is None:
													return inputs

									elif audio is None:
													return encodings
									else:
													UpperCAmelCase__    =							encodings['input_ids']
													return inputs







					def 	__lowerCAmelCase		(       self     :			Union[str, Any]					,*lowerCamelCase__     :			List[str]					,**lowerCamelCase__     :			str    ):
									return self.tokenizer.batch_decode(*__UpperCamelCase					,**__UpperCamelCase    )







					def 	__lowerCAmelCase		(       self     :			str					,*lowerCamelCase__     :			Dict					,**lowerCamelCase__     :			Any    ):
									return self.tokenizer.decode(*__UpperCamelCase					,**__UpperCamelCase    )







					def 	__lowerCAmelCase		(       self     :			Any					,lowerCamelCase__     :			str					,lowerCamelCase__     :			List[Any]="np"    ):
									return self.tokenizer.get_prompt_ids(__UpperCamelCase					,return_tensors=__UpperCamelCase    )




"""simple docstring"""






import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


lowerCAmelCase__						:						Optional[int]		  =			False
class        snake_case (				unittest.TestCase       ):




					"""simple docstring"""

					pass






@slow
@require_torch_gpu
class        snake_case (				unittest.TestCase       ):




					"""simple docstring"""

					def 	__lowerCAmelCase		(       self     :			Tuple    ):
									UpperCAmelCase__    =							VersatileDiffusionImageVariationPipeline.from_pretrained('shi-labs/versatile-diffusion'    )
									pipe.to(lowerCamelCase__    )
									pipe.set_progress_bar_config(disable=lowerCamelCase__    )

									UpperCAmelCase__    =							load_image(
									    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'    )
									UpperCAmelCase__    =							torch.manual_seed(0    )
									UpperCAmelCase__    =							pipe(
									    image=lowerCamelCase__					,generator=lowerCamelCase__					,guidance_scale=7.5					,num_inference_steps=50					,output_type='numpy'					,).images

									UpperCAmelCase__    =							image[0, 253:256, 253:256, -1]

									assert image.shape == (1, 512, 512, 3)
									UpperCAmelCase__    =							np.array([0.0_4_4_1, 0.0_4_6_9, 0.0_5_0_7, 0.0_5_7_5, 0.0_6_3_2, 0.0_6_5_0, 0.0_8_6_5, 0.0_9_0_9, 0.0_9_4_5]    )

									assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2



