File size: 696 Bytes
3b60122
 
 
 
ce74472
 
58df11d
ce74472
 
 
 
 
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
# 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):
    # audio is a tuple: (sample_rate, numpy array)
    if audio is None:
        return "No audio provided"
    return classifier(audio)

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()