Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,9 +26,15 @@ def loading_sound_file(sound_file, sr=22050, duration=10):
|
|
| 26 |
# print ("fixing audio lenght :", file_name)
|
| 27 |
# y = lib.util.fix_length(X, input_length)
|
| 28 |
# extract normalized mfcc feature from data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
mfccs = np.mean(lib.feature.mfcc(y=X, sr=sr, n_mfcc=25).T,axis=0)
|
| 30 |
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
return data
|
| 34 |
|
|
@@ -37,15 +43,26 @@ def loading_sound_file(sound_file, sr=22050, duration=10):
|
|
| 37 |
def heart_signal_classification(data):
|
| 38 |
X = loading_sound_file(data)
|
| 39 |
pred = model.predict(X)
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
labels = {
|
| 43 |
-
0: '
|
| 44 |
-
1: '
|
| 45 |
-
2: '
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return label
|
| 50 |
################### Gradio Web APP ################################
|
| 51 |
title = "Heart Signal Classification App"
|
|
|
|
| 26 |
# print ("fixing audio lenght :", file_name)
|
| 27 |
# y = lib.util.fix_length(X, input_length)
|
| 28 |
# extract normalized mfcc feature from data
|
| 29 |
+
|
| 30 |
+
## pad audio to same duration
|
| 31 |
+
if round(dur) < duration:
|
| 32 |
+
X = lib.util.fix_length(X, input_length)
|
| 33 |
+
|
| 34 |
mfccs = np.mean(lib.feature.mfcc(y=X, sr=sr, n_mfcc=25).T,axis=0)
|
| 35 |
|
| 36 |
+
## Reshape to match the model's input shape
|
| 37 |
+
data = np.array(mfccs).reshape([1, -1, 1)
|
| 38 |
|
| 39 |
return data
|
| 40 |
|
|
|
|
| 43 |
def heart_signal_classification(data):
|
| 44 |
X = loading_sound_file(data)
|
| 45 |
pred = model.predict(X)
|
| 46 |
+
## Define the threshold
|
| 47 |
+
threshold = 0.6
|
| 48 |
+
max_prob = np.max(pred)
|
| 49 |
+
|
| 50 |
+
## Create labels
|
| 51 |
labels = {
|
| 52 |
+
0: 'artifact',
|
| 53 |
+
1: 'unlabel',
|
| 54 |
+
2: 'extrastole',
|
| 55 |
+
3: 'extrahls',
|
| 56 |
+
4: 'normal',
|
| 57 |
+
5: 'murmur'
|
| 58 |
}
|
| 59 |
+
|
| 60 |
+
if max_prob < threshold:
|
| 61 |
+
label = 'unknown'
|
| 62 |
+
else:
|
| 63 |
+
result = pred[0].argmax()
|
| 64 |
+
label = labels[result]
|
| 65 |
+
|
| 66 |
return label
|
| 67 |
################### Gradio Web APP ################################
|
| 68 |
title = "Heart Signal Classification App"
|