
    qiL                     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
)zVision service implementation.

Provides base classes and implementations for computer vision services that can
analyze images and generate textual descriptions or answers to questions about
visual content.
    )abstractmethod)AsyncGeneratorOptional)FrameUserImageRawFrame)FrameDirection)	AIService)VisionSettingsc                   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 )VisionServicea  Base class for vision services.

    Provides common functionality for vision services that process images and
    generate textual responses. Handles image frame processing and integrates
    with the AI service infrastructure for metrics and lifecycle management.
    N)settingsr   c                N    t        |   dd|xs
 t               i| d| _        y)zInitialize the vision service.

        Args:
            settings: The runtime-updatable settings for the vision service.
            **kwargs: Additional arguments passed to the parent AIService.
        r   N )super__init__r
   _describe_text)selfr   kwargs	__class__s      Q/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/vision_service.pyr   zVisionService.__init__   s;     	 	
   		

 	
 #    framereturnc                    K   yw)a  Process the given vision image and generate results.

        This method must be implemented by subclasses to provide actual computer
        vision functionality such as image description, object detection, or
        visual question answering.

        Args:
            frame: The image frame to process.

        Yields:
            Frame: Frames containing the vision analysis results, typically TextFrame
            objects with descriptions or answers.
        Nr   )r   r   s     r   
run_visionzVisionService.run_vision/   s      	s   	directionc                 p  K   t         |   ||       d{    t        |t              re|j                  rY| j                          d{    | j                  | j                  |             d{    | j                          d{    y| j                  ||       d{    y7 7 b7 <7 &7 w)aW  Process frames, handling vision image frames for analysis.

        Automatically processes UserImageRawFrame objects by calling run_vision
        and handles metrics tracking. Other frames are passed through unchanged.

        Args:
            frame: The frame to process.
            direction: The direction of frame processing.
        N)
r   process_frame
isinstancer   textstart_processing_metricsprocess_generatorr   stop_processing_metrics
push_frame)r   r   r   r   s      r   r   zVisionService.process_frame@   s      g#E9555e./EJJ//111(()?@@@..000//%333 	6 2@03sW   B6B,3B6B.'B63B04B6B2B6&B4'B6.B60B62B64B6)__name__
__module____qualname____doc__r   r
   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      se     @D #H^$< #  &7 N5RV;<W   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>r0      s*     + : = 1 4:4I :4r   