
    g                     ^    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
dS )
    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                      j        |i | d S )Nvision)r   super__init__)selfargskwargs	__class__s      h/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/agents/image_question_answering.pyr   z#ImageQuestionAnsweringTool.__init__-   s7    $
+++$)&)))))    r   r   c                 2    |                      ||d          S )Npt)return_tensors)pre_processor)r   r   r   s      r   encodez!ImageQuestionAnsweringTool.encode1   s    !!%$!GGGr   c                     t          j                    5   | j        di |j        cd d d            S # 1 swxY w Y   d S )N )torchno_gradmodellogits)r   inputss     r   forwardz"ImageQuestionAnsweringTool.forward4   s    ]__ 	/ 	/4:''''.	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   377c                 ~    |                     d                                          }| j        j        j        |         S )N)argmaxitemr%   configid2label)r   outputsidxs      r   decodez!ImageQuestionAnsweringTool.decode8   s2    nnR  %%''z )#..r   )__name__
__module____qualname__default_checkpointr   namer   pre_processor_classr   model_classr'   output_typer   strr    r(   r1   __classcell__)r   s   @r   r   r      s        :	=  D'5K t
 
 &6OPP F K* * * * *HG Hs H H H H/ / // / / / / / /r   r   )r#   PILr   models.autor   r   utilsr   toolsr	   r   r"   r   r   <module>r@      s   $        L L L L L L L L % % % % % %       /  /  /  /  /  /  /  /  /  /r   