§
    ‚Štjã  ã                   ó  — d dl mZmZmZ ddlmZmZmZmZm	Z	 ddl
mZmZ  e¦   «         rd dlmZ ddlmZ  e¦   «         rddlmZ  ej        e¦  «        Z e ed	¬
¦  «        ¦  «         G d„ de¦  «        ¦   «         ZdS )é    )ÚAnyÚUnionÚoverloadé   )Úadd_end_docstringsÚis_torch_availableÚis_vision_availableÚloggingÚrequires_backendsé   )ÚPipelineÚbuild_pipeline_init_args)ÚImage)Ú
load_image)Ú(MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMEST)Úhas_image_processorc            
       ód  ‡ — e Zd ZdZdZdZdZdZˆ fd„Ze	de
edf         dedeeef         fd	„¦   «         Ze	dee
edf                  dedeeeef                  fd
„¦   «         Zde
eee         ded         f         dedeeef         eeeef                  z  fˆ fd„Zdd„Zdd„Zd„ Zd„ Zˆ xZS )ÚDepthEstimationPipelineaœ  
    Depth estimation pipeline using any `AutoModelForDepthEstimation`. This pipeline predicts the depth of an image.

    Example:

    ```python
    >>> from transformers import pipeline

    >>> depth_estimator = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
    >>> output = depth_estimator("http://images.cocodataset.org/val2017/000000039769.jpg")
    >>> # This is a tensor with the values being the depth expressed in meters for each pixel
    >>> output["predicted_depth"].shape
    torch.Size([1, 384, 384])
    ```

    Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)


    This depth estimation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
    `"depth-estimation"`.

    See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=depth-estimation).
    FTc                 óŽ   •—  t          ¦   «         j        |i |¤Ž t          | d¦  «         |                      t          ¦  «         d S )NÚvision)ÚsuperÚ__init__r   Úcheck_model_typer   )ÚselfÚargsÚkwargsÚ	__class__s      €úe/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/pipelines/depth_estimation.pyr   z DepthEstimationPipeline.__init__7   sJ   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)Ý˜$ Ñ)Ô)Ð)Ø×ÒÕFÑGÔGÐGÐGÐGó    ÚinputszImage.Imager   Úreturnc                 ó   — d S ©N© ©r   r    r   s      r   Ú__call__z DepthEstimationPipeline.__call__<   s   € Ø\_Ð\_r   c                 ó   — d S r#   r$   r%   s      r   r&   z DepthEstimationPipeline.__call__?   s   € ØhkÐhkr   c                 óŒ   •— d|v r|                      d¦  «        }|€t          d¦  «        ‚ t          ¦   «         j        |fi |¤ŽS )að  
        Predict the depth(s) of the image(s) passed as inputs.

        Args:
            inputs (`str`, `list[str]`, `PIL.Image` or `list[PIL.Image]`):
                The pipeline handles three types of images:

                - A string containing a http link pointing to an image
                - A string containing a local path to an image
                - An image loaded in PIL directly

                The pipeline accepts either a single image or a batch of images, which must then be passed as a string.
                Images in a batch must all be in the same format: all as http links, all as local paths, or all as PIL
                images.
            parameters (`Dict`, *optional*):
                A dictionary of argument names to parameter values, to control pipeline behaviour.
                The only parameter available right now is `timeout`, which is the length of time, in seconds,
                that the pipeline should wait before giving up on trying to download an image.
            timeout (`float`, *optional*, defaults to None):
                The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
                the call may block forever.

        Return:
            A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
            dictionary, if the input is a list of several images, will return a list of dictionaries corresponding to
            the images.

            The dictionaries contain the following keys:

            - **predicted_depth** (`torch.Tensor`) -- The predicted depth by the model as a `torch.Tensor`.
            - **depth** (`PIL.Image`) -- The predicted depth by the model as a `PIL.Image`.
        ÚimagesNzECannot call the depth-estimation pipeline without an inputs argument!)ÚpopÚ
