File size: 646 Bytes
83d8dae 54f3543 83d8dae 54f3543 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from transformers import pipeline, Wav2Vec2Processor, Wav2Vec2ForSequenceClassification
import gradio as gr
model_id = "Tirath5504/distilhubert-finetuned-gtzan"
processor = Wav2Vec2Processor.from_pretrained(model_id)
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_id)
pipe = pipeline("audio-classification", model=model, processor=processor)
def classify_audio(filepath):
preds = pipe(filepath)
outputs = {}
for p in preds:
outputs[p["label"]] = p["score"]
return outputs
demo = gr.Interface(
fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.outputs.Label()
)
demo.launch(debug=True) |