Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -100,26 +100,20 @@ def ensemble_prediction(audio_file, apply_noise_reduction=False, segment_duratio
|
|
| 100 |
return most_common
|
| 101 |
|
| 102 |
def predict_emotion(audio_file, use_ensemble=False, apply_noise_reduction=False, segment_duration=3.0, overlap=1.0):
|
| 103 |
-
"""
|
| 104 |
-
Main prediction function:
|
| 105 |
-
- Uses ensemble prediction if enabled.
|
| 106 |
-
- Otherwise, processes the entire audio at once.
|
| 107 |
-
Returns the emotion label enhanced with an emoji.
|
| 108 |
-
"""
|
| 109 |
try:
|
| 110 |
if use_ensemble:
|
| 111 |
label = ensemble_prediction(audio_file, apply_noise_reduction, segment_duration, overlap)
|
| 112 |
else:
|
| 113 |
temp_file = preprocess_audio(audio_file, apply_noise_reduction)
|
| 114 |
-
result = classifier.classify_file(temp_file)
|
| 115 |
os.remove(temp_file)
|
| 116 |
|
| 117 |
-
if isinstance(result,
|
| 118 |
-
label = result[
|
| 119 |
else:
|
| 120 |
-
label = result
|
| 121 |
|
| 122 |
-
return add_emoji_to_label(
|
| 123 |
except Exception as e:
|
| 124 |
return f"Error processing file: {str(e)}"
|
| 125 |
|
|
|
|
| 100 |
return most_common
|
| 101 |
|
| 102 |
def predict_emotion(audio_file, use_ensemble=False, apply_noise_reduction=False, segment_duration=3.0, overlap=1.0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
try:
|
| 104 |
if use_ensemble:
|
| 105 |
label = ensemble_prediction(audio_file, apply_noise_reduction, segment_duration, overlap)
|
| 106 |
else:
|
| 107 |
temp_file = preprocess_audio(audio_file, apply_noise_reduction)
|
| 108 |
+
result = classifier.classify_file(temp_file)
|
| 109 |
os.remove(temp_file)
|
| 110 |
|
| 111 |
+
if isinstance(result, tuple) and len(result) > 3:
|
| 112 |
+
label = result[3][0] # Extract the predicted label (e.g., 'hap')
|
| 113 |
else:
|
| 114 |
+
label = str(result) # Convert to string if unexpected format
|
| 115 |
|
| 116 |
+
return add_emoji_to_label(label.lower()) # Ensure lowercase for consistency
|
| 117 |
except Exception as e:
|
| 118 |
return f"Error processing file: {str(e)}"
|
| 119 |
|