From 85859ccf152d9792a4ee2070e4a4a6a4a7190061 Mon Sep 17 00:00:00 2001 From: sshell Date: Mon, 6 Jan 2025 18:17:14 -0500 Subject: [PATCH 1/2] fixed is_soundfile_available import --- src/smolagents/types.py | 6 +++--- tests/test_types.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/smolagents/types.py b/src/smolagents/types.py index dbc5d5bd7..4af2dba57 100644 --- a/src/smolagents/types.py +++ b/src/smolagents/types.py @@ -22,7 +22,7 @@ import numpy as np import requests from transformers.utils import ( - is_soundfile_availble, + is_soundfile_available, is_torch_available, is_vision_available, ) @@ -41,7 +41,7 @@ else: Tensor = object -if is_soundfile_availble(): +if is_soundfile_available(): import soundfile as sf @@ -189,7 +189,7 @@ class AgentAudio(AgentType, str): def __init__(self, value, samplerate=16_000): super().__init__(value) - if not is_soundfile_availble(): + if not is_soundfile_available(): raise ImportError("soundfile must be installed in order to handle audio.") self._path = None diff --git a/tests/test_types.py b/tests/test_types.py index e988e8b20..26cddc792 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -26,12 +26,12 @@ require_vision, ) from transformers.utils import ( - is_soundfile_availble, + is_soundfile_available, ) from smolagents.types import AgentAudio, AgentImage, AgentText -if is_soundfile_availble(): +if is_soundfile_available(): import soundfile as sf From 5d10f462ae75c6c3e1cc7f122ee81568cd63127e Mon Sep 17 00:00:00 2001 From: sshell Date: Mon, 6 Jan 2025 18:33:52 -0500 Subject: [PATCH 2/2] add fallback to not break current with previous transformers versions --- src/smolagents/types.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/smolagents/types.py b/src/smolagents/types.py index 4af2dba57..585b569f6 100644 --- a/src/smolagents/types.py +++ b/src/smolagents/types.py @@ -22,11 +22,16 @@ import numpy as np import requests from transformers.utils import ( - is_soundfile_available, is_torch_available, is_vision_available, ) +# for compatibility with mispelling old transformers versions (fixed in https://github.com/huggingface/transformers/pull/35030) +try: + from transformers.utils import is_soundfile_available +except ImportError: + from transformers.utils import is_soundfile_availble as is_soundfile_available + logger = logging.getLogger(__name__) if is_vision_available():