Teapack1's picture
Update app.py
e189ca5
raw
history blame
1.32 kB
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."
example_samples = [
("path_to_audio_file_1.wav",),
("path_to_audio_file_2.wav",),
# Add more example samples as needed
]
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,
description=description
)
file_classify = gr.Interface(
fn=classify_audio,
title=title,
description=description,
inputs=gr.Audio(sources="upload", type="filepath"),
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)