Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,13 +8,13 @@ model_id = f"{username}/distil-wav2vec2-finetuned-giga-speech"
|
|
8 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
9 |
pipe = pipeline("audio-classification", model=model_id, device=device)
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
|
19 |
|
20 |
def classify_audio(filepath):
|
@@ -26,8 +26,10 @@ def classify_audio(filepath):
|
|
26 |
{"Gaming": 0.8339303731918335, "Audiobook":0.11914275586605072}
|
27 |
"""
|
28 |
start_time = timer()
|
29 |
-
preds = pipe(filepath)
|
30 |
-
|
|
|
|
|
31 |
outputs = {}
|
32 |
pred_time = round(timer() - start_time, 5)
|
33 |
for p in preds:
|
|
|
8 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
9 |
pipe = pipeline("audio-classification", model=model_id, device=device)
|
10 |
|
11 |
+
def predict_trunc(filepath):
|
12 |
+
preprocessed = pipe.preprocess(filepath)
|
13 |
+
truncated = pipe.feature_extractor.pad(preprocessed,truncation=True, max_length = 16_000*30)
|
14 |
+
model_outputs = pipe.forward(truncated)
|
15 |
+
outputs = pipe.postprocess(model_outputs)
|
16 |
|
17 |
+
return outputs
|
18 |
|
19 |
|
20 |
def classify_audio(filepath):
|
|
|
26 |
{"Gaming": 0.8339303731918335, "Audiobook":0.11914275586605072}
|
27 |
"""
|
28 |
start_time = timer()
|
29 |
+
#preds = pipe(filepath)
|
30 |
+
|
31 |
+
preds = predict_trunc(filepath)
|
32 |
+
|
33 |
outputs = {}
|
34 |
pred_time = round(timer() - start_time, 5)
|
35 |
for p in preds:
|