Ë
    FêñiÑ  ã                   ó  — d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 e j                  j                  dd«      Ze j                  j                  dd«      Z e
d«      Zd	Zd
edefd„Zded
efd„Z	 	 	 	 	 	 dded
ededededededefd„Zy)é    N)ÚAny)ÚIS_COLABÚLOGGERÚTQDMÚ	TryExceptÚcolorstrÚULTRALYTICS_HUB_APIzhttps://api.ultralytics.comÚULTRALYTICS_HUB_WEBzhttps://hub.ultralytics.comzUltralytics HUB: z]If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance.ÚurlÚreturnc                 ó¦   — t         st        d«      ‚ddlm} ddlm} |j                  |j                  d| › d�«      «       |j                  d«      S )a*  Make an AJAX request with cookies attached in a Google Colab environment.

    Args:
        url (str): The URL to make the request to.

    Returns:
        (Any): The response data from the AJAX request.

    Raises:
        OSError: If the function is not run in a Google Colab environment.
    z:request_with_credentials() must run in a Colab environmentr   )Úoutput)ÚdisplayzÊ
            window._hub_tmp = new Promise((resolve, reject) => {
                const timeout = setTimeout(() => reject("Failed authenticating existing browser session"), 5000)
                fetch("až  ", {
                    method: 'POST',
                    credentials: 'include'
                })
                    .then((response) => resolve(response.json()))
                    .then((json) => {
                    clearTimeout(timeout);
                    }).catch((err) => {
                    clearTimeout(timeout);
                    reject(err);
                });
            });
            Ú_hub_tmp)r   ÚOSErrorÚgoogle.colabr   ÚIPythonr   Ú
JavascriptÚeval_js)r   r   r   s      úW/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/hub/utils.pyÚrequest_with_credentialsr      sZ   € õ ÜÐRÓSÐSÝ#Ýà‡O�OØ×Ñðð �uð ðó	
ôð( �>‰>˜*Ó%Ð%ó    Úmethodc                 óú  — ddl }|j                  dd«      }|s |j                  | |fi |¤ŽS  |j                  | |fddi|¤Ž}t        t	        |t
        «      r|j                  j                  dd«      n|«      }	 t        |ddd	¬
«      }|j                  d	¬«      D ]  }|j                  t        |«      «       Œ |j                  «        |S # |j                  j                  $ r |j                  «        Y |S w xY w)a£  Make an HTTP request using the specified method and URL, with an optional progress bar.

    Args:
        method (str): The HTTP method to use (e.g. 'GET', 'POST').
        url (str): The URL to send the request to.
        **kwargs (Any): Additional keyword arguments to pass to the underlying `requests.request` function.

    Returns:
        (requests.Response): The response object from the HTTP request.

    Notes:
        - If 'progress' is set to True, the progress bar will display the download progress for responses with a known
          content length.
        - If 'progress' is a number then progress bar will display assuming content length = progress.
    r   NÚprogressFÚstreamTzcontent-lengthÚBi   )ÚtotalÚunitÚ
