Bartosz Pietrzak commited on
Commit
506e0f1
·
1 Parent(s): 78d27e3

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import librosa
3
+ import json
4
+ import gradio as gr
5
+
6
+
7
+ def audio_pipeline(file_path: str, top_k: int = 7) -> dict[str, float]:
8
+ y, _ = librosa.load(file_path, sr=config['sampling_rate'])
9
+ out = pipe(y, top_k=top_k)
10
+ print(out)
11
+ return {clas['label']: clas['score'] for clas in out}
12
+
13
+
14
+ with open('config.json', 'r') as f:
15
+ config = json.load(f)
16
+
17
+ pipe = pipeline("audio-classification", model=config['models_path'])
18
+
19
+ demo = gr.Interface(
20
+ fn=audio_pipeline,
21
+ inputs=[gr.Audio(type="filepath"), gr.Slider(1, 10, 1,
22
+ label="Top K Results")],
23
+ outputs=gr.Label(num_top_classes=7),
24
+ title="Music Mind Audio Classification",
25
+ description="Upload an .mp3 or .ogg audio file "
26
+ "to classify the content using a pre-trained model.")
27
+
28
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch
2
+ datasets
3
+ transformers[torch]
4
+ evaluate
5
+ numpy
6
+ librosa
7
+ soundfile