o
    i>	                     @   sZ   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dd	e	d
e	de
f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)	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_dataFco2_eq_emissions	emissionsz\d+\.\d+|\d+r   )
ValueErrormathinfgetattr
isinstancedictr   getresearchstrfloatgroup)r   r   r   r   emissionmatchedemission_value r   c/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/huggingface_hub/utils/endpoint_helpers.py_is_emission_within_threshold   s&   
r   )__doc__r   r   typingr   repocard_datar   hf_apir   r   boolr   r   r   r   r   <module>   s   