Revert "Add download button for audio (#4977)" (#4992)

This reverts commit c58ea4780f.
This commit is contained in:
Abubakar Abid 2023-07-21 08:00:33 +03:00 committed by GitHub
parent c58ea4780f
commit ad99df4fdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 44 deletions

View File

@ -1,7 +1,5 @@
# Upcoming Release
- Add a download button for audio, with `show_download_button` param that determines its visibility in static Audio components by [@leuryr](https://github.com/leuryr) in [PR 4977](https://github.com/gradio-app/gradio/pull/4977)
## New Features:
No changes to highlight.

View File

@ -67,7 +67,6 @@ class Audio(
elem_classes: list[str] | str | None = None,
format: Literal["wav", "mp3"] = "wav",
autoplay: bool = False,
show_download_button=True,
show_share_button: bool | None = None,
**kwargs,
):
@ -89,7 +88,6 @@ class Audio(
elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
format: The file format to save audio files. Either 'wav' or 'mp3'. wav files are lossless but will tend to be larger files. mp3 files tend to be smaller. Default is wav. Applies both when this component is used as an input (when `type` is "format") and when this component is used as an output.
autoplay: Whether to automatically play the audio when the component is used as an output. Note: browsers will not autoplay audio files if the user has not interacted with the page yet.
show_download_button: If True, will show a download button in the corner of the component for saving audio. If False, icon does not appear.
show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.
"""
valid_sources = ["upload", "microphone"]
@ -111,7 +109,6 @@ class Audio(
)
self.format = format
self.autoplay = autoplay
self.show_download_button = show_download_button
self.show_share_button = (
(utils.get_space() is not None)
if show_share_button is None
@ -140,7 +137,6 @@ class Audio(
"value": self.value,
"streaming": self.streaming,
"autoplay": self.autoplay,
"show_download_button": self.show_download_button,
"show_share_button": self.show_share_button,
**IOComponent.get_config(self),
}
@ -163,7 +159,6 @@ class Audio(
interactive: bool | None = None,
visible: bool | None = None,
autoplay: bool | None = None,
show_download_button: bool | None = None,
show_share_button: bool | None = None,
):
return {
@ -177,7 +172,6 @@ class Audio(
"visible": visible,
"value": value,
"autoplay": autoplay,
"show_download_button": show_download_button,
"show_share_button": show_share_button,
"__type__": "update",
}

View File

@ -34,13 +34,12 @@
export let pending: boolean;
export let streaming: boolean;
export let root_url: null | string;
export let container = true;
export let container: boolean = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
export let autoplay = false;
export let show_download_button = true;
export let show_share_button = false;
export let show_share_button: boolean = false;
let _value: null | FileData;
$: _value = normalise_file(value, root, root_url);
@ -106,7 +105,6 @@
<StaticAudio
{autoplay}
{show_label}
{show_download_button}
{show_share_button}
value={_value}
name={_value?.name || "audio_file"}

View File

@ -10,8 +10,8 @@
<script lang="ts">
import { createEventDispatcher, tick } from "svelte";
import { uploadToHuggingFace } from "@gradio/utils";
import { BlockLabel, ShareButton, IconButton } from "@gradio/atoms";
import { Music, Download } from "@gradio/icons";
import { BlockLabel, ShareButton } from "@gradio/atoms";
import { Music } from "@gradio/icons";
import { loaded } from "./utils";
@ -20,8 +20,7 @@
export let name: string;
export let show_label = true;
export let autoplay: boolean;
export let show_download_button = true;
export let show_share_button = false;
export let show_share_button: boolean = false;
const dispatch = createEventDispatcher<{
change: AudioData;
@ -44,29 +43,18 @@
</script>
<BlockLabel {show_label} Icon={Music} float={false} label={label || "Audio"} />
{#if value !== null}
<div class="icon-buttons">
{#if show_download_button}
<a
href={value.data}
target={window.__is_colab__ ? "_blank" : null}
download={value.name}
>
<IconButton Icon={Download} label="Download" />
</a>
{/if}
{#if show_share_button}
<ShareButton
on:error
on:share
formatter={async (value) => {
if (!value) return "";
let url = await uploadToHuggingFace(value.data, "url");
return `<audio controls src="${url}"></audio>`;
}}
{value}
/>
{/if}
{#if show_share_button && value !== null}
<div class="icon-button">
<ShareButton
on:error
on:share
formatter={async (value) => {
if (!value) return "";
let url = await uploadToHuggingFace(value.data, "url");
return `<audio controls src="${url}"></audio>`;
}}
{value}
/>
</div>
{/if}
@ -93,11 +81,9 @@
width: var(--size-full);
height: var(--size-14);
}
.icon-buttons {
display: flex;
.icon-button {
position: absolute;
top: 6px;
right: 6px;
gap: var(--size-1);
}
</style>

View File

@ -838,7 +838,6 @@ class TestAudio:
"autoplay": False,
"source": "upload",
"name": "audio",
"show_download_button": True,
"show_share_button": False,
"streaming": False,
"show_label": True,
@ -877,7 +876,6 @@ class TestAudio:
assert audio_output.get_config() == {
"autoplay": False,
"name": "audio",
"show_download_button": True,
"show_share_button": False,
"streaming": False,
"show_label": True,