o
    h                     @   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                       sR   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
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.image_captionerimagetextc                    s"   t | dg t j|i | d S )Nvision)r   super__init__)selfargskwargs	__class__ Y/var/www/html/ai/venv/lib/python3.10/site-packages/transformers/tools/image_captioning.pyr   (   s   zImageCaptioningTool.__init__r   c                 C   s   | j |ddS )Npt)imagesreturn_tensors)pre_processor)r   r   r   r   r   encode,   s   zImageCaptioningTool.encodec                 C   s   | j jdi |S )Nr   )modelgenerate)r   inputsr   r   r   forward/   s   zImageCaptioningTool.forwardc                 C   s   | j j|ddd  S )NT)skip_special_tokensr   )r   batch_decodestrip)r   outputsr   r   r   decode2   s   zImageCaptioningTool.decode)r   r   )__name__
__module____qualname__default_checkpointdescriptionnamer   model_classr   r#   r   r   r   r$   __classcell__r   r   r   r   r	      s    
r	   N)typingr   models.autor   utilsr   baser   PILr   r	   r   r   r   r   <module>   s   