Spaces:
Sleeping
Sleeping
Commit
路
5d02408
1
Parent(s):
c1e8004
Initial commit
Browse files
app.py
CHANGED
|
@@ -14,24 +14,9 @@ SR = 22050
|
|
| 14 |
DURATION = 5
|
| 15 |
N_MELS = 128
|
| 16 |
|
| 17 |
-
def preprocess_audio(file):
|
| 18 |
-
y, _ = librosa.load(file.name, sr=SR, duration=DURATION)
|
| 19 |
-
if len(y) < SR * DURATION:
|
| 20 |
-
y = np.pad(y, (0, SR * DURATION - len(y)))
|
| 21 |
-
mel = librosa.feature.melspectrogram(y=y, sr=SR, n_mels=N_MELS)
|
| 22 |
-
mel_db = librosa.power_to_db(mel, ref=np.max)
|
| 23 |
-
mel_db = mel_db[..., np.newaxis] # Dodaj kana艂
|
| 24 |
-
mel_db = np.expand_dims(mel_db, axis=0) # Dodaj batch
|
| 25 |
-
return mel_db
|
| 26 |
-
|
| 27 |
-
def predict_instrument(audio_file):
|
| 28 |
-
mel_input = preprocess_audio(audio_file)
|
| 29 |
-
preds = model.predict(mel_input)[0]
|
| 30 |
-
result = {cls: float(score) for cls, score in zip(INSTRUMENTS, preds)}
|
| 31 |
-
return result
|
| 32 |
|
| 33 |
demo = gr.Interface(
|
| 34 |
-
fn=
|
| 35 |
inputs=gr.Audio(type="file", label="Wgraj plik WAV"),
|
| 36 |
outputs=gr.Label(num_top_classes=3),
|
| 37 |
title="Rozpoznawanie Instrument贸w",
|
|
|
|
| 14 |
DURATION = 5
|
| 15 |
N_MELS = 128
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
+
fn=print("F"),
|
| 20 |
inputs=gr.Audio(type="file", label="Wgraj plik WAV"),
|
| 21 |
outputs=gr.Label(num_top_classes=3),
|
| 22 |
title="Rozpoznawanie Instrument贸w",
|