


'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowercase      :		List[str]			=      logging.get_logger(__name__)

__lowercase      :		Tuple			=      {
    'facebook/s2t-small-librispeech-asr': (
        'https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class 				__UpperCamelCase							(						_a   ):
	A_           =       "speech_to_text"
	A_           =       ["past_key_values"]
	A_           =       {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}




	def __init__(  self		,							__a=1_0000		,							__a=12		,							__a=2048		,							__a=4		,							__a=6		,							__a=2048		,							__a=4		,							__a=0.0		,							__a=0.0		,							__a=True		,							__a=True		,							__a="relu"		,							__a=256		,							__a=0.1		,							__a=0.0		,							__a=0.0		,							__a=0.02		,							__a=2		,							__a=True		,							__a=1		,							__a=0		,							__a=2		,							__a=6000		,							__a=1024		,							__a=2		,							__a=(5, 5)		,							__a=1024		,							__a=80		,							__a=1		,							**__a		,							):

						'''simple docstring'''





						__a     :			Dict          =    vocab_size
						__a     :			Any          =    d_model
						__a     :			Union[str, Any]          =    encoder_ffn_dim
						__a     :			List[str]          =    encoder_layers
						__a     :			Tuple          =    encoder_attention_heads
						__a     :			List[str]          =    decoder_ffn_dim
						__a     :			int          =    decoder_layers
						__a     :			int          =    decoder_attention_heads
						__a     :			Tuple          =    dropout
						__a     :			Any          =    attention_dropout
						__a     :			Dict          =    activation_dropout
						__a     :			Optional[Any]          =    activation_function
						__a     :			int          =    init_std
						__a     :			Dict          =    encoder_layerdrop
						__a     :			List[str]          =    decoder_layerdrop
						__a     :			Optional[int]          =    use_cache
						__a     :			List[str]          =    encoder_layers
						__a     :			Optional[int]          =    scale_embedding  # scale factor will be sqrt(d_model) if True
						__a     :			str          =    max_source_positions
						__a     :			Any          =    max_target_positions
						__a     :			Optional[int]          =    num_conv_layers
						__a     :			Optional[int]          =    list(_SCREAMING_SNAKE_CASE				)
						__a     :			str          =    conv_channels
						__a     :			List[Any]          =    input_feat_per_channel
						__a     :			List[str]          =    input_channels

						if len(self.conv_kernel_sizes				) != self.num_conv_layers:
											raise ValueError(
											    'Configuration for convolutional module is incorrect. '
											    'It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '
											    f"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes				)}`, """
											    f"""`config.num_conv_layers = {self.num_conv_layers}`."""				)

						super().__init__(
						    pad_token_id=_SCREAMING_SNAKE_CASE		,							bos_token_id=_SCREAMING_SNAKE_CASE		,							eos_token_id=_SCREAMING_SNAKE_CASE		,							is_encoder_decoder=_SCREAMING_SNAKE_CASE		,							decoder_start_token_id=_SCREAMING_SNAKE_CASE		,							**_SCREAMING_SNAKE_CASE		,							)









# 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.
import numpy as np
import torch

from ..models.clipseg import CLIPSegForImageSegmentation
from ..utils import is_vision_available, requires_backends
from .base import PipelineTool


if is_vision_available():
     from PIL import Image

class     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = (
        '''This is a tool that creates a segmentation mask of an image according to a label. It cannot create an image.'''
        '''It takes two arguments named `image` which should be the original image, and `label` which should be a text '''
        '''describing the elements what should be identified in the segmentation mask. The tool returns the mask.'''
    )
    lowerCAmelCase         = '''CIDAS/clipseg-rd64-refined'''
    lowerCAmelCase         = '''image_segmenter'''
    lowerCAmelCase         = CLIPSegForImageSegmentation

    lowerCAmelCase         = ['''image''', '''text''']
    lowerCAmelCase         = ['''image''']





    def __init__( self  ,*_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )					->						Dict:
         requires_backends(self  ,['''vision''']    )
         super().__init__(*_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )





    def 				a__ ( self  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE    )					->						Tuple:
         return self.pre_processor(text=[label]  ,images=[image]  ,padding=_SCREAMING_SNAKE_CASE  ,return_tensors='''pt'''    )





    def 				a__ ( self  ,_SCREAMING_SNAKE_CASE    )					->						str:
         with torch.no_grad():
              UpperCAmelCase_     :				Dict  =     self.model(**_SCREAMING_SNAKE_CASE    ).logits
         return logits





    def 				a__ ( self  ,_SCREAMING_SNAKE_CASE    )					->						Dict:
         UpperCAmelCase_     :				Dict  =     outputs.cpu().detach().numpy()
         UpperCAmelCase_     :				Any  =     0
         UpperCAmelCase_     :				List[Any]  =     1
         return Image.fromarray((array * 255).astype(np.uinta    )    )