bvallegc commited on
Commit
752c5ce
·
1 Parent(s): 3aea850

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirement.txt +2 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio
3
+ from gradio import Interface, Audio, Label, Number
4
+
5
+ username = 'bvallegc' ## Complete your username
6
+ model_id = f"{username}/distilhubert-finetuned-gtzan"
7
+ pipe = pipeline("audio-classification", model=model_id)
8
+
9
+ def classify_audio(filepath):
10
+ """
11
+ Goes from
12
+ [{'score': 0.8339303731918335, 'label': 'country'},
13
+ {'score': 0.11914275586605072, 'label': 'rock'},]
14
+ to
15
+ {"country": 0.8339303731918335, "rock":0.11914275586605072}
16
+ """
17
+ preds = pipe(filepath)
18
+ classification = [{"label": p["label"], "score": p["score"]} for p in preds]
19
+ label = classification[0]["label"]
20
+ number = classification[0]["score"]
21
+ return label, number
22
+
23
+ interface_options = {
24
+ "title": "Spoofing Classification",
25
+ "description": "The audio classifier for those who are the best and only want and require the best",
26
+ # Audio from validation file
27
+ "allow_flagging": "never"
28
+ }
29
+
30
+ demo = Interface(
31
+ fn=classify_audio, inputs= Audio(type="filepath"), outputs=[Label(), Number()], **interface_options
32
+ )
33
+ demo.launch(debug=False)
requirement.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ git+https://github.com/huggingface/transformers