"""simple docstring"""







from typing import TYPE_CHECKING

from ..models.auto import AutoModelForVisionaSeq
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
   from PIL import Image







class  UpperCamelCase	(    lowercase_						):
   lowercase							=						'Salesforce/blip-image-captioning-base'
   lowercase							=						(
       'This 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.'
   )
   lowercase							=						'image_captioner'
   lowercase							=						AutoModelForVisionaSeq

   lowercase							=						['image']
   lowercase							=						['text']
   def __init__(    self  ,*__UpperCamelCase  ,**__UpperCamelCase    )			->   List[Any]:


        '''simple docstring'''


        requires_backends(self  ,['vision']    )
        super().__init__(*__UpperCamelCase  ,**__UpperCamelCase    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase    )			->   Dict:


        '''simple docstring'''


        return self.pre_processor(images=__UpperCamelCase  ,return_tensors='pt'    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase    )			->   Union[str, Any]:


        '''simple docstring'''


        return self.model.generate(**__UpperCamelCase    )







   def     _UpperCAmelCase     (    self  ,__UpperCamelCase    )			->   List[Any]:


        '''simple docstring'''


        return self.pre_processor.batch_decode(__UpperCamelCase  ,skip_special_tokens=__UpperCamelCase    )[0].strip()


"""simple docstring"""







from argparse import ArgumentParser

from .env import EnvironmentCommand



def     lowercase__( ):
     lowercase_			:       List[Any]									=			ArgumentParser('Diffusers CLI tool'  ,    usage='diffusers-cli <command> [<args>]'   )
     lowercase_			:       int									=			parser.add_subparsers(help='diffusers-cli command helpers'   )

     # Register commands
     EnvironmentCommand.register_subcommand(__SCREAMING_SNAKE_CASE   )

     # Let's go
     lowercase_			:       str									=			parser.parse_args()

     if not hasattr(__SCREAMING_SNAKE_CASE  ,    'func'   ):
          parser.print_help()
          exit(1   )

     # Run
     lowercase_			:       Optional[Any]									=			args.func(__SCREAMING_SNAKE_CASE   )
     service.run()


if __name__ == "__main__":
       main()

