o
    Zh@%                     @   s   d Z 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
 ddlmZ er.ddlmZ dd	d
ededefddZeG dd dZeG dd dZdS )zz
Helpful utility functions and classes in relation to exploring API endpoints
with the aim for a user-friendly interface.
    N)	dataclass)TYPE_CHECKINGListOptionalUnion   )ModelCardData)	ModelInfo
model_infor	   minimum_thresholdmaximum_thresholdreturnc                 C   s   |du r|du rt d|du rd}|du rtj}t| dd}|du s*t|ttfs,dS |dd}t|tr;|d }|s?dS t	dt
|}|du rMdS t|d	}||  ko]|kS   S )
a  Checks if a model's emission is within a given threshold.

    Args:
        model_info (`ModelInfo`):
            A model info object containing the model's emission information.
        minimum_threshold (`float`):
            A minimum carbon threshold to filter by, such as 1.
        maximum_threshold (`float`):
            A maximum carbon threshold to filter by, such as 10.

    Returns:
        `bool`: Whether the model's emission is within the given threshold.
    NzFBoth `minimum_threshold` and `maximum_threshold` cannot both be `None`	card_dataFZco2_eq_emissionsZ	emissionsz\d+\.\d+|\d+r   )
ValueErrormathinfgetattr
isinstancedictr   getresearchstrfloatgroup)r
   r   r   r   ZemissionZmatchedZemission_value r   ]/var/www/html/lang_env/lib/python3.10/site-packages/huggingface_hub/utils/endpoint_helpers.py_is_emission_within_treshold   s&   
r   c                   @   s   e Zd ZU dZdZee ed< dZee	ee
e f  ed< dZee ed< dZee	ee
e f  ed< dZee	ee
e f  ed< dZee	ee
e f  ed< dZee	ee
e f  ed	< dZee	ee
e f  ed
< dZee	ee
e f  ed< dd ZdS )DatasetFiltera  
    A class that converts human-readable dataset search parameters into ones
    compatible with the REST API. For all parameters capitalization does not
    matter.

    <Tip warning={true}>

        The `DatasetFilter` class is deprecated and will be removed in huggingface_hub>=0.24. Please pass the filter parameters as keyword arguments directly to [`list_datasets`].

    </Tip>

    Args:
        author (`str`, *optional*):
            A string that can be used to identify datasets on
            the Hub by the original uploader (author or organization), such as
            `facebook` or `huggingface`.
        benchmark (`str` or `List`, *optional*):
            A string or list of strings that can be used to identify datasets on
            the Hub by their official benchmark.
        dataset_name (`str`, *optional*):
            A string or list of strings that can be used to identify datasets on
            the Hub by its name, such as `SQAC` or `wikineural`
        language_creators (`str` or `List`, *optional*):
            A string or list of strings that can be used to identify datasets on
            the Hub with how the data was curated, such as `crowdsourced` or
            `machine_generated`.
        language (`str` or `List`, *optional*):
            A string or list of strings representing a two-character language to
            filter datasets by on the Hub.
        multilinguality (`str` or `List`, *optional*):
            A string or list of strings representing a filter for datasets that
            contain multiple languages.
        size_categories (`str` or `List`, *optional*):
            A string or list of strings that can be used to identify datasets on
            the Hub by the size of the dataset such as `100K<n<1M` or
            `1M<n<10M`.
        task_categories (`str` or `List`, *optional*):
            A string or list of strings that can be used to identify datasets on
            the Hub by the designed task, such as `audio_classification` or
            `named_entity_recognition`.
        task_ids (`str` or `List`, *optional*):
            A string or list of strings that can be used to identify datasets on
            the Hub by the specific task such as `speech_emotion_recognition` or
            `paraphrase`.

    Examples:

    ```py
    >>> from huggingface_hub import DatasetFilter

    >>> # Using author
    >>> new_filter = DatasetFilter(author="facebook")

    >>> # Using benchmark
    >>> new_filter = DatasetFilter(benchmark="raft")

    >>> # Using dataset_name
    >>> new_filter = DatasetFilter(dataset_name="wikineural")

    >>> # Using language_creator
    >>> new_filter = DatasetFilter(language_creator="crowdsourced")

    >>> # Using language
    >>> new_filter = DatasetFilter(language="en")

    >>> # Using multilinguality
    >>> new_filter = DatasetFilter(multilinguality="multilingual")

    >>> # Using size_categories
    >>> new_filter = DatasetFilter(size_categories="100K<n<1M")

    >>> # Using task_categories
    >>> new_filter = DatasetFilter(task_categories="audio_classification")

    >>> # Using task_ids
    >>> new_filter = DatasetFilter(task_ids="paraphrase")
    ```
    Nauthor	benchmarkdataset_namelanguage_creatorslanguagemultilingualitysize_categoriestask_categoriestask_idsc                 C   s   t jdtd d S )Nz'DatasetFilter' is deprecated and will be removed in huggingface_hub>=0.24. Please pass the filter parameters as keyword arguments directly to the `list_datasets` method.)categorywarningswarnFutureWarningselfr   r   r   __post_init__   s   
