File size: 1,274 Bytes
2e35d02
7b88933
a54b6d7
0b472d5
9422011
2e35d02
3b3366c
9422011
 
 
 
5852718
3b3366c
9226479
b370699
 
 
 
 
 
b9908bd
5852718
8a9e88a
b9908bd
 
0cce770
c4da767
0cce770
b44551d
8a9e88a
5852718
 
 
 
c4da767
 
e189ca5
5852718
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
from transformers import pipeline


model_id = "Teapack1/model_KWS"  # update with your model id
pipe = pipeline("audio-classification", model=model_id)


title = "Keyword Spotting Wav2Vec2"
description = "Gradio demo for finetuned Wav2Vec2 model on a custom dataset to perform keyword spotting task. Classes are scene 1, scene 2, scene 3, yes, no and stop."

demo = gr.Blocks()

def classify_audio(audio):
    preds = pipe(audio)
    outputs = {}
    for p in preds:
        outputs[p["label"]] = p["score"]
    return outputs

    
mic_classify = gr.Interface(
    fn=classify_audio,
    inputs=gr.inputs.Audio(source="microphone", type="filepath", label="Record your audio"),
    outputs=gr.outputs.Label(),
    title=title,
    theme="huggingface",
    description=description
)

file_classify = gr.Interface(
    fn=classify_audio,
    title=title,
    description=description,
    inputs=gr.inputs.Audio(source="upload", optional=True, label="Audio file", type="filepath"),
    theme="huggingface",
    outputs=gr.outputs.Label(),
)

# iface.test_examples(example_samples)


with demo:
    gr.TabbedInterface(
        [mic_classify, file_classify],
        ["Classify Microphone", "Classify Audio File"],
    )


demo.launch(debug=True, share=True)