Spaces:
Sleeping
Sleeping
Commit
·
96fc794
1
Parent(s):
e57aff9
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,19 +18,26 @@ pipe = pipeline("audio-classification", model=model_id, device=device)
|
|
| 18 |
|
| 19 |
def classify_audio(filepath):
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
{'score': 0.11914275586605072, 'label': 'rock'},]
|
| 24 |
-
|
| 25 |
-
|
| 26 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
preds = pipe(filepath)
|
| 28 |
-
|
| 29 |
outputs = {}
|
| 30 |
for p in preds:
|
| 31 |
outputs[p["label"]] = p["score"]
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
title = "🎵 Music Genre Classifier"
|
| 36 |
description = """
|
|
@@ -38,14 +45,15 @@ Music Genre Classifier model (Fine-tuned "ntu-spml/distilhubert") Dataset: [GTZA
|
|
| 38 |
"""
|
| 39 |
|
| 40 |
filenames = ['rock-it-21275.mp3']
|
| 41 |
-
filenames = [
|
| 42 |
demo = gr.Interface(
|
| 43 |
fn=classify_audio,
|
| 44 |
inputs=gr.Audio(type="filepath"),
|
| 45 |
outputs=[gr.outputs.Label(), gr.Number(label="Prediction time (s)")],
|
| 46 |
title=title,
|
| 47 |
description=description,
|
| 48 |
-
examples=filenames,
|
| 49 |
)
|
| 50 |
|
|
|
|
| 51 |
demo.launch()
|
|
|
|
| 18 |
|
| 19 |
def classify_audio(filepath):
|
| 20 |
"""
|
| 21 |
+
Goes from
|
| 22 |
+
[{'score': 0.8339303731918335, 'label': 'country'},
|
| 23 |
{'score': 0.11914275586605072, 'label': 'rock'},]
|
| 24 |
+
to
|
| 25 |
+
{"country": 0.8339303731918335, "rock":0.11914275586605072}
|
| 26 |
"""
|
| 27 |
+
import time
|
| 28 |
+
start_time = time.time()
|
| 29 |
+
|
| 30 |
+
# Assuming `pipe` is your model pipeline for inference
|
| 31 |
preds = pipe(filepath)
|
| 32 |
+
|
| 33 |
outputs = {}
|
| 34 |
for p in preds:
|
| 35 |
outputs[p["label"]] = p["score"]
|
| 36 |
+
|
| 37 |
+
end_time = time.time()
|
| 38 |
+
prediction_time = end_time - start_time
|
| 39 |
+
|
| 40 |
+
return outputs, prediction_time
|
| 41 |
|
| 42 |
title = "🎵 Music Genre Classifier"
|
| 43 |
description = """
|
|
|
|
| 45 |
"""
|
| 46 |
|
| 47 |
filenames = ['rock-it-21275.mp3']
|
| 48 |
+
filenames = [f"./{f}" for f in filenames]
|
| 49 |
demo = gr.Interface(
|
| 50 |
fn=classify_audio,
|
| 51 |
inputs=gr.Audio(type="filepath"),
|
| 52 |
outputs=[gr.outputs.Label(), gr.Number(label="Prediction time (s)")],
|
| 53 |
title=title,
|
| 54 |
description=description,
|
| 55 |
+
examples=[(f,) for f in filenames],
|
| 56 |
)
|
| 57 |
|
| 58 |
+
|
| 59 |
demo.launch()
|