
"""simple docstring"""




import torch

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

class     _UpperCamelCase			(   _A					):






			'''simple docstring'''

			__UpperCamelCase :  Dict    =	"facebook/bart-large-mnli"
			__UpperCamelCase :  Optional[int]    =	(
			    "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."
			)
			__UpperCamelCase :  str    =	"text_classifier"
			__UpperCamelCase :  Dict    =	AutoTokenizer
			__UpperCamelCase :  List[str]    =	AutoModelForSequenceClassification

			__UpperCamelCase :  List[str]    =	["text", ["text"]]
			__UpperCamelCase :  str    =	["text"]

			def  lowerCAmelCase__		(    self	:    Union[str, Any] ):
							super().setup()
							UpperCamelCase_:							Tuple		=  self.model.config
							UpperCamelCase_:							List[Any]		=  -1
							for idx, label in config.idalabel.items():
											if label.lower().startswith("""entail""" ):
															UpperCamelCase_:							Any		=  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  lowerCAmelCase__		(    self	:    Optional[int]  ,		snake_case_	:    List[str]  ,		snake_case_	:    Dict ):
							UpperCamelCase_:							Any		=  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  lowerCAmelCase__		(    self	:    Optional[Any]  ,		snake_case_	:    Any ):
							UpperCamelCase_:							List[str]		=  outputs.logits
							UpperCamelCase_:							List[Any]		=  torch.argmax(logits[:, 2] ).item()
							return self._labels[label_id]








from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class     _UpperCamelCase			(   _A					):






			'''simple docstring'''

			__UpperCamelCase :  Union[str, Any]    =	["""image_processor""", """tokenizer"""]
			__UpperCamelCase :  List[Any]    =	"""AutoImageProcessor"""
			__UpperCamelCase :  Tuple    =	"""AutoTokenizer"""

			def __init__(    self	:    Any  ,		snake_case_	:    Optional[Any]  ,		snake_case_	:    Any ):
							super().__init__(snake_case_  ,		snake_case_ )
							UpperCamelCase_:							int		=  self.image_processor

			def __call__(    self	:    str  ,		snake_case_	:    Optional[int]=None  ,		snake_case_	:    int=None  ,		snake_case_	:    Dict=None  ,		**snake_case_	:    Optional[int] ):

							if text is None and images is None:
											raise ValueError("""You have to specify either text or images. Both cannot be none.""" )

							if text is not None:
											UpperCamelCase_:							List[Any]		=  self.tokenizer(snake_case_  ,		return_tensors=snake_case_  ,		**snake_case_ )

							if images is not None:
											UpperCamelCase_:							Any		=  self.image_processor(snake_case_  ,		return_tensors=snake_case_  ,		**snake_case_ )

							if text is not None and images is not None:
											UpperCamelCase_:							Tuple		=  image_features.pixel_values
											return encoding
							elif text is not None:
											return encoding
							else:
											return BatchEncoding(data=dict(**snake_case_ )  ,		tensor_type=snake_case_ )

			def  lowerCAmelCase__		(    self	:    List[str]  ,		*snake_case_	:    int  ,		**snake_case_	:    Optional[Any] ):
							return self.tokenizer.batch_decode(*snake_case_  ,		**snake_case_ )

			def  lowerCAmelCase__		(    self	:    int  ,		*snake_case_	:    Optional[Any]  ,		**snake_case_	:    str ):
							return self.tokenizer.decode(*snake_case_  ,		**snake_case_ )




			@property
			def  lowerCAmelCase__		(    self	:    Union[str, Any] ):
							return ["input_ids", "attention_mask", "pixel_values"]






