Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -36,11 +36,12 @@ def augment_and_extract_features(audio_path, sr=16000, n_mfcc=40, n_fft=2048, ho
|
|
36 |
def predict_voice(audio_file_path):
|
37 |
try:
|
38 |
features_tensor = augment_and_extract_features(audio_file_path)
|
39 |
-
#
|
40 |
-
if features_tensor.dim()
|
41 |
-
features_tensor = features_tensor.
|
42 |
-
#
|
43 |
-
|
|
|
44 |
with torch.no_grad():
|
45 |
outputs = model(features_tensor)
|
46 |
|
|
|
36 |
def predict_voice(audio_file_path):
|
37 |
try:
|
38 |
features_tensor = augment_and_extract_features(audio_file_path)
|
39 |
+
# Correct the tensor shape to match expected input format for convolutional layers
|
40 |
+
if features_tensor.dim() > 4: # Check if tensor has extra dimensions
|
41 |
+
features_tensor = features_tensor.squeeze() # Remove unnecessary dimensions
|
42 |
+
if features_tensor.shape[-1] < model.config.num_labels: # Ensure sufficient length for model input
|
43 |
+
padding_size = model.config.num_labels - features_tensor.shape[-1]
|
44 |
+
features_tensor = torch.nn.functional.pad(features_tensor, (0, padding_size), "constant", 0)
|
45 |
with torch.no_grad():
|
46 |
outputs = model(features_tensor)
|
47 |
|