Skip to content

Commit

Permalink
Merge pull request #20 from apolinario/main
Browse files Browse the repository at this point in the history
Add `download_button`
  • Loading branch information
pngwn authored Apr 18, 2024
2 parents b0c834e + d330c3e commit 9496dac
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"trailingComma": "none",
"printWidth": 80,
"plugins": ["prettier-plugin-svelte"]
}
}
3 changes: 3 additions & 0 deletions frontend/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
export let visible = true;
export let value: [FileData | null, FileData | null] = [null, null];
export let label: string;
export let show_download_button: boolean;
export let show_label: boolean;
export let root: string;
export let height: number | undefined;
Expand Down Expand Up @@ -57,12 +58,14 @@
/>
{:else}
<StaticImage
i18n={gradio.i18n}
{elem_id}
{elem_classes}
{visible}
bind:value
{label}
{show_label}
{show_download_button}
{loading_status}
{height}
{width}
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@gradio/statustracker": "0.4.0",
"@gradio/upload": "0.5.1",
"@gradio/utils": "0.2.0",
"@gradio/wasm": "^0.10.0",
"cropperjs": "^1.5.12",
"d3-drag": "^3.0.0",
"d3-selection": "^3.0.0",
Expand Down
18 changes: 18 additions & 0 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions frontend/shared/Image.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<script lang="ts">
import Slider from "../shared/Slider.svelte";
import { createEventDispatcher, tick, onMount } from "svelte";
import { BlockLabel, Empty } from "@gradio/atoms";
import { BlockLabel, Empty, IconButton } from "@gradio/atoms";
import { Download } from "@gradio/icons";
import { Image } from "@gradio/icons";
import { type SelectData } from "@gradio/utils";
import ClearImage from "./ClearImage.svelte";
import { Upload } from "@gradio/upload";
import { DownloadLink } from "@gradio/wasm/svelte";
import { type FileData, normalise_file } from "@gradio/client";
Expand All @@ -17,7 +19,7 @@
export let root: string;
export let position: number;
export let upload_count: number = 2;
export let layer_images = true;
export let show_download_button = true;
let value_: [FileData | null, FileData | null] = value || [null, null];
Expand Down Expand Up @@ -77,6 +79,15 @@
}}
/>
{/if}
{#if value?.[1]?.url}
<div class="icon-buttons">
{#if show_download_button}
<DownloadLink href={value[1].url} download={value[1].orig_name || "image"}>
<IconButton Icon={Download} />
</DownloadLink>
{/if}
</div>
{/if}
<Slider bind:position disabled={upload_count == 2 || !value?.[0]}>
<div
class="upload-wrap"
Expand Down Expand Up @@ -186,4 +197,22 @@
.empty-wrap {
pointer-events: none;
}
.icon-button {
position: absolute;
top: 0px;
right: 0px;
z-index: var(--layer-1);
}
.icon-buttons {
display: flex;
position: absolute;
right: 34px;
z-index: var(--layer-2);
top: 8px;
}
.icon-buttons .download-button-container {
margin: var(--size-1) 0;
}
</style>
33 changes: 29 additions & 4 deletions frontend/shared/ImagePreview.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script lang="ts">
import Slider from "./Slider.svelte";
import { BlockLabel, Empty } from "@gradio/atoms";
import { Image } from "@gradio/icons";
import { BlockLabel, Empty, IconButton } from "@gradio/atoms";
import { Image, Download } from "@gradio/icons";
import { type FileData, normalise_file } from "@gradio/client";
import type { I18nFormatter } from "@gradio/utils";
import { DownloadLink } from "@gradio/wasm/svelte";
export let value: [null | FileData, null | FileData] = [null, null];
export let label: string | undefined = undefined;
export let show_download_button = true;
export let show_label: boolean;
export let root: string;
export let i18n: I18nFormatter;
Expand All @@ -29,7 +30,13 @@
{:else}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions-->

<div class="icon-buttons">
{#if show_download_button}
<DownloadLink href={value[1].url} download={value[1].orig_name || "image"}>
<IconButton Icon={Download} label={i18n("common.download")} />
</DownloadLink>
{/if}
</div>
<div class="slider-wrap" bind:clientWidth={el_width}>
<Slider bind:position>
<img src={value?.[0]?.url} alt="" loading="lazy" />
Expand Down Expand Up @@ -65,4 +72,22 @@
.hidden {
opacity: 0;
}
.icon-button {
position: absolute;
top: 0px;
right: 0px;
z-index: var(--layer-1);
}
.icon-buttons {
display: flex;
position: absolute;
right: 6px;
z-index: var(--layer-1);
top: 6px;
}
.icon-buttons .download-button-container {
margin: var(--size-1) 0;
}
</style>
4 changes: 2 additions & 2 deletions frontend/shared/InteractiveImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<script lang="ts">
import type { Gradio, SelectData, ShareData } from "@gradio/utils";
import Image from "./Image.svelte";
import { normalise_file } from "@gradio/client";
import { Block } from "@gradio/atoms";
Expand All @@ -29,7 +31,6 @@
export let root: string;
export let position: number;
export let upload_count: number = 2;
export let layer_images = true;
export let gradio: Gradio<{
change: never;
Expand Down Expand Up @@ -94,7 +95,6 @@
{label}
{show_label}
{upload_count}
{layer_images}
>
<UploadText i18n={gradio.i18n} type="image" />
</Image>
Expand Down
25 changes: 22 additions & 3 deletions frontend/shared/StaticImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import type { Gradio, SelectData } from "@gradio/utils";
import StaticImage from "./ImagePreview.svelte";
import { Block } from "@gradio/atoms";
import { Block, IconButton } from "@gradio/atoms";
import { StatusTracker } from "@gradio/statustracker";
import type { LoadingStatus } from "@gradio/statustracker";
import type { FileData } from "@gradio/client";
import { DownloadLink } from "@gradio/wasm/svelte";
import { Download } from "@gradio/icons";
import type { I18nFormatter } from "@gradio/utils";
export let elem_id = "";
export let elem_classes: string[] = [];
Expand All @@ -18,10 +20,11 @@
export let show_label: boolean;
export let root: string;
export let upload_count: number = 2;
export let show_download_button = true;
export let height: number;
export let width: number | undefined;
export let layer_images = true;
export let i18n: I18nFormatter;
export let container = true;
export let scale: number | null = null;
Expand Down Expand Up @@ -58,6 +61,15 @@
{scale}
{min_width}
>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions-->
<div class="icon-buttons">
{#if show_download_button && value && value[1]}
<DownloadLink href={value[1].url} download={value[1].orig_name || "image"}>
<IconButton Icon={Download} label={i18n("common.download")} />
</DownloadLink>
{/if}
</div>
<div
class="status-wrap"
class:half={is_half}
Expand Down Expand Up @@ -126,4 +138,11 @@
.status-wrap.half :global(.eta-bar) {
opacity: 0;
}
.icon-buttons {
display: flex;
position: absolute;
right: 6px;
z-index: var(--layer-1);
top: 6px;
}
</style>

0 comments on commit 9496dac

Please sign in to comment.