Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,21 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return classifier({"array": data, "sampling_rate": sr})
|
| 17 |
-
|
| 18 |
-
demo = gr.Interface(
|
| 19 |
-
fn=classify_audio,
|
| 20 |
-
inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
|
| 21 |
-
outputs=gr.Label(),
|
| 22 |
-
title="🎵 Audio Classification",
|
| 23 |
-
description="Upload or record audio. Model: wav2vec2-base-superb-ks"
|
| 24 |
-
)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Load pipeline (pretrained model)
|
| 6 |
+
classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
|
| 7 |
|
| 8 |
+
def classify_audio(audio):
|
| 9 |
+
# audio is a tuple: (sample_rate, numpy array)
|
| 10 |
+
if audio is None:
|
| 11 |
+
return "No audio provided"
|
| 12 |
+
return classifier(audio)
|
| 13 |
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("## 🎵 Audio Classification (Keyword Spotting)")
|
| 16 |
+
with gr.Row():
|
| 17 |
+
audio_input = gr.Audio(sources=["microphone", "upload"], type="numpy")
|
| 18 |
+
output = gr.JSON()
|
| 19 |
+
audio_input.change(classify_audio, audio_input, output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
demo.launch()
|