Spaces:
Sleeping
Sleeping
Commit
路
a2e21e4
1
Parent(s):
a07b202
comit
Browse files
app.py
CHANGED
|
@@ -56,18 +56,15 @@ def resize_spectrogram(S, target_frames=TARGET_FRAMES):
|
|
| 56 |
return S
|
| 57 |
|
| 58 |
def predict_and_plot(audio_path):
|
| 59 |
-
# Wczytaj d藕wi臋k
|
| 60 |
y, _ = librosa.load(audio_path, sr=SR)
|
| 61 |
|
| 62 |
-
# Oblicz i przeskaluj spektrogram
|
| 63 |
S_full = compute_melspectrogram(y)
|
| 64 |
S = resize_spectrogram(S_full)
|
| 65 |
|
| 66 |
-
# Przygotuj do predykcji
|
| 67 |
x = S[np.newaxis, ..., np.newaxis]
|
| 68 |
preds = model.predict(x, verbose=0)[0]
|
| 69 |
|
| 70 |
-
|
| 71 |
fig, ax = plt.subplots(figsize=(8, 4))
|
| 72 |
librosa.display.specshow(S_full, sr=SR, x_axis='time', y_axis='mel', cmap='magma', ax=ax)
|
| 73 |
ax.set_title("Mel-spektrogram")
|
|
@@ -79,7 +76,6 @@ def predict_and_plot(audio_path):
|
|
| 79 |
buf.seek(0)
|
| 80 |
image = Image.open(buf)
|
| 81 |
|
| 82 |
-
# Predykcje jako s艂ownik z polskimi nazwami
|
| 83 |
pred_dict = {polskie_nazwy[label]: float(p) for label, p in zip(LABELS, preds)}
|
| 84 |
return pred_dict, image
|
| 85 |
|
|
@@ -91,7 +87,7 @@ demo = gr.Interface(
|
|
| 91 |
gr.Image(label="Spektrogram")
|
| 92 |
],
|
| 93 |
title="Rozpoznawanie instrument贸w",
|
| 94 |
-
description="Model klasyfikuje d藕wi臋ki do
|
| 95 |
theme=dark_theme,
|
| 96 |
submit_btn="Zatwierd藕",
|
| 97 |
clear_btn="Wyczy艣膰"
|
|
|
|
| 56 |
return S
|
| 57 |
|
| 58 |
def predict_and_plot(audio_path):
|
|
|
|
| 59 |
y, _ = librosa.load(audio_path, sr=SR)
|
| 60 |
|
|
|
|
| 61 |
S_full = compute_melspectrogram(y)
|
| 62 |
S = resize_spectrogram(S_full)
|
| 63 |
|
|
|
|
| 64 |
x = S[np.newaxis, ..., np.newaxis]
|
| 65 |
preds = model.predict(x, verbose=0)[0]
|
| 66 |
|
| 67 |
+
|
| 68 |
fig, ax = plt.subplots(figsize=(8, 4))
|
| 69 |
librosa.display.specshow(S_full, sr=SR, x_axis='time', y_axis='mel', cmap='magma', ax=ax)
|
| 70 |
ax.set_title("Mel-spektrogram")
|
|
|
|
| 76 |
buf.seek(0)
|
| 77 |
image = Image.open(buf)
|
| 78 |
|
|
|
|
| 79 |
pred_dict = {polskie_nazwy[label]: float(p) for label, p in zip(LABELS, preds)}
|
| 80 |
return pred_dict, image
|
| 81 |
|
|
|
|
| 87 |
gr.Image(label="Spektrogram")
|
| 88 |
],
|
| 89 |
title="Rozpoznawanie instrument贸w",
|
| 90 |
+
description="Model klasyfikuje d藕wi臋ki do kilku z klas instrument贸w.",
|
| 91 |
theme=dark_theme,
|
| 92 |
submit_btn="Zatwierd藕",
|
| 93 |
clear_btn="Wyczy艣膰"
|