

'''simple docstring'''



import copy
import os
from typing import Union

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


__snake_case					:      int 		=     logging.get_logger(__name__)

__snake_case					:      Any 		=     {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}



class lowerCamelCase					(    snake_case__		):



			'''simple docstring'''






			__snake_case             =			"""altclip_text_model"""


			def __init__( self			:		Tuple						,     lowerCAmelCase_			:		Dict=25_00_02						,     lowerCAmelCase_			:		Union[str, Any]=10_24						,     lowerCAmelCase_			:		Optional[int]=24						,     lowerCAmelCase_			:		List[Any]=16						,     lowerCAmelCase_			:		int=40_96						,     lowerCAmelCase_			:		Union[str, Any]="gelu"						,     lowerCAmelCase_			:		Optional[int]=0.1						,     lowerCAmelCase_			:		Optional[int]=0.1						,     lowerCAmelCase_			:		Union[str, Any]=5_14						,     lowerCAmelCase_			:		Dict=1						,     lowerCAmelCase_			:		int=0.02						,     lowerCAmelCase_			:		Optional[int]=0.02						,     lowerCAmelCase_			:		Optional[Any]=1e-05						,     lowerCAmelCase_			:		str=1						,     lowerCAmelCase_			:		Tuple=0						,     lowerCAmelCase_			:		List[str]=2						,     lowerCAmelCase_			:		str="absolute"						,     lowerCAmelCase_			:		Tuple=True						,     lowerCAmelCase_			:		Optional[int]=7_68						,     **lowerCAmelCase_			:		Union[str, Any]						,     )     ->						int:





									'''simple docstring'''
									super().__init__(pad_token_id=__lowercase						,     bos_token_id=__lowercase						,     eos_token_id=__lowercase						,     **__lowercase					)

									A__	:  int           =vocab_size
									A__	:  int           =hidden_size
									A__	:  Dict           =num_hidden_layers
									A__	:  Optional[int]           =num_attention_heads
									A__	:  str           =hidden_act
									A__	:  Optional[Any]           =intermediate_size
									A__	:  Tuple           =hidden_dropout_prob
									A__	:  str           =attention_probs_dropout_prob
									A__	:  Optional[int]           =max_position_embeddings
									A__	:  Dict           =type_vocab_size
									A__	:  Tuple           =initializer_range
									A__	:  int           =initializer_factor
									A__	:  List[Any]           =layer_norm_eps
									A__	:  List[Any]           =position_embedding_type
									A__	:  str           =use_cache
									A__	:  str           =project_dim