zDatasetFilter.__post_init__)__name__
__module____qualname____doc__r    r   r   __annotations__r!   r   r   r"   r#   r$   r%   r&   r'   r(   r0   r   r   r   r   r   G   s   
 Or   c                   @   s   e Zd ZU dZdZee ed< dZee	ee
e f  ed< dZee	ee
e f  ed< dZee ed< dZee	ee
e f  ed< dZee	ee
e f  ed< dZee	ee
e f  ed	< d
d ZdS )ModelFiltera	  
    A class that converts human-readable model search parameters into ones
    compatible with the REST API. For all parameters capitalization does not
    matter.

    <Tip warning={true}>

        The `ModelFilter` class is deprecated and will be removed in huggingface_hub>=0.24. Please pass the filter parameters as keyword arguments directly to [`list_models`].

    </Tip>

    Args:
        author (`str`, *optional*):
            A string that can be used to identify models on the Hub by the
            original uploader (author or organization), such as `facebook` or
            `huggingface`.
        library (`str` or `List`, *optional*):
            A string or list of strings of foundational libraries models were
            originally trained from, such as pytorch, tensorflow, or allennlp.
        language (`str` or `List`, *optional*):
            A string or list of strings of languages, both by name and country
            code, such as "en" or "English"
        model_name (`str`, *optional*):
            A string that contain complete or partial names for models on the
            Hub, such as "bert" or "bert-base-cased"
        task (`str` or `List`, *optional*):
            A string or list of strings of tasks models were designed for, such
            as: "fill-mask" or "automatic-speech-recognition"
        tags (`str` or `List`, *optional*):
            A string tag or a list of tags to filter models on the Hub by, such
            as `text-generation` or `spacy`.
        trained_dataset (`str` or `List`, *optional*):
            A string tag or a list of string tags of the trained dataset for a
            model on the Hub.

    Examples:

    ```python
    >>> from huggingface_hub import ModelFilter

    >>> # For the author_or_organization
    >>> new_filter = ModelFilter(author_or_organization="facebook")

    >>> # For the library
    >>> new_filter = ModelFilter(library="pytorch")

    >>> # For the language
    >>> new_filter = ModelFilter(language="french")

    >>> # For the model_name
    >>> new_filter = ModelFilter(model_name="bert")

    >>> # For the task
    >>> new_filter = ModelFilter(task="text-classification")

    >>> from huggingface_hub import HfApi

    >>> api = HfApi()
    # To list model tags

    >>> new_filter = ModelFilter(tags="benchmark:raft")

    >>> # Related to the dataset
    >>> new_filter = ModelFilter(trained_dataset="common_voice")
    ```
    Nr    libraryr$   
model_nametasktrained_datasettagsc                 C   s   t dt d S )Nz'ModelFilter' is deprecated and will be removed in huggingface_hub>=0.24. Please pass the filter parameters as keyword arguments directly to the `list_models` method.r*   r.   r   r   r   r0      s   zModelFilter.__post_init__)r1   r2   r3   r4   r    r   r   r5   r7   r   r   r$   r8   r9   r:   r;   r0   r   r   r   r   r6      s   
 Cr6   )r4   r   r   r+   dataclassesr   typingr   r   r   r   Zrepocard_datar   Zhf_apir	   r   boolr   r   r6   r   r   r   r   <module>   s   )a