Upload folder using huggingface_hub
Browse files- 6.0.0-dev.4/audio/Index.svelte +4 -0
- 6.0.0-dev.4/audio/interactive/InteractiveAudio.svelte +4 -1
- 6.0.0-dev.4/audio/package.json +1 -1
- 6.0.0-dev.4/audio/player/AudioPlayer.svelte +5 -0
- 6.0.0-dev.4/audio/shared/MinimalAudioPlayer.svelte +184 -0
- 6.0.0-dev.4/audio/shared/index.ts +1 -0
- 6.0.0-dev.4/audio/shared/types.ts +1 -0
- 6.0.0-dev.4/audio/static/StaticAudio.svelte +47 -41
6.0.0-dev.4/audio/Index.svelte
CHANGED
|
@@ -32,6 +32,9 @@
|
|
| 32 |
|
| 33 |
const gradio = new AudioGradio(props);
|
| 34 |
let label = $derived(gradio.shared.label || gradio.i18n("audio.audio"));
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
// let uploading = $state(false);
|
| 37 |
let active_source = $derived.by(() =>
|
|
@@ -143,6 +146,7 @@
|
|
| 143 |
{waveform_settings}
|
| 144 |
waveform_options={gradio.props.waveform_options}
|
| 145 |
editable={gradio.props.editable}
|
|
|
|
| 146 |
on:share={(e) => gradio.dispatch("share", e.detail)}
|
| 147 |
on:error={(e) => gradio.dispatch("error", e.detail)}
|
| 148 |
on:play={() => gradio.dispatch("play")}
|
|
|
|
| 32 |
|
| 33 |
const gradio = new AudioGradio(props);
|
| 34 |
let label = $derived(gradio.shared.label || gradio.i18n("audio.audio"));
|
| 35 |
+
let minimal = $derived(
|
| 36 |
+
(props as any).minimal ?? (gradio.props as any).minimal ?? false
|
| 37 |
+
);
|
| 38 |
|
| 39 |
// let uploading = $state(false);
|
| 40 |
let active_source = $derived.by(() =>
|
|
|
|
| 146 |
{waveform_settings}
|
| 147 |
waveform_options={gradio.props.waveform_options}
|
| 148 |
editable={gradio.props.editable}
|
| 149 |
+
{minimal}
|
| 150 |
on:share={(e) => gradio.dispatch("share", e.detail)}
|
| 151 |
on:error={(e) => gradio.dispatch("error", e.detail)}
|
| 152 |
on:play={() => gradio.dispatch("play")}
|
6.0.0-dev.4/audio/interactive/InteractiveAudio.svelte
CHANGED
|
@@ -238,7 +238,10 @@
|
|
| 238 |
float={active_source === "upload" && value === null}
|
| 239 |
label={label || i18n("audio.audio")}
|
| 240 |
/>
|
| 241 |
-
<div
|
|
|
|
|
|
|
|
|
|
| 242 |
<StreamingBar {time_limit} />
|
| 243 |
{#if value === null || streaming}
|
| 244 |
{#if active_source === "microphone"}
|
|
|
|
| 238 |
float={active_source === "upload" && value === null}
|
| 239 |
label={label || i18n("audio.audio")}
|
| 240 |
/>
|
| 241 |
+
<div
|
| 242 |
+
class="audio-container {class_name}"
|
| 243 |
+
data-testid={label ? "waveform-" + label : "unlabelled-audio"}
|
| 244 |
+
>
|
| 245 |
<StreamingBar {time_limit} />
|
| 246 |
{#if value === null || streaming}
|
| 247 |
{#if active_source === "microphone"}
|
6.0.0-dev.4/audio/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
| 20 |
"hls.js": "1.5.13",
|
| 21 |
"resize-observer-polyfill": "1.5.1",
|
| 22 |
"svelte-range-slider-pips": "4.1.0",
|
| 23 |
-
"wavesurfer.js": "7.
|
| 24 |
},
|
| 25 |
"devDependencies": {
|
| 26 |
"@gradio/preview": "workspace:^"
|
|
|
|
| 20 |
"hls.js": "1.5.13",
|
| 21 |
"resize-observer-polyfill": "1.5.1",
|
| 22 |
"svelte-range-slider-pips": "4.1.0",
|
| 23 |
+
"wavesurfer.js": "7.11.0"
|
| 24 |
},
|
| 25 |
"devDependencies": {
|
| 26 |
"@gradio/preview": "workspace:^"
|
6.0.0-dev.4/audio/player/AudioPlayer.svelte
CHANGED
|
@@ -91,6 +91,11 @@
|
|
| 91 |
timeRef && (timeRef.textContent = format_time(currentTime))
|
| 92 |
);
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
waveform?.on("ready", () => {
|
| 95 |
if (!waveform_settings.autoplay) {
|
| 96 |
waveform?.stop();
|
|
|
|
| 91 |
timeRef && (timeRef.textContent = format_time(currentTime))
|
| 92 |
);
|
| 93 |
|
| 94 |
+
waveform?.on("interaction", () => {
|
| 95 |
+
const currentTime = waveform?.getCurrentTime() || 0;
|
| 96 |
+
timeRef && (timeRef.textContent = format_time(currentTime));
|
| 97 |
+
});
|
| 98 |
+
|
| 99 |
waveform?.on("ready", () => {
|
| 100 |
if (!waveform_settings.autoplay) {
|
| 101 |
waveform?.stop();
|
6.0.0-dev.4/audio/shared/MinimalAudioPlayer.svelte
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { onMount, onDestroy } from "svelte";
|
| 3 |
+
import WaveSurfer from "wavesurfer.js";
|
| 4 |
+
import type { FileData } from "@gradio/client";
|
| 5 |
+
import { format_time } from "@gradio/utils";
|
| 6 |
+
|
| 7 |
+
export let value: FileData;
|
| 8 |
+
export let label: string;
|
| 9 |
+
export let loop = false;
|
| 10 |
+
|
| 11 |
+
let container: HTMLDivElement;
|
| 12 |
+
let waveform: WaveSurfer | undefined;
|
| 13 |
+
let playing = false;
|
| 14 |
+
let duration = 0;
|
| 15 |
+
let currentTime = 0;
|
| 16 |
+
let waveform_ready = false;
|
| 17 |
+
|
| 18 |
+
$: resolved_src = value.url;
|
| 19 |
+
|
| 20 |
+
const create_waveform = async (): Promise<void> => {
|
| 21 |
+
if (!container || !resolved_src || waveform_ready) return;
|
| 22 |
+
|
| 23 |
+
if (waveform) {
|
| 24 |
+
waveform.destroy();
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const accentColor =
|
| 28 |
+
getComputedStyle(document.documentElement).getPropertyValue(
|
| 29 |
+
"--color-accent"
|
| 30 |
+
) || "#ff7c00";
|
| 31 |
+
|
| 32 |
+
waveform = WaveSurfer.create({
|
| 33 |
+
container,
|
| 34 |
+
height: 32,
|
| 35 |
+
waveColor: "rgba(128, 128, 128, 0.5)",
|
| 36 |
+
progressColor: accentColor,
|
| 37 |
+
cursorColor: "transparent",
|
| 38 |
+
barWidth: 2,
|
| 39 |
+
barGap: 2,
|
| 40 |
+
barRadius: 2,
|
| 41 |
+
normalize: true,
|
| 42 |
+
interact: true,
|
| 43 |
+
dragToSeek: true,
|
| 44 |
+
hideScrollbar: true
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
waveform.on("play", () => (playing = true));
|
| 48 |
+
waveform.on("pause", () => (playing = false));
|
| 49 |
+
waveform.on("ready", () => {
|
| 50 |
+
duration = waveform?.getDuration() || 0;
|
| 51 |
+
waveform_ready = true;
|
| 52 |
+
});
|
| 53 |
+
waveform.on("audioprocess", () => {
|
| 54 |
+
currentTime = waveform?.getCurrentTime() || 0;
|
| 55 |
+
});
|
| 56 |
+
waveform.on("interaction", () => {
|
| 57 |
+
currentTime = waveform?.getCurrentTime() || 0;
|
| 58 |
+
});
|
| 59 |
+
waveform.on("finish", () => {
|
| 60 |
+
playing = false;
|
| 61 |
+
if (loop) {
|
| 62 |
+
waveform?.play();
|
| 63 |
+
}
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
await waveform.load(resolved_src);
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
onMount(async () => {
|
| 70 |
+
await create_waveform();
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
onDestroy(() => {
|
| 74 |
+
if (waveform) {
|
| 75 |
+
waveform.destroy();
|
| 76 |
+
}
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
const togglePlay = (): void => {
|
| 80 |
+
if (waveform) {
|
| 81 |
+
waveform.playPause();
|
| 82 |
+
}
|
| 83 |
+
};
|
| 84 |
+
</script>
|
| 85 |
+
|
| 86 |
+
<div
|
| 87 |
+
class="minimal-audio-player"
|
| 88 |
+
aria-label={label || "Audio"}
|
| 89 |
+
data-testid={label && typeof label === "string" && label.trim()
|
| 90 |
+
? "waveform-" + label
|
| 91 |
+
: "unlabelled-audio"}
|
| 92 |
+
>
|
| 93 |
+
<button
|
| 94 |
+
class="play-btn"
|
| 95 |
+
on:click={togglePlay}
|
| 96 |
+
aria-label={playing ? "Pause" : "Play"}
|
| 97 |
+
>
|
| 98 |
+
{#if playing}
|
| 99 |
+
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 100 |
+
<rect x="6" y="5" width="4" height="14" rx="1" fill="currentColor" />
|
| 101 |
+
<rect x="14" y="5" width="4" height="14" rx="1" fill="currentColor" />
|
| 102 |
+
</svg>
|
| 103 |
+
{:else}
|
| 104 |
+
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 105 |
+
<path
|
| 106 |
+
d="M8 5.74537C8 5.06444 8.77346 4.64713 9.35139 5.02248L18.0227 10.2771C18.5518 10.6219 18.5518 11.3781 18.0227 11.7229L9.35139 16.9775C8.77346 17.3529 8 16.9356 8 16.2546V5.74537Z"
|
| 107 |
+
fill="currentColor"
|
| 108 |
+
/>
|
| 109 |
+
</svg>
|
| 110 |
+
{/if}
|
| 111 |
+
</button>
|
| 112 |
+
|
| 113 |
+
<div class="waveform-wrapper" bind:this={container}></div>
|
| 114 |
+
|
| 115 |
+
<div class="timestamp">{format_time(playing ? currentTime : duration)}</div>
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
<style>
|
| 119 |
+
.minimal-audio-player {
|
| 120 |
+
display: flex;
|
| 121 |
+
align-items: center;
|
| 122 |
+
gap: var(--spacing-sm);
|
| 123 |
+
border-radius: var(--radius-sm);
|
| 124 |
+
width: var(--size-52);
|
| 125 |
+
padding: var(--spacing-sm);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.play-btn {
|
| 129 |
+
display: inline-flex;
|
| 130 |
+
align-items: center;
|
| 131 |
+
justify-content: center;
|
| 132 |
+
padding: 0;
|
| 133 |
+
border: none;
|
| 134 |
+
background: none;
|
| 135 |
+
color: var(--body-text-color);
|
| 136 |
+
opacity: 0.7;
|
| 137 |
+
cursor: pointer;
|
| 138 |
+
border-radius: 50%;
|
| 139 |
+
transition: all 0.2s ease;
|
| 140 |
+
flex-shrink: 0;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
.play-btn:hover {
|
| 144 |
+
color: var(--color-accent);
|
| 145 |
+
opacity: 1;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.play-btn:active {
|
| 149 |
+
transform: scale(0.95);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.play-btn svg {
|
| 153 |
+
width: var(--size-5);
|
| 154 |
+
height: var(--size-5);
|
| 155 |
+
display: block;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.waveform-wrapper {
|
| 159 |
+
flex: 1 1 auto;
|
| 160 |
+
cursor: pointer;
|
| 161 |
+
width: auto;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
.waveform-wrapper :global(::part(wrapper)) {
|
| 165 |
+
margin-bottom: 0;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.timestamp {
|
| 169 |
+
font-size: 13px;
|
| 170 |
+
font-weight: 500;
|
| 171 |
+
color: var(--body-text-color);
|
| 172 |
+
opacity: 0.7;
|
| 173 |
+
font-variant-numeric: tabular-nums;
|
| 174 |
+
flex-shrink: 0;
|
| 175 |
+
min-width: 40px;
|
| 176 |
+
text-align: center;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
@media (prefers-reduced-motion: reduce) {
|
| 180 |
+
.play-btn {
|
| 181 |
+
transition: none;
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
</style>
|
6.0.0-dev.4/audio/shared/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
export { default as Audio } from "./Audio.svelte";
|
|
|
|
|
|
| 1 |
export { default as Audio } from "./Audio.svelte";
|
| 2 |
+
export { default as MinimalAudioPlayer } from "./MinimalAudioPlayer.svelte";
|
6.0.0-dev.4/audio/shared/types.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface AudioProps {
|
|
| 35 |
streaming: boolean;
|
| 36 |
stream_every: number;
|
| 37 |
input_ready: boolean;
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
export interface AudioEvents {
|
|
|
|
| 35 |
streaming: boolean;
|
| 36 |
stream_every: number;
|
| 37 |
input_ready: boolean;
|
| 38 |
+
minimal?: boolean;
|
| 39 |
}
|
| 40 |
|
| 41 |
export interface AudioEvents {
|
6.0.0-dev.4/audio/static/StaticAudio.svelte
CHANGED
|
@@ -11,6 +11,7 @@
|
|
| 11 |
import { Download, Music } from "@gradio/icons";
|
| 12 |
import type { I18nFormatter } from "@gradio/utils";
|
| 13 |
import AudioPlayer from "../player/AudioPlayer.svelte";
|
|
|
|
| 14 |
import { createEventDispatcher } from "svelte";
|
| 15 |
import type { FileData } from "@gradio/client";
|
| 16 |
import type { WaveformOptions, SubtitleData } from "../shared/types";
|
|
@@ -28,6 +29,7 @@
|
|
| 28 |
export let editable = true;
|
| 29 |
export let loop: boolean;
|
| 30 |
export let display_icon_button_wrapper_top_corner = false;
|
|
|
|
| 31 |
|
| 32 |
const dispatch = createEventDispatcher<{
|
| 33 |
change: FileData;
|
|
@@ -48,48 +50,52 @@
|
|
| 48 |
/>
|
| 49 |
|
| 50 |
{#if value !== null}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
| 93 |
{:else}
|
| 94 |
<Empty size="small">
|
| 95 |
<Music />
|
|
|
|
| 11 |
import { Download, Music } from "@gradio/icons";
|
| 12 |
import type { I18nFormatter } from "@gradio/utils";
|
| 13 |
import AudioPlayer from "../player/AudioPlayer.svelte";
|
| 14 |
+
import MinimalAudioPlayer from "../shared/MinimalAudioPlayer.svelte";
|
| 15 |
import { createEventDispatcher } from "svelte";
|
| 16 |
import type { FileData } from "@gradio/client";
|
| 17 |
import type { WaveformOptions, SubtitleData } from "../shared/types";
|
|
|
|
| 29 |
export let editable = true;
|
| 30 |
export let loop: boolean;
|
| 31 |
export let display_icon_button_wrapper_top_corner = false;
|
| 32 |
+
export let minimal = false;
|
| 33 |
|
| 34 |
const dispatch = createEventDispatcher<{
|
| 35 |
change: FileData;
|
|
|
|
| 50 |
/>
|
| 51 |
|
| 52 |
{#if value !== null}
|
| 53 |
+
{#if minimal}
|
| 54 |
+
<MinimalAudioPlayer {value} label={label || i18n("audio.audio")} {loop} />
|
| 55 |
+
{:else}
|
| 56 |
+
<IconButtonWrapper
|
| 57 |
+
display_top_corner={display_icon_button_wrapper_top_corner}
|
| 58 |
+
>
|
| 59 |
+
{#if buttons === null ? true : buttons.includes("download")}
|
| 60 |
+
<DownloadLink
|
| 61 |
+
href={value.is_stream
|
| 62 |
+
? value.url?.replace("playlist.m3u8", "playlist-file")
|
| 63 |
+
: value.url}
|
| 64 |
+
download={value.orig_name || value.path}
|
| 65 |
+
>
|
| 66 |
+
<IconButton Icon={Download} label={i18n("common.download")} />
|
| 67 |
+
</DownloadLink>
|
| 68 |
+
{/if}
|
| 69 |
+
{#if buttons === null ? true : buttons.includes("share")}
|
| 70 |
+
<ShareButton
|
| 71 |
+
{i18n}
|
| 72 |
+
on:error
|
| 73 |
+
on:share
|
| 74 |
+
formatter={async (value) => {
|
| 75 |
+
if (!value) return "";
|
| 76 |
+
let url = await uploadToHuggingFace(value.url, "url");
|
| 77 |
+
return `<audio controls src="${url}"></audio>`;
|
| 78 |
+
}}
|
| 79 |
+
{value}
|
| 80 |
+
/>
|
| 81 |
+
{/if}
|
| 82 |
+
</IconButtonWrapper>
|
| 83 |
|
| 84 |
+
<AudioPlayer
|
| 85 |
+
{value}
|
| 86 |
+
subtitles={Array.isArray(subtitles) ? subtitles : subtitles?.url}
|
| 87 |
+
{label}
|
| 88 |
+
{i18n}
|
| 89 |
+
{waveform_settings}
|
| 90 |
+
{waveform_options}
|
| 91 |
+
{editable}
|
| 92 |
+
{loop}
|
| 93 |
+
on:pause
|
| 94 |
+
on:play
|
| 95 |
+
on:stop
|
| 96 |
+
on:load
|
| 97 |
+
/>
|
| 98 |
+
{/if}
|
| 99 |
{:else}
|
| 100 |
<Empty size="small">
|
| 101 |
<Music />
|