Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,18 @@ from transformers import pipeline
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
gr.Markdown("## 🎵 Audio Classification (Keyword Spotting)")
|
|
|
|
| 6 |
classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
|
| 7 |
|
| 8 |
def classify_audio(audio):
|
|
|
|
| 9 |
if audio is None:
|
| 10 |
+
return {"error": "No audio provided"}
|
| 11 |
+
|
| 12 |
+
# Gradio audio returns (sample_rate, data)
|
| 13 |
+
sr, data = audio
|
| 14 |
+
|
| 15 |
+
# Convert to Hugging Face expected format
|
| 16 |
+
inputs = {"array": data, "sampling_rate": sr}
|
| 17 |
+
|
| 18 |
+
# Run classification
|
| 19 |
+
results = classifier(inputs)
|
| 20 |
+
return results
|
| 21 |
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
gr.Markdown("## 🎵 Audio Classification (Keyword Spotting)")
|