clement-pages commited on
Commit
b3a508e
·
1 Parent(s): 5a63470

update component frontend

Browse files
pyannote_viewer/backend/pyannote_viewer/pyannote_viewer.py CHANGED
@@ -21,7 +21,6 @@ from gradio.exceptions import Error
21
  from pyannote.core.annotation import Annotation
22
  from pyannote.core.feature import SlidingWindowFeature
23
 
24
- import torchaudio
25
 
26
  @dataclasses.dataclass
27
  class WaveformOptions:
@@ -269,7 +268,7 @@ class PyannoteViewer(
269
  # format diarization output
270
  segments = []
271
  for segment, _, label in annotations.itertracks(yield_label=True):
272
- label_idx = labels.index(label) if isinstance(audio, SlidingWindowFeature) else 0
273
  segments.append(
274
  Segment(start=segment.start, end=segment.end, channel=label_idx)
275
  )
 
21
  from pyannote.core.annotation import Annotation
22
  from pyannote.core.feature import SlidingWindowFeature
23
 
 
24
 
25
  @dataclasses.dataclass
26
  class WaveformOptions:
 
268
  # format diarization output
269
  segments = []
270
  for segment, _, label in annotations.itertracks(yield_label=True):
271
+ label_idx = labels.index(label)
272
  segments.append(
273
  Segment(start=segment.start, end=segment.end, channel=label_idx)
274
  )
pyannote_viewer/frontend/player/AudioPlayer.svelte CHANGED
@@ -9,6 +9,7 @@
9
  import { Empty } from "@gradio/atoms";
10
  import type { WaveformOptions, PipelineOutput } from "../shared/types";
11
  import { createEventDispatcher } from "svelte";
 
12
 
13
  export let value: PipelineOutput | null = null;
14
  export let label: string;
@@ -87,7 +88,7 @@
87
  const region = wsRegion.addRegion({
88
  start: segment.start,
89
  end: segment.end,
90
- channelIdx: segment.channel,
91
  drag: false,
92
  resize: false,
93
  color: colors[segment.channel % colors.length],
@@ -159,20 +160,30 @@
159
  <div class="viewer">
160
  <div class="source-selection">
161
  {#if audioDecoded}
162
- {#each [...Array(waveform.getDecodedData().numberOfChannels).keys()] as channelIdx}
163
- <label class="source" style={`height: ${waveform_settings.height}px`}>
164
- <input
165
- type="radio"
166
- name="channels"
167
- value={`${channelIdx}`}
168
- on:change={(ev) => {
169
- splitter.disconnect()
170
- splitter.connect(audioContext.destination, Number(ev.target.value), 0);
171
- }}
172
- />
173
- {value.labels[channelIdx]}
174
- </label>
175
- {/each}
 
 
 
 
 
 
 
 
 
 
176
  {/if}
177
  </div>
178
  <div class="waveform-container">
@@ -225,6 +236,15 @@
225
  background-color: var(--color-accent);
226
  }
227
 
 
 
 
 
 
 
 
 
 
228
  .component-wrapper {
229
  padding: var(--size-3);
230
  width: 100%;
@@ -240,11 +260,6 @@
240
  margin-right: 1em;
241
  }
242
 
243
- .source {
244
- display: flex;
245
- align-items: center;
246
- }
247
-
248
  :global(::part(wrapper)) {
249
  margin-bottom: var(--size-2);
250
  }
 
9
  import { Empty } from "@gradio/atoms";
10
  import type { WaveformOptions, PipelineOutput } from "../shared/types";
11
  import { createEventDispatcher } from "svelte";
12
+ import Color from "@gradio/icons/src/Color.svelte";
13
 
14
  export let value: PipelineOutput | null = null;
15
  export let label: string;
 
88
  const region = wsRegion.addRegion({
89
  start: segment.start,
90
  end: segment.end,
91
+ channelIdx: value.multichannel ? segment.channel : 0,
92
  drag: false,
93
  resize: false,
94
  color: colors[segment.channel % colors.length],
 
160
  <div class="viewer">
161
  <div class="source-selection">
162
  {#if audioDecoded}
163
+ {#if value.multichannel}
164
+ <!-- Separation pipeline case -->
165
+ {#each [...Array(waveform.getDecodedData().numberOfChannels).keys()] as channelIdx}
166
+ <label style={`height: ${waveform_settings.height}px; background-color: ${colors[channelIdx % colors.length]}`}>
167
+ <input
168
+ type="radio"
169
+ name="channels"
170
+ value={`${channelIdx}`}
171
+ on:change={(ev) => {
172
+ splitter.disconnect()
173
+ splitter.connect(audioContext.destination, Number(ev.target.value), 0);
174
+ }}
175
+ />
176
+ {value.labels[channelIdx]}
177
+ </label>
178
+ {/each}
179
+ {:else}
180
+ {#each [...Array(value.labels.length)].keys() as labelIdx}
181
+ <label style={`background-color: ${colors[labelIdx % colors.length]};`}>
182
+ <input type="hidden">
183
+ {value.labels[labelIdx]}
184
+ </label>
185
+ {/each}
186
+ {/if}
187
  {/if}
188
  </div>
189
  <div class="waveform-container">
 
236
  background-color: var(--color-accent);
237
  }
238
 
239
+ label {
240
+ display: flex;
241
+ align-items: center;
242
+ margin-bottom: 0.25em;
243
+ padding-left: 0.5em;
244
+ padding-right: 0.5em;
245
+ }
246
+
247
+
248
  .component-wrapper {
249
  padding: var(--size-3);
250
  width: 100%;
 
260
  margin-right: 1em;
261
  }
262
 
 
 
 
 
 
263
  :global(::part(wrapper)) {
264
  margin-bottom: var(--size-2);
265
  }