Upload folder using huggingface_hub
Browse files- 6.5.0/code/Example.svelte +7 -3
- 6.5.0/code/Index.svelte +3 -3
- 6.5.0/code/shared/Code.svelte +64 -33
- 6.5.0/code/shared/Copy.svelte +7 -2
- 6.5.0/code/shared/Download.svelte +10 -6
- 6.5.0/code/shared/Widgets.svelte +13 -4
6.5.0/code/Example.svelte
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
function truncate_text(text: string | null, max_length = 60): string {
|
| 7 |
if (!text) return "";
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
interface Props {
|
| 3 |
+
value: string | null;
|
| 4 |
+
type: "gallery" | "table";
|
| 5 |
+
selected?: boolean;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
let { value, type, selected = false }: Props = $props();
|
| 9 |
|
| 10 |
function truncate_text(text: string | null, max_length = 60): string {
|
| 11 |
if (!text) return "";
|
6.5.0/code/Index.svelte
CHANGED
|
@@ -88,9 +88,9 @@
|
|
| 88 |
show_line_numbers={gradio.props.show_line_numbers}
|
| 89 |
autocomplete={gradio.props.autocomplete}
|
| 90 |
readonly={!gradio.shared.interactive}
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
/>
|
| 95 |
{/if}
|
| 96 |
</Block>
|
|
|
|
| 88 |
show_line_numbers={gradio.props.show_line_numbers}
|
| 89 |
autocomplete={gradio.props.autocomplete}
|
| 90 |
readonly={!gradio.shared.interactive}
|
| 91 |
+
onblur={() => gradio.dispatch("blur")}
|
| 92 |
+
onfocus={() => gradio.dispatch("focus")}
|
| 93 |
+
oninput={() => gradio.dispatch("input")}
|
| 94 |
/>
|
| 95 |
{/if}
|
| 96 |
</Block>
|
6.5.0/code/shared/Code.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import {
|
| 3 |
import {
|
| 4 |
EditorView,
|
| 5 |
ViewUpdate,
|
|
@@ -16,41 +16,72 @@
|
|
| 16 |
import { basicSetup } from "./extensions";
|
| 17 |
import { getLanguageExtension } from "./language";
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
let
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
let element: HTMLDivElement;
|
| 42 |
let view: EditorView;
|
| 43 |
|
| 44 |
-
$: get_lang(language);
|
| 45 |
-
|
| 46 |
async function get_lang(val: string): Promise<void> {
|
| 47 |
const ext = await getLanguageExtension(val);
|
| 48 |
lang_extension = ext;
|
| 49 |
}
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
function set_doc(new_doc: string): void {
|
| 56 |
if (view && new_doc !== view.state.doc.toString()) {
|
|
@@ -81,11 +112,11 @@
|
|
| 81 |
}
|
| 82 |
|
| 83 |
function handle_focus(): void {
|
| 84 |
-
|
| 85 |
}
|
| 86 |
|
| 87 |
function handle_blur(): void {
|
| 88 |
-
|
| 89 |
}
|
| 90 |
|
| 91 |
function getGutterLineHeight(_view: EditorView): string | null {
|
|
@@ -136,10 +167,10 @@
|
|
| 136 |
|
| 137 |
const user_change = is_user_input(vu);
|
| 138 |
if (user_change) {
|
| 139 |
-
|
| 140 |
-
|
| 141 |
} else {
|
| 142 |
-
|
| 143 |
}
|
| 144 |
|
| 145 |
view.requestMeasure({ read: resize });
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { onMount } from "svelte";
|
| 3 |
import {
|
| 4 |
EditorView,
|
| 5 |
ViewUpdate,
|
|
|
|
| 16 |
import { basicSetup } from "./extensions";
|
| 17 |
import { getLanguageExtension } from "./language";
|
| 18 |
|
| 19 |
+
interface Props {
|
| 20 |
+
class_names?: string;
|
| 21 |
+
value?: string;
|
| 22 |
+
dark_mode: boolean;
|
| 23 |
+
basic?: boolean;
|
| 24 |
+
language: string;
|
| 25 |
+
lines?: number;
|
| 26 |
+
max_lines?: number | null;
|
| 27 |
+
extensions?: Extension[];
|
| 28 |
+
use_tab?: boolean;
|
| 29 |
+
readonly?: boolean;
|
| 30 |
+
placeholder?: string | HTMLElement | null | undefined;
|
| 31 |
+
wrap_lines?: boolean;
|
| 32 |
+
show_line_numbers?: boolean;
|
| 33 |
+
autocomplete?: boolean;
|
| 34 |
+
onchange?: (value: string) => void;
|
| 35 |
+
onblur?: () => void;
|
| 36 |
+
onfocus?: () => void;
|
| 37 |
+
oninput?: () => void;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
let {
|
| 41 |
+
class_names = "",
|
| 42 |
+
value = $bindable(),
|
| 43 |
+
dark_mode,
|
| 44 |
+
basic = true,
|
| 45 |
+
language,
|
| 46 |
+
lines = 5,
|
| 47 |
+
max_lines = null,
|
| 48 |
+
extensions = [],
|
| 49 |
+
use_tab = true,
|
| 50 |
+
readonly = false,
|
| 51 |
+
placeholder = undefined,
|
| 52 |
+
wrap_lines = false,
|
| 53 |
+
show_line_numbers = true,
|
| 54 |
+
autocomplete = false,
|
| 55 |
+
onchange,
|
| 56 |
+
onblur,
|
| 57 |
+
onfocus,
|
| 58 |
+
oninput
|
| 59 |
+
}: Props = $props();
|
| 60 |
+
|
| 61 |
+
let lang_extension: Extension | undefined = $state();
|
| 62 |
let element: HTMLDivElement;
|
| 63 |
let view: EditorView;
|
| 64 |
|
|
|
|
|
|
|
| 65 |
async function get_lang(val: string): Promise<void> {
|
| 66 |
const ext = await getLanguageExtension(val);
|
| 67 |
lang_extension = ext;
|
| 68 |
}
|
| 69 |
|
| 70 |
+
$effect(() => {
|
| 71 |
+
get_lang(language);
|
| 72 |
+
});
|
| 73 |
+
|
| 74 |
+
$effect(() => {
|
| 75 |
+
lang_extension;
|
| 76 |
+
readonly;
|
| 77 |
+
reconfigure();
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
$effect(() => {
|
| 81 |
+
set_doc(value);
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
update_lines();
|
| 85 |
|
| 86 |
function set_doc(new_doc: string): void {
|
| 87 |
if (view && new_doc !== view.state.doc.toString()) {
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
function handle_focus(): void {
|
| 115 |
+
onfocus?.();
|
| 116 |
}
|
| 117 |
|
| 118 |
function handle_blur(): void {
|
| 119 |
+
onblur?.();
|
| 120 |
}
|
| 121 |
|
| 122 |
function getGutterLineHeight(_view: EditorView): string | null {
|
|
|
|
| 167 |
|
| 168 |
const user_change = is_user_input(vu);
|
| 169 |
if (user_change) {
|
| 170 |
+
onchange?.(text);
|
| 171 |
+
oninput?.();
|
| 172 |
} else {
|
| 173 |
+
onchange?.(text);
|
| 174 |
}
|
| 175 |
|
| 176 |
view.requestMeasure({ read: resize });
|
6.5.0/code/shared/Copy.svelte
CHANGED
|
@@ -3,8 +3,13 @@
|
|
| 3 |
import { Copy, Check } from "@gradio/icons";
|
| 4 |
import { IconButton } from "@gradio/atoms";
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
let timer: NodeJS.Timeout;
|
| 9 |
|
| 10 |
function copy_feedback(): void {
|
|
|
|
| 3 |
import { Copy, Check } from "@gradio/icons";
|
| 4 |
import { IconButton } from "@gradio/atoms";
|
| 5 |
|
| 6 |
+
interface Props {
|
| 7 |
+
value: string;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
let { value }: Props = $props();
|
| 11 |
+
|
| 12 |
+
let copied = $state(false);
|
| 13 |
let timer: NodeJS.Timeout;
|
| 14 |
|
| 15 |
function copy_feedback(): void {
|
6.5.0/code/shared/Download.svelte
CHANGED
|
@@ -4,10 +4,14 @@
|
|
| 4 |
import { DownloadLink } from "@gradio/atoms";
|
| 5 |
import { IconButton } from "@gradio/atoms";
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
|
| 12 |
function get_ext_for_type(type: string): string {
|
| 13 |
const exts: Record<string, string> = {
|
|
@@ -36,7 +40,7 @@
|
|
| 36 |
return exts[type] || "txt";
|
| 37 |
}
|
| 38 |
|
| 39 |
-
let copied = false;
|
| 40 |
let timer: NodeJS.Timeout;
|
| 41 |
|
| 42 |
function copy_feedback(): void {
|
|
@@ -47,7 +51,7 @@
|
|
| 47 |
}, 2000);
|
| 48 |
}
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
onDestroy(() => {
|
| 53 |
if (timer) clearTimeout(timer);
|
|
@@ -57,7 +61,7 @@
|
|
| 57 |
<DownloadLink
|
| 58 |
download="file.{ext}"
|
| 59 |
href={download_value}
|
| 60 |
-
|
| 61 |
>
|
| 62 |
<IconButton Icon={copied ? Check : Download} />
|
| 63 |
</DownloadLink>
|
|
|
|
| 4 |
import { DownloadLink } from "@gradio/atoms";
|
| 5 |
import { IconButton } from "@gradio/atoms";
|
| 6 |
|
| 7 |
+
interface Props {
|
| 8 |
+
value: string;
|
| 9 |
+
language: string;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
let { value, language }: Props = $props();
|
| 13 |
|
| 14 |
+
let ext = $derived(get_ext_for_type(language));
|
| 15 |
|
| 16 |
function get_ext_for_type(type: string): string {
|
| 17 |
const exts: Record<string, string> = {
|
|
|
|
| 40 |
return exts[type] || "txt";
|
| 41 |
}
|
| 42 |
|
| 43 |
+
let copied = $state(false);
|
| 44 |
let timer: NodeJS.Timeout;
|
| 45 |
|
| 46 |
function copy_feedback(): void {
|
|
|
|
| 51 |
}, 2000);
|
| 52 |
}
|
| 53 |
|
| 54 |
+
let download_value = $derived(URL.createObjectURL(new Blob([value])));
|
| 55 |
|
| 56 |
onDestroy(() => {
|
| 57 |
if (timer) clearTimeout(timer);
|
|
|
|
| 61 |
<DownloadLink
|
| 62 |
download="file.{ext}"
|
| 63 |
href={download_value}
|
| 64 |
+
onclick={copy_feedback}
|
| 65 |
>
|
| 66 |
<IconButton Icon={copied ? Check : Download} />
|
| 67 |
</DownloadLink>
|
6.5.0/code/shared/Widgets.svelte
CHANGED
|
@@ -4,10 +4,19 @@
|
|
| 4 |
import { IconButtonWrapper } from "@gradio/atoms";
|
| 5 |
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
</script>
|
| 12 |
|
| 13 |
<IconButtonWrapper {buttons} {on_custom_button_click}>
|
|
|
|
| 4 |
import { IconButtonWrapper } from "@gradio/atoms";
|
| 5 |
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
| 6 |
|
| 7 |
+
interface Props {
|
| 8 |
+
value: string;
|
| 9 |
+
language: string;
|
| 10 |
+
buttons?: (string | CustomButtonType)[] | null;
|
| 11 |
+
on_custom_button_click?: ((id: number) => void) | null;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
let {
|
| 15 |
+
value,
|
| 16 |
+
language,
|
| 17 |
+
buttons = null,
|
| 18 |
+
on_custom_button_click = null
|
| 19 |
+
}: Props = $props();
|
| 20 |
</script>
|
| 21 |
|
| 22 |
<IconButtonWrapper {buttons} {on_custom_button_click}>
|