Spaces:
Runtime error
Runtime error
File size: 1,439 Bytes
752c5ce 29c68df 752c5ce ae21422 752c5ce 29c68df 752c5ce 29c68df 4cb2d25 29c68df |
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 |
from transformers import pipeline
import gradio as gr
from gradio import Interface, Audio, Label, Number
username = 'bvallegc' ## Complete your username
model_id = f"{username}/wav2vec2_spoof_dection1-finetuned-spoofing-classifier"
pipe = pipeline("audio-classification", model=model_id)
def classify_audio(filepath):
"""
Goes from
[{'score': 0.8339303731918335, 'label': 'country'},
{'score': 0.11914275586605072, 'label': 'rock'},]
to
{"country": 0.8339303731918335, "rock":0.11914275586605072}
"""
preds = pipe(filepath)
classification = [{"label": p["label"], "score": p["score"]} for p in preds]
label = classification[0]["label"]
number = classification[0]["score"]
return label, number
examples=['TTS_F_LA_E_7682468.wav', 'TTS_M_LA_E_3371601.wav', 'TTS_M_LA_E_7056254.wav']
examples = [[f"./{f}"] for f in examples]
gr.Interface(
fn = classify_audio,
inputs=[
gr.inputs.Audio(source="microphone", type='filepath', optional=True),
gr.inputs.Audio(source="upload", type='filepath', optional=True),
gr.Textbox(label="Paste audio here"),
],
outputs=[
gr.outputs.Textbox(label="Verification"),
gr.Number(label="Probability"),
],
verbose=True,
examples = examples,
title="Spoofing verification classifier",
description="Detect machine created audios from human-speech.",
theme="huggingface"
).launch() |