Claude commited on
Commit
c084bdc
·
1 Parent(s): 1e87d34

Shim torchaudio.AudioMetaData for pyannote 3.4.0 compat with newer torchaudio, without touching torch stack versions

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -156,6 +156,34 @@ def _get_diar_pipe():
156
  if _diar_pipe is not None:
157
  return _diar_pipe
158
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  from pyannote.audio import Pipeline as DiarPipeline
160
 
161
  token = os.environ.get("HF_TOKEN")
 
156
  if _diar_pipe is not None:
157
  return _diar_pipe
158
  import os
159
+ import torchaudio
160
+
161
+ # Compat shim: pyannote.audio 3.4.0 expects `torchaudio.AudioMetaData` at
162
+ # the top level (true in torchaudio 2.2.x). Newer torchaudio releases
163
+ # dropped that re-export even though the underlying class still exists.
164
+ # Reattach it from wherever it actually lives, without touching the
165
+ # installed torch/torchaudio versions (which the image/video generation
166
+ # tabs on this Space depend on).
167
+ if not hasattr(torchaudio, "AudioMetaData"):
168
+ _meta_cls = None
169
+ for _modpath in (
170
+ "torchaudio._backend.common",
171
+ "torchaudio.backend.common",
172
+ "torchaudio.io",
173
+ ):
174
+ try:
175
+ _mod = __import__(_modpath, fromlist=["AudioMetaData"])
176
+ _meta_cls = getattr(_mod, "AudioMetaData", None)
177
+ if _meta_cls is not None:
178
+ break
179
+ except ImportError:
180
+ continue
181
+ if _meta_cls is not None:
182
+ torchaudio.AudioMetaData = _meta_cls
183
+ print(f"Shimmed torchaudio.AudioMetaData from {_modpath}", flush=True)
184
+ else:
185
+ print("WARN: could not find AudioMetaData to shim onto torchaudio", flush=True)
186
+
187
  from pyannote.audio import Pipeline as DiarPipeline
188
 
189
  token = os.environ.get("HF_TOKEN")