bismayatosh713 commited on
Commit
4acc3cd
1 Parent(s): 64fbfaf

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+
5
+ MODEL_NAME = "JackismyShephard/whisper-medium.en-finetuned-gtzan"
6
+
7
+ device = 0 if torch.cuda.is_available() else "cpu"
8
+
9
+ pipe = pipeline(
10
+ task="audio-classification",
11
+ model=MODEL_NAME,
12
+ device=device,
13
+ )
14
+
15
+ def classify_audio(filepath):
16
+ preds = pipe(filepath, top_k = 10)
17
+ outputs = {}
18
+ for p in preds:
19
+ outputs[p["label"]] = p["score"]
20
+ return outputs
21
+
22
+ demo = gr.Interface(
23
+ fn=classify_audio,
24
+ inputs= gr.Audio(label="Audio file", type="filepath"),
25
+ outputs=gr.Label(),
26
+ title="Music Genre Classification",
27
+ description=(
28
+ "Classify long-form audio or microphone inputs with the click of a button! Demo uses the"
29
+ f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to classify audio files"
30
+ " of arbitrary length."
31
+ ),
32
+ examples="./examples",
33
+ cache_examples=True,
34
+ allow_flagging="never",
35
+ )
36
+
37
+ demo.launch()