shamik-lseg commited on
Commit
bbb0227
โ€ข
1 Parent(s): ac23769

Added app.py, sample sound recordings and readme.

Browse files
Files changed (7) hide show
  1. README.md +0 -12
  2. app.py +33 -0
  3. shazam.png +0 -0
  4. song1.ogg +0 -0
  5. song2.ogg +0 -0
  6. song3.ogg +0 -0
  7. song4.ogg +0 -0
README.md CHANGED
@@ -1,13 +1 @@
1
- ---
2
- title: Music Genre Classifier
3
- emoji: ๐Ÿ†
4
- colorFrom: pink
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 4.7.1
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
1
 
 
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import librosa
3
+ from transformers import pipeline
4
+
5
+ pipe = pipeline("audio-classification", model="Shamik/whisper-base.en-finetuned-gtzan")
6
+
7
+ title = """Music Genre Classifier"""
8
+ description = """
9
+ Next time you think of how Shazam <img src="shzam.png" width=200px> finds the name of the song,
10
+ well it might certainly be classifying the genre of the music too. This tool classifies music based
11
+ on pre-defined genre from the [GTZAN](https://huggingface.co/datasets/marsyas/gtzan) dataset,
12
+ which contains music from the following genres:
13
+ `blues, classical, country, disco, hiphop, jazz, metal, pop, reggae, and rock`.
14
+ """
15
+
16
+ def classify_audio(filepath):
17
+ audio, sampling_rate = librosa.load(filepath, sr=16_000)
18
+ preds = pipe(audio)
19
+ outputs = {}
20
+ for p in preds:
21
+ outputs[p["label"]] = p["score"]
22
+ return outputs
23
+
24
+
25
+ label = gr.outputs.Label()
26
+
27
+ demo = gr.Interface(fn=classify_audio,
28
+ inputs=gr.Audio(type="filepath"),
29
+ outputs=label,
30
+ title=title,
31
+ description=description,
32
+ examples=[["song1.ogg"], ["song2.ogg"], ["song3.ogg"], ["song4.ogg"]],)
33
+ demo.launch()
shazam.png ADDED
song1.ogg ADDED
Binary file (341 kB). View file
 
song2.ogg ADDED
Binary file (408 kB). View file
 
song3.ogg ADDED
Binary file (384 kB). View file
 
song4.ogg ADDED
Binary file (396 kB). View file