Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
# Load audio classification pipeline
|
| 5 |
-
classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
|
| 6 |
-
|
| 7 |
-
def classify_audio(
|
| 8 |
-
# audio
|
| 9 |
-
return classifier(
|
| 10 |
-
|
| 11 |
-
# Gradio UI
|
| 12 |
-
demo = gr.Interface(
|
| 13 |
-
fn=classify_audio,
|
| 14 |
-
inputs=gr.Audio(type="filepath"),
|
| 15 |
-
outputs=gr.Label(num_top_classes=5),
|
| 16 |
-
title="Audio Classification",
|
| 17 |
-
description="Upload an audio file
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
if __name__ == "__main__":
|
| 21 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load audio classification pipeline
|
| 5 |
+
classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
|
| 6 |
+
|
| 7 |
+
def classify_audio(file_path):
|
| 8 |
+
# Hugging Face audio pipeline works best with a filepath
|
| 9 |
+
return classifier(file_path)
|
| 10 |
+
|
| 11 |
+
# Gradio UI
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
fn=classify_audio,
|
| 14 |
+
inputs=gr.Audio(type="filepath", label="Upload or Record Audio"),
|
| 15 |
+
outputs=gr.Label(num_top_classes=5),
|
| 16 |
+
title="Audio Classification App",
|
| 17 |
+
description="Upload or record an audio file (mp3, wav, flac, etc.) and classify the sound."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
demo.launch()
|