Teapack1's picture
Update app.py
8a9e88a
raw
history blame
990 Bytes
from transformers import pipeline
import gradio as gr
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."
def classify_audio(filepath):
preds = pipe(filepath)
outputs = {}
for p in preds:
outputs[p["label"]] = p["score"]
return outputs
demo = gr.Blocks()
mic_transcribe = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(sources="microphone", type="filepath"),
outputs=gr.outputs.Label()
)
mic_transcribe = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(sources="upload", type="filepath"),
outputs=gr.outputs.Label()
)
with demo:
gr.TabbedInterface(
[mic_transcribe, file_transcribe],
["Transcribe Microphone", "Transcribe Audio File"],
)