Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional labels fe #1105

Merged
merged 18 commits into from
Apr 27, 2022
Merged
50 changes: 29 additions & 21 deletions demo/blocks_outputs/run.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import gradio as gr

with gr.Blocks() as demo:
txt = gr.Textbox(label="Small Textbox", lines=1)
txt = gr.Textbox(label="Large Textbox", lines=5)
num = gr.Number(label="Number")
check = gr.Checkbox(label="Checkbox")
check_g = gr.CheckboxGroup(label="Checkbox Group", choices=["One", "Two", "Three"])
radio = gr.Radio(label="Radio", choices=["One", "Two", "Three"])
drop = gr.Dropdown(label="Dropdown", choices=["One", "Two", "Three"])
slider = gr.Slider(label="Slider")
audio = gr.Audio()
video = gr.Video()
image = gr.Image()
ts = gr.Timeseries()
df = gr.Dataframe()
html = gr.HTML()
json = gr.JSON()
md = gr.Markdown()
label = gr.Label()
highlight = gr.HighlightedText()
# layout components are static only
# carousel doesn't work like other components
# carousel = gr.Carousel()
with gr.Column():
txt = gr.Textbox(label="Small Textbox", lines=1, show_label=False)
txt = gr.Textbox(label="Large Textbox", lines=5, show_label=False)
num = gr.Number(label="Number", show_label=False)
check = gr.Checkbox(label="Checkbox", show_label=False)
check_g = gr.CheckboxGroup(
label="Checkbox Group", choices=["One", "Two", "Three"], show_label=False
)
radio = gr.Radio(
label="Radio", choices=["One", "Two", "Three"], show_label=False
)
drop = gr.Dropdown(
label="Dropdown", choices=["One", "Two", "Three"], show_label=False
)
slider = gr.Slider(label="Slider", show_label=False)
audio = gr.Audio(show_label=False)
file = gr.File(show_label=False)
video = gr.Video(show_label=False)
image = gr.Image(show_label=False)
ts = gr.Timeseries(show_label=False)
df = gr.Dataframe(show_label=False)
html = gr.HTML(show_label=False)
json = gr.JSON(show_label=False)
md = gr.Markdown(show_label=False)
label = gr.Label(show_label=False)
highlight = gr.HighlightedText(show_label=False)
# layout components are static only
# carousel doesn't work like other components
# carousel = gr.Carousel()


