






from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
				from transformers import (
				    AutoConfig,
				    BertConfig,
				    GPTaConfig,
				    TaConfig,
				    TFAutoModel,
				    TFAutoModelForCausalLM,
				    TFAutoModelForMaskedLM,
				    TFAutoModelForPreTraining,
				    TFAutoModelForQuestionAnswering,
				    TFAutoModelForSeqaSeqLM,
				    TFAutoModelForSequenceClassification,
				    TFAutoModelWithLMHead,
				    TFBertForMaskedLM,
				    TFBertForPreTraining,
				    TFBertForQuestionAnswering,
				    TFBertForSequenceClassification,
				    TFBertModel,
				    TFGPTaLMHeadModel,
				    TFRobertaForMaskedLM,
				    TFTaForConditionalGeneration,
				)
				from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
				from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
				from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
				from transformers import (
				    AutoModel,
				    AutoModelForCausalLM,
				    AutoModelForMaskedLM,
				    AutoModelForPreTraining,
				    AutoModelForQuestionAnswering,
				    AutoModelForSeqaSeqLM,
				    AutoModelForSequenceClassification,
				    AutoModelWithLMHead,
				    BertForMaskedLM,
				    BertForPreTraining,
				    BertForQuestionAnswering,
				    BertForSequenceClassification,
				    BertModel,
				    GPTaLMHeadModel,
				    RobertaForMaskedLM,
				    TaForConditionalGeneration,
				)







@is_pt_tf_cross_test
class 					lowerCamelCase_  (						unittest.TestCase  ):
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Optional[int]       ):





								'''simple docstring'''



								for model_name in ["bert-base-uncased"]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModel.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModel.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Optional[int]       ):





								'''simple docstring'''



								for model_name in ["bert-base-uncased"]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelForPreTraining.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelForPreTraining.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Any       ):





								'''simple docstring'''



								for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelForCausalLM.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									a						,			a												=      TFAutoModelForCausalLM.from_pretrained(
									    __lowerCAmelCase				,output_loading_info=__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelForCausalLM.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									a						,			a												=      AutoModelForCausalLM.from_pretrained(
									    __lowerCAmelCase				,output_loading_info=__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Optional[Any]       ):





								'''simple docstring'''



								for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelWithLMHead.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelWithLMHead.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       List[str]       ):





								'''simple docstring'''



								for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelForMaskedLM.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									a						,			a												=      TFAutoModelForMaskedLM.from_pretrained(
									    __lowerCAmelCase				,output_loading_info=__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelForMaskedLM.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									a						,			a												=      AutoModelForMaskedLM.from_pretrained(
									    __lowerCAmelCase				,output_loading_info=__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Optional[int]       ):





								'''simple docstring'''



								for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelForSeqaSeqLM.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									a						,			a												=      TFAutoModelForSeqaSeqLM.from_pretrained(
									    __lowerCAmelCase				,output_loading_info=__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelForSeqaSeqLM.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									a						,			a												=      AutoModelForSeqaSeqLM.from_pretrained(
									    __lowerCAmelCase				,output_loading_info=__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Any       ):





								'''simple docstring'''



								for model_name in ["bert-base-uncased"]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelForSequenceClassification.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelForSequenceClassification.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							@slow
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Optional[int]       ):





								'''simple docstring'''



								for model_name in ["bert-base-uncased"]:
									a												=      AutoConfig.from_pretrained(__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      TFAutoModelForQuestionAnswering.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )

									a												=      AutoModelForQuestionAnswering.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
									self.assertIsNotNone(__lowerCAmelCase       )
									self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
							def 			SCREAMING_SNAKE_CASE_			(    self		:       Dict       ):





								'''simple docstring'''



								a												=      TFAutoModelWithLMHead.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
								self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
								self.assertEqual(model.num_parameters()				,1_44_10       )
								self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase       )				,1_44_10       )

								a												=      AutoModelWithLMHead.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
								self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
								self.assertEqual(model.num_parameters()				,1_44_10       )
								self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase       )				,1_44_10       )




							def 			SCREAMING_SNAKE_CASE_			(    self		:       Any       ):





								'''simple docstring'''



								a												=      TFAutoModelWithLMHead.from_pretrained(__lowerCAmelCase				,from_pt=__lowerCAmelCase       )
								self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
								self.assertEqual(model.num_parameters()				,1_44_10       )
								self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase       )				,1_44_10       )

								a												=      AutoModelWithLMHead.from_pretrained(__lowerCAmelCase				,from_tf=__lowerCAmelCase       )
								self.assertIsInstance(__lowerCAmelCase				,__lowerCAmelCase       )
								self.assertEqual(model.num_parameters()				,1_44_10       )
								self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase       )				,1_44_10       )






"""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 					_A		(			lowerCAmelCase      ):
      snake_case__     :  List[Any]				    =      'philschmid/bart-large-cnn-samsum'
      snake_case__     :  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__     :  Tuple				    =      'summarizer'
      snake_case__     :  int				    =      AutoTokenizer
      snake_case__     :  Any				    =      AutoModelForSeqaSeqLM

      snake_case__     :  Optional[int]				    =      ['text']
      snake_case__     :  Optional[int]				    =      ['text']

      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



            return self.pre_processor(__lowerCAmelCase						,			return_tensors="""pt"""						,			truncation=__lowerCAmelCase		)

      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



            return self.model.generate(**__lowerCAmelCase		)[0]







      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



            return self.pre_processor.decode(__lowerCAmelCase						,			skip_special_tokens=__lowerCAmelCase						,			clean_up_tokenization_spaces=__lowerCAmelCase		)



