@gradio/multimodaltextbox 0.10.22-dev.0 → 0.11.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/Index.svelte +103 -111
- package/dist/Example.svelte +27 -21
- package/dist/Example.svelte.d.ts +23 -21
- package/dist/Index.svelte +146 -111
- package/dist/Index.svelte.d.ts +3 -199
- package/dist/shared/MultimodalTextbox.svelte +714 -545
- package/dist/shared/MultimodalTextbox.svelte.d.ts +71 -67
- package/dist/types.d.ts +46 -0
- package/dist/types.js +1 -0
- package/package.json +12 -11
- package/shared/MultimodalTextbox.svelte +404 -314
- package/types.ts +42 -0
package/dist/Index.svelte
CHANGED
|
@@ -1,133 +1,168 @@
|
|
|
1
1
|
<svelte:options accessors={true} />
|
|
2
2
|
|
|
3
|
-
<script context="module"
|
|
4
|
-
export { default as
|
|
3
|
+
<script context="module" lang="ts">
|
|
4
|
+
export { default as BaseMultimodalTextbox } from "./shared/MultimodalTextbox.svelte";
|
|
5
|
+
export { default as BaseExample } from "./Example.svelte";
|
|
5
6
|
</script>
|
|
6
7
|
|
|
7
|
-
<script
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { Gradio, type SelectData } from "@gradio/utils";
|
|
10
|
+
import MultimodalTextbox from "./shared/MultimodalTextbox.svelte";
|
|
11
|
+
import { Block } from "@gradio/atoms";
|
|
12
|
+
import { StatusTracker } from "@gradio/statustracker";
|
|
13
|
+
import { onMount, tick } from "svelte";
|
|
14
|
+
import type { WaveformOptions } from "../audio/shared/types";
|
|
15
|
+
import type {
|
|
16
|
+
MultimodalTextboxProps,
|
|
17
|
+
MultimodalTextboxEvents
|
|
18
|
+
} from "./types";
|
|
19
|
+
|
|
20
|
+
let upload_promise = $state<Promise<any>>();
|
|
21
|
+
|
|
22
|
+
class MultimodalTextboxGradio extends Gradio<
|
|
23
|
+
MultimodalTextboxEvents,
|
|
24
|
+
MultimodalTextboxProps
|
|
25
|
+
> {
|
|
26
|
+
async get_data() {
|
|
27
|
+
if (upload_promise) {
|
|
28
|
+
await upload_promise;
|
|
29
|
+
await tick();
|
|
30
|
+
}
|
|
31
|
+
const data = await super.get_data();
|
|
32
|
+
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let props = $props();
|
|
38
|
+
const gradio = new MultimodalTextboxGradio(props);
|
|
39
|
+
|
|
40
|
+
const value = $derived(gradio.props.value || { text: "", files: [] });
|
|
41
|
+
|
|
42
|
+
let dragging: boolean;
|
|
43
|
+
let active_source: "microphone" | null = null;
|
|
44
|
+
|
|
45
|
+
let color_accent = "darkorange";
|
|
46
|
+
|
|
47
|
+
const waveform_settings = {
|
|
48
|
+
height: 50,
|
|
49
|
+
barWidth: 2,
|
|
50
|
+
barGap: 3,
|
|
51
|
+
cursorWidth: 2,
|
|
52
|
+
cursorColor: "#ddd5e9",
|
|
53
|
+
autoplay: false,
|
|
54
|
+
barRadius: 10,
|
|
55
|
+
dragToSeek: true,
|
|
56
|
+
normalize: true,
|
|
57
|
+
minPxPerSec: 20,
|
|
58
|
+
waveColor: "",
|
|
59
|
+
progressColor: "",
|
|
60
|
+
mediaControls: false as boolean | undefined,
|
|
61
|
+
sampleRate: 44100
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
onMount(() => {
|
|
65
|
+
color_accent = getComputedStyle(document?.documentElement).getPropertyValue(
|
|
66
|
+
"--color-accent"
|
|
67
|
+
);
|
|
68
|
+
set_trim_region_colour();
|
|
69
|
+
waveform_settings.waveColor =
|
|
70
|
+
gradio.props?.waveform_options?.waveform_color || "#9ca3af";
|
|
71
|
+
waveform_settings.progressColor =
|
|
72
|
+
gradio.props?.waveform_options?.waveform_progress_color || color_accent;
|
|
73
|
+
waveform_settings.mediaControls =
|
|
74
|
+
gradio.props?.waveform_options?.show_controls;
|
|
75
|
+
waveform_settings.sampleRate =
|
|
76
|
+
gradio.props?.waveform_options?.sample_rate || 44100;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const trim_region_settings = {
|
|
80
|
+
color: gradio.props?.waveform_options?.trim_region_color,
|
|
81
|
+
drag: true,
|
|
82
|
+
resize: true
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function set_trim_region_colour(): void {
|
|
86
|
+
document.documentElement.style.setProperty(
|
|
87
|
+
"--trim-region-color",
|
|
88
|
+
trim_region_settings.color || color_accent
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Create const references to the callbacks so that afterUpdate in child is not called on every prop change
|
|
93
|
+
// in the DOM. See https://github.com/gradio-app/gradio/issues/11933
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
95
|
+
const upload_fn = (...args: Parameters<typeof gradio.shared.client.upload>) =>
|
|
96
|
+
gradio.shared.client.upload(...args);
|
|
97
|
+
const i18n = (s: string | null | undefined): string => gradio.i18n(s);
|
|
98
|
+
const stream_handler_fn = (
|
|
99
|
+
...args: Parameters<typeof gradio.shared.client.stream>
|
|
100
|
+
): EventSource => gradio.shared.client.stream(...args);
|
|
101
|
+
|
|
102
|
+
let sources_string = $derived(
|
|
103
|
+
gradio.props.sources.join(",") as
|
|
104
|
+
| "upload"
|
|
105
|
+
| "upload,microphone"
|
|
106
|
+
| "microphone"
|
|
107
|
+
| "microphone,upload"
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
let file_types_string = $derived.by(
|
|
111
|
+
() => (gradio.props.file_types || []).join(",") || null
|
|
112
|
+
);
|
|
85
113
|
</script>
|
|
86
114
|
|
|
87
115
|
<Block
|
|
88
|
-
{visible}
|
|
89
|
-
{elem_id}
|
|
90
|
-
elem_classes={[...elem_classes, "multimodal-textbox"]}
|
|
91
|
-
{scale}
|
|
92
|
-
{min_width}
|
|
116
|
+
visible={gradio.shared.visible}
|
|
117
|
+
elem_id={gradio.shared.elem_id}
|
|
118
|
+
elem_classes={[...(gradio.shared.elem_classes || []), "multimodal-textbox"]}
|
|
119
|
+
scale={gradio.shared.scale}
|
|
120
|
+
min_width={gradio.shared.min_width}
|
|
93
121
|
allow_overflow={false}
|
|
94
122
|
padding={false}
|
|
95
123
|
border_mode={dragging ? "focus" : "base"}
|
|
96
124
|
>
|
|
97
|
-
{#if loading_status}
|
|
125
|
+
{#if gradio.shared.loading_status}
|
|
98
126
|
<StatusTracker
|
|
99
|
-
autoscroll={gradio.autoscroll}
|
|
127
|
+
autoscroll={gradio.shared.autoscroll}
|
|
100
128
|
i18n={gradio.i18n}
|
|
101
|
-
{...loading_status}
|
|
102
|
-
on:clear_status={() =>
|
|
129
|
+
{...gradio.shared.loading_status}
|
|
130
|
+
on:clear_status={() =>
|
|
131
|
+
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
|
103
132
|
/>
|
|
104
133
|
{/if}
|
|
105
134
|
|
|
106
135
|
<MultimodalTextbox
|
|
107
|
-
bind:
|
|
108
|
-
|
|
136
|
+
bind:upload_promise
|
|
137
|
+
{value}
|
|
138
|
+
value_is_output
|
|
109
139
|
bind:dragging
|
|
110
140
|
bind:active_source
|
|
111
141
|
{file_types_string}
|
|
112
|
-
{root}
|
|
113
|
-
{label}
|
|
114
|
-
{info}
|
|
115
|
-
{show_label}
|
|
116
|
-
{lines}
|
|
117
|
-
{rtl}
|
|
118
|
-
{text_align}
|
|
119
|
-
{waveform_settings}
|
|
142
|
+
root={gradio.shared.root}
|
|
143
|
+
label={gradio.shared.label || "MultimodalTextbox"}
|
|
144
|
+
info={gradio.props.info}
|
|
145
|
+
show_label={gradio.shared.show_label}
|
|
146
|
+
lines={gradio.props.lines}
|
|
147
|
+
rtl={gradio.props.rtl}
|
|
148
|
+
text_align={gradio.props.text_align}
|
|
149
|
+
waveform_settings={waveform_settings as WaveformOptions}
|
|
120
150
|
{i18n}
|
|
121
|
-
max_lines={!max_lines
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
{
|
|
126
|
-
{
|
|
127
|
-
{
|
|
151
|
+
max_lines={!gradio.props.max_lines
|
|
152
|
+
? gradio.props.lines + 1
|
|
153
|
+
: gradio.props.max_lines}
|
|
154
|
+
placeholder={gradio.props.placeholder}
|
|
155
|
+
submit_btn={gradio.props.submit_btn}
|
|
156
|
+
stop_btn={gradio.props.stop_btn}
|
|
157
|
+
autofocus={gradio.props.autofocus}
|
|
158
|
+
autoscroll={gradio.shared.autoscroll}
|
|
159
|
+
file_count={gradio.props.file_count}
|
|
128
160
|
{sources_string}
|
|
129
|
-
max_file_size={gradio.max_file_size}
|
|
130
|
-
on:change={() =>
|
|
161
|
+
max_file_size={gradio.shared.max_file_size}
|
|
162
|
+
on:change={(e) => (
|
|
163
|
+
(gradio.props.value = e.detail),
|
|
164
|
+
gradio.dispatch("change", gradio.props.value)
|
|
165
|
+
)}
|
|
131
166
|
on:input={() => gradio.dispatch("input")}
|
|
132
167
|
on:submit={() => gradio.dispatch("submit")}
|
|
133
168
|
on:stop={() => gradio.dispatch("stop")}
|
|
@@ -142,10 +177,10 @@ $: file_types_string = (file_types || []).join(",") || null;
|
|
|
142
177
|
on:stop_recording={() => gradio.dispatch("stop_recording")}
|
|
143
178
|
on:upload={(e) => gradio.dispatch("upload", e.detail)}
|
|
144
179
|
on:clear={() => gradio.dispatch("clear")}
|
|
145
|
-
disabled={!interactive}
|
|
180
|
+
disabled={!gradio.shared.interactive}
|
|
146
181
|
upload={upload_fn}
|
|
147
182
|
stream_handler={stream_handler_fn}
|
|
148
|
-
{max_plain_text_length}
|
|
149
|
-
{html_attributes}
|
|
183
|
+
max_plain_text_length={gradio.props.max_plain_text_length}
|
|
184
|
+
html_attributes={gradio.props.html_attributes}
|
|
150
185
|
/>
|
|
151
186
|
</Block>
|
package/dist/Index.svelte.d.ts
CHANGED
|
@@ -1,201 +1,5 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
export { default as BaseMultimodalTextbox } from "./shared/MultimodalTextbox.svelte";
|
|
3
2
|
export { default as BaseExample } from "./Example.svelte";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import type { InputHTMLAttributes } from "./shared/types";
|
|
8
|
-
declare const __propDef: {
|
|
9
|
-
props: {
|
|
10
|
-
gradio: Gradio<{
|
|
11
|
-
change: {
|
|
12
|
-
text: string;
|
|
13
|
-
files: FileData[];
|
|
14
|
-
};
|
|
15
|
-
submit: never;
|
|
16
|
-
stop: never;
|
|
17
|
-
blur: never;
|
|
18
|
-
select: SelectData;
|
|
19
|
-
input: never;
|
|
20
|
-
focus: never;
|
|
21
|
-
error: string;
|
|
22
|
-
clear_status: LoadingStatus;
|
|
23
|
-
start_recording: never;
|
|
24
|
-
pause_recording: never;
|
|
25
|
-
stop_recording: never;
|
|
26
|
-
upload: FileData[] | FileData;
|
|
27
|
-
clear: undefined;
|
|
28
|
-
}>;
|
|
29
|
-
elem_id?: string;
|
|
30
|
-
elem_classes?: string[];
|
|
31
|
-
visible?: boolean | "hidden";
|
|
32
|
-
value?: {
|
|
33
|
-
text: string;
|
|
34
|
-
files: FileData[];
|
|
35
|
-
};
|
|
36
|
-
file_types?: string[] | null;
|
|
37
|
-
lines: number;
|
|
38
|
-
placeholder?: string;
|
|
39
|
-
label?: string;
|
|
40
|
-
info?: string | undefined;
|
|
41
|
-
show_label: boolean;
|
|
42
|
-
max_lines: number;
|
|
43
|
-
scale?: number | null;
|
|
44
|
-
min_width?: number | undefined;
|
|
45
|
-
submit_btn?: string | boolean | null;
|
|
46
|
-
stop_btn?: string | boolean | null;
|
|
47
|
-
loading_status?: LoadingStatus | undefined;
|
|
48
|
-
value_is_output?: boolean;
|
|
49
|
-
rtl?: boolean;
|
|
50
|
-
text_align?: "left" | "right" | undefined;
|
|
51
|
-
autofocus?: boolean;
|
|
52
|
-
autoscroll?: boolean;
|
|
53
|
-
interactive: boolean;
|
|
54
|
-
root: string;
|
|
55
|
-
file_count: "single" | "multiple" | "directory";
|
|
56
|
-
max_plain_text_length: number;
|
|
57
|
-
sources?: ["microphone" | "upload"];
|
|
58
|
-
waveform_options?: any;
|
|
59
|
-
html_attributes?: InputHTMLAttributes | null;
|
|
60
|
-
};
|
|
61
|
-
events: {
|
|
62
|
-
[evt: string]: CustomEvent<any>;
|
|
63
|
-
};
|
|
64
|
-
slots: {};
|
|
65
|
-
exports?: {} | undefined;
|
|
66
|
-
bindings?: string | undefined;
|
|
67
|
-
};
|
|
68
|
-
export type IndexProps = typeof __propDef.props;
|
|
69
|
-
export type IndexEvents = typeof __propDef.events;
|
|
70
|
-
export type IndexSlots = typeof __propDef.slots;
|
|
71
|
-
export default class Index extends SvelteComponent<IndexProps, IndexEvents, IndexSlots> {
|
|
72
|
-
get gradio(): Gradio<{
|
|
73
|
-
change: {
|
|
74
|
-
text: string;
|
|
75
|
-
files: FileData[];
|
|
76
|
-
};
|
|
77
|
-
submit: never;
|
|
78
|
-
stop: never;
|
|
79
|
-
blur: never;
|
|
80
|
-
select: SelectData;
|
|
81
|
-
input: never;
|
|
82
|
-
focus: never;
|
|
83
|
-
error: string;
|
|
84
|
-
clear_status: LoadingStatus;
|
|
85
|
-
start_recording: never;
|
|
86
|
-
pause_recording: never;
|
|
87
|
-
stop_recording: never;
|
|
88
|
-
upload: FileData[] | FileData;
|
|
89
|
-
clear: undefined;
|
|
90
|
-
}>;
|
|
91
|
-
/**accessor*/
|
|
92
|
-
set gradio(_: Gradio<{
|
|
93
|
-
change: {
|
|
94
|
-
text: string;
|
|
95
|
-
files: FileData[];
|
|
96
|
-
};
|
|
97
|
-
submit: never;
|
|
98
|
-
stop: never;
|
|
99
|
-
blur: never;
|
|
100
|
-
select: SelectData;
|
|
101
|
-
input: never;
|
|
102
|
-
focus: never;
|
|
103
|
-
error: string;
|
|
104
|
-
clear_status: LoadingStatus;
|
|
105
|
-
start_recording: never;
|
|
106
|
-
pause_recording: never;
|
|
107
|
-
stop_recording: never;
|
|
108
|
-
upload: FileData[] | FileData;
|
|
109
|
-
clear: undefined;
|
|
110
|
-
}>);
|
|
111
|
-
get elem_id(): string | undefined;
|
|
112
|
-
/**accessor*/
|
|
113
|
-
set elem_id(_: string | undefined);
|
|
114
|
-
get elem_classes(): string[] | undefined;
|
|
115
|
-
/**accessor*/
|
|
116
|
-
set elem_classes(_: string[] | undefined);
|
|
117
|
-
get visible(): boolean | "hidden" | undefined;
|
|
118
|
-
/**accessor*/
|
|
119
|
-
set visible(_: boolean | "hidden" | undefined);
|
|
120
|
-
get value(): {
|
|
121
|
-
text: string;
|
|
122
|
-
files: FileData[];
|
|
123
|
-
} | undefined;
|
|
124
|
-
/**accessor*/
|
|
125
|
-
set value(_: {
|
|
126
|
-
text: string;
|
|
127
|
-
files: FileData[];
|
|
128
|
-
} | undefined);
|
|
129
|
-
get file_types(): string[] | null | undefined;
|
|
130
|
-
/**accessor*/
|
|
131
|
-
set file_types(_: string[] | null | undefined);
|
|
132
|
-
get lines(): number;
|
|
133
|
-
/**accessor*/
|
|
134
|
-
set lines(_: number);
|
|
135
|
-
get placeholder(): string | undefined;
|
|
136
|
-
/**accessor*/
|
|
137
|
-
set placeholder(_: string | undefined);
|
|
138
|
-
get label(): string | undefined;
|
|
139
|
-
/**accessor*/
|
|
140
|
-
set label(_: string | undefined);
|
|
141
|
-
get info(): string | undefined;
|
|
142
|
-
/**accessor*/
|
|
143
|
-
set info(_: string | undefined);
|
|
144
|
-
get show_label(): boolean;
|
|
145
|
-
/**accessor*/
|
|
146
|
-
set show_label(_: boolean);
|
|
147
|
-
get max_lines(): number;
|
|
148
|
-
/**accessor*/
|
|
149
|
-
set max_lines(_: number);
|
|
150
|
-
get scale(): number | null | undefined;
|
|
151
|
-
/**accessor*/
|
|
152
|
-
set scale(_: number | null | undefined);
|
|
153
|
-
get min_width(): number | undefined;
|
|
154
|
-
/**accessor*/
|
|
155
|
-
set min_width(_: number | undefined);
|
|
156
|
-
get submit_btn(): string | boolean | null | undefined;
|
|
157
|
-
/**accessor*/
|
|
158
|
-
set submit_btn(_: string | boolean | null | undefined);
|
|
159
|
-
get stop_btn(): string | boolean | null | undefined;
|
|
160
|
-
/**accessor*/
|
|
161
|
-
set stop_btn(_: string | boolean | null | undefined);
|
|
162
|
-
get loading_status(): LoadingStatus | undefined;
|
|
163
|
-
/**accessor*/
|
|
164
|
-
set loading_status(_: LoadingStatus | undefined);
|
|
165
|
-
get value_is_output(): boolean | undefined;
|
|
166
|
-
/**accessor*/
|
|
167
|
-
set value_is_output(_: boolean | undefined);
|
|
168
|
-
get rtl(): boolean | undefined;
|
|
169
|
-
/**accessor*/
|
|
170
|
-
set rtl(_: boolean | undefined);
|
|
171
|
-
get text_align(): "left" | "right" | undefined;
|
|
172
|
-
/**accessor*/
|
|
173
|
-
set text_align(_: "left" | "right" | undefined);
|
|
174
|
-
get autofocus(): boolean | undefined;
|
|
175
|
-
/**accessor*/
|
|
176
|
-
set autofocus(_: boolean | undefined);
|
|
177
|
-
get autoscroll(): boolean | undefined;
|
|
178
|
-
/**accessor*/
|
|
179
|
-
set autoscroll(_: boolean | undefined);
|
|
180
|
-
get interactive(): boolean;
|
|
181
|
-
/**accessor*/
|
|
182
|
-
set interactive(_: boolean);
|
|
183
|
-
get root(): string;
|
|
184
|
-
/**accessor*/
|
|
185
|
-
set root(_: string);
|
|
186
|
-
get file_count(): "multiple" | "single" | "directory";
|
|
187
|
-
/**accessor*/
|
|
188
|
-
set file_count(_: "multiple" | "single" | "directory");
|
|
189
|
-
get max_plain_text_length(): number;
|
|
190
|
-
/**accessor*/
|
|
191
|
-
set max_plain_text_length(_: number);
|
|
192
|
-
get sources(): ["upload" | "microphone"] | undefined;
|
|
193
|
-
/**accessor*/
|
|
194
|
-
set sources(_: ["upload" | "microphone"] | undefined);
|
|
195
|
-
get waveform_options(): any;
|
|
196
|
-
/**accessor*/
|
|
197
|
-
set waveform_options(_: any);
|
|
198
|
-
get html_attributes(): any;
|
|
199
|
-
/**accessor*/
|
|
200
|
-
set html_attributes(_: any);
|
|
201
|
-
}
|
|
3
|
+
declare const Index: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
4
|
+
type Index = ReturnType<typeof Index>;
|
|
5
|
+
export default Index;
|