


'''simple docstring'''

import os
import sys
import unittest


lowerCAmelCase				:Optional[Any]        =      os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


lowerCAmelCase				:Any        =      os.path.join('''tests''', '''models''', '''bert''', '''test_modeling_bert.py''')
lowerCAmelCase				:Dict        =      os.path.join('''tests''', '''models''', '''blip''', '''test_modeling_blip.py''')
class _lowerCamelCase	(						unittest.TestCase							):



		'''simple docstring'''







		def        __lowerCAmelCase		( self		:						str      )  ->			str:
			__magic_name__	:   Optional[Any]					     =					get_test_to_tester_mapping(_A      )
			__magic_name__	:   Any					     =					get_test_to_tester_mapping(_A      )

			__magic_name__	:   Union[str, Any]					     =					{'BertModelTest': 'BertModelTester'}

			__magic_name__	:   Dict					     =					{
			    'BlipModelTest': 'BlipModelTester',
			    'BlipTextImageModelTest': 'BlipTextImageModelsModelTester',
			    'BlipTextModelTest': 'BlipTextModelTester',
			    'BlipTextRetrievalModelTest': 'BlipTextRetrievalModelTester',
			    'BlipVQAModelTest': 'BlipVQAModelTester',
			    'BlipVisionModelTest': 'BlipVisionModelTester',
			}

			self.assertEqual(get_test_info.to_json(_A      )  ,					_A      )
			self.assertEqual(get_test_info.to_json(_A      )  ,					_A      )







		def        __lowerCAmelCase		( self		:						Optional[Any]      )  ->			Union[str, Any]:
			__magic_name__	:   Dict					     =					get_model_to_test_mapping(_A      )
			__magic_name__	:   List[str]					     =					get_model_to_test_mapping(_A      )

			__magic_name__	:   Dict					     =					{
			    'BertForMaskedLM': ['BertModelTest'],
			    'BertForMultipleChoice': ['BertModelTest'],
			    'BertForNextSentencePrediction': ['BertModelTest'],
			    'BertForPreTraining': ['BertModelTest'],
			    'BertForQuestionAnswering': ['BertModelTest'],
			    'BertForSequenceClassification': ['BertModelTest'],
			    'BertForTokenClassification': ['BertModelTest'],
			    'BertLMHeadModel': ['BertModelTest'],
			    'BertModel': ['BertModelTest'],
			}

			__magic_name__	:   Optional[Any]					     =					{
			    'BlipForConditionalGeneration': ['BlipTextImageModelTest'],
			    'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTest'],
			    'BlipForQuestionAnswering': ['BlipVQAModelTest'],
			    'BlipModel': ['BlipModelTest'],
			    'BlipTextModel': ['BlipTextModelTest'],
			    'BlipVisionModel': ['BlipVisionModelTest'],
			}

			self.assertEqual(get_test_info.to_json(_A      )  ,					_A      )
			self.assertEqual(get_test_info.to_json(_A      )  ,					_A      )







		def        __lowerCAmelCase		( self		:						Union[str, Any]      )  ->			Dict:
			__magic_name__	:   Union[str, Any]					     =					get_model_to_tester_mapping(_A      )
			__magic_name__	:   Union[str, Any]					     =					get_model_to_tester_mapping(_A      )

			__magic_name__	:   Any					     =					{
			    'BertForMaskedLM': ['BertModelTester'],
			    'BertForMultipleChoice': ['BertModelTester'],
			    'BertForNextSentencePrediction': ['BertModelTester'],
			    'BertForPreTraining': ['BertModelTester'],
			    'BertForQuestionAnswering': ['BertModelTester'],
			    'BertForSequenceClassification': ['BertModelTester'],
			    'BertForTokenClassification': ['BertModelTester'],
			    'BertLMHeadModel': ['BertModelTester'],
			    'BertModel': ['BertModelTester'],
			}

			__magic_name__	:   Tuple					     =					{
			    'BlipForConditionalGeneration': ['BlipTextImageModelsModelTester'],
			    'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTester'],
			    'BlipForQuestionAnswering': ['BlipVQAModelTester'],
			    'BlipModel': ['BlipModelTester'],
			    'BlipTextModel': ['BlipTextModelTester'],
			    'BlipVisionModel': ['BlipVisionModelTester'],
			}

			self.assertEqual(get_test_info.to_json(_A      )  ,					_A      )
			self.assertEqual(get_test_info.to_json(_A      )  ,					_A      )



'''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 typing import TYPE_CHECKING

from ..models.auto import AutoModelForVisionaSeq
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
							from PIL import Image
class _lowerCamelCase	(						lowercase__							):



		'''simple docstring'''







		A_     :      Any				   =    """Salesforce/blip-image-captioning-base"""
		A_     :      Any				   =    (
		    """This is a tool that generates a description of an image. It takes an input named `image` which should be the """
		    """image to caption, and returns a text that contains the description in English."""
		)
		A_     :      List[str]				   =    """image_captioner"""
		A_     :      Optional[Any]				   =    AutoModelForVisionaSeq

		A_     :      Any				   =    ["""image"""]
		A_     :      Union[str, Any]				   =    ["""text"""]







		def __init__( self		:						Dict  ,					*_A		:						Dict  ,					**_A		:						Any      )  ->			Dict:
			requires_backends(self  ,					['vision']      )
			super().__init__(*_A  ,					**_A      )







		def        __lowerCAmelCase		( self		:						Tuple  ,					_A		:						"Image"      )  ->			Union[str, Any]:
			return self.pre_processor(images=_A  ,					return_tensors='pt'      )







		def        __lowerCAmelCase		( self		:						Optional[Any]  ,					_A		:						str      )  ->			List[Any]:
			return self.model.generate(**_A      )







		def        __lowerCAmelCase		( self		:						int  ,					_A		:						Optional[int]      )  ->			Union[str, Any]:
			return self.pre_processor.batch_decode(_A  ,					skip_special_tokens=_A      )[0].strip()