Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- ear/semantic.py +8 -5
- requirements.txt +4 -2
ear/semantic.py
CHANGED
|
@@ -129,12 +129,15 @@ class _Semantic:
|
|
| 129 |
best_e, best_s = e, s
|
| 130 |
mono48 = mono48[best_s : best_s + want]
|
| 131 |
|
|
|
|
| 132 |
with self._lock, torch.no_grad():
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
sampling_rate=CLAP_SR,
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
audio_emb = self._model.get_audio_features(**inputs)
|
| 139 |
audio_emb = audio_emb / audio_emb.norm(dim=-1, keepdim=True)
|
| 140 |
sims = (audio_emb @ self._text_emb.T).squeeze(0).cpu().numpy()
|
|
|
|
| 129 |
best_e, best_s = e, s
|
| 130 |
mono48 = mono48[best_s : best_s + want]
|
| 131 |
|
| 132 |
+
clip = mono48.astype(np.float32)
|
| 133 |
with self._lock, torch.no_grad():
|
| 134 |
+
# transformers 4.x takes `audios`, 5.x renamed it to `audio`.
|
| 135 |
+
try:
|
| 136 |
+
inputs = self._processor(audio=clip, sampling_rate=CLAP_SR,
|
| 137 |
+
return_tensors="pt")
|
| 138 |
+
except TypeError:
|
| 139 |
+
inputs = self._processor(audios=clip, sampling_rate=CLAP_SR,
|
| 140 |
+
return_tensors="pt")
|
| 141 |
audio_emb = self._model.get_audio_features(**inputs)
|
| 142 |
audio_emb = audio_emb / audio_emb.norm(dim=-1, keepdim=True)
|
| 143 |
sims = (audio_emb @ self._text_emb.T).squeeze(0).cpu().numpy()
|
requirements.txt
CHANGED
|
@@ -5,5 +5,7 @@ numpy
|
|
| 5 |
scipy
|
| 6 |
soundfile
|
| 7 |
torch==2.6.0+cpu
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
|
|
|
|
|
| 5 |
scipy
|
| 6 |
soundfile
|
| 7 |
torch==2.6.0+cpu
|
| 8 |
+
# Unpinned on purpose: pinning <5 forces huggingface-hub<1.0, which collides
|
| 9 |
+
# with the version the Spaces runtime preinstalls. semantic.py handles the
|
| 10 |
+
# 4.x/5.x processor signature difference at the call site instead.
|
| 11 |
+
transformers
|