Lightmourne commited on
Commit
bb2ea49
1 Parent(s): 8576747

Add application file

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ model_id = "Lightmourne/distilhubert-finetuned-gtzan"
5
+ pipe = pipeline("audio-classification", model=model_id)
6
+
7
+ def classify_audio(filepath):
8
+ preds = pipe(filepath)
9
+ outputs = {}
10
+ for p in preds:
11
+ outputs[p["label"]] = p["score"]
12
+ return outputs
13
+
14
+
15
+ demo = gr.Blocks()
16
+
17
+ title = "Simple music genre classifier"
18
+ description = """
19
+ A simple music genre classifier allows you to categorize a music track into one of ten music genres, such as: "blues", "classical", "country", "disco", "hiphop", "jazz", "metal", "pop", "reggae", "rock". Link to the fine-tuned model checkpoint: https://huggingface.co/Lightmourne/distilhubert-finetuned-gtzan
20
+ """
21
+
22
+ mic_classify_audio = gr.Interface(
23
+ fn=classify_audio,
24
+ inputs=gr.Audio(source="microphone", type="filepath"),
25
+ outputs=gr.outputs.Label(),
26
+ title=title,
27
+ description=description,
28
+ )
29
+
30
+ file_classify_audio = gr.Interface(
31
+ fn=classify_audio,
32
+ inputs=gr.Audio(source="upload", type="filepath"),
33
+ outputs=gr.outputs.Label(),
34
+ #examples=[["./example.wav"]],
35
+ title=title,
36
+ description=description,
37
+ )
38
+
39
+ with demo:
40
+ gr.TabbedInterface([mic_classify_audio, file_classify_audio], ["Microphone", "Audio File"])
41
+
42
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/huggingface/transformers