
    qi
                     n    d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ  G d d	e      Zy
)zImage generation service implementation.

Provides base functionality for AI-powered image generation services that convert
text prompts into images.
    )abstractmethod)AsyncGeneratorOptional)Frame	TextFrame)FrameDirection)	AIService)ImageGenSettingsc                   l     e Zd ZdZdddee   f fdZedede	e
df   fd       Zd	e
d
ef fdZ xZS )ImageGenServicea  Base class for image generation services.

    Processes TextFrames by using their content as prompts for image generation.
    Subclasses must implement the run_image_gen method to provide actual image
    generation functionality using their specific AI service.
    N)settingsr   c                @    t        |   dd|xs
 t               i| y)zInitialize the image generation service.

        Args:
            settings: The runtime-updatable settings for the image generation service.
            **kwargs: Additional arguments passed to the parent AIService.
        r   N )super__init__r
   )selfr   kwargs	__class__s      P/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/image_service.pyr   zImageGenService.__init__   s1     	 	
 "  !		

 	
    promptreturnc                    K   yw)a  Generate an image from a text prompt.

        This method must be implemented by subclasses to provide actual image
        generation functionality using their specific AI service.

        Args:
            prompt: The text prompt to generate an image from.

        Yields:
            Frame: Frames containing the generated image (typically ImageRawFrame
                or URLImageRawFrame).
        Nr   )r   r   s     r   run_image_genzImageGenService.run_image_gen.   s      	s   frame	directionc                   K   t         |   ||       d{    t        |t              r}| j	                  ||       d{    | j                          d{    | j                  | j                  |j                               d{    | j                          d{    y| j	                  ||       d{    y7 7 7 n7 >7 (7 w)a  Process frames for image generation.

        TextFrames are used as prompts for image generation, while other frames
        are passed through unchanged.

        Args:
            frame: The frame to process.
            direction: The direction of frame processing.
        N)
r   process_frame
isinstancer   
push_framestart_processing_metricsprocess_generatorr   textstop_processing_metrics)r   r   r   r   s      r   r   zImageGenService.process_frame>   s      g#E9555eY'//%333//111((););EJJ)GHHH..000//%333 	6 41H03si   CC)CCCC1CC
C#C$C>C?CCC
CCC)__name__
__module____qualname____doc__r   r
   r   r   strr   r   r   r   r   __classcell__)r   s   @r   r   r      sd     BF 
H-=$> 
  # .2M  4 4> 4 4r   r   N)r(   abcr   typingr   r   pipecat.frames.framesr   r   "pipecat.processors.frame_processorr   pipecat.services.ai_servicer	   pipecat.services.settingsr
   r   r   r   r   <module>r1      s*     + 2 = 1 6:4i :4r   