






"""simple docstring"""





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    __lowerCamelCase    (  _a  ):
   a      :				Tuple 						="""dandelin/vilt-b32-finetuned-vqa"""
   a      :				str 						=(
       """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."""
   )
   a      :				Optional[Any] 						="""image_qa"""
   a      :				Dict 						=AutoProcessor
   a      :				int 						=AutoModelForVisualQuestionAnswering

   a      :				str 						=["""image""", """text"""]
   a      :				List[Any] 						=["""text"""]

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

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_      )		->       Any:
       return self.pre_processor(snake_case_ ,				snake_case_ ,				return_tensors='pt'      )

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_      )		->       Dict:
       with torch.no_grad():
           return self.model(**snake_case_      ).logits







   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_      )		->       List[Any]:
       UpperCamelCase__         =    outputs.argmax(-1      ).item()
       return self.model.config.idalabel[idx]







"""simple docstring"""





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


A__					: List[str]=	logging.get_logger(__name__)
class    __lowerCamelCase    (  _a  ):
   a      :				Optional[int] 						="""timm_backbone"""

   def __init__(					self ,				snake_case_=None ,				snake_case_=3 ,				snake_case_=True ,				snake_case_=True ,				snake_case_=None ,				**snake_case_ ,				)		->       Dict:
       super().__init__(**snake_case_      )
       UpperCamelCase__         =    backbone
       UpperCamelCase__         =    num_channels
       UpperCamelCase__         =    features_only
       UpperCamelCase__         =    use_pretrained_backbone
       UpperCamelCase__         =    True
       UpperCamelCase__         =    out_indices if out_indices is not None else (-1,)