unit_scaleÚunit_divisor)Ú
chunk_size)ÚrequestsÚpopÚrequestÚintÚ
isinstanceÚboolÚheadersÚgetr   Úiter_contentÚupdateÚlenÚcloseÚ
exceptionsÚChunkedEncodingError)	r   r   Úkwargsr#   r   Úresponser   ÚpbarÚdatas	            r   Úrequests_with_progressr5   ?   sû   € ó  à�z‰z˜* eÓ,€HÙØˆx×Ñ ¨Ñ6¨vÑ6Ð6Øˆx×Ñ ¨ÑC°DÐC¸FÑC€HÜ¼ZÈÔRVÔ=W�× Ñ ×$Ñ$Ð%5°qÔ9Ð]eÓf€EðÜ˜% c°dÈÔNˆØ×)Ñ)°TÐ)Ó:ò 	#ˆDØ�K‰Kœ˜D›	Õ"ð	#à�
‰
Œð €Oøð ×Ñ×3Ñ3ò Ø�‰ÕØ€Oðús   Á;AC Ã)C:Ã9C:ÚretryÚtimeoutÚthreadÚcodeÚverboser   c                 ó¶   ‡‡‡‡‡— dŠt        ‰¬«      ˆˆˆˆˆfd„«       }	| |f}
||d<   |r(t        j                  |	|
|d¬«      j                  «        y |	|
i |¤ŽS )a$  Make an HTTP request using the 'requests' library, with exponential backoff retries up to a specified timeout.

    Args:
        method (str): The HTTP method to use for the request. Choices are 'post' and 'get'.
        url (str): The URL to make the request to.
        retry (int, optional): Number of retries to attempt before giving up.
        timeout (int, optional): Timeout in seconds after which the function will give up retrying.
        thread (bool, optional): Whether to execute the request in a separate daemon thread.
        code (int, optional): An identifier for the request, used for logging purposes.
        verbose (bool, optional): A flag to determine whether to print out to console or not.
        progress (bool, optional): Whether to show a progress bar during the request.
        **kwargs (Any): Keyword arguments to be passed to the requests function specified in method.

    Returns:
        (requests.Response | None): The HTTP response object. If the request is executed in a separate thread, returns
            None.
    )i˜  iô  )r:   c                 ó¤  •— d}t        j                   «       }t        ‰	dz   «      D �]  }t        j                   «       |z
  ‰kD  r |S t        | |fi |¤Ž}|j                  dk  r |S 	 |j	                  «       j                  dd«      }|dk(  r˜|j                  ‰
v r|‰	r	d‰	› d	‰› d
�ndz  }n0|j                  dk(  r!|j                  }d|d   › d|d   › d|d   › d
�}‰r5t        j                  t        › |› dt        › d|j                  › d‰› d�	«       |j                  ‰
vr|c S t        j                  d|z  «       �Œ |S # t        $ r d}Y ŒÇw xY w)zNMake HTTP requests with retries and timeouts, with optional progress tracking.Né   i,  ÚmessagezNo JSON message.zUnable to read JSON.r   z
 Retrying zx for zs.Ú i­  zRate limit reached (zX-RateLimit-Remainingú/zX-RateLimit-Limitz). Please retry after zRetry-Afterú z (z #ú)é   )ÚtimeÚranger5   Ústatus_codeÚjsonr*   ÚAttributeErrorr)   r   ÚwarningÚPREFIXÚHELP_MSGÚsleep)Úfunc_methodÚfunc_urlÚfunc_kwargsÚrÚt0ÚiÚmÚhr9   r6   Úretry_codesr7   r:   s           €€€€€r   Úfunczsmart_request.<locals>.func~   s€  ø€ ð ˆÜ�Y‰Y‹[ˆÜ�u˜q‘yÓ!ó 	ˆAÜ—	‘	“˜bÑ  GÒ+Øð, ˆô+ ' {°HÑLÀÑLˆAØ�}‰}˜sÒ"Øð& ˆð%+Ø—F‘F“H—L‘L Ð,>Ó?�ð �AŠvØ—=‘= KÑ/ØÁ%˜: e W¨F°7°)¸2Ñ>ÈRÑO‘AØ—]‘] cÒ)ØŸ	™	�Aà.¨qÐ1HÑ/IÐ.JÈ!ÈAÐNaÑLbÐKcð d.Ø./°Ñ.>Ð-?¸rðCð ñ Ü—N‘N¤f X¨a¨S°´(°¸2¸a¿m¹m¸_ÈBÈtÈfÐTUÐ#VÔWØ—=‘=¨Ñ3Ø’HÜ�J‰J�q˜!‘tÖð/	ð0 ˆøô! "ò +Ø*’ð+ús   Á' EÅEÅEr   T)ÚtargetÚargsr1   ÚdaemonN)r   Ú	threadingÚThreadÚstart)r   r   r6   r7   r8   r9   r:   r   r1   rV   rX   rU   s     `` ``    @r   Úsmart_requestr]   `   sf   ü€ ð8 €Kä�wÔ÷ó  ðð< �3ˆ;€DØ!€Fˆ:ÑÙÜ×Ñ ¨4¸ÀtÔL×RÑRÕTá�TÐ$˜VÑ$Ð$r   )é   é   TéÿÿÿÿTF)ÚosrZ   rD   Útypingr   Úultralytics.utilsr   r   r   r   r   Úenvironr*   ÚHUB_API_ROOTÚHUB_WEB_ROOTrJ   rK   Ústrr   r5   r&   r(   r]   © r   r   ú<module>ri      sñ   ðó 
Û Û Ý ÷õ ð �z‰z�~‰~Ð3Ð5RÓS€Ø�z‰z�~‰~Ð3Ð5RÓS€á	Ð%Ó	&€Øj€ð%& #ð %&¨#ó %&ðP 3ð ¨Só ðH ØØØØØñB%ØðB%à	ðB%ð ðB%ð ð	B%ð
 ðB%ð ðB%ð ðB%ð ôB%r   