Repository: huggingface/huggingface_hub
Pull request #757 (2022-03-09 16:30:43)

New release (requirements are still too strict.)
Missed the real `requirements.txt` earlier.

Fixes #758 


Patch:
diff --git a/api-inference-community/requirements.txt b/api-inference-community/requirements.txt
index e7194fc6..119957cc 100644
--- a/api-inference-community/requirements.txt
+++ b/api-inference-community/requirements.txt
@@ -1,7 +1,7 @@
-starlette==0.14.2
+starlette>=0.14.2
 numpy>=1.18.0
-pydantic==1.8.1
-parameterized==0.8.1
-pillow==8.2.0
+pydantic>=1.8.1
+parameterized>=0.8.1
+pillow>=8.2.0
 huggingface_hub>=0.0.12
-datasets==1.10
+datasets>=1.10
diff --git a/api-inference-community/setup.py b/api-inference-community/setup.py
index c795fe44..19485292 100644
--- a/api-inference-community/setup.py
+++ b/api-inference-community/setup.py
@@ -3,7 +3,7 @@ from setuptools import setup
 
 setup(
     name="api_inference_community",
-    version="0.0.21",
+    version="0.0.23",
     description="A package with helper tools to build an API Inference docker app for Hugging Face API inference using huggingface_hub",
     url="http://github.com/huggingface/api-inference-community",
     author="Nicolas Patry",
diff --git a/src/huggingface_hub/utils/endpoint_helpers.py b/src/huggingface_hub/utils/endpoint_helpers.py
index 0285cecd..196de655 100644
--- a/src/huggingface_hub/utils/endpoint_helpers.py
+++ b/src/huggingface_hub/utils/endpoint_helpers.py
@@ -49,12 +49,12 @@ def _filter_emissions(
         if hasattr(model, "cardData"):
             if isinstance(model.cardData, dict):
                 emission = model.cardData.get("co2_eq_emissions", None)
-                if isinstance(emissions, dict):
-                    emission = emissions["emissions"]
+                if isinstance(emission, dict):
+                    emission = emission["emissions"]
                 if emission:
                     emission = str(emission)
                     if any(char.isdigit() for char in emission):
-                        emission = re.search("\d+\.\d+", str(emission)).group(0)
+                        emission = re.search("\d+\.\d+|\d+", emission).group(0)
                         emissions.append((i, float(emission)))
     filtered_results = []
     for (idx, emission) in emissions:


Test patch:
diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py
index 507b6754..674d6dca 100644
--- a/tests/test_hf_api.py
+++ b/tests/test_hf_api.py
@@ -47,7 +47,11 @@ from huggingface_hub.hf_api import (
     repo_type_and_id_from_hf_id,
 )
 from huggingface_hub.utils import logging
-from huggingface_hub.utils.endpoint_helpers import DatasetFilter, ModelFilter
+from huggingface_hub.utils.endpoint_helpers import (
+    DatasetFilter,
+    ModelFilter,
+    _filter_emissions,
+)
 from requests.exceptions import HTTPError
 
 from .testing_constants import (
@@ -861,6 +865,14 @@ class HfApiPublicTest(unittest.TestCase):
         models = _api.list_models("co2_eq_emissions")
         self.assertTrue(all([not hasattr(model, "cardData") for model in models]))
 
+    def test_filter_emissions_dict(self):
+        # tests that dictionary is handled correctly as "emissions" and that
+        # 17g is accepted and parsed correctly as a value
+        # regression test for #753
+        model = ModelInfo(cardData={"co2_eq_emissions": {"emissions": "17g"}})
+        res = _filter_emissions([model], -1, 100)
+        assert len(res) == 1
+
     @with_production_testing
     def test_filter_emissions_with_max(self):
         _api = HfApi()