






"""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

import torch

from ..models.auto import AutoModelForVisualQuestionAnswering, AutoProcessor
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
			from PIL import Image







class      UpperCamelCase_			(__A	):
	__magic_name__       =							'''dandelin/vilt-b32-finetuned-vqa'''
	__magic_name__       =							(
	    '''This is a tool that answers a question about an image. It takes an input named `image` which should be the '''
	    '''image containing the information, as well as a `question` which should be the question in English. It '''
	    '''returns a text that is the answer to the question.'''
	)
	__magic_name__       =							'''image_qa'''
	__magic_name__       =							AutoProcessor
	__magic_name__       =							AutoModelForVisualQuestionAnswering

	__magic_name__       =							['''image''', '''text''']
	__magic_name__       =							['''text''']





	def __init__( self   :					Optional[Any]      ,      *lowerCAmelCase_   :					List[str]      ,      **lowerCAmelCase_   :					List[Any]		)		->     Optional[int]:
				requires_backends(self      ,      ["vision"]		)
				super().__init__(*lowerCAmelCase_      ,      **lowerCAmelCase_		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]      ,      lowerCAmelCase_   :					"Image"      ,      lowerCAmelCase_   :					str		)		->     Optional[Any]:
				return self.pre_processor(lowerCAmelCase_      ,      lowerCAmelCase_      ,      return_tensors="pt"		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					Union[str, Any]      ,      lowerCAmelCase_   :					str		)		->     Union[str, Any]:
				with torch.no_grad():
							return self.model(**lowerCAmelCase_		).logits





	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]      ,      lowerCAmelCase_   :					Any		)		->     str:
				UpperCAmelCase_	:					List[Any]     	=   outputs.argmax(-1		).item()
				return self.model.config.idalabel[idx]





from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase					   =       logging.get_logger(__name__)

__lowerCAmelCase					   =       {
    'alibaba-damo/mgp-str-base': 'https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json',
}





class     lowerCamelCase      (       __lowerCamelCase					):
	UpperCamelCase_  :					Union[str, Any]    		=	'mgp-str'







	def __init__(     self      :Union[str, Any]   ,     lowercase      :Union[str, Any]=[3_2, 1_2_8]   ,     lowercase      :Tuple=4   ,     lowercase      :Optional[int]=3   ,     lowercase      :Union[str, Any]=2_7   ,     lowercase      :List[str]=3_8   ,     lowercase      :Optional[Any]=5_0_2_5_7   ,     lowercase      :str=3_0_5_2_2   ,     lowercase      :Dict=7_6_8   ,     lowercase      :List[Any]=1_2   ,     lowercase      :List[str]=1_2   ,     lowercase      :Optional[Any]=4.0   ,     lowercase      :Optional[Any]=True   ,     lowercase      :str=False   ,     lowercase      :Optional[Any]=1e-5   ,     lowercase      :List[str]=0.0   ,     lowercase      :List[Any]=0.0   ,     lowercase      :Optional[int]=0.0   ,     lowercase      :Dict=False   ,     lowercase      :Optional[Any]=0.02   ,     **lowercase      :Optional[Any]   ,     )		->      Dict:







				"""simple docstring"""






				super().__init__(**lowercase			)

				SCREAMING_SNAKE_CASE     						= image_size
				SCREAMING_SNAKE_CASE     						= patch_size
				SCREAMING_SNAKE_CASE     						= num_channels
				SCREAMING_SNAKE_CASE     						= max_token_length
				SCREAMING_SNAKE_CASE     						= num_character_labels
				SCREAMING_SNAKE_CASE     						= num_bpe_labels
				SCREAMING_SNAKE_CASE     						= num_wordpiece_labels
				SCREAMING_SNAKE_CASE     						= hidden_size
				SCREAMING_SNAKE_CASE     						= num_hidden_layers
				SCREAMING_SNAKE_CASE     						= num_attention_heads
				SCREAMING_SNAKE_CASE     						= mlp_ratio
				SCREAMING_SNAKE_CASE     						= distilled
				SCREAMING_SNAKE_CASE     						= layer_norm_eps
				SCREAMING_SNAKE_CASE     						= drop_rate
				SCREAMING_SNAKE_CASE     						= qkv_bias
				SCREAMING_SNAKE_CASE     						= attn_drop_rate
				SCREAMING_SNAKE_CASE     						= drop_path_rate
				SCREAMING_SNAKE_CASE     						= output_aa_attentions
				SCREAMING_SNAKE_CASE     						= initializer_range