@gradio/core 0.0.4 → 0.1.0-beta.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 +76 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/src/Blocks.svelte +129 -42
- package/dist/src/Blocks.svelte.d.ts +4 -0
- package/dist/src/MountComponents.svelte +12 -10
- package/dist/src/Render.svelte +14 -12
- package/dist/src/RenderComponent.svelte +2 -2
- package/dist/src/RenderComponent.svelte.d.ts +0 -2
- package/dist/src/api_docs/ApiDocs.svelte +4 -1
- package/dist/src/api_docs/CodeSnippet.svelte +7 -2
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +1 -0
- package/dist/src/css.js +2 -1
- package/dist/src/init.d.ts +4 -1
- package/dist/src/init.js +46 -6
- package/dist/src/lang/en.json +5 -3
- package/dist/src/lang/zh-CN.json +2 -1
- package/dist/src/stores.d.ts +2 -1
- package/dist/src/stores.js +1 -1
- package/dist/src/types.d.ts +5 -0
- package/index.ts +1 -0
- package/package.json +56 -56
- package/src/Blocks.svelte +202 -84
- package/src/MountComponents.svelte +12 -10
- package/src/Render.svelte +16 -13
- package/src/RenderComponent.svelte +2 -2
- package/src/api_docs/ApiDocs.svelte +4 -1
- package/src/api_docs/CodeSnippet.svelte +6 -2
- package/src/css.ts +1 -0
- package/src/init.ts +62 -10
- package/src/lang/en.json +5 -3
- package/src/lang/zh-CN.json +2 -1
- package/src/stores.ts +5 -2
- package/src/types.ts +5 -0
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
export let theme_mode: ThemeMode;
|
|
14
14
|
export let instance: ComponentMeta["instance"];
|
|
15
15
|
export let value: any;
|
|
16
|
-
export let gradio: Gradio;
|
|
16
|
+
// export let gradio: Gradio;
|
|
17
17
|
export let elem_id: string;
|
|
18
18
|
export let elem_classes: string[];
|
|
19
19
|
export let _id: number;
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
function report(props: string) {
|
|
34
34
|
return function (propargs: any) {
|
|
35
|
+
if (!target) return;
|
|
35
36
|
const ev = s(_id, props, propargs);
|
|
36
37
|
target.dispatchEvent(ev);
|
|
37
38
|
};
|
|
@@ -61,7 +62,6 @@
|
|
|
61
62
|
{...$$restProps}
|
|
62
63
|
{theme_mode}
|
|
63
64
|
{root}
|
|
64
|
-
{gradio}
|
|
65
65
|
>
|
|
66
66
|
<slot />
|
|
67
67
|
</svelte:component>
|
|
@@ -59,7 +59,9 @@
|
|
|
59
59
|
named_endpoints: any;
|
|
60
60
|
unnamed_endpoints: any;
|
|
61
61
|
}> {
|
|
62
|
-
let response = await fetch(
|
|
62
|
+
let response = await fetch(
|
|
63
|
+
root.replace(/\/$/, "") + app.api_prefix + "/info"
|
|
64
|
+
);
|
|
63
65
|
let data = await response.json();
|
|
64
66
|
return data;
|
|
65
67
|
}
|
|
@@ -235,6 +237,7 @@
|
|
|
235
237
|
{root}
|
|
236
238
|
{space_id}
|
|
237
239
|
{username}
|
|
240
|
+
api_prefix={app.api_prefix}
|
|
238
241
|
/>
|
|
239
242
|
|
|
240
243
|
<ParametersSnippet
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
export let dependency: Dependency;
|
|
18
18
|
export let dependency_index: number;
|
|
19
19
|
export let root: string;
|
|
20
|
+
export let api_prefix: string;
|
|
20
21
|
export let space_id: string | null;
|
|
21
22
|
export let endpoint_parameters: any;
|
|
22
23
|
export let named: boolean;
|
|
@@ -35,6 +36,9 @@
|
|
|
35
36
|
let blob_examples: any[] = endpoint_parameters.filter(
|
|
36
37
|
(param: EndpointParameter) => blob_components.includes(param.component)
|
|
37
38
|
);
|
|
39
|
+
|
|
40
|
+
$: normalised_api_prefix = api_prefix ? api_prefix : "/";
|
|
41
|
+
$: normalised_root = root.replace(/\/$/, "");
|
|
38
42
|
</script>
|
|
39
43
|
|
|
40
44
|
<div class="container">
|
|
@@ -135,7 +139,7 @@ console.log(result.data);
|
|
|
135
139
|
</div>
|
|
136
140
|
|
|
137
141
|
<div bind:this={bash_post_code}>
|
|
138
|
-
<pre>curl -X POST {
|
|
142
|
+
<pre>curl -X POST {normalised_root}{normalised_api_prefix}/call/{dependency.api_name} -s -H "Content-Type: application/json" -d '{"{"}
|
|
139
143
|
"data": [{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}
|
|
140
144
|
<!--
|
|
141
145
|
-->{represent_value(
|
|
@@ -147,7 +151,7 @@ console.log(result.data);
|
|
|
147
151
|
{/each}
|
|
148
152
|
]{"}"}' \
|
|
149
153
|
| awk -F'"' '{"{"} print $4{"}"}' \
|
|
150
|
-
| read EVENT_ID; curl -N {
|
|
154
|
+
| read EVENT_ID; curl -N {normalised_root}{normalised_api_prefix}/call/{dependency.api_name}/$EVENT_ID</pre>
|
|
151
155
|
</div>
|
|
152
156
|
</code>
|
|
153
157
|
</Block>
|
package/src/css.ts
CHANGED
package/src/init.ts
CHANGED
|
@@ -18,6 +18,10 @@ export interface UpdateTransaction {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
let pending_updates: UpdateTransaction[][] = [];
|
|
21
|
+
const is_browser = typeof window !== "undefined";
|
|
22
|
+
const raf = is_browser
|
|
23
|
+
? requestAnimationFrame
|
|
24
|
+
: async (fn: () => Promise<void> | void) => await fn();
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* Create a store with the layout and a map of targets
|
|
@@ -28,6 +32,9 @@ export function create_components(): {
|
|
|
28
32
|
targets: Writable<TargetMap>;
|
|
29
33
|
update_value: (updates: UpdateTransaction[]) => void;
|
|
30
34
|
get_data: (id: number) => any | Promise<any>;
|
|
35
|
+
modify_stream: (id: number, state: "open" | "waiting" | "closed") => void;
|
|
36
|
+
get_stream_state: (id: number) => "open" | "waiting" | "closed" | "not_set";
|
|
37
|
+
set_time_limit: (id: number, time_limit: number | undefined) => void;
|
|
31
38
|
loading_status: ReturnType<typeof create_loading_status_store>;
|
|
32
39
|
scheduled_updates: Writable<boolean>;
|
|
33
40
|
create_layout: (args: {
|
|
@@ -39,7 +46,7 @@ export function create_components(): {
|
|
|
39
46
|
options: {
|
|
40
47
|
fill_height: boolean;
|
|
41
48
|
};
|
|
42
|
-
}) => void
|
|
49
|
+
}) => Promise<void>;
|
|
43
50
|
rerender_layout: (args: {
|
|
44
51
|
render_id: number;
|
|
45
52
|
components: ComponentMeta[];
|
|
@@ -64,7 +71,20 @@ export function create_components(): {
|
|
|
64
71
|
let keyed_component_values: Record<string | number, any> = {};
|
|
65
72
|
let _rootNode: ComponentMeta;
|
|
66
73
|
|
|
67
|
-
function
|
|
74
|
+
function set_event_specific_args(dependencies: Dependency[]): void {
|
|
75
|
+
dependencies.forEach((dep) => {
|
|
76
|
+
dep.targets.forEach((target) => {
|
|
77
|
+
const instance = instance_map[target[0]];
|
|
78
|
+
if (instance && dep.event_specific_args?.length > 0) {
|
|
79
|
+
dep.event_specific_args?.forEach((arg: string) => {
|
|
80
|
+
instance.props[arg] = dep[arg as keyof Dependency];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function create_layout({
|
|
68
88
|
app: _app,
|
|
69
89
|
components,
|
|
70
90
|
layout,
|
|
@@ -80,7 +100,9 @@ export function create_components(): {
|
|
|
80
100
|
options: {
|
|
81
101
|
fill_height: boolean;
|
|
82
102
|
};
|
|
83
|
-
}): void {
|
|
103
|
+
}): Promise<void> {
|
|
104
|
+
// make sure the state is settled before proceeding
|
|
105
|
+
flush();
|
|
84
106
|
app = _app;
|
|
85
107
|
store_keyed_values(_components);
|
|
86
108
|
|
|
@@ -130,9 +152,10 @@ export function create_components(): {
|
|
|
130
152
|
{} as { [id: number]: ComponentMeta }
|
|
131
153
|
);
|
|
132
154
|
|
|
133
|
-
walk_layout(layout, root)
|
|
134
|
-
|
|
135
|
-
|
|
155
|
+
await walk_layout(layout, root);
|
|
156
|
+
|
|
157
|
+
layout_store.set(_rootNode);
|
|
158
|
+
set_event_specific_args(dependencies);
|
|
136
159
|
}
|
|
137
160
|
|
|
138
161
|
/**
|
|
@@ -208,6 +231,8 @@ export function create_components(): {
|
|
|
208
231
|
walk_layout(layout, root, current_element.parent).then(() => {
|
|
209
232
|
layout_store.set(_rootNode);
|
|
210
233
|
});
|
|
234
|
+
|
|
235
|
+
set_event_specific_args(dependencies);
|
|
211
236
|
}
|
|
212
237
|
|
|
213
238
|
async function walk_layout(
|
|
@@ -301,7 +326,6 @@ export function create_components(): {
|
|
|
301
326
|
}
|
|
302
327
|
return layout;
|
|
303
328
|
});
|
|
304
|
-
|
|
305
329
|
pending_updates = [];
|
|
306
330
|
update_scheduled = false;
|
|
307
331
|
update_scheduled_store.set(false);
|
|
@@ -314,7 +338,7 @@ export function create_components(): {
|
|
|
314
338
|
if (!update_scheduled) {
|
|
315
339
|
update_scheduled = true;
|
|
316
340
|
update_scheduled_store.set(true);
|
|
317
|
-
|
|
341
|
+
raf(flush);
|
|
318
342
|
}
|
|
319
343
|
}
|
|
320
344
|
|
|
@@ -329,15 +353,43 @@ export function create_components(): {
|
|
|
329
353
|
return comp.props.value;
|
|
330
354
|
}
|
|
331
355
|
|
|
356
|
+
function modify_stream(
|
|
357
|
+
id: number,
|
|
358
|
+
state: "open" | "closed" | "waiting"
|
|
359
|
+
): void {
|
|
360
|
+
const comp = _component_map.get(id);
|
|
361
|
+
if (comp && comp.instance.modify_stream_state) {
|
|
362
|
+
comp.instance.modify_stream_state(state);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function get_stream_state(
|
|
367
|
+
id: number
|
|
368
|
+
): "open" | "closed" | "waiting" | "not_set" {
|
|
369
|
+
const comp = _component_map.get(id);
|
|
370
|
+
if (comp && comp.instance.get_stream_state)
|
|
371
|
+
return comp.instance.get_stream_state();
|
|
372
|
+
return "not_set";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function set_time_limit(id: number, time_limit: number | undefined): void {
|
|
376
|
+
const comp = _component_map.get(id);
|
|
377
|
+
if (comp && comp.instance.set_time_limit) {
|
|
378
|
+
comp.instance.set_time_limit(time_limit);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
332
382
|
return {
|
|
333
383
|
layout: layout_store,
|
|
334
384
|
targets: target_map,
|
|
335
385
|
update_value,
|
|
336
386
|
get_data,
|
|
387
|
+
modify_stream,
|
|
388
|
+
get_stream_state,
|
|
389
|
+
set_time_limit,
|
|
337
390
|
loading_status,
|
|
338
391
|
scheduled_updates: update_scheduled_store,
|
|
339
|
-
create_layout:
|
|
340
|
-
requestAnimationFrame(() => create_layout(...args)),
|
|
392
|
+
create_layout: create_layout,
|
|
341
393
|
rerender_layout
|
|
342
394
|
};
|
|
343
395
|
}
|
package/src/lang/en.json
CHANGED
|
@@ -16,12 +16,14 @@
|
|
|
16
16
|
"record": "Record",
|
|
17
17
|
"no_microphone": "No microphone found",
|
|
18
18
|
"pause": "Pause",
|
|
19
|
-
"play": "Play"
|
|
19
|
+
"play": "Play",
|
|
20
|
+
"waiting": "Waiting"
|
|
20
21
|
},
|
|
21
22
|
"blocks": {
|
|
22
23
|
"connection_can_break": "On mobile, the connection can break if this tab is unfocused or the device sleeps, losing your position in queue.",
|
|
23
24
|
"long_requests_queue": "There is a long queue of requests pending. Duplicate this Space to skip.",
|
|
24
|
-
"lost_connection": "Lost connection due to leaving page. Rejoining queue..."
|
|
25
|
+
"lost_connection": "Lost connection due to leaving page. Rejoining queue...",
|
|
26
|
+
"waiting_for_inputs": "Waiting for file(s) to finish uploading, please retry."
|
|
25
27
|
},
|
|
26
28
|
"checkbox": {
|
|
27
29
|
"checkbox": "Checkbox",
|
|
@@ -112,7 +114,7 @@
|
|
|
112
114
|
"drop_file": "Drop File Here",
|
|
113
115
|
"drop_image": "Drop Image Here",
|
|
114
116
|
"drop_video": "Drop Video Here",
|
|
115
|
-
"drop_gallery": "Drop
|
|
117
|
+
"drop_gallery": "Drop Media Here",
|
|
116
118
|
"paste_clipboard": "Paste from Clipboard"
|
|
117
119
|
}
|
|
118
120
|
}
|
package/src/lang/zh-CN.json
CHANGED
package/src/stores.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Writable, writable, get } from "svelte/store";
|
|
|
2
2
|
|
|
3
3
|
export interface LoadingStatus {
|
|
4
4
|
eta: number | null;
|
|
5
|
-
status: "pending" | "error" | "complete" | "generating";
|
|
5
|
+
status: "pending" | "error" | "complete" | "generating" | "streaming";
|
|
6
6
|
queue: boolean;
|
|
7
7
|
queue_position: number | null;
|
|
8
8
|
queue_size?: number;
|
|
@@ -10,6 +10,7 @@ export interface LoadingStatus {
|
|
|
10
10
|
message?: string | null;
|
|
11
11
|
scroll_to_output?: boolean;
|
|
12
12
|
show_progress?: "full" | "minimal" | "hidden";
|
|
13
|
+
time_limit?: number | null | undefined;
|
|
13
14
|
progress?: {
|
|
14
15
|
progress: number | null;
|
|
15
16
|
index: number | null;
|
|
@@ -48,7 +49,8 @@ export function create_loading_status_store(): LoadingStatusStore {
|
|
|
48
49
|
position = null,
|
|
49
50
|
eta = null,
|
|
50
51
|
message = null,
|
|
51
|
-
progress
|
|
52
|
+
progress,
|
|
53
|
+
time_limit = null
|
|
52
54
|
}: {
|
|
53
55
|
fn_index: LoadingStatus["fn_index"];
|
|
54
56
|
status: LoadingStatus["status"];
|
|
@@ -58,6 +60,7 @@ export function create_loading_status_store(): LoadingStatusStore {
|
|
|
58
60
|
eta?: LoadingStatus["eta"];
|
|
59
61
|
message?: LoadingStatus["message"];
|
|
60
62
|
progress?: LoadingStatus["progress"];
|
|
63
|
+
time_limit?: LoadingStatus["time_limit"];
|
|
61
64
|
}): void {
|
|
62
65
|
const outputs = fn_outputs[fn_index];
|
|
63
66
|
const inputs = fn_inputs[fn_index];
|
package/src/types.ts
CHANGED
|
@@ -69,6 +69,11 @@ export interface Dependency {
|
|
|
69
69
|
final_event: Payload | null;
|
|
70
70
|
show_api: boolean;
|
|
71
71
|
rendered_in: number | null;
|
|
72
|
+
connection: "stream" | "sse";
|
|
73
|
+
time_limit: number;
|
|
74
|
+
stream_every: number;
|
|
75
|
+
like_user_message: boolean;
|
|
76
|
+
event_specific_args: string[];
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
interface TypeDescription {
|