



# 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    lowerCamelCase__  (						UpperCAmelCase_):
     """simple docstring"""



     _A       =			'openai/whisper-base'
     _A       =			(
         'This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the '
         'transcribed text.'
     )
     _A       =			'transcriber'
     _A       =			WhisperProcessor
     _A       =			WhisperForConditionalGeneration

     _A       =			['audio']
     _A       =			['text']







     def 						_a      (self				,			__a    ):






           '''simple docstring'''



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







     def 						_a      (self				,			__a    ):






           '''simple docstring'''



           return self.model.generate(inputs=__a    )







     def 						_a      (self				,			__a    ):






           '''simple docstring'''



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




import gc
import unittest

from diffusers import FlaxStableDiffusionInpaintPipeline
from diffusers.utils import is_flax_available, load_image, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
     import jax
     import jax.numpy as jnp
     from flax.jax_utils import replicate
     from flax.training.common_utils import shard





@slow
@require_flax
class    lowerCamelCase__  (						unittest.TestCase):
     """simple docstring"""



     def 						_a      (self    ):






           '''simple docstring'''



           super().tearDown()
           gc.collect()







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		load_image(
               "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
               "/sd2-inpaint/init_image.png"    )
           lowerCamelCase								=		load_image(
               "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png"    )

           lowerCamelCase								=		"xvjiarui/stable-diffusion-2-inpainting"
           lowerCamelCase			,							lowerCamelCase								=		FlaxStableDiffusionInpaintPipeline.from_pretrained(__a				,			safety_checker=__a    )

           lowerCamelCase								=		"Face of a yellow cat, high resolution, sitting on a park bench"

           lowerCamelCase								=		jax.random.PRNGKey(0    )
           lowerCamelCase								=		50

           lowerCamelCase								=		jax.device_count()
           lowerCamelCase								=		num_samples * [prompt]
           lowerCamelCase								=		num_samples * [init_image]
           lowerCamelCase								=		num_samples * [mask_image]
           lowerCamelCase			,							lowerCamelCase			,							lowerCamelCase								=		pipeline.prepare_inputs(__a				,			__a				,			__a    )

           # shard inputs and rng
           lowerCamelCase								=		replicate(__a    )
           lowerCamelCase								=		jax.random.split(__a				,			jax.device_count()    )
           lowerCamelCase								=		shard(__a    )
           lowerCamelCase								=		shard(__a    )
           lowerCamelCase								=		shard(__a    )

           lowerCamelCase								=		pipeline(
               __a				,			__a				,			__a				,			__a				,			__a				,			__a				,			jit=__a    )

           lowerCamelCase								=		output.images.reshape(__a				,			5_12				,			5_12				,			3    )

           lowerCamelCase								=		images[0, 2_53:2_56, 2_53:2_56, -1]

           lowerCamelCase								=		jnp.asarray(jax.device_get(image_slice.flatten()    )    )
           lowerCamelCase								=		jnp.array(
               [0.361_1307, 0.3764_9736, 0.375_7408, 0.3821_3953, 0.3929_5167, 0.384_1631, 0.4155_4978, 0.413_7475, 0.421_7084]    )
           print(F"""output_slice: {output_slice}"""    )
           assert jnp.abs(output_slice - expected_slice    ).max() < 1E-2