File size: 1,089 Bytes
752c5ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio
from gradio import Interface, Audio, Label, Number

username = 'bvallegc' ## Complete your username
model_id = f"{username}/distilhubert-finetuned-gtzan"
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

interface_options = {
    "title": "Spoofing Classification",
    "description": "The audio classifier for those who are the best and only want and require the best",
    # Audio from validation file
    "allow_flagging": "never"
}

demo = Interface(
    fn=classify_audio, inputs= Audio(type="filepath"), outputs=[Label(), Number()], **interface_options
)
demo.launch(debug=False)