
    sg                     V    d dl Z d dlmZ ddlmZmZ ddlmZ ddlm	Z	  G d d	e	      Z
y)
    N)Image   )#AutoModelForVisualQuestionAnsweringAutoProcessor)requires_backends   )PipelineToolc                   h     e Zd ZdZdZdZeZeZ	ddddddd	Z
dZ fd
ZdddefdZd Zd Z xZS )ImageQuestionAnsweringToolzdandelin/vilt-b32-finetuned-vqazlThis is a tool that answers a question about an image. It returns a text that is the answer to the question.image_qaimagezWThe image containing the information. Can be a PIL Image or a string path to the image.)typedescriptionstringzThe question in English)r   questionc                 >    t        | dg       t        |   |i | y )Nvision)r   super__init__)selfargskwargs	__class__s      _/var/www/html/venv/lib/python3.12/site-packages/transformers/agents/image_question_answering.pyr   z#ImageQuestionAnsweringTool.__init__-   s!    $
+$)&)    r   r   c                 *    | j                  ||d      S )Npt)return_tensors)pre_processor)r   r   r   s      r   encodez!ImageQuestionAnsweringTool.encode1   s    !!%$!GGr   c                     t        j                         5   | j                  di |j                  cd d d        S # 1 sw Y   y xY w)N )torchno_gradmodellogits)r   inputss     r   forwardz"ImageQuestionAnsweringTool.forward4   s7    ]]_ 	/4::''..	/ 	/ 	/s	   ;Ac                     |j                  d      j                         }| j                  j                  j                  |   S )N)argmaxitemr%   configid2label)r   outputsidxs      r   decodez!ImageQuestionAnsweringTool.decode8   s4    nnR %%'zz  ))#..r   )__name__
__module____qualname__default_checkpointr   namer   pre_processor_classr   model_classr'   output_typer   strr    r(   r1   __classcell__)r   s   @r   r   r      sp    :	=  D'5K t
 &6OPF K*HG Hs H//r   r   )r#   PILr   models.autor   r   utilsr   toolsr	   r   r"   r   r   <module>r@      s"   $   L %  /  /r   