Skip to content

Commit

Permalink
Revert "Add download button for audio (#4977)"
Browse files Browse the repository at this point in the history
This reverts commit c58ea47.
  • Loading branch information
abidlabs committed Jul 21, 2023
1 parent c58ea47 commit 8bfd1e4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 44 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 0 additions & 6 deletions gradio/components/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def __init__(
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,
):
Expand All @@ -89,7 +88,6 @@ def __init__(
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"]
Expand All @@ -111,7 +109,6 @@ def __init__(
)
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
Expand Down Expand Up @@ -140,7 +137,6 @@ def get_config(self):
"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),
}
Expand All @@ -163,7 +159,6 @@ def update(
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 {
Expand All @@ -177,7 +172,6 @@ def update(
"visible": visible,
"value": value,
"autoplay": autoplay,
"show_download_button": show_download_button,
"show_share_button": show_share_button,
"__type__": "update",
}
Expand Down
6 changes: 2 additions & 4 deletions js/app/src/components/Audio/Audio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -106,7 +105,6 @@
<StaticAudio
{autoplay}
{show_label}
{show_download_button}
{show_share_button}
value={_value}
name={_value?.name || "audio_file"}
Expand Down
46 changes: 16 additions & 30 deletions js/audio/src/StaticAudio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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}

Expand All @@ -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>
2 changes: 0 additions & 2 deletions test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@ def test_component_functions(self):
"autoplay": False,
"source": "upload",
"name": "audio",
"show_download_button": True,
"show_share_button": False,
"streaming": False,
"show_label": True,
Expand Down Expand Up @@ -877,7 +876,6 @@ def test_component_functions(self):
assert audio_output.get_config() == {
"autoplay": False,
"name": "audio",
"show_download_button": True,
"show_share_button": False,
"streaming": False,
"show_label": True,
Expand Down

0 comments on commit 8bfd1e4

Please sign in to comment.