Teapack1's picture
Update app.py
f9191fe
raw
history blame
No virus
1.45 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."
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,
examples=[
["./scene3_329.wav",],
["./scene1_200.wav"],
["./light_422.wav"],
["./ambient_476.wav"],
],
cache_examples=True,
)
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)