Nanboy commited on
Commit
3b92d83
·
verified ·
1 Parent(s): 90ab8fd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -20,6 +20,42 @@ import numpy as np
20
  import plotly.graph_objects as go
21
  import soundfile as sf
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # ── paths ────────────────────────────────────────────────────────────────────
24
 
25
  SAMPLES = os.path.join(os.path.dirname(__file__), "samples", "1089")
@@ -358,17 +394,19 @@ def make_waveform_figure(
358
  ) -> go.Figure:
359
  """Overlay waveform plot: original vs. protected audio."""
360
  n = min(len(original), len(protected), sr * 5) # cap at 5 s
361
- t = np.arange(n) / sr
 
 
362
 
363
  fig = go.Figure()
364
  fig.add_trace(go.Scatter(
365
- x=t, y=original[:n],
366
  name="Original",
367
  line=dict(color="#1565c0", width=1),
368
  opacity=0.85,
369
  ))
370
  fig.add_trace(go.Scatter(
371
- x=t, y=protected[:n],
372
  name="Protected",
373
  line=dict(color="#c62828", width=1),
374
  opacity=0.85,
 
20
  import plotly.graph_objects as go
21
  import soundfile as sf
22
 
23
+ try:
24
+ import _plotly_utils.basevalidators as _plotly_basevalidators
25
+
26
+ def _plotly_to_scalar_or_list_without_pandas(value):
27
+ np_mod = _plotly_basevalidators.get_module("numpy", should_load=False)
28
+ if np_mod and np_mod.isscalar(value) and hasattr(value, "item"):
29
+ return _plotly_basevalidators.to_non_numpy_type(np_mod, value)
30
+ if isinstance(value, (list, tuple)):
31
+ return [_plotly_to_scalar_or_list_without_pandas(item) for item in value]
32
+ if np_mod and isinstance(value, np_mod.ndarray):
33
+ if value.ndim == 0:
34
+ return _plotly_basevalidators.to_non_numpy_type(np_mod, value)
35
+ return [_plotly_to_scalar_or_list_without_pandas(item) for item in value]
36
+ if _plotly_basevalidators.is_numpy_convertable(value):
37
+ np_mod = _plotly_basevalidators.get_module("numpy", should_load=True)
38
+ if np_mod:
39
+ return _plotly_to_scalar_or_list_without_pandas(np_mod.array(value))
40
+ return value
41
+
42
+ def _plotly_is_homogeneous_array_without_pandas(value):
43
+ np_mod = _plotly_basevalidators.get_module("numpy", should_load=False)
44
+ if np_mod and isinstance(value, np_mod.ndarray):
45
+ return True
46
+ if isinstance(value, _plotly_basevalidators.nw.Series):
47
+ return True
48
+ if _plotly_basevalidators.is_numpy_convertable(value):
49
+ np_mod = _plotly_basevalidators.get_module("numpy", should_load=True)
50
+ if np_mod:
51
+ return np_mod.array(value).shape != ()
52
+ return False
53
+
54
+ _plotly_basevalidators.to_scalar_or_list = _plotly_to_scalar_or_list_without_pandas
55
+ _plotly_basevalidators.is_homogeneous_array = _plotly_is_homogeneous_array_without_pandas
56
+ except Exception:
57
+ pass
58
+
59
  # ── paths ────────────────────────────────────────────────────────────────────
60
 
61
  SAMPLES = os.path.join(os.path.dirname(__file__), "samples", "1089")
 
394
  ) -> go.Figure:
395
  """Overlay waveform plot: original vs. protected audio."""
396
  n = min(len(original), len(protected), sr * 5) # cap at 5 s
397
+ t = (np.arange(n) / sr).tolist()
398
+ original_wave = original[:n].tolist()
399
+ protected_wave = protected[:n].tolist()
400
 
401
  fig = go.Figure()
402
  fig.add_trace(go.Scatter(
403
+ x=t, y=original_wave,
404
  name="Original",
405
  line=dict(color="#1565c0", width=1),
406
  opacity=0.85,
407
  ))
408
  fig.add_trace(go.Scatter(
409
+ x=t, y=protected_wave,
410
  name="Protected",
411
  line=dict(color="#c62828", width=1),
412
  opacity=0.85,