






import unittest

from transformers.testing_utils import require_bsa
from transformers.utils import is_bsa_available

from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin


if is_bsa_available():
 from transformers import MarkupLMFeatureExtractor





class 			__a  (    unittest.TestCase       ):







 def __init__(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   List[str]						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  parent







 def 					__lowercase					(		self					:   Any						):


      '''simple docstring'''






      return {}







def 		SCREAMING_SNAKE_CASE							(					) ->	Optional[int]:
     UpperCamelCase__			:   List[Any]       				=  "<HTML>\n\n    <HEAD>\n    <TITLE>sample document</TITLE>\n    </HEAD>\n\n    <BODY BGCOLOR=\"FFFFFF\">\n    <HR>\n    <a href=\"http://google.com\">Goog</a>\n    <H1>This is one header</H1>\n    <H2>This is a another Header</H2>\n    <P>Travel from\n        <P>\n        <B>SFO to JFK</B>\n        <BR>\n        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>\n        <HR>\n        <div style=\"color:#0000FF\">\n            <h3>Traveler <b> name </b> is\n            <p> John Doe </p>\n        </div>"

     UpperCamelCase__			:   Dict       				=  "\n    <!DOCTYPE html>\n    <html>\n    <body>\n\n    <h1>My First Heading</h1>\n    <p>My first paragraph.</p>\n\n    </body>\n    </html>\n    "

     return [html_string_a, html_string_a]





@require_bsa
class 			__a  (    A__       ,   unittest.TestCase       ):
 _lowerCAmelCase       :       List[str]        = MarkupLMFeatureExtractor if is_bsa_available() else None







 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      UpperCamelCase__			:   int       				=  MarkupLMFeatureExtractionTester(self						)







 @property
 def 					__lowercase					(		self					:   Dict						):


      '''simple docstring'''






      return self.feature_extract_tester.prepare_feat_extract_dict()







 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      UpperCamelCase__			:   List[Any]       				=  self.feature_extraction_class()

      # Test not batched input
      UpperCamelCase__			:   Tuple       				=  get_html_strings()[0]
      UpperCamelCase__			:   Dict       				=  feature_extractor(SCREAMING_SNAKE_CASE						)

      # fmt: off
      UpperCamelCase__			:   str       				=  [["sample document", "Goog", "This is one header", "This is a another Header", "Travel from", "SFO to JFK", "on May 2, 2015 at 2:00 pm. For details go to confirm.com", "Traveler", "name", "is", "John Doe"]]
      UpperCamelCase__			:   Dict       				=  [["/html/head/title", "/html/body/a", "/html/body/h1", "/html/body/h2", "/html/body/p", "/html/body/p/p/b[1]", "/html/body/p/p/b[2]/i", "/html/body/p/p/div/h3", "/html/body/p/p/div/h3/b", "/html/body/p/p/div/h3", "/html/body/p/p/div/h3/p"]]
      # fmt: on

      self.assertEqual(encoding.nodes							,   SCREAMING_SNAKE_CASE						)
      self.assertEqual(encoding.xpaths							,   SCREAMING_SNAKE_CASE						)

      # Test batched
      UpperCamelCase__			:   Optional[Any]       				=  get_html_strings()
      UpperCamelCase__			:   List[Any]       				=  feature_extractor(SCREAMING_SNAKE_CASE						)

      # fmt: off
      UpperCamelCase__			:   str       				=  expected_nodes + [["My First Heading", "My first paragraph."]]
      UpperCamelCase__			:   Tuple       				=  expected_xpaths + [["/html/body/h1", "/html/body/p"]]

      self.assertEqual(len(encoding.nodes						)							,   2						)
      self.assertEqual(len(encoding.xpaths						)							,   2						)

      self.assertEqual(encoding.nodes							,   SCREAMING_SNAKE_CASE						)
      self.assertEqual(encoding.xpaths							,   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 torch

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





class 			__a  (    A__       ):
 _lowerCAmelCase       :       str        = '''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       :       int        = AutoTokenizer
 _lowerCAmelCase       :       Union[str, Any]        = AutoModelForSequenceClassification

 _lowerCAmelCase       :       Union[str, Any]        = ['''text''', ['''text''']]
 _lowerCAmelCase       :       Dict        = ['''text''']







 def 					__lowercase					(		self					:   int						):


      '''simple docstring'''






      super().setup()
      UpperCamelCase__			:   Dict       				=  self.model.config
      UpperCamelCase__			:   Union[str, Any]       				=  -1
      for idx, label in config.idalabel.items():
           if label.lower().startswith("entail"						):
                UpperCamelCase__			:   List[str]       				=  int(SCREAMING_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 					__lowercase					(		self					:   Tuple							,   SCREAMING_SNAKE_CASE					:   Tuple							,   SCREAMING_SNAKE_CASE					:   List[Any]						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  labels
      return self.pre_processor(
          [text] * len(SCREAMING_SNAKE_CASE						)							,   [F'This example is {label}' for label in labels]							,   return_tensors="pt"							,   padding="max_length"							,   )







 def 					__lowercase					(		self					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   Dict						):


      '''simple docstring'''






      UpperCamelCase__			:   List[Any]       				=  outputs.logits
      UpperCamelCase__			:   Any       				=  torch.argmax(logits[:, 2]						).item()
      return self._labels[label_id]