Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -12,6 +12,7 @@ import io
|
|
| 12 |
import random
|
| 13 |
import datetime as dt
|
| 14 |
import copy
|
|
|
|
| 15 |
|
| 16 |
import numpy as np
|
| 17 |
import pandas as pd
|
|
@@ -38,6 +39,30 @@ TRANSPARENT_BG = dict(
|
|
| 38 |
# Speaker sample helpers
|
| 39 |
# ---------------------------------------------------------------------------
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def extract_clip_bytes(waveform, sample_rate, seg_start, seg_end):
|
| 42 |
"""Return WAV bytes for the loudest SAMPLE_MIN–SAMPLE_MAX window in [seg_start, seg_end]."""
|
| 43 |
total_samples = waveform.shape[-1]
|
|
|
|
| 12 |
import random
|
| 13 |
import datetime as dt
|
| 14 |
import copy
|
| 15 |
+
import cv2
|
| 16 |
|
| 17 |
import numpy as np
|
| 18 |
import pandas as pd
|
|
|
|
| 39 |
# Speaker sample helpers
|
| 40 |
# ---------------------------------------------------------------------------
|
| 41 |
|
| 42 |
+
def colorsCSS(n, startingHue=None):
|
| 43 |
+
"""Creates n distinctive CSS hex colors evenly spaced across the hue wheel.
|
| 44 |
+
|
| 45 |
+
Drop-in replacement for su.colorsCSS that accepts an optional startingHue
|
| 46 |
+
so related color pools (catTypeColors, speakerColors, catColors) can share
|
| 47 |
+
the same starting point and stay visually consistent across rerenders.
|
| 48 |
+
"""
|
| 49 |
+
if n == 0:
|
| 50 |
+
return []
|
| 51 |
+
ret = []
|
| 52 |
+
h = startingHue if startingHue is not None else int(random.random() * 180)
|
| 53 |
+
step = 180 / n
|
| 54 |
+
for _ in range(n):
|
| 55 |
+
h += step
|
| 56 |
+
h = int(h) % 180
|
| 57 |
+
hsv = np.uint8([[[h, 200, 200]]])
|
| 58 |
+
bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
| 59 |
+
b = f'{bgr[0][0][0].item():02x}'
|
| 60 |
+
g = f'{bgr[0][0][1].item():02x}'
|
| 61 |
+
r = f'{bgr[0][0][2].item():02x}'
|
| 62 |
+
ret.append('#' + b + g + r)
|
| 63 |
+
return ret
|
| 64 |
+
|
| 65 |
+
|
| 66 |
def extract_clip_bytes(waveform, sample_rate, seg_start, seg_end):
|
| 67 |
"""Return WAV bytes for the loudest SAMPLE_MIN–SAMPLE_MAX window in [seg_start, seg_end]."""
|
| 68 |
total_samples = waveform.shape[-1]
|