U
    9%e                     @   sT   d dl mZ ddlmZ ddlmZ ddlmZ er@d dlm	Z	 G dd	 d	eZ
d
S )    )TYPE_CHECKING   )AutoModelForVision2Seq)requires_backends   )PipelineTool)Imagec                       sV   e Zd ZdZdZdZeZdgZdgZ	 fddZ
dd	d
dZdd Zdd Z  ZS )ImageCaptioningToolz%Salesforce/blip-image-captioning-basezThis 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.Zimage_captionerimagetextc                    s   t | dg t j|| d S )NZvision)r   super__init__)selfargskwargs	__class__ b/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/tools/image_captioning.pyr   (   s    zImageCaptioningTool.__init__r   )r
   c                 C   s   | j |ddS )Npt)ZimagesZreturn_tensors)pre_processor)r   r
   r   r   r   encode,   s    zImageCaptioningTool.encodec                 C   s   | j jf |S )N)modelgenerate)r   inputsr   r   r   forward/   s    zImageCaptioningTool.forwardc                 C   s   | j j|ddd  S )NT)Zskip_special_tokensr   )r   Zbatch_decodestrip)r   outputsr   r   r   decode2   s    zImageCaptioningTool.decode)__name__
__module____qualname__Zdefault_checkpointdescriptionnamer   Zmodel_classr   r   r   r   r   r   __classcell__r   r   r   r   r	      s   r	   N)typingr   Zmodels.autor   utilsr   baser   ZPILr   r	   r   r   r   r   <module>   s   