ValueErrorr   r&   )r   r    r   r   s      €r   r&   z DepthEstimationPipeline.__call__B   sU   ø€ ðH �vÐÐØ—Z’Z Ñ)Ô)ˆFØˆ>ÝÐdÑeÔeÐeØ�u‰wŒwÔ Ð1Ð1¨&Ð1Ð1Ð1r   Nc                 óf   — i }|�||d<   t          |t          ¦  «        rd|v r|d         |d<   |i i fS )NÚtimeout)Ú
isinstanceÚdict)r   r-   Ú
parametersr   Úpreprocess_paramss        r   Ú_sanitize_parametersz,DepthEstimationPipeline._sanitize_parametersl   sS   € ØÐØÐØ+2Ð˜iÑ(Ý�j¥$Ñ'Ô'ð 	A¨I¸Ð,CÐ,CØ+5°iÔ+@Ð˜iÑ(Ø  " bÐ(Ð(r   c                 ó®   — t          ||¦  «        }|                      |d¬¦  «        }|                     | j        ¦  «        }|j        d d d…         |d<   |S )NÚpt)r)   Úreturn_tensorséÿÿÿÿÚtarget_size)r   Úimage_processorÚtoÚdtypeÚsize)r   Úimager-   Úmodel_inputss       r   Ú
preprocessz"DepthEstimationPipeline.preprocesst   sY   € Ý˜5 'Ñ*Ô*ˆØ×+Ò+°5ÈÐ+ÑNÔNˆØ#—’ t¤zÑ2Ô2ˆØ&+¤j°°°2°Ô&6ˆ�]Ñ#ØÐr   c                 óT   — |                      d¦  «        } | j        di |¤Ž}||d<   |S )Nr7   r$   )r*   Úmodel)r   r=   r7   Úmodel_outputss       r   Ú_forwardz DepthEstimationPipeline._forward{   s<   € Ø"×&Ò& }Ñ5Ô5ˆØ"˜œ
Ð2Ð2 \Ð2Ð2ˆØ'2ˆ�mÑ$ØÐr   c                 ó  — | j                              ||d         g¦  «        }g }|D ]É}|d                              ¦   «                              ¦   «                              ¦   «         }||                     ¦   «         z
  |                     ¦   «         |                     ¦   «         z
  z  }t          j        |dz   	                    d¦  «        ¦  «        }| 
                    |d         |dœ¦  «         ŒÊt          |¦  «        dk    r|d         n|S )Nr7   Úpredicted_depthéÿ   Úuint8)rD   Údepthr   r   )r8   Úpost_process_depth_estimationÚdetachÚcpuÚnumpyÚminÚmaxr   Ú	fromarrayÚastypeÚappendÚlen)r   rA   ÚoutputsÚformatted_outputsÚoutputrG   s         r   Úpostprocessz#DepthEstimationPipeline.postprocess�   s  € ØÔ&×DÒDØð ˜=Ô)Ð*ñ	
ô 
ˆð ÐØð 	eð 	eˆFØÐ,Ô-×4Ò4Ñ6Ô6×:Ò:Ñ<Ô<×BÒBÑDÔDˆEØ˜UŸYšY™[œ[Ñ(¨U¯YªY©[¬[¸5¿9º9¹;¼;Ñ-FÑGˆEÝ”O U¨S¡[×$8Ò$8¸Ñ$AÔ$AÑBÔBˆEà×$Ò$¸Ð@QÔ9RÐ]bÐ%cÐ%cÑdÔdÐdÐdå'*¨7¡|¤|°qÒ'8Ð'8Ð  Ô#Ð#Ð>OÐOr   )NNr#   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   r   r   Ústrr   r/   r&   Úlistr2   r>   rB   rU   Ú__classcell__)r   s   @r   r   r      s—  ø€ € € € € ðð ð0 €OØ ÐØ#ÐØ€OðHð Hð Hð Hð Hð
 Ø_˜u S¨-Ð%7Ô8Ð_ÀCÐ_ÈDÐQTÐVYÐQYÌNÐ_Ð_Ð_ñ „XØ_àØk˜t E¨#¨}Ð*<Ô$=Ô>ÐkÈ#ÐkÐRVÐW[Ð\_ÐadÐ\dÔWeÔRfÐkÐkÐkñ „XØkð(2Ø˜C  c¤¨M¸4ÀÔ;NÐNÔOð(2Ø[^ð(2à	ˆc�3ˆhŒ˜$˜t C¨ Hœ~Ô.Ñ	.ð(2ð (2ð (2ð (2ð (2ð (2ðT)ð )ð )ð )ðð ð ð ðð ð ðPð Pð Pð Pð Pð Pð Pr   r   N)Útypingr   r   r   Úutilsr   r   r	   r
   r   Úbaser   r   ÚPILr   Úimage_utilsr   Úmodels.auto.modeling_autor   Ú
get_loggerrV   Úloggerr   r$   r   r   ú<module>ri      s`  ðØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 5Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4ð ÐÑÔð )ØÐÐÐÐÐà(Ð(Ð(Ð(Ð(Ð(àÐÑÔð UØTÐTÐTÐTÐTÐTà	ˆÔ	˜HÑ	%Ô	%€ð ÐÐ,Ð,ÀÐFÑFÔFÑGÔGðxPð xPð xPð xPð xP˜hñ xPô xPñ HÔGðxPð xPð xPr   