Spaces:
Sleeping
Sleeping
| # 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() | |