if __name__ == "__main__":
Expand Down
9 changes: 8 additions & 1 deletion ui/packages/app/src/components/Audio/Audio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
export let type: "normal" | "numpy" = "normal";
export let label: string;
export let root: string;
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -39,6 +40,7 @@
{#if mode === "dynamic"}
<Audio
{label}
{show_label}
value={_value}
on:change={({ detail }) => (value = detail)}
on:drag={({ detail }) => (dragging = detail)}
Expand All @@ -55,6 +57,11 @@
upload_text={$_("interface.click_to_upload")}
/>
{:else}
<StaticAudio value={_value} name={_value?.name || "audio_file"} {label} />
<StaticAudio
{show_label}
value={_value}
name={_value?.name || "audio_file"}
{label}
/>
{/if}
</Block>
10 changes: 9 additions & 1 deletion ui/packages/app/src/components/Checkbox/Checkbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let label: string = "Checkbox";
export let mode: "static" | "dynamic";
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -18,5 +19,12 @@
<Block {form_position}>
<StatusTracker tracked_status={loading_status} />

<Checkbox {style} {label} bind:value on:change disabled={mode === "static"} />
<Checkbox
{style}
{label}
{show_label}
bind:value
on:change
disabled={mode === "static"}
/>
</Block>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
export let style: string = "";
export let label: string = "Checkbox Group";
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -25,6 +26,7 @@
{choices}
{style}
{label}
{show_label}
on:change
disabled={mode === "static"}
/>
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/app/src/components/Dropdown/Dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let style: string = "";
export let choices: Array<string>;
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -25,6 +26,7 @@
{style}
{choices}
{label}
{show_label}
on:change
disabled={mode === "static"}
/>
Expand Down
5 changes: 4 additions & 1 deletion ui/packages/app/src/components/File/File.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let mode: "static" | "dynamic";
export let root: string;
export let label: string;
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -33,6 +34,8 @@

{#if mode === "dynamic"}
<FileUpload
{label}
{show_label}
value={_value}
on:change={({ detail }) => (value = detail)}
on:drag={({ detail }) => (dragging = detail)}
Expand All @@ -44,6 +47,6 @@
upload_text={$_("interface.click_to_upload")}
/>
{:else}
<File value={_value} {style} {label} />
<File value={_value} {style} {label} {show_label} />
{/if}
</Block>
4 changes: 3 additions & 1 deletion ui/packages/app/src/components/Image/Image.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
export let source: "canvas" | "webcam" | "upload" = "upload";
export let tool: "editor" | "select" = "editor";
export let label: string;
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -34,7 +35,7 @@
>
<StatusTracker tracked_status={loading_status} />
{#if mode === "static"}
<StaticImage {value} {label} {style} />
<StaticImage {value} {label} {style} {show_label} />
{:else}
<Image
bind:value
Expand All @@ -46,6 +47,7 @@
on:change
on:drag={({ detail }) => (dragging = detail)}
{label}
{show_label}
drop_text={$_("interface.drop_image")}
or_text={$_("or")}
upload_text={$_("interface.click_to_upload")}
Expand Down
3 changes: 2 additions & 1 deletion ui/packages/app/src/components/Label/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export let style: string = "";
export let loading_status: "complete" | "pending" | "error";
export let show_label: boolean;

const dispatch = createEventDispatcher<{ change: undefined }>();

Expand All @@ -28,6 +29,6 @@
<StatusTracker tracked_status={loading_status} />

{#if value !== undefined && value !== null}
<Label {style} {value} />
<Label {style} {value} {show_label} />
{/if}
</Block>
8 changes: 6 additions & 2 deletions ui/packages/app/src/components/Model3D/Model3D.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
export let style: string = "";
export let mode: "static" | "dynamic";
export let root: string;
export let clearColor: [];
export let clearColor: Array<number>;

export let loading_status: "complete" | "pending" | "error";
export let label: string;
export let show_label: boolean;

if (default_value) value = default_value;

Expand All @@ -33,6 +35,8 @@

{#if mode === "dynamic"}
<Model3DUpload
{label}
{show_label}
value={_value}
on:change={({ detail }) => (value = detail)}
on:drag={({ detail }) => (dragging = detail)}
Expand All @@ -44,6 +48,6 @@
upload_text={$_("interface.click_to_upload")}
/>
{:else if _value}
<Model3D value={_value} {clearColor} {style} />
<Model3D value={_value} {clearColor} {style} {label} {show_label} />
{/if}
</Block>
2 changes: 2 additions & 0 deletions ui/packages/app/src/components/Number/Number.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export let value: number = 0;
export let default_value: number;
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -23,6 +24,7 @@
<Number
bind:value
{label}
{show_label}
{style}
disabled={mode === "static"}
on:change
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/app/src/components/Radio/Radio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export let choices: Array<string> = [];
export let mode: "static" | "dynamic";
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -23,6 +24,7 @@
{form_position}
bind:value
{label}
{show_label}
{style}
{choices}
disabled={mode === "static"}
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/app/src/components/Slider/Slider.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
export let step: number;
export let mode: "static" | "dynamic";
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -26,6 +27,7 @@
<Range
bind:value
{label}
{show_label}
{style}
{minimum}
{maximum}
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/app/src/components/Textbox/Textbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
export let lines: number;
export let placeholder: string = "";
export let form_position: "first" | "last" | "mid" | "single" = "single";
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand All @@ -26,6 +27,7 @@
<TextBox
bind:value
{label}
{show_label}
{style}
{lines}
autoheight={mode === "static"}
Expand Down
3 changes: 2 additions & 1 deletion ui/packages/app/src/components/TimeSeries/TimeSeries.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
export let x: string;
export let mode: "static" | "dynamic";
export let label: string;
export let show_label: boolean;

export let loading_status: "complete" | "pending" | "error";

Expand Down Expand Up @@ -118,7 +119,7 @@
color={"grey"}
padding={false}
>
<BlockLabel image={chart_icon} label={label || "TimeSeries"} />
<BlockLabel {show_label} image={chart_icon} label={label || "TimeSeries"} />
<StatusTracker tracked_status={loading_status} />

{#if mode === "static"}
Expand Down
5 changes: 3 additions & 2 deletions ui/packages/app/src/components/Video/Video.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
export let style: string = "";
export let source: string;
export let root: string;

export let show_label: boolean;
export let loading_status: "complete" | "pending" | "error";

export let mode: "static" | "dynamic";
Expand All @@ -36,13 +36,14 @@
<StatusTracker tracked_status={loading_status} />

{#if mode === "static"}
<StaticVideo value={_value} {label} {style} />
<StaticVideo value={_value} {label} {show_label} {style} />
{:else}
<Video
value={_value}
on:change={({ detail }) => (value = detail)}
on:drag={({ detail }) => (dragging = detail)}
{label}
{show_label}
{style}
{source}
drop_text={$_("interface.drop_video")}
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/atoms/src/BlockLabel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

export let label: string | null = null;
export let image: string | undefined = undefined;
export let show_label: boolean = true;

// const type_labels = {
// "audio/*": { text: "Audio", icon: audio_icon },
Expand All @@ -21,6 +22,7 @@
</script>

<div
class:sr-only={!show_label}
class="absolute left-0 top-0 py-1 px-2 rounded-br-lg shadow-sm text-xs text-gray-500 flex items-center pointer-events-none bg-white z-20 border-b border-r border-gray-100"
>
<img src={image} alt="" class="mr-2 h-[12px] w-[12px] opacity-50" />
Expand Down
9 changes: 8 additions & 1 deletion ui/packages/atoms/src/BlockTitle.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<span class="text-gray-600 text-[0.855rem] mb-2 block">
<script lang="ts">
export let show_label: boolean = true;
</script>

<span
class="text-gray-600 text-[0.855rem] mb-2 block"
class:sr-only={!show_label}
>
<slot />
</span>
3 changes: 2 additions & 1 deletion ui/packages/audio/src/Audio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

export let value: null | { name: string; data: string } = null;
export let label: string;
export let show_label: boolean;
export let style: string = "";
export let name: string;
export let source: "microphone" | "upload" | "none";
Expand Down Expand Up @@ -152,7 +153,7 @@
$: dispatch("drag", dragging);
</script>

<BlockLabel image={audio_icon} label={label || "Audio"} />
<BlockLabel {show_label} image={audio_icon} label={label || "Audio"} />
{#if value === null}
{#if source === "microphone"}
<div class="mt-6 p-2">
Expand Down