Upload folder using huggingface_hub
Browse files
5.49.1/downloadbutton/Index.svelte
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script context="module" lang="ts">
|
| 2 |
+
export { default as BaseButton } from "./shared/DownloadButton.svelte";
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<script lang="ts">
|
| 6 |
+
import type { Gradio } from "@gradio/utils";
|
| 7 |
+
import { type FileData } from "@gradio/client";
|
| 8 |
+
|
| 9 |
+
import DownloadButton from "./shared/DownloadButton.svelte";
|
| 10 |
+
|
| 11 |
+
export let elem_id = "";
|
| 12 |
+
export let elem_classes: string[] = [];
|
| 13 |
+
export let visible: boolean | "hidden" = true;
|
| 14 |
+
export let value: null | FileData;
|
| 15 |
+
export let variant: "primary" | "secondary" | "stop" = "secondary";
|
| 16 |
+
export let interactive: boolean;
|
| 17 |
+
export let size: "sm" | "lg" = "lg";
|
| 18 |
+
export let scale: number | null = null;
|
| 19 |
+
export let icon: null | FileData = null;
|
| 20 |
+
export let min_width: number | undefined = undefined;
|
| 21 |
+
export let label: string | null = null;
|
| 22 |
+
export let gradio: Gradio<{
|
| 23 |
+
click: never;
|
| 24 |
+
}>;
|
| 25 |
+
</script>
|
| 26 |
+
|
| 27 |
+
<DownloadButton
|
| 28 |
+
{value}
|
| 29 |
+
{variant}
|
| 30 |
+
{elem_id}
|
| 31 |
+
{elem_classes}
|
| 32 |
+
{size}
|
| 33 |
+
{scale}
|
| 34 |
+
{icon}
|
| 35 |
+
{min_width}
|
| 36 |
+
{visible}
|
| 37 |
+
disabled={!interactive}
|
| 38 |
+
on:click={() => gradio.dispatch("click")}
|
| 39 |
+
>
|
| 40 |
+
{label ?? ""}
|
| 41 |
+
</DownloadButton>
|
5.49.1/downloadbutton/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/downloadbutton",
|
| 3 |
+
"version": "0.4.12",
|
| 4 |
+
"description": "Gradio UI packages",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"author": "",
|
| 7 |
+
"license": "ISC",
|
| 8 |
+
"private": false,
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"@gradio/button": "workspace:^",
|
| 11 |
+
"@gradio/client": "workspace:^",
|
| 12 |
+
"@gradio/utils": "workspace:^"
|
| 13 |
+
},
|
| 14 |
+
"devDependencies": {
|
| 15 |
+
"@gradio/preview": "workspace:^"
|
| 16 |
+
},
|
| 17 |
+
"main": "./Index.svelte",
|
| 18 |
+
"main_changeset": true,
|
| 19 |
+
"exports": {
|
| 20 |
+
".": {
|
| 21 |
+
"gradio": "./Index.svelte",
|
| 22 |
+
"svelte": "./dist/Index.svelte",
|
| 23 |
+
"types": "./dist/Index.svelte.d.ts"
|
| 24 |
+
},
|
| 25 |
+
"./package.json": "./package.json"
|
| 26 |
+
},
|
| 27 |
+
"peerDependencies": {
|
| 28 |
+
"svelte": "^4.0.0"
|
| 29 |
+
},
|
| 30 |
+
"repository": {
|
| 31 |
+
"type": "git",
|
| 32 |
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 33 |
+
"directory": "js/downloadbutton"
|
| 34 |
+
}
|
| 35 |
+
}
|
5.49.1/downloadbutton/shared/DownloadButton.svelte
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { createEventDispatcher } from "svelte";
|
| 3 |
+
import { type FileData } from "@gradio/client";
|
| 4 |
+
import { BaseButton } from "@gradio/button";
|
| 5 |
+
|
| 6 |
+
export let elem_id = "";
|
| 7 |
+
export let elem_classes: string[] = [];
|
| 8 |
+
export let visible: boolean | "hidden" = true;
|
| 9 |
+
export let variant: "primary" | "secondary" | "stop" = "secondary";
|
| 10 |
+
export let size: "sm" | "md" | "lg" = "lg";
|
| 11 |
+
export let value: null | FileData;
|
| 12 |
+
export let icon: null | FileData;
|
| 13 |
+
export let disabled = false;
|
| 14 |
+
export let scale: number | null = null;
|
| 15 |
+
export let min_width: number | undefined = undefined;
|
| 16 |
+
const dispatch = createEventDispatcher();
|
| 17 |
+
|
| 18 |
+
function download_file(): void {
|
| 19 |
+
dispatch("click");
|
| 20 |
+
if (!value?.url) {
|
| 21 |
+
return;
|
| 22 |
+
}
|
| 23 |
+
let file_name;
|
| 24 |
+
if (!value.orig_name && value.url) {
|
| 25 |
+
const parts = value.url.split("/");
|
| 26 |
+
file_name = parts[parts.length - 1];
|
| 27 |
+
file_name = file_name.split("?")[0].split("#")[0];
|
| 28 |
+
} else {
|
| 29 |
+
file_name = value.orig_name;
|
| 30 |
+
}
|
| 31 |
+
const a = document.createElement("a");
|
| 32 |
+
a.href = value.url;
|
| 33 |
+
a.download = file_name || "file";
|
| 34 |
+
document.body.appendChild(a);
|
| 35 |
+
a.click();
|
| 36 |
+
document.body.removeChild(a);
|
| 37 |
+
}
|
| 38 |
+
</script>
|
| 39 |
+
|
| 40 |
+
<BaseButton
|
| 41 |
+
{size}
|
| 42 |
+
{variant}
|
| 43 |
+
{elem_id}
|
| 44 |
+
{elem_classes}
|
| 45 |
+
{visible}
|
| 46 |
+
on:click={download_file}
|
| 47 |
+
{scale}
|
| 48 |
+
{min_width}
|
| 49 |
+
{disabled}
|
| 50 |
+
>
|
| 51 |
+
{#if icon}
|
| 52 |
+
<img class="button-icon" src={icon.url} alt={`${value} icon`} />
|
| 53 |
+
{/if}
|
| 54 |
+
<slot />
|
| 55 |
+
</BaseButton>
|
| 56 |
+
|
| 57 |
+
<style>
|
| 58 |
+
.button-icon {
|
| 59 |
+
width: var(--text-xl);
|
| 60 |
+
height: var(--text-xl);
|
| 61 |
+
margin-right: var(--spacing-xl);
|
| 62 |
+
}
|
| 63 |
+
</style>
|