o
    5ti                     @   s   d dl mZ d dlZd dlmZmZ d dlmZ ddlm	Z	 ddl
mZ eeZ								dd	ed
ededededededededededeeef dedeeef defddZdS )    )DictN)dataset_info
model_info)metadata_update   )HF_HUB_ALLOWED_TASKS)
get_loggerFmodel_id	task_typedataset_typedataset_namemetric_typemetric_namemetric_value	task_namedataset_configdataset_splitdataset_revisiondataset_argsmetric_configmetric_args	overwritec              	   C   sl  |t vrtdt  zt| W n tjjy'   td| d|  Y nw zt|  W n tjjyA   td|  d|  w d|i||d||dgd	}|d
ur[||d d< |	d
ure|	|d d< |
d
uro|
|d d< |d
ury||d d< |d
ur||d d< |d
ur||d d d< |d
ur||d d d< |d
ur||d d d< dd|gigi}t	| ||dS )a  
    Pushes the result of a metric to the metadata of a model repository in the Hub.

    Args:
        model_id (`str`):
            Model id from https://hf.co/models.
        task_type (`str`):
            Task id, refer to the [Hub allowed tasks](https://github.com/huggingface/evaluate/blob/main/src/evaluate/config.py#L154) for allowed values.
        dataset_type (`str`):
            Dataset id from https://hf.co/datasets.
        dataset_name (`str`):
            Pretty name for the dataset.
        metric_type (`str`):
            Metric id from https://hf.co/metrics.
        metric_name (`str`):
            Pretty name for the metric.
        metric_value (`float`):
            Computed metric value.
        task_name (`str`, *optional*):
            Pretty name for the task.
        dataset_config (`str`, *optional*):
            Dataset configuration used in [`~datasets.load_dataset`].
            See [`~datasets.load_dataset`] for more info.
        dataset_split (`str`, *optional*):
            Name of split used for metric computation.
        dataset_revision (`str`, *optional*):
            Git hash for the specific version of the dataset.
        dataset_args (`dict[str, int]`, *optional*):
            Additional arguments passed to [`~datasets.load_dataset`].
        metric_config (`str`, *optional*):
            Configuration for the metric (e.g. the GLUE metric has a configuration for each subset).
        metric_args (`dict[str, int]`, *optional*):
            Arguments passed during [`~evaluate.EvaluationModule.compute`].
        overwrite (`bool`, *optional*, defaults to `False`):
            If set to `True` an existing metric field can be overwritten, otherwise
             attempting to overwrite any existing fields will cause an error.

    Example:

    ```python
    >>> push_to_hub(
    ...     model_id="huggingface/gpt2-wikitext2",
    ...     metric_value=0.5
    ...     metric_type="bleu",
    ...     metric_name="BLEU",
    ...     dataset_name="WikiText",
    ...     dataset_type="wikitext",
    ...     dataset_split="test",
    ...     task_type="text-generation",
    ...     task_name="Text Generation"
    ... )
    ```z/Task type not supported. Task has to be one of zDataset z( not found on the Hub at hf.co/datasets/zModel z not found on the Hub at hf.co/type)r   name)r   value)taskdatasetmetricsNr   configsplitrevisionargsr   r   r   r   zmodel-indexresults)repo_idmetadatar   )
r   
ValueErrorr   requests
exceptions	HTTPErrorloggerwarningr   r   )r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   resultr$    r,   @/home/ubuntu/.local/lib/python3.10/site-packages/evaluate/hub.pypush_to_hub   sP   Er.   )NNNNNNNF)typingr   r&   huggingface_hubr   r   huggingface_hub.repocardr   r   r   utils.loggingr   __name__r)   strfloatintboolr.   r,   r,   r,   r-   <module>   s\    	


