a
    ¬Àh>	  ã                   @   sT   d Z ddlZddlZddlmZ ddlmZ er<ddlmZ de	e	e
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)ÚTYPE_CHECKINGé   )ÚModelCardData)Ú	ModelInfor   )Ú
model_infoÚminimum_thresholdÚmaximum_thresholdÚreturnc                 C   sÀ   |du r|du rt dƒ‚|du r$d}|du r2tj}t| ddƒ}|du sTt|ttfƒsXdS | dd¡}t|tƒrv|d }|s~dS t 	dt
|ƒ¡}|du ršd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   úb/var/www/html/assistant/venv/lib/python3.9/site-packages/huggingface_hub/utils/endpoint_helpers.pyÚ_is_emission_within_threshold   s&    
r   )Ú__doc__r   r   Útypingr   Zrepocard_datar   Zhf_apir   r   Úboolr   r   r   r   r   Ú<module>   s   