Skip to content

Commit

Permalink
Add show_edit_button param to gr.Audio (#5149)
Browse files Browse the repository at this point in the history
* add show_edit_button param

* add changeset

* formatting

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
hannahblair and gradio-pr-bot committed Aug 9, 2023
1 parent 22aa5eb commit 144df45
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/true-dots-invent.md
@@ -0,0 +1,6 @@
---
"@gradio/audio": minor
"gradio": minor
---

feat:Add `show_edit_button` param to `gr.Audio`
6 changes: 6 additions & 0 deletions gradio/components/audio.py
Expand Up @@ -72,6 +72,7 @@ def __init__(
autoplay: bool = False,
show_download_button=True,
show_share_button: bool | None = None,
show_edit_button: bool | None = True,
**kwargs,
):
"""
Expand All @@ -94,6 +95,7 @@ def __init__(
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.
show_edit_button: If True, will show an edit icon in the corner of the component that allows user to edit the audio. If False, icon does not appear. Default is True.
"""
valid_sources = ["upload", "microphone"]
source = source if source else ("microphone" if streaming else "upload")
Expand Down Expand Up @@ -121,6 +123,7 @@ def __init__(
if show_share_button is None
else show_share_button
)
self.show_edit_button = show_edit_button
IOComponent.__init__(
self,
label=label,
Expand All @@ -146,6 +149,7 @@ def get_config(self):
"autoplay": self.autoplay,
"show_download_button": self.show_download_button,
"show_share_button": self.show_share_button,
"show_edit_button": self.show_edit_button,
**IOComponent.get_config(self),
}

Expand All @@ -169,6 +173,7 @@ def update(
autoplay: bool | None = None,
show_download_button: bool | None = None,
show_share_button: bool | None = None,
show_edit_button: bool | None = None,
):
return {
"source": source,
Expand All @@ -183,6 +188,7 @@ def update(
"autoplay": autoplay,
"show_download_button": show_download_button,
"show_share_button": show_share_button,
"show_edit_button": show_edit_button,
"__type__": "update",
}

Expand Down
2 changes: 2 additions & 0 deletions js/audio/index.svelte
Expand Up @@ -27,6 +27,7 @@
export let autoplay = false;
export let show_download_button = true;
export let show_share_button = false;
export let show_edit_button = true;
</script>

{#if mode === "dynamic"}
Expand All @@ -49,6 +50,7 @@
{min_width}
{loading_status}
{autoplay}
{show_edit_button}
on:change
on:stream
on:drag
Expand Down
13 changes: 7 additions & 6 deletions js/audio/interactive/Audio.svelte
Expand Up @@ -27,6 +27,7 @@
export let pending = false;
export let streaming = false;
export let autoplay = false;
export let show_edit_button = true;
// TODO: make use of this
// export let type: "normal" | "numpy" = "normal";
Expand All @@ -51,7 +52,7 @@
function get_modules(): void {
module_promises = [
import("extendable-media-recorder"),
import("extendable-media-recorder-wav-encoder")
import("extendable-media-recorder-wav-encoder"),
];
}
Expand Down Expand Up @@ -91,7 +92,7 @@
let _audio_blob = new Blob(blobs, { type: "audio/wav" });
value = {
data: await blob_to_data_url(_audio_blob),
name: "audio.wav"
name: "audio.wav",
};
dispatch(event, value);
};
Expand Down Expand Up @@ -203,7 +204,7 @@
}
function handle_change({
detail: { values }
detail: { values },
}: {
detail: { values: [number, number] };
}): void {
Expand All @@ -213,14 +214,14 @@
data: value.data,
name,
crop_min: values[0],
crop_max: values[1]
crop_max: values[1],
});
dispatch("edit");
}
function handle_load({
detail
detail,
}: {
detail: {
data: string;
Expand Down Expand Up @@ -283,7 +284,7 @@
<ModifyUpload
on:clear={clear}
on:edit={() => (mode = "edit")}
editable
editable={show_edit_button}
absolute={true}
/>

Expand Down
2 changes: 2 additions & 0 deletions js/audio/interactive/InteractiveAudio.svelte
Expand Up @@ -38,6 +38,7 @@
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
export let autoplay = false;
export let show_edit_button = true;
let old_value: null | FileData | string = null;
Expand Down Expand Up @@ -83,6 +84,7 @@
{pending}
{streaming}
{autoplay}
{show_edit_button}
on:edit
on:play
on:pause
Expand Down
2 changes: 1 addition & 1 deletion js/audio/static/AudioPlayer.svelte
Expand Up @@ -34,7 +34,7 @@
$: value &&
dispatch("change", {
name: name,
data: value?.data
data: value?.data,
});
function handle_ended(): void {
Expand Down
2 changes: 2 additions & 0 deletions test/test_components.py
Expand Up @@ -844,6 +844,7 @@ def test_component_functions(self):
"name": "audio",
"show_download_button": True,
"show_share_button": False,
"show_edit_button": True,
"streaming": False,
"show_label": True,
"label": "Upload Your Audio",
Expand Down Expand Up @@ -883,6 +884,7 @@ def test_component_functions(self):
"name": "audio",
"show_download_button": True,
"show_share_button": False,
"show_edit_button": True,
"streaming": False,
"show_label": True,
"label": None,
Expand Down

1 comment on commit 144df45

@vercel
Copy link

@vercel vercel bot commented on 144df45 Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.