class lowerCamelCase					(    snake_case__		):



			'''simple docstring'''






			__snake_case             =			"""altclip_vision_model"""


			def __init__( self			:		Dict						,     lowerCAmelCase_			:		Optional[int]=7_68						,     lowerCAmelCase_			:		Dict=30_72						,     lowerCAmelCase_			:		Dict=5_12						,     lowerCAmelCase_			:		Optional[Any]=12						,     lowerCAmelCase_			:		Tuple=12						,     lowerCAmelCase_			:		Optional[int]=3						,     lowerCAmelCase_			:		Any=2_24						,     lowerCAmelCase_			:		List[Any]=32						,     lowerCAmelCase_			:		Optional[Any]="quick_gelu"						,     lowerCAmelCase_			:		Optional[int]=1e-5						,     lowerCAmelCase_			:		List[Any]=0.0						,     lowerCAmelCase_			:		Dict=0.02						,     lowerCAmelCase_			:		Optional[int]=1.0						,     **lowerCAmelCase_			:		Dict						,     )     ->						List[str]:





									'''simple docstring'''
									super().__init__(**__lowercase					)

									A__	:  Tuple           =hidden_size
									A__	:  List[Any]           =intermediate_size
									A__	:  int           =projection_dim
									A__	:  Union[str, Any]           =num_hidden_layers
									A__	:  Optional[int]           =num_attention_heads
									A__	:  Tuple           =num_channels
									A__	:  str           =patch_size
									A__	:  str           =image_size
									A__	:  str           =initializer_range
									A__	:  Optional[int]           =initializer_factor
									A__	:  int           =attention_dropout
									A__	:  Dict           =layer_norm_eps
									A__	:  Optional[Any]           =hidden_act



			@classmethod
			def lowercase__		( cls			:		str						,     lowerCAmelCase_			:		Union[str, os.PathLike]						,     **lowerCAmelCase_			:		Dict					)     ->						List[Any]:





									'''simple docstring'''
									cls._set_token_in_kwargs(__lowercase					)

									A__	:  List[Any]           =cls.get_config_dict(__lowercase						,     **__lowercase					)

									# get the vision config dict if we are loading from AltCLIPConfig
									if config_dict.get("""model_type"""					) == "altclip":
															A__	:  str           =config_dict['''vision_config''']

									if "model_type" in config_dict and hasattr(cls						,     """model_type"""					) and config_dict["model_type"] != cls.model_type:
															logger.warning(
															    f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
															    f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."					)

									return cls.from_dict(__lowercase						,     **__lowercase					)



class lowerCamelCase					(    snake_case__		):



			'''simple docstring'''






			__snake_case             =			"""altclip"""
			__snake_case             =			True


			def __init__( self			:		Any						,     lowerCAmelCase_			:		Union[str, Any]=None						,     lowerCAmelCase_			:		str=None						,     lowerCAmelCase_			:		Tuple=7_68						,     lowerCAmelCase_			:		Any=2.6592						,     **lowerCAmelCase_			:		Any					)     ->						int:





									'''simple docstring'''
									# If `_config_dict` exist, we use them for the backward compatibility.
									# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
									# of confusion!).
									A__	:  Union[str, Any]           =kwargs.pop("""text_config_dict"""						,     __lowercase					)
									A__	:  List[str]           =kwargs.pop("""vision_config_dict"""						,     __lowercase					)

									super().__init__(**__lowercase					)

									# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
									# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
									# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
									if text_config_dict is not None:
															if text_config is None:
																					A__	:  Any           ={}

															# This is the complete result when using `text_config_dict`.
															A__	:  Any           =AltCLIPTextConfig(**__lowercase					).to_dict()

															# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
															for key, value in _text_config_dict.items():
																					if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
																											# If specified in `text_config_dict`
																											if key in text_config_dict:
																																	A__	:  Dict           =(
																																	    f"`{key}` is found in both `text_config_dict` and `text_config` but with different values. "
																																	    f"The value `text_config_dict[\"{key}\"]` will be used instead."
																																	)
																											# If inferred from default argument values (just to be super careful)
																											else:
																																	A__	:  Dict           =(
																																	    f"`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The "
																																	    f"value `text_config[\"{key}\"]` will be overriden."
																																	)
																											logger.warning(__lowercase					)

            # Update all values in `text_config` with the ones in `_text_config_dict`.
															text_config.update(_text_config_dict					)

									if vision_config_dict is not None:
															if vision_config is None:
																					A__	:  int           ={}

															# This is the complete result when using `vision_config_dict`.
															A__	:  Dict           =AltCLIPVisionConfig(**__lowercase					).to_dict()
															# convert keys to string instead of integer
															if "id2label" in _vision_config_dict:
																					A__	:  Any           ={
																					    str(__lowercase					): value for key, value in _vision_config_dict['''id2label'''].items()
																					}

															# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
															for key, value in _vision_config_dict.items():
																					if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
																											# If specified in `vision_config_dict`
																											if key in vision_config_dict:
																																	A__	:  List[str]           =(
																																	    f"`{key}` is found in both `vision_config_dict` and `vision_config` but with different "
																																	    f"values. The value `vision_config_dict[\"{key}\"]` will be used instead."
																																	)
																											# If inferred from default argument values (just to be super careful)
																											else:
																																	A__	:  Union[str, Any]           =(
																																	    f"`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. "
																																	    f"The value `vision_config[\"{key}\"]` will be overriden."
																																	)
																											logger.warning(__lowercase					)

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
															vision_config.update(_vision_config_dict					)

									if text_config is None:
															A__	:  Any           ={}
															logger.info("""`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."""					)

									if vision_config is None:
															A__	:  int           ={}
															logger.info("""`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."""					)

									A__	:  Any           =AltCLIPTextConfig(**__lowercase					)
									A__	:  Union[str, Any]           =AltCLIPVisionConfig(**__lowercase					)

									A__	:  Tuple           =projection_dim
									A__	:  Tuple           =logit_scale_init_value
									A__	:  Tuple           =1.0


			@classmethod
			def lowercase__		( cls			:		Union[str, Any]						,     lowerCAmelCase_			:		AltCLIPTextConfig						,     lowerCAmelCase_			:		AltCLIPVisionConfig						,     **lowerCAmelCase_			:		List[str]					)     ->						str:





									'''simple docstring'''
									return cls(text_config=text_config.to_dict()						,     vision_config=vision_config.to_dict()						,     **__lowercase					)



			def lowercase__		( self			:		List[str]					)     ->						str:





									'''simple docstring'''
									A__	:  int           =copy.deepcopy(self.__dict__					)
									A__	:  int           =self.text_config.to_dict()
									A__	:  int           =self.vision_config.to_dict()
									A__	:  Optional[int]           =self.__class__.model_type
									return output








"""simple docstring"""





# 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.auto import AutoModelForSeqaSeqLM, AutoTokenizer
from .base import PipelineTool
class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							int									=		"""philschmid/bart-large-cnn-samsum"""
				__snake_case :							Optional[int]									=		(
				    """This is a tool that summarizes an English text. It takes an input `text` containing the text to summarize, """
				    """and returns a summary of the text."""
				)
				__snake_case :							Dict									=		"""summarizer"""
				__snake_case :							str									=		AutoTokenizer
				__snake_case :							List[str]									=		AutoModelForSeqaSeqLM

				__snake_case :							List[Any]									=		["""text"""]
				__snake_case :							Dict									=		["""text"""]




				def        __lowercase	(  self	:int    ,     __lowercase	:List[Any]      ):
											return self.pre_processor(__lowercase    ,     return_tensors='''pt'''    ,     truncation=__lowercase      )




				def        __lowercase	(  self	:Optional[int]    ,     __lowercase	:Optional[int]      ):
											return self.model.generate(**__lowercase      )[0]




				def        __lowercase	(  self	:List[Any]    ,     __lowercase	:str      ):
											return self.pre_processor.decode(__lowercase    ,     skip_special_tokens=__lowercase    ,     clean_up_tokenization_spaces=__lowercase      )




