Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -32,6 +32,15 @@ def get_melspec_feature(X, target_sr, frame_size, frame_shift_len, n_mels):
|
|
32 |
melspec_feature.append(audio_melspec)
|
33 |
return np.array(melspec_feature, dtype=np.float32)
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def predict_genre(audio):
|
37 |
sr, audio = audio
|
@@ -39,7 +48,7 @@ def predict_genre(audio):
|
|
39 |
# audio = np.ndarray(audio)
|
40 |
audio = audio.astype(np.float32)
|
41 |
melspec = get_melspec_feature(audio, target_sr, frame_size, frame_shift_len, 128)
|
42 |
-
melspec = melspec
|
43 |
prediction = model.predict(melspec)[0]
|
44 |
return {genre_classes[i]: float(prediction[i]) for i in range(5)}
|
45 |
|
|
|
32 |
melspec_feature.append(audio_melspec)
|
33 |
return np.array(melspec_feature, dtype=np.float32)
|
34 |
|
35 |
+
def process_data_for_conv2D(X, resize_shape=None):
|
36 |
+
X_conv2D = []
|
37 |
+
for sample in X:
|
38 |
+
sample = np.reshape(sample, newshape=(sample.shape[0], sample.shape[1], 1))
|
39 |
+
if resize_shape:
|
40 |
+
sample = resize(sample, output_shape=resize_shape)
|
41 |
+
X_conv2D.append(sample)
|
42 |
+
return np.array(X_conv2D, dtype=np.float32)
|
43 |
+
|
44 |
|
45 |
def predict_genre(audio):
|
46 |
sr, audio = audio
|
|
|
48 |
# audio = np.ndarray(audio)
|
49 |
audio = audio.astype(np.float32)
|
50 |
melspec = get_melspec_feature(audio, target_sr, frame_size, frame_shift_len, 128)
|
51 |
+
melspec = process_data_for_conv2D(melspec)
|
52 |
prediction = model.predict(melspec)[0]
|
53 |
return {genre_classes[i]: float(prediction[i]) for i in range(5)}
|
54 |
|