Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- handler.py +19 -10
- requirements.txt +1 -0
handler.py
CHANGED
|
@@ -64,16 +64,25 @@ class EmotionCNN:
|
|
| 64 |
from skimage.transform import resize
|
| 65 |
mel_resized = resize(mel_spec_norm, (224, 224), mode="constant")
|
| 66 |
except ImportError:
|
| 67 |
-
# Fallback:
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
try:
|
| 79 |
from matplotlib import cm
|
|
|
|
| 64 |
from skimage.transform import resize
|
| 65 |
mel_resized = resize(mel_spec_norm, (224, 224), mode="constant")
|
| 66 |
except ImportError:
|
| 67 |
+
# Fallback: resizing with numpy interpolation (nearest neighbor for rows, linear for cols)
|
| 68 |
+
target_h, target_w = 224, 224
|
| 69 |
+
source_h, source_w = mel_spec_norm.shape
|
| 70 |
+
|
| 71 |
+
if source_h > 0 and source_w > 0:
|
| 72 |
+
# 1. Resize height (rows)
|
| 73 |
+
row_indices = np.linspace(0, source_h - 1, target_h).astype(int)
|
| 74 |
+
# Select rows (nearest neighbor)
|
| 75 |
+
temp = mel_spec_norm[row_indices, :]
|
| 76 |
+
|
| 77 |
+
# 2. Resize width (cols)
|
| 78 |
+
mel_resized = np.zeros((target_h, target_w), dtype=mel_spec_norm.dtype)
|
| 79 |
+
x_source = np.arange(source_w)
|
| 80 |
+
x_target = np.linspace(0, source_w - 1, target_w)
|
| 81 |
+
|
| 82 |
+
for i in range(target_h):
|
| 83 |
+
mel_resized[i, :] = np.interp(x_target, x_source, temp[i, :])
|
| 84 |
+
else:
|
| 85 |
+
mel_resized = np.zeros((224, 224))
|
| 86 |
|
| 87 |
try:
|
| 88 |
from matplotlib import cm
|
requirements.txt
CHANGED
|
@@ -15,3 +15,4 @@ fastapi==0.95.2
|
|
| 15 |
uvicorn==0.22.0
|
| 16 |
python-multipart==0.0.6
|
| 17 |
huggingface_hub>=0.19.0
|
|
|
|
|
|
| 15 |
uvicorn==0.22.0
|
| 16 |
python-multipart==0.0.6
|
| 17 |
huggingface_hub>=0.19.0
|
| 18 |
+
scikit-image>=0.21.0
|