§
    ‚Štj�  ã                   ó2  — U d dl mZ d dlmZmZmZmZ d dlmZ ddl	m
Z
 ddlmZmZ ddlmZ  e¦   «         rd d	lmZ dd
l	mZ eedef                  Zeed<    G d„ de¦  «        Z G d„ de¦  «        Zdedeee                  fd„Z G d„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚ	TypeAliasÚ	TypedDictÚUnion)Úoverloadé   )Úis_pil_image)Úis_vision_availableÚrequires_backendsé   )ÚPipeline)ÚImage©Ú
load_imagezImage.ImageÚ	ImagePairc                   ó$   — e Zd ZU eed<   eed<   dS )ÚKeypointÚxÚyN)Ú__name__Ú
__module__Ú__qualname__ÚfloatÚ__annotations__© ó    úf/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/pipelines/keypoint_matching.pyr   r   "   s"   € € € € € € Ø€H€H�HØ€H€H�H€H€Hr   r   c                   ó.   — e Zd ZU eed<   eed<   eed<   dS )ÚMatchÚkeypoint_image_0Úkeypoint_image_1ÚscoreN)r   r   r   r   r   r   r   r   r   r    r    '   s1   € € € € € € ØÐÐÑØÐÐÑØ€L€L�L€L€Lr   r    ÚimagesÚreturnc                 óò   ‡— d}d„ Št          | t          ¦  «        rNt          | ¦  «        dk    rt          ˆfd„| D ¦   «         ¦  «        r| gS t          ˆfd„| D ¦   «         ¦  «        r| S t	          |¦  «        ‚)N)z-Input images must be a one of the following :z - A pair of images.z - A list of pairs of images.c                 óJ   — t          | ¦  «        pt          | t          ¦  «        S )z"images is a PIL Image or a string.)r
   Ú
