
"""simple docstring"""


import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVePipeline, ScoreSdeVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class  lowerCAmelCase_ (					unittest.TestCase			):



						'''simple docstring'''


						@property
						def   _SCREAMING_SNAKE_CASE					(       self   :					Union[str, Any]					)   ->      Union[str, Any]:
							torch.manual_seed(0					)
							A        =      UNetaDModel(
							    block_out_channels=(32, 64)     ,layers_per_block=2     ,sample_size=32     ,in_channels=3     ,out_channels=3     ,down_block_types=('DownBlock2D', 'AttnDownBlock2D')     ,up_block_types=('AttnUpBlock2D', 'UpBlock2D')     ,)
							return model




						def   _SCREAMING_SNAKE_CASE					(       self   :					Tuple					)   ->      Optional[Any]:
							A        =      self.dummy_uncond_unet
							A        =      ScoreSdeVeScheduler()

							A        =      ScoreSdeVePipeline(unet=__A     ,scheduler=__A					)
							sde_ve.to(__A					)
							sde_ve.set_progress_bar_config(disable=__A					)

							A        =      torch.manual_seed(0					)
							A        =      sde_ve(num_inference_steps=2     ,output_type='numpy'     ,generator=__A					).images

							A        =      torch.manual_seed(0					)
							A        =      sde_ve(num_inference_steps=2     ,output_type='numpy'     ,generator=__A     ,return_dict=__A					)[
							    0
							]

							A        =      image[0, -3:, -3:, -1]
							A        =      image_from_tuple[0, -3:, -3:, -1]

							assert image.shape == (1, 32, 32, 3)
							A        =      np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]					)

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







@slow
@require_torch
class  lowerCAmelCase_ (					unittest.TestCase			):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE					(       self   :					Optional[int]					)   ->      Optional[int]:
							A        =      "google/ncsnpp-church-256"
							A        =      UNetaDModel.from_pretrained(__A					)

							A        =      ScoreSdeVeScheduler.from_pretrained(__A					)

							A        =      ScoreSdeVePipeline(unet=__A     ,scheduler=__A					)
							sde_ve.to(__A					)
							sde_ve.set_progress_bar_config(disable=__A					)

							A        =      torch.manual_seed(0					)
							A        =      sde_ve(num_inference_steps=10     ,output_type='numpy'     ,generator=__A					).images

							A        =      image[0, -3:, -3:, -1]

							assert image.shape == (1, 256, 256, 3)

							A        =      np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]					)

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



# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool
class 	UpperCAmelCase_					(					UpperCamelCase    ):

   '''simple docstring'''




   __A :      Dict     		=		"openai/whisper-base"
   __A :      str     		=		(
       "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
       "transcribed text."
   )
   __A :      Any     		=		"transcriber"
   __A :      Any     		=		WhisperProcessor
   __A :      int     		=		WhisperForConditionalGeneration

   __A :      Any     		=		["audio"]
   __A :      List[str]     		=		["text"]






   def _snake_case    (		self						,				__A ):






     """simple docstring"""





     return self.pre_processor(__A						,				return_tensors="pt" ).input_features






   def _snake_case    (		self						,				__A ):






     """simple docstring"""





     return self.model.generate(inputs=__A )






   def _snake_case    (		self						,				__A ):






     """simple docstring"""





     return self.pre_processor.batch_decode(__A						,				skip_special_tokens=__A )[0]



