Spaces:
Sleeping
Sleeping
File size: 883 Bytes
3b60122 ce74472 58df11d ce74472 4149bce 3b60122 ce74472 3b60122 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# audio_classification_app.py
import gradio as gr
from transformers import pipeline
# Load pipeline (pretrained model)
classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
def classify_audio(audio):
if audio is None:
return {"error": "No audio provided"}
# Gradio audio returns (sample_rate, data)
sr, data = audio
# Convert to Hugging Face expected format
inputs = {"array": data, "sampling_rate": sr}
# Run classification
results = classifier(inputs)
return results
with gr.Blocks() as demo:
gr.Markdown("## 🎵 Audio Classification (Keyword Spotting)")
with gr.Row():
audio_input = gr.Audio(sources=["microphone", "upload"], type="numpy")
output = gr.JSON()
audio_input.change(classify_audio, audio_input, output)
if __name__ == "__main__":
demo.launch()
|