Spaces:
Runtime error
Runtime error
David GG
commited on
Commit
·
4aeaa67
1
Parent(s):
45d9377
add possibility of truncating
Browse files
app.py
CHANGED
|
@@ -7,6 +7,14 @@ model_id = f"{username}/distilhubert-finetuned-gtzan"
|
|
| 7 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 8 |
pipe = pipeline("audio-classification", model=model_id, device=device)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def classify_audio(filepath):
|
| 12 |
"""
|
|
@@ -18,6 +26,7 @@ def classify_audio(filepath):
|
|
| 18 |
{"country": 0.8339303731918335, "rock":0.11914275586605072}
|
| 19 |
"""
|
| 20 |
preds = pipe(filepath)
|
|
|
|
| 21 |
outputs = {}
|
| 22 |
for p in preds:
|
| 23 |
outputs[p["label"]] = p["score"]
|
|
|
|
| 7 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 8 |
pipe = pipeline("audio-classification", model=model_id, device=device)
|
| 9 |
|
| 10 |
+
# def predict_trunc(filepath):
|
| 11 |
+
# preprocessed = pipe.preprocess(filepath)
|
| 12 |
+
# truncated = pipe.feature_extractor.pad(preprocessed,truncation=True, max_length = 16_000*30)
|
| 13 |
+
# model_outputs = pipe.forward(truncated)
|
| 14 |
+
# outputs = pipe.postprocess(model_outputs)
|
| 15 |
+
|
| 16 |
+
# return outputs
|
| 17 |
+
|
| 18 |
|
| 19 |
def classify_audio(filepath):
|
| 20 |
"""
|
|
|
|
| 26 |
{"country": 0.8339303731918335, "rock":0.11914275586605072}
|
| 27 |
"""
|
| 28 |
preds = pipe(filepath)
|
| 29 |
+
# preds = predict_trunc(filepath)
|
| 30 |
outputs = {}
|
| 31 |
for p in preds:
|
| 32 |
outputs[p["label"]] = p["score"]
|