isinstanceÚstr)Úimages    r   Ú_is_valid_imagez-validate_image_pairs.<locals>._is_valid_image4   s   € å˜EÑ"Ô"Ð<¥j°½Ñ&<Ô&<Ð<r   r	   c              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S ©Nr   ©Ú.0r*   r+   s     €r   ú	<genexpr>z'validate_image_pairs.<locals>.<genexpr>9   s-   øè è € Ð#QÐ#QÀ _ _°UÑ%;Ô%;Ð#QÐ#QÐ#QÐ#QÐ#QÐ#Qr   c              3   óž   •K  — | ]G}t          |t          ¦  «        o-t          |¦  «        d k    ot          ˆfd„|D ¦   «         ¦  «        V — ŒHdS )r	   c              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S r-   r   r.   s     €r   r0   z1validate_image_pairs.<locals>.<genexpr>.<genexpr>>   s-   øè è € ÐCÐC¨u�O�O EÑ*Ô*ÐCÐCÐCÐCÐCÐCr   N)r(   r   ÚlenÚall)r/   Ú
image_pairr+   s     €r   r0   z'validate_image_pairs.<locals>.<genexpr>;   s}   øè è € ð 
ð 
ð õ �z¥8Ñ,Ô,ð DÝ�J‘” 1Ò$ðDåÐCÐCÐCÐC¸
ÐCÑCÔCÑCÔCð
ð 
ð 
ð 
ð 
ð 
r   )r(   r   r3   r4   Ú
ValueError)r$   Úerror_messager+   s     @r   Úvalidate_image_pairsr8   -   s¶   ø€ ð€Mð=ð =ð =õ �&�(Ñ#Ô#ð 	Ýˆv‰;Œ;˜!ÒÐ¥Ð#QÐ#QÐ#QÐ#QÈ&Ð#QÑ#QÔ#QÑ QÔ QÐØ�8ˆOÝð 
ð 
ð 
ð 
ð %ð	
ñ 
ô 
ñ 
ô 
ð 	ð ˆMÝ
�]Ñ
#Ô
#Ð#r   c                   óB  ‡ — e Zd ZdZdZdZdZdZˆ fd„Zdd„Z	e
dded	ed
edee         fd„¦   «         Ze
ddee         d	ed
edeee                  fd„¦   «         Z	 ddee         ez  d	ed
edee         eee                  z  fˆ fd„Zdd„Zd„ Zddee         fd„Zˆ xZS )ÚKeypointMatchingPipelinez‚
    Keypoint matching pipeline using any `AutoModelForKeypointMatching`. This pipeline matches keypoints between two images.
    FTc                 óZ   •—  t          ¦   «         j        |i |¤Ž t          | d¦  «         d S )NÚvision)ÚsuperÚ__init__r   )ÚselfÚargsÚkwargsÚ	__class__s      €r   r>   z!KeypointMatchingPipeline.__init__O   s5   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)Ý˜$ Ñ)Ô)Ð)Ð)Ð)r   Nc                 ó0   — i }|�||d<   i }|�||d<   |i |fS )NÚtimeoutÚ	thresholdr   )r?   rE   rD   Úpreprocess_paramsÚpostprocess_paramss        r   Ú_sanitize_parametersz-KeypointMatchingPipeline._sanitize_parametersS   s>   € ØÐØÐØ+2Ð˜iÑ(ØÐØÐ Ø.7Ð˜{Ñ+Ø  "Ð&8Ð8Ð8r   ç        ÚinputsrE   rA   r%   c                 ó   — d S r-   r   ©r?   rJ   rE   rA   s       r   Ú__call__z!KeypointMatchingPipeline.__call__\   s   € ØadÐadr   c                 ó   — d S r-   r   rL   s       r   rM   z!KeypointMatchingPipeline.__call___   s   € ØmpÐmpr   c                 ó¶   •— |€t          d¦  «        ‚t          |¦  «        } t          ¦   «         j        |fd|i|¤Ž}t	          |¦  «        dk    r|d         S |S )aø  
        Find matches between keypoints in two images.

        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 pair of images or a batch of image pairs, 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.

            threshold (`float`, *optional*, defaults to 0.0):
                The threshold to use for keypoint matching. Keypoints matched with a lower matching score will be filtered out.
                A value of 0 means that all matched keypoints will be returned.

            kwargs:
                `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:
            Union[list[Match], list[list[Match]]]:
                A list of matches or a list if a single image pair is provided, or of lists of matches if a batch
                of image pairs is provided. Each match is a dictionary containing the following keys:

                - **keypoint_image_0** (`Keypoint`): The keypoint in the first image (x, y coordinates).
                - **keypoint_image_1** (`Keypoint`): The keypoint in the second image (x, y coordinates).
                - **score** (`float`): The matching score between the two keypoints.
        NzFCannot call the keypoint-matching pipeline without an inputs argument!rE   r   r   )r6   r8   r=   rM   r3   )r?   rJ   rE   rA   Úformatted_inputsÚoutputsrB   s         €r   rM   z!KeypointMatchingPipeline.__call__b   so   ø€ ðN ˆ>ÝÐeÑfÔfÐfÝ/°Ñ7Ô7ÐØ"•%‘'”'Ô"Ð#3ÐSÐS¸yÐSÈFÐSÐSˆÝÐÑ Ô  AÒ%Ð%Ø˜1”:ÐØˆr   c                 ó¨   ‡— ˆfd„|D ¦   «         }|                       |d¬¦  «        }|                     | j        ¦  «        }d„ |D ¦   «         }||dœ}|S )Nc                 ó2   •— g | ]}t          |‰¬ ¦  «        ‘ŒS ))rD   r   )r/   r*   rD   s     €r   ú
<listcomp>z7KeypointMatchingPipeline.preprocess.<locals>.<listcomp>’   s&   ø€ ÐIÐIÐI¸•*˜U¨GÐ4Ñ4Ô4ÐIÐIÐIr   Úpt)r$   Úreturn_tensorsc                 ó   — g | ]	}|j         ‘Œ
S r   )Úsize)r/   r*   s     r   rT   z7KeypointMatchingPipeline.preprocess.<locals>.<listcomp>•   s   € Ð7Ð7Ð7 u˜œ
Ð7Ð7Ð7r   )Úmodel_inputsÚtarget_sizes)Úimage_processorÚtoÚdtype)r?   r$   rD   rY   rZ   Úpreprocess_outputss     `   r   Ú
preprocessz#KeypointMatchingPipeline.preprocess‘   sn   ø€ ØIÐIÐIÐIÀ&ÐIÑIÔIˆØ×+Ò+°6È$Ð+ÑOÔOˆØ#—’ t¤zÑ2Ô2ˆØ7Ð7°Ð7Ñ7Ô7ˆØ.:ÈLÐYÐYÐØ!Ð!r   c                 óH   — |d         } | j         di |¤Ž}||d         gdœ}|S )NrY   rZ   )Úmodel_outputsrZ   r   )Úmodel)r?   r^   rY   ra   Úforward_outputss        r   Ú_forwardz!KeypointMatchingPipeline._forward™   s@   € Ø)¨.Ô9ˆØ"˜œ
Ð2Ð2 \Ð2Ð2ˆØ,9ÐL^Ð_mÔLnÐKoÐpÐpˆØÐr   c           	      ó`  — |d         }|d         }| j                              |||¬¦  «        }|d         }g }t          |d         |d         |d         ¦  «        D ]¿\  }}}	t          |d                              ¦   «         |d                              ¦   «         ¬	¦  «        }t          |d                              ¦   «         |d                              ¦   «         ¬	¦  «        }|                     t          |||	                     ¦   «         ¬
¦  «        ¦  «         ŒÀt          |d„ d¬¦  «        }|S )Nra   rZ   )rZ   rE   r   Ú
keypoints0Ú
keypoints1Úmatching_scoresr   )r   r   )r!   r"   r#   c                 ó   — | d         S )Nr#   r   )r   s    r   ú<lambda>z6KeypointMatchingPipeline.postprocess.<locals>.<lambda>¯   s
   € ¸¸'¼
€ r   T)ÚkeyÚreverse)r[   Úpost_process_keypoint_matchingÚzipr   ÚitemÚappendr    Úsorted)
r?   rc   rE   ra   rZ   Úpostprocess_outputsÚpair_resultÚkp_0Úkp_1r#   s
             r   Úpostprocessz$KeypointMatchingPipeline.postprocessŸ   s0  € Ø'¨Ô8ˆØ& ~Ô6ˆØ"Ô2×QÒQØ¨À	ð Rñ 
ô 
Ðð 2°!Ô4ÐØˆÝ!$Ø Ô-Ø Ô-ØÐ 1Ô2ñ"
ô "
ð 	hð 	hÑˆD�$˜õ
 ˜d 1œgŸlšl™nœn°°Q´·²±´Ð?Ñ?Ô?ˆDÝ˜d 1œgŸlšl™nœn°°Q´·²±´Ð?Ñ?Ô?ˆDØ×Ò�u°dÈTÐY^×YcÒYcÑYeÔYeÐfÑfÔfÑgÔgÐgÐgÝ˜[Ð.BÐ.BÈDÐQÑQÔQˆØÐr   )NN)rI   r-   )r   r   r   Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr>   rH   r   r   r   r   Úlistr    rM   r_   rd   rv   Ú__classcell__)rB   s   @r   r:   r:   E   s”  ø€ € € € € ðð ð €OØ ÐØ#ÐØ€Oð*ð *ð *ð *ð *ð9ð 9ð 9ð 9ð ØdÐd˜yÐd°UÐdÈCÐdÐTXÐY^ÔT_ÐdÐdÐdñ „XØdàØpÐp˜t IœÐp¸5ÐpÐRUÐpÐZ^Ð_cÐdiÔ_jÔZkÐpÐpÐpñ „XØpð
 ð-ð -à�Y” )Ñ+ð-ð ð-ð ð	-ð
 
ˆeŒ�t˜D œKÔ(Ñ	(ð-ð -ð -ð -ð -ð -ð^"ð "ð "ð "ðð ð ðð ¸TÀ%¼[ð ð ð ð ð ð ð ð r   r:   N)Úcollections.abcr   Útypingr   r   r   r   Útyping_extensionsr   Úimage_utilsr
   Úutilsr   r   Úbaser   ÚPILr   r   r)   r   r   r   r    r8   r:   r   r   r   ú<module>r…      s¤  ðð %Ð $Ð $Ð $Ð $Ð $Ð $Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3à &Ð &Ð &Ð &Ð &Ð &à &Ð &Ð &Ð &Ð &Ð &Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø Ð Ð Ð Ð Ð ð ÐÑÔð )ØÐÐÐÐÐà(Ð(Ð(Ð(Ð(Ð(ð    m°SÐ&8Ô 9Ô:€	ˆ9Ð :Ð :Ñ :ðð ð ð ð ˆyñ ô ð ð
ð ð ð ð ˆIñ ô ð ð$ ð $¨°(¸9Ô2EÔ)Fð $ð $ð $ð $ð0kð kð kð kð k˜xñ kô kð kð kð kr   