Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ def embed_audio(path):
|
|
| 31 |
audio = load_audio(path)
|
| 32 |
|
| 33 |
inputs = processor(
|
| 34 |
-
|
| 35 |
sampling_rate=TARGET_SR,
|
| 36 |
return_tensors="pt",
|
| 37 |
padding=True,
|
|
@@ -40,11 +40,15 @@ def embed_audio(path):
|
|
| 40 |
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 41 |
|
| 42 |
with torch.no_grad():
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
embedding = embedding.detach().cpu().numpy().astype(np.float32)[0]
|
| 46 |
|
| 47 |
-
# Normalize for cosine similarity
|
| 48 |
norm = np.linalg.norm(embedding)
|
| 49 |
if norm == 0:
|
| 50 |
return embedding
|
|
|
|
| 31 |
audio = load_audio(path)
|
| 32 |
|
| 33 |
inputs = processor(
|
| 34 |
+
audios=audio,
|
| 35 |
sampling_rate=TARGET_SR,
|
| 36 |
return_tensors="pt",
|
| 37 |
padding=True,
|
|
|
|
| 40 |
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 41 |
|
| 42 |
with torch.no_grad():
|
| 43 |
+
output = model.get_audio_features(**inputs)
|
| 44 |
+
|
| 45 |
+
if hasattr(output, "pooler_output"):
|
| 46 |
+
embedding = output.pooler_output
|
| 47 |
+
else:
|
| 48 |
+
embedding = output
|
| 49 |
|
| 50 |
embedding = embedding.detach().cpu().numpy().astype(np.float32)[0]
|
| 51 |
|
|
|
|
| 52 |
norm = np.linalg.norm(embedding)
|
| 53 |
if norm == 0:
|
| 54 |
return embedding
|