




# 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(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''philschmid/bart-large-cnn-samsum'''
    lowerCAmelCase         = (
        '''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.'''
    )
    lowerCAmelCase         = '''summarizer'''
    lowerCAmelCase         = AutoTokenizer
    lowerCAmelCase         = AutoModelForSeqaSeqLM

    lowerCAmelCase         = ['''text''']
    lowerCAmelCase         = ['''text''']





    def 				a__ ( self  ,_SCREAMING_SNAKE_CASE    )					->						Optional[Any]:
         return self.pre_processor(_SCREAMING_SNAKE_CASE  ,return_tensors='''pt'''  ,truncation=_SCREAMING_SNAKE_CASE    )





    def 				a__ ( self  ,_SCREAMING_SNAKE_CASE    )					->						int:
         return self.model.generate(**_SCREAMING_SNAKE_CASE    )[0]





    def 				a__ ( self  ,_SCREAMING_SNAKE_CASE    )					->						Optional[Any]:
         return self.pre_processor.decode(_SCREAMING_SNAKE_CASE  ,skip_special_tokens=_SCREAMING_SNAKE_CASE  ,clean_up_tokenization_spaces=_SCREAMING_SNAKE_CASE    )





import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
     import torch

     from transformers import AutoModelForImageClassification

if is_vision_available():
     from transformers import AutoImageProcessor

@require_torch
@require_vision
class     __a(	unittest.TestCase  ):






    """simple docstring"""





    @slow
    def 				a__ ( self    )					->						List[str]:
         UpperCAmelCase_     :				Tuple  =     AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''    )
         UpperCAmelCase_     :				Union[str, Any]  =     AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''    )
         model.to(_SCREAMING_SNAKE_CASE    )

         from datasets import load_dataset

         UpperCAmelCase_     :				Optional[int]  =     load_dataset('''nielsr/rvlcdip-demo'''    )

         UpperCAmelCase_     :				Optional[Any]  =     dataset['''train'''][0]['''image'''].convert('''RGB'''    )

         UpperCAmelCase_     :				str  =     image_processor(_SCREAMING_SNAKE_CASE  ,return_tensors='''pt'''    ).to(_SCREAMING_SNAKE_CASE    )

         # forward pass
         with torch.no_grad():
              UpperCAmelCase_     :				Optional[int]  =     model(**_SCREAMING_SNAKE_CASE    )
              UpperCAmelCase_     :				List[Any]  =     outputs.logits

         UpperCAmelCase_     :				Tuple  =     torch.Size((1, 16)    )
         self.assertEqual(logits.shape  ,_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				int  =     torch.tensor(
             [-0.41_58, -0.40_92, -0.43_47]  ,device=_SCREAMING_SNAKE_CASE  ,dtype=torch.float  ,)
         self.assertTrue(torch.allclose(logits[0, :3]  ,_SCREAMING_SNAKE_CASE  ,atol=1e-4    )    )