
    |h                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	m
Z
mZ d dlmZmZmZ dZdded	ed
efdZd ZddefdZd ZddedefdZddedefdZdeded
dfdZy)    N)HUBDatasetStats)Auth)HUBTrainingSession)HUB_API_ROOTHUB_WEB_ROOTPREFIXevents)LOGGERSETTINGSchecks)r   r   r   loginlogoutreset_modelexport_fmts_hubexport_model
get_exportcheck_datasetr	   api_keysavereturnc                    t        j                  d       ddlm} t         d}t        j                  d      }| xs |}|r	|dk7  rd|ind} ||      }|j                  re|r0|j                  |k7  r!t        j                  d|j                  i       |j                  | k(  s|sdnd	}t        j                  t         |        y
t        j                  t         d| d       y)aa  
    Log in to the Ultralytics HUB API using the provided API key.

    The session is not stored; a new session is created when needed using the saved SETTINGS or the HUB_API_KEY
    environment variable if successfully authenticated.

    Args:
        api_key (str, optional): API key to use for authentication. If not provided, it will be retrieved from
            SETTINGS or HUB_API_KEY environment variable.
        save (bool, optional): Whether to save the API key to SETTINGS if authentication is successful.

    Returns:
        (bool): True if authentication is successful, False otherwise.
    zhub-sdk>=0.0.12r   )	HUBClientz/settings?tab=api+keysr    Nu!   New authentication successful ✅u   Authenticated ✅TzGet API key from z" and then run 'yolo login API_KEY'F)r   check_requirementshub_sdkr   r   r   getauthenticatedr   updater
   infor   )	r   r   r   api_key_url	saved_key
active_keycredentialsclientlog_messages	            W/var/www/html/test/engine/venv/lib/python3.12/site-packages/ultralytics/hub/__init__.pyr   r      s     /0!!N"89KY'I%IJ-7J"<L9j)RVK{#F FNNi/OOY78 4:>>W3LT_/ex 	 	vh{m,- 	vh/}<^_`    c                  N    dt         d<   t        j                  t         d       y)zJLog out of Ultralytics HUB by removing the API key from the settings file.r   r   u2   logged out ✅. To log in again, use 'yolo login'.N)r   r
   r   r    r'   r&   r   r   F   s     HY
KK6(LMNr'   model_idc                 0   t        j                  t         dd| idt               j                  i      }|j
                  dk(  rt        j                  t         d       yt        j                  t         d|j
                   d	|j                          y)
z,Reset a trained model to an untrained state.z/model-resetmodelId	x-api-keyjsonheaders   zModel reset successfullyNzModel reset failure  )requestspostr   r   r   status_coder
   r   r   warningreason)r*   rs     r&   r   r   L   sy    l39h:OZegkgmguguYvwA}}vh678
NNfX1!--!((LMr'   c                  D    ddl m}  t         |        d   dd       ddgz   S )z.Return a list of HUB-supported export formats.r   export_formatsArgument   Nultralytics_tfliteultralytics_coreml)ultralytics.engine.exporterr;   listr:   s    r&   r   r   U   s+    : ,QR015IK_4```r'   formatc                 b   |t               v sJ d| dt                       t        j                  t         d|  dd|idt	               j
                  i      }|j                  dk(  s)J t         | d	|j                   d
|j                          t        j                  t         | d       y)aC  
    Export a model to a specified format for deployment via the Ultralytics HUB API.

    Args:
        model_id (str): The ID of the model to export. An empty string will use the default model.
        format (str): The format to export the model to. Must be one of the supported formats returned by
            export_fmts_hub().

    Raises:
        AssertionError: If the specified format is not supported or if the export request fails.

    Examples:
        >>> from ultralytics import hub
        >>> hub.export_model(model_id="your_model_id", format="torchscript")
    Unsupported export format '', valid formats are z/v1/models/z/exportrB   r-   r.   r1   z export failure r2   u    export started ✅N)r   r3   r4   r   r   r   r5   r   r7   r
   r   r*   rB   r8   s      r&   r   r   \   s      _&&v*EfXMbcrctbu(vv&.H:W5Xv<NYdfjflftftXu	A ==C^F8F83CAMM?RSTUT\T\S]!^^
KK6(6("567r'   c                 f   |t               v sJ d| dt                       t        j                  t         dt	               j
                  | |ddt	               j
                  i      }|j                  dk(  s)J t         | d|j                   d	|j                          |j                         S )
a  
    Retrieve an exported model in the specified format from Ultralytics HUB using the model ID.

    Args:
        model_id (str): The ID of the model to retrieve from Ultralytics HUB.
        format (str): The export format to retrieve. Must be one of the supported formats returned by
            export_fmts_hub().

    Returns:
        (dict): JSON response containing the exported model information.

    Raises:
        AssertionError: If the specified format is not supported or if the API request fails.

    Examples:
        >>> from ultralytics import hub
        >>> result = hub.get_export(model_id="your_model_id", format="torchscript")
    rD   rE   z/get-export)apiKeyr,   rB   r-   r.   r1   z get_export failure r2   )
r   r3   r4   r   r   r   r5   r   r7   r/   rF   s      r&   r   r   t   s    & _&&v*EfXMbcrctbu(vv&.$8vNdfnn-	A
 ==CbF8F83GVWXYX`X`Wa!bb668Or'   pathtaskc                 t    t        | |      j                          t        j                  dt         d       y)a  
    Check HUB dataset Zip file for errors before upload.

    Args:
        path (str): Path to data.zip (with data.yaml inside data.zip).
        task (str): Dataset task. Options are 'detect', 'segment', 'pose', 'classify', 'obb'.

    Examples:
        >>> from ultralytics.hub import check_dataset
        >>> check_dataset("path/to/coco8.zip", task="detect")  # detect dataset
        >>> check_dataset("path/to/coco8-seg.zip", task="segment")  # segment dataset
        >>> check_dataset("path/to/coco8-pose.zip", task="pose")  # pose dataset
        >>> check_dataset("path/to/dota8.zip", task="obb")  # OBB dataset
        >>> check_dataset("path/to/imagenet10.zip", task="classify")  # classification dataset

    Notes:
        Download *.zip files from https://github.com/ultralytics/hub/tree/main/example_datasets
        i.e. https://github.com/ultralytics/hub/raw/main/example_datasets/coco8.zip for coco8.zip.
    rI   rJ   u7   Checks completed correctly ✅. Upload this dataset to z/datasets/.N)r   get_jsonr
   r   r   rL   s     r&   r   r      s.    ( D)224
KKI,Wbcdr'   )NT)r   )r   torchscript)r3   ultralytics.data.utilsr   ultralytics.hub.authr   ultralytics.hub.sessionr   ultralytics.hub.utilsr   r   r   r	   ultralytics.utilsr
   r   r   __all__strboolr   r   r   r   r   r   r   r)   r'   r&   <module>rW      s     2 % 6 L L 6 6)3 )T )T )XON# Na83 8S 80 3 :e e3 e4 er'   