






"""simple docstring"""


import torch

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


class _lowerCamelCase    (					lowerCamelCase__						):
   _lowerCamelCase    :Tuple     				=     'facebook/bart-large-mnli'
   _lowerCamelCase    :Tuple     				=     (
       '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.'
   )
   _lowerCamelCase    :Any     				=     'text_classifier'
   _lowerCamelCase    :Any     				=     AutoTokenizer
   _lowerCamelCase    :Dict     				=     AutoModelForSequenceClassification

   _lowerCamelCase    :Any     				=     ['text', ['text']]
   _lowerCamelCase    :int     				=     ['text']






   def 	_lowerCAmelCase   (		self       :		Union[str, Any]   )			->						str:

         """simple docstring"""
         super().setup()
         lowerCAmelCase__      :			str   =	self.model.config
         lowerCAmelCase__      :			Optional[Any]   =	-1
         for idx, label in config.idalabel.items():
               if label.lower().startswith("""entail"""   ):
                     lowerCAmelCase__      :			Tuple   =	int(UpperCamelCase   )
         if self.entailment_id == -1:
               raise ValueError("""Could not determine the entailment ID from the model config, please pass it at init."""   )






   def 	_lowerCAmelCase   (		self       :		Optional[Any]   ,     UpperCamelCase       :		int   ,     UpperCamelCase       :		Union[str, Any]   )			->						str:

         """simple docstring"""
         lowerCAmelCase__      :			List[str]   =	labels
         return self.pre_processor(
             [text] * len(UpperCamelCase   )   ,     [f"""This example is {label}""" for label in labels]   ,     return_tensors="""pt"""   ,     padding="""max_length"""   ,     )






   def 	_lowerCAmelCase   (		self       :		List[Any]   ,     UpperCamelCase       :		str   )			->						Optional[int]:

         """simple docstring"""
         lowerCAmelCase__      :			Dict   =	outputs.logits
         lowerCAmelCase__      :			Optional[Any]   =	torch.argmax(logits[:, 2]   ).item()
         return self._labels[label_id]











"""simple docstring"""


# This is the module that test_patching.py uses to test patch_submodule()

import os  # noqa: this is just for tests
import os as renamed_os  # noqa: this is just for tests
from os import path  # noqa: this is just for tests
from os import path as renamed_path  # noqa: this is just for tests
from os.path import join  # noqa: this is just for tests
from os.path import join as renamed_join  # noqa: this is just for tests


_A													=      open  # noqa: we just need to have a builtin inside this module to test it properly





