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

update value type

Browse files
pyannote_viewer/backend/pyannote_viewer/pyannote_viewer.py CHANGED
@@ -295,7 +295,7 @@ class PyannoteViewer(
295
  "segments": segments,
296
  "labels": labels,
297
  "multichannel": multichannel,
298
- "sources_file": FileData(path=audio_filepath, orig_name=orig_name),
299
  }
300
 
301
  def stream_output(
 
295
  "segments": segments,
296
  "labels": labels,
297
  "multichannel": multichannel,
298
+ "audio_file": FileData(path=audio_filepath, orig_name=orig_name),
299
  }
300
 
301
  def stream_output(
pyannote_viewer/frontend/Index.svelte CHANGED
@@ -10,13 +10,13 @@
10
  import InteractiveAudio from "./interactive/InteractiveAudio.svelte";
11
  import { StatusTracker } from "@gradio/statustracker";
12
  import { Block, UploadText } from "@gradio/atoms";
13
- import type { WaveformOptions, Segment } from "./shared/types";
14
 
15
  export let elem_id = "";
16
  export let elem_classes: string[] = [];
17
  export let visible = true;
18
  export let interactive: boolean;
19
- export let value: null | {"segments": Segment[], "labels" : string[], "multichannel": boolean, "sources_file": FileData} = null;
20
  export let sources:
21
  | ["microphone"]
22
  | ["upload"]
 
10
  import InteractiveAudio from "./interactive/InteractiveAudio.svelte";
11
  import { StatusTracker } from "@gradio/statustracker";
12
  import { Block, UploadText } from "@gradio/atoms";
13
+ import type { WaveformOptions, PipelineOutput } from "./shared/types";
14
 
15
  export let elem_id = "";
16
  export let elem_classes: string[] = [];
17
  export let visible = true;
18
  export let interactive: boolean;
19
+ export let value: PipelineOutput | null = null;
20
  export let sources:
21
  | ["microphone"]
22
  | ["upload"]
pyannote_viewer/frontend/interactive/InteractiveAudio.svelte CHANGED
@@ -16,9 +16,9 @@
16
  import AudioRecorder from "../recorder/AudioRecorder.svelte";
17
  import StreamAudio from "../streaming/StreamAudio.svelte";
18
  import { SelectSource } from "@gradio/atoms";
19
- import type { WaveformOptions, Segment } from "../shared/types";
20
 
21
- export let value: null | {"segments": Segment[], "labels": string[], "sources_file": FileData} = null;
22
  export let label: string;
23
  export let root: string;
24
  export let show_label = true;
@@ -74,7 +74,7 @@
74
 
75
  const dispatch = createEventDispatcher<{
76
  change: typeof value;
77
- stream: FileData;
78
  edit: never;
79
  play: never;
80
  pause: never;
@@ -95,7 +95,7 @@
95
  ): Promise<void> => {
96
  let _audio_blob = new File(blobs, "audio.wav");
97
  const val = await prepare_files([_audio_blob], event === "stream");
98
- value.sources_file = (
99
  (await upload(val, root, undefined, upload_fn))?.filter(
100
  Boolean
101
  ) as FileData[]
@@ -192,8 +192,8 @@
192
  }
193
 
194
  function handle_load({ detail }: { detail: FileData }): void {
195
- value = {"segments": [], "labels": [], "sources_file": null}
196
- value.sources_file = detail;
197
  dispatch("change", value);
198
  dispatch("upload", detail);
199
  }
@@ -264,7 +264,7 @@
264
  {i18n}
265
  on:clear={clear}
266
  on:edit={() => (mode = "edit")}
267
- download={show_download_button ? value.sources_file.url : null}
268
  absolute={true}
269
  />
270
 
 
16
  import AudioRecorder from "../recorder/AudioRecorder.svelte";
17
  import StreamAudio from "../streaming/StreamAudio.svelte";
18
  import { SelectSource } from "@gradio/atoms";
19
+ import type { WaveformOptions, PipelineOutput } from "../shared/types";
20
 
21
+ export let value: PipelineOutput | null = null;
22
  export let label: string;
23
  export let root: string;
24
  export let show_label = true;
 
74
 
75
  const dispatch = createEventDispatcher<{
76
  change: typeof value;
77
+ stream: typeof value;
78
  edit: never;
79
  play: never;
80
  pause: never;
 
95
  ): Promise<void> => {
96
  let _audio_blob = new File(blobs, "audio.wav");
97
  const val = await prepare_files([_audio_blob], event === "stream");
98
+ value.audio_file = (
99
  (await upload(val, root, undefined, upload_fn))?.filter(
100
  Boolean
101
  ) as FileData[]
 
192
  }
193
 
194
  function handle_load({ detail }: { detail: FileData }): void {
195
+ value = {"segments": [], "labels": [], "multichannel": false, "audioFile": null}
196
+ value.audio_file = detail;
197
  dispatch("change", value);
198
  dispatch("upload", detail);
199
  }
 
264
  {i18n}
265
  on:clear={clear}
266
  on:edit={() => (mode = "edit")}
267
+ download={show_download_button ? value.audio_file.url : null}
268
  absolute={true}
269
  />
270
 
pyannote_viewer/frontend/player/AudioPlayer.svelte CHANGED
@@ -3,15 +3,14 @@
3
  import { Music } from "@gradio/icons";
4
  import { format_time, type I18nFormatter } from "@gradio/utils";
5
  import WaveSurfer from "wavesurfer.js";
6
- import RegionsPlugin, {type Region} from "wavesurfer.js/dist/plugins/regions";
7
- import { skip_audio, process_audio } from "../shared/utils";
8
  import WaveformControls from "../shared/WaveformControls.svelte";
9
  import { Empty } from "@gradio/atoms";
10
- import type { FileData } from "@gradio/client";
11
- import type { WaveformOptions, Segment } from "../shared/types";
12
  import { createEventDispatcher } from "svelte";
13
 
14
- export let value: null | {"segments": Segment[], "labels": string[], "sources_file": FileData}= null;
15
  export let label: string;
16
  export let root: string;
17
  export let i18n: I18nFormatter;
@@ -50,7 +49,7 @@
50
  }>();
51
 
52
  const create_waveform = (): void => {
53
- const audio = new Audio(root + `/file=${value.sources_file.path}`)
54
  audio.crossOrigin = "anonymous"
55
 
56
  audioContext = new AudioContext();
@@ -145,10 +144,10 @@
145
  <Empty size="small">
146
  <Music />
147
  </Empty>
148
- {:else if value.sources_file.is_stream}
149
  <audio
150
  class="standard-player"
151
- src={value.sources_file.url}
152
  controls
153
  autoplay={waveform_settings.autoplay}
154
  />
 
3
  import { Music } from "@gradio/icons";
4
  import { format_time, type I18nFormatter } from "@gradio/utils";
5
  import WaveSurfer from "wavesurfer.js";
6
+ import RegionsPlugin from "wavesurfer.js/dist/plugins/regions";
7
+ import { skip_audio } from "../shared/utils";
8
  import WaveformControls from "../shared/WaveformControls.svelte";
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;
15
  export let root: string;
16
  export let i18n: I18nFormatter;
 
49
  }>();
50
 
51
  const create_waveform = (): void => {
52
+ const audio = new Audio(root + `/file=${value.audio_file.path}`)
53
  audio.crossOrigin = "anonymous"
54
 
55
  audioContext = new AudioContext();
 
144
  <Empty size="small">
145
  <Music />
146
  </Empty>
147
+ {:else if value.audio_file.is_stream}
148
  <audio
149
  class="standard-player"
150
+ src={value.audio_file.url}
151
  controls
152
  autoplay={waveform_settings.autoplay}
153
  />
pyannote_viewer/frontend/shared/types.ts CHANGED
@@ -1,3 +1,5 @@
 
 
1
  export type WaveformOptions = {
2
  waveform_color?: string;
3
  waveform_progress_color?: string;
@@ -13,3 +15,10 @@ export type Segment = {
13
  end: number;
14
  channel: number;
15
  }
 
 
 
 
 
 
 
 
1
+ import type { FileData } from "@gradio/client";
2
+
3
  export type WaveformOptions = {
4
  waveform_color?: string;
5
  waveform_progress_color?: string;
 
15
  end: number;
16
  channel: number;
17
  }
18
+
19
+ export type PipelineOutput = {
20
+ segments: Segment[];
21
+ labels: string[];
22
+ multichannel: boolean;
23
+ audio_file: FileData;
24
+ }
pyannote_viewer/frontend/static/StaticAudio.svelte CHANGED
@@ -6,11 +6,10 @@
6
  import type { I18nFormatter } from "@gradio/utils";
7
  import AudioPlayer from "../player/AudioPlayer.svelte";
8
  import { createEventDispatcher } from "svelte";
9
- import type { FileData } from "@gradio/client";
10
  import { DownloadLink } from "@gradio/wasm/svelte";
11
- import type { WaveformOptions, Segment } from "../shared/types";
12
 
13
- export let value: null | {"segments": Segment[], "labels":string[], "sources_file": FileData} = null;
14
  export let label: string;
15
  export let root: string;
16
  export let show_label = true;
@@ -42,7 +41,7 @@
42
  {#if value !== null}
43
  <div class="icon-buttons">
44
  {#if show_download_button}
45
- <DownloadLink href={value.sources_file.url} download={value.sources_file.orig_name || value.sources_file.path}>
46
  <IconButton Icon={Download} label={i18n("common.download")} />
47
  </DownloadLink>
48
  {/if}
 
6
  import type { I18nFormatter } from "@gradio/utils";
7
  import AudioPlayer from "../player/AudioPlayer.svelte";
8
  import { createEventDispatcher } from "svelte";
 
9
  import { DownloadLink } from "@gradio/wasm/svelte";
10
+ import type { WaveformOptions, PipelineOutput } from "../shared/types";
11
 
12
+ export let value: PipelineOutput | null = null;
13
  export let label: string;
14
  export let root: string;
15
  export let show_label = true;
 
41
  {#if value !== null}
42
  <div class="icon-buttons">
43
  {#if show_download_button}
44
+ <DownloadLink href={value.audio_file.url} download={value.audio_file.orig_name || value.audio_file.path}>
45
  <IconButton Icon={Download} label={i18n("common.download")} />
46
  </DownloadLink>
47
  {/if}