

import unittest

import numpy as np

from diffusers import LMSDiscreteScheduler, OnnxStableDiffusionInpaintPipeline
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
      import onnxruntime as ort




class      UpperCamelCase (     SCREAMING_SNAKE_CASE	,			unittest.TestCase   ):
    # FIXME: add fast tests
    pass




@nightly
@require_onnxruntime
@require_torch_gpu
class      UpperCamelCase (     unittest.TestCase   ):

    @property
    def UpperCamelCase			(			self :      Optional[int]    ):

     """simple docstring"""






     return (
         "CUDAExecutionProvider",
         {
             "gpu_mem_limit": "15000000000",  # 15GB
             "arena_extend_strategy": "kSameAsRequested",
         },
     )

    @property
    def UpperCamelCase			(			self :      Any    ):

     """simple docstring"""






     SCREAMING_SNAKE_CASE								=			ort.SessionOptions()
     SCREAMING_SNAKE_CASE								=			False
     return options

    def UpperCamelCase			(			self :      Optional[Any]    ):

     """simple docstring"""






     SCREAMING_SNAKE_CASE								=			load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
         '/in_paint/overture-creations-5sI6fQgYIuo.png'    )
     SCREAMING_SNAKE_CASE								=			load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
         '/in_paint/overture-creations-5sI6fQgYIuo_mask.png'    )
     SCREAMING_SNAKE_CASE								=			OnnxStableDiffusionInpaintPipeline.from_pretrained(
         'runwayml/stable-diffusion-inpainting'							,    revision='onnx'							,    safety_checker=snake_case__							,    feature_extractor=snake_case__							,    provider=self.gpu_provider							,    sess_options=self.gpu_options							,    )
     pipe.set_progress_bar_config(disable=snake_case__    )

     SCREAMING_SNAKE_CASE								=			'A red cat sitting on a park bench'

     SCREAMING_SNAKE_CASE								=			np.random.RandomState(0    )
     SCREAMING_SNAKE_CASE								=			pipe(
         prompt=snake_case__							,    image=snake_case__							,    mask_image=snake_case__							,    guidance_scale=7.5							,    num_inference_steps=1_0							,    generator=snake_case__							,    output_type='np'							,    )
     SCREAMING_SNAKE_CASE								=			output.images
     SCREAMING_SNAKE_CASE								=			images[0, 2_5_5:2_5_8, 2_5_5:2_5_8, -1]

     assert images.shape == (1, 5_1_2, 5_1_2, 3)
     SCREAMING_SNAKE_CASE								=			np.array([0.2_514, 0.3_007, 0.3_517, 0.1_790, 0.2_382, 0.3_167, 0.1_944, 0.2_273, 0.2_464]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1E-3




    def UpperCamelCase			(			self :      Any    ):

     """simple docstring"""






     SCREAMING_SNAKE_CASE								=			load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
         '/in_paint/overture-creations-5sI6fQgYIuo.png'    )
     SCREAMING_SNAKE_CASE								=			load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
         '/in_paint/overture-creations-5sI6fQgYIuo_mask.png'    )
     SCREAMING_SNAKE_CASE								=			LMSDiscreteScheduler.from_pretrained(
         'runwayml/stable-diffusion-inpainting'							,    subfolder='scheduler'							,    revision='onnx'    )
     SCREAMING_SNAKE_CASE								=			OnnxStableDiffusionInpaintPipeline.from_pretrained(
         'runwayml/stable-diffusion-inpainting'							,    revision='onnx'							,    scheduler=snake_case__							,    safety_checker=snake_case__							,    feature_extractor=snake_case__							,    provider=self.gpu_provider							,    sess_options=self.gpu_options							,    )
     pipe.set_progress_bar_config(disable=snake_case__    )

     SCREAMING_SNAKE_CASE								=			'A red cat sitting on a park bench'

     SCREAMING_SNAKE_CASE								=			np.random.RandomState(0    )
     SCREAMING_SNAKE_CASE								=			pipe(
         prompt=snake_case__							,    image=snake_case__							,    mask_image=snake_case__							,    guidance_scale=7.5							,    num_inference_steps=2_0							,    generator=snake_case__							,    output_type='np'							,    )
     SCREAMING_SNAKE_CASE								=			output.images
     SCREAMING_SNAKE_CASE								=			images[0, 2_5_5:2_5_8, 2_5_5:2_5_8, -1]

     assert images.shape == (1, 5_1_2, 5_1_2, 3)
     SCREAMING_SNAKE_CASE								=			np.array([0.0_086, 0.0_077, 0.0_083, 0.0_093, 0.0_107, 0.0_139, 0.0_094, 0.0_097, 0.0_125]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1E-3





# 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 (     SCREAMING_SNAKE_CASE   ):
    __UpperCamelCase         ="openai/whisper-base"
    __UpperCamelCase         =(
        "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
        "transcribed text."
    )
    __UpperCamelCase         ="transcriber"
    __UpperCamelCase         =WhisperProcessor
    __UpperCamelCase         =WhisperForConditionalGeneration

    __UpperCamelCase         =["audio"]
    __UpperCamelCase         =["text"]

    def UpperCamelCase			(			self :      Dict							,    snake_case__ :      Tuple    ):

     """simple docstring"""






     return self.pre_processor(snake_case__							,    return_tensors='pt'    ).input_features

    def UpperCamelCase			(			self :      Optional[int]							,    snake_case__ :      Tuple    ):

     """simple docstring"""






     return self.model.generate(inputs=snake_case__    )




    def UpperCamelCase			(			self :      str							,    snake_case__ :      Union[str, Any]    ):

     """simple docstring"""






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

