

"""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.
import torch

from ..models.auto import AutoModelForSequenceClassification, AutoTokenizer
from .base import PipelineTool







class 			lowercase    (	lowercase_      ):
				__SCREAMING_SNAKE_CASE :			List[str]	      =      '''facebook/bart-large-mnli'''
				__SCREAMING_SNAKE_CASE :			List[str]	      =      (
				    '''This is a tool that classifies an English text using provided labels. It takes two inputs: `text`, which '''
				    '''should be the text to classify, and `labels`, which should be the list of labels to use for classification. '''
				    '''It returns the most likely label in the list of provided `labels` for the input text.'''
				)
				__SCREAMING_SNAKE_CASE :			List[Any]	      =      '''text_classifier'''
				__SCREAMING_SNAKE_CASE :			Union[str, Any]	      =      AutoTokenizer
				__SCREAMING_SNAKE_CASE :			Optional[int]	      =      AutoModelForSequenceClassification

				__SCREAMING_SNAKE_CASE :			List[str]	      =      ['''text''', ['''text''']]
				__SCREAMING_SNAKE_CASE :			Dict	      =      ['''text''']




				def    a							( self	):
											super().setup()
											snake_case_          =   self.model.config
											snake_case_          =   -1
											for idx, label in config.idalabel.items():
																		if label.lower().startswith('entail'	):
																									snake_case_          =   int(snake_case	)
											if self.entailment_id == -1:
																		raise ValueError('Could not determine the entailment ID from the model config, please pass it at init.'	)




				def    a							( self				,       snake_case				,       snake_case	):
											snake_case_          =   labels
											return self.pre_processor(
											    [text] * len(snake_case	)				,       [F'''This example is {label}''' for label in labels]				,       return_tensors='pt'				,       padding='max_length'				,       )




				def    a							( self				,       snake_case	):
											snake_case_          =   outputs.logits
											snake_case_          =   torch.argmax(logits[:, 2]	).item()
											return self._labels[label_id]







from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
					if not (is_transformers_available() and is_torch_available() and is_transformers_version(""">=""", """4.25.0""")):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from ...utils.dummy_torch_and_transformers_objects import UnCLIPImageVariationPipeline, UnCLIPPipeline
else:
					from .pipeline_unclip import UnCLIPPipeline
					from .pipeline_unclip_image_variation import UnCLIPImageVariationPipeline
					from .text_proj import UnCLIPTextProjModel




