@gradio/core 0.11.1 → 0.12.0
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 +17 -0
- package/dist/src/Blocks.svelte +17 -1
- package/dist/src/init.d.ts +1 -1
- package/dist/src/init.js +1 -1
- package/dist/src/types.d.ts +2 -0
- package/package.json +32 -32
- package/src/Blocks.svelte +19 -1
- package/src/init.ts +2 -2
- package/src/types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @gradio/core
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#10500](https://github.com/gradio-app/gradio/pull/10500) [`16d419b`](https://github.com/gradio-app/gradio/commit/16d419b9f1f18ae4507d18a4739eb83ac4f3fae9) - Allow functions that solely update component properties to run in the frontend by setting `js=True`. Thanks @abidlabs!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/upload@0.15.3
|
|
12
|
+
- @gradio/video@0.14.3
|
|
13
|
+
- @gradio/code@0.11.1
|
|
14
|
+
- @gradio/client@1.13.0
|
|
15
|
+
- @gradio/button@0.4.8
|
|
16
|
+
- @gradio/image@0.21.3
|
|
17
|
+
- @gradio/gallery@0.15.8
|
|
18
|
+
- @gradio/file@0.12.8
|
|
19
|
+
|
|
3
20
|
## 0.11.1
|
|
4
21
|
|
|
5
22
|
### Features
|
package/dist/src/Blocks.svelte
CHANGED
|
@@ -212,7 +212,7 @@ async function trigger_api_call(dep_index, trigger_id = null, event_data = null)
|
|
|
212
212
|
event_data: dep.collects_event_data ? event_data : null,
|
|
213
213
|
trigger_id
|
|
214
214
|
};
|
|
215
|
-
if (dep.frontend_fn) {
|
|
215
|
+
if (dep.frontend_fn && typeof dep.frontend_fn !== "boolean") {
|
|
216
216
|
dep.frontend_fn(
|
|
217
217
|
payload.data.concat(
|
|
218
218
|
await Promise.all(dep.outputs.map((id) => get_data(id)))
|
|
@@ -235,6 +235,19 @@ async function trigger_api_call(dep_index, trigger_id = null, event_data = null)
|
|
|
235
235
|
);
|
|
236
236
|
} else {
|
|
237
237
|
if (dep.backend_fn) {
|
|
238
|
+
if (dep.js_implementation) {
|
|
239
|
+
let js_fn = new AsyncFunction(
|
|
240
|
+
`let result = await (${dep.js_implementation})(...arguments);
|
|
241
|
+
return (!Array.isArray(result)) ? [result] : result;`
|
|
242
|
+
);
|
|
243
|
+
js_fn(...payload.data).then((js_result) => {
|
|
244
|
+
handle_update(js_result, dep_index);
|
|
245
|
+
payload.js_implementation = true;
|
|
246
|
+
}).catch((error) => {
|
|
247
|
+
console.error(error);
|
|
248
|
+
payload.js_implementation = false;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
238
251
|
trigger_prediction(dep, payload);
|
|
239
252
|
}
|
|
240
253
|
}
|
|
@@ -299,6 +312,9 @@ async function trigger_api_call(dep_index, trigger_id = null, event_data = null)
|
|
|
299
312
|
}
|
|
300
313
|
submit_map.set(dep_index, submission);
|
|
301
314
|
for await (const message of submission) {
|
|
315
|
+
if (payload2.js_implementation) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
302
318
|
if (message.type === "data") {
|
|
303
319
|
handle_data(message);
|
|
304
320
|
} else if (message.type === "render") {
|
package/dist/src/init.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare const AsyncFunction: new (...args: string[]) => (...args: any[])
|
|
|
45
45
|
* @param output_length the number of outputs
|
|
46
46
|
* @returns The function, or null if the source code is invalid or missing
|
|
47
47
|
*/
|
|
48
|
-
export declare function process_frontend_fn(source: string | null | undefined |
|
|
48
|
+
export declare function process_frontend_fn(source: string | null | undefined | boolean, backend_fn: boolean, input_length: number, output_length: number): ((...args: unknown[]) => Promise<unknown[]>) | null;
|
|
49
49
|
/**
|
|
50
50
|
* `Dependency.targets` is an array of `[id, trigger]` pairs with the ids as the `fn_id`.
|
|
51
51
|
* This function take a single list of `Dependency.targets` and add those to the target_map.
|
package/dist/src/init.js
CHANGED
|
@@ -298,7 +298,7 @@ export const AsyncFunction = Object.getPrototypeOf(async function () { }).constr
|
|
|
298
298
|
* @returns The function, or null if the source code is invalid or missing
|
|
299
299
|
*/
|
|
300
300
|
export function process_frontend_fn(source, backend_fn, input_length, output_length) {
|
|
301
|
-
if (!source)
|
|
301
|
+
if (!source || source === true)
|
|
302
302
|
return null;
|
|
303
303
|
const wrap = backend_fn ? input_length === 1 : output_length === 1;
|
|
304
304
|
try {
|
package/dist/src/types.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export interface Payload {
|
|
|
39
39
|
data: unknown[];
|
|
40
40
|
event_data?: unknown | null;
|
|
41
41
|
trigger_id?: number | null;
|
|
42
|
+
js_implementation?: boolean | null;
|
|
42
43
|
}
|
|
43
44
|
/** A dependency as received from the backend */
|
|
44
45
|
export interface Dependency {
|
|
@@ -70,6 +71,7 @@ export interface Dependency {
|
|
|
70
71
|
stream_every: number;
|
|
71
72
|
like_user_message: boolean;
|
|
72
73
|
event_specific_args: string[];
|
|
74
|
+
js_implementation: string | null;
|
|
73
75
|
}
|
|
74
76
|
interface TypeDescription {
|
|
75
77
|
input_payload?: string;
|
package/package.json
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@gradio/accordion": "^0.5.8",
|
|
7
|
-
"@gradio/annotatedimage": "^0.9.8",
|
|
8
7
|
"@gradio/atoms": "^0.13.3",
|
|
8
|
+
"@gradio/audio": "^0.17.3",
|
|
9
9
|
"@gradio/box": "^0.2.12",
|
|
10
|
+
"@gradio/annotatedimage": "^0.9.9",
|
|
11
|
+
"@gradio/button": "^0.4.8",
|
|
12
|
+
"@gradio/chatbot": "^0.24.2",
|
|
10
13
|
"@gradio/checkbox": "^0.4.14",
|
|
11
|
-
"@gradio/button": "^0.4.7",
|
|
12
|
-
"@gradio/chatbot": "^0.24.1",
|
|
13
|
-
"@gradio/audio": "^0.17.2",
|
|
14
14
|
"@gradio/checkboxgroup": "^0.6.14",
|
|
15
|
-
"@gradio/client": "^1.
|
|
15
|
+
"@gradio/client": "^1.13.0",
|
|
16
|
+
"@gradio/code": "^0.11.1",
|
|
16
17
|
"@gradio/colorpicker": "^0.4.14",
|
|
17
|
-
"@gradio/
|
|
18
|
-
"@gradio/column": "^0.2.0",
|
|
19
|
-
"@gradio/dataframe": "^0.16.3",
|
|
20
|
-
"@gradio/dataset": "^0.4.7",
|
|
21
|
-
"@gradio/downloadbutton": "^0.3.7",
|
|
22
|
-
"@gradio/dropdown": "^0.9.13",
|
|
18
|
+
"@gradio/dataset": "^0.4.8",
|
|
23
19
|
"@gradio/datetime": "^0.3.6",
|
|
20
|
+
"@gradio/column": "^0.2.0",
|
|
21
|
+
"@gradio/downloadbutton": "^0.3.8",
|
|
22
|
+
"@gradio/dataframe": "^0.16.4",
|
|
24
23
|
"@gradio/fallback": "^0.4.14",
|
|
25
|
-
"@gradio/
|
|
26
|
-
"@gradio/
|
|
24
|
+
"@gradio/file": "^0.12.8",
|
|
25
|
+
"@gradio/dropdown": "^0.9.13",
|
|
27
26
|
"@gradio/form": "^0.2.12",
|
|
27
|
+
"@gradio/fileexplorer": "^0.5.19",
|
|
28
|
+
"@gradio/gallery": "^0.15.8",
|
|
28
29
|
"@gradio/group": "^0.2.0",
|
|
29
|
-
"@gradio/gallery": "^0.15.7",
|
|
30
|
-
"@gradio/highlightedtext": "^0.8.14",
|
|
31
30
|
"@gradio/html": "^0.6.5",
|
|
32
|
-
"@gradio/image": "^0.21.2",
|
|
33
|
-
"@gradio/imageeditor": "^0.12.9",
|
|
34
31
|
"@gradio/icons": "^0.10.0",
|
|
35
|
-
"@gradio/
|
|
32
|
+
"@gradio/highlightedtext": "^0.8.14",
|
|
33
|
+
"@gradio/imageeditor": "^0.12.10",
|
|
34
|
+
"@gradio/image": "^0.21.3",
|
|
36
35
|
"@gradio/json": "^0.5.14",
|
|
36
|
+
"@gradio/label": "^0.5.6",
|
|
37
37
|
"@gradio/browserstate": "^0.3.1",
|
|
38
38
|
"@gradio/markdown": "^0.13.4",
|
|
39
|
-
"@gradio/
|
|
39
|
+
"@gradio/multimodaltextbox": "^0.9.9",
|
|
40
|
+
"@gradio/model3d": "^0.14.3",
|
|
40
41
|
"@gradio/nativeplot": "^0.5.8",
|
|
41
|
-
"@gradio/number": "^0.5.14",
|
|
42
|
-
"@gradio/multimodaltextbox": "^0.9.8",
|
|
43
42
|
"@gradio/paramviewer": "^0.7.2",
|
|
44
43
|
"@gradio/plot": "^0.9.9",
|
|
44
|
+
"@gradio/number": "^0.5.14",
|
|
45
45
|
"@gradio/radio": "^0.6.14",
|
|
46
|
-
"@gradio/row": "^0.2.1",
|
|
47
|
-
"@gradio/sidebar": "^0.1.5",
|
|
48
46
|
"@gradio/simpledropdown": "^0.3.14",
|
|
49
|
-
"@gradio/
|
|
47
|
+
"@gradio/row": "^0.2.1",
|
|
48
|
+
"@gradio/simpleimage": "^0.8.19",
|
|
50
49
|
"@gradio/simpletextbox": "^0.3.14",
|
|
51
|
-
"@gradio/
|
|
50
|
+
"@gradio/sidebar": "^0.1.5",
|
|
52
51
|
"@gradio/sketchbox": "^0.6.0",
|
|
53
|
-
"@gradio/
|
|
52
|
+
"@gradio/slider": "^0.6.2",
|
|
54
53
|
"@gradio/state": "^0.1.2",
|
|
54
|
+
"@gradio/statustracker": "^0.10.4",
|
|
55
55
|
"@gradio/tabitem": "^0.4.2",
|
|
56
56
|
"@gradio/tabs": "^0.4.2",
|
|
57
|
-
"@gradio/textbox": "^0.10.4",
|
|
58
57
|
"@gradio/theme": "^0.4.0",
|
|
59
|
-
"@gradio/upload": "^0.15.2",
|
|
60
58
|
"@gradio/timer": "^0.4.4",
|
|
61
|
-
"@gradio/
|
|
62
|
-
"@gradio/
|
|
59
|
+
"@gradio/upload": "^0.15.3",
|
|
60
|
+
"@gradio/textbox": "^0.10.4",
|
|
61
|
+
"@gradio/uploadbutton": "^0.8.8",
|
|
63
62
|
"@gradio/utils": "^0.10.1",
|
|
64
|
-
"@gradio/video": "^0.14.
|
|
63
|
+
"@gradio/video": "^0.14.3",
|
|
64
|
+
"@gradio/wasm": "^0.17.3"
|
|
65
65
|
},
|
|
66
66
|
"msw": {
|
|
67
67
|
"workerDirectory": "public"
|
package/src/Blocks.svelte
CHANGED
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
trigger_id: trigger_id
|
|
290
290
|
};
|
|
291
291
|
|
|
292
|
-
if (dep.frontend_fn) {
|
|
292
|
+
if (dep.frontend_fn && typeof dep.frontend_fn !== "boolean") {
|
|
293
293
|
dep
|
|
294
294
|
.frontend_fn(
|
|
295
295
|
payload.data.concat(
|
|
@@ -314,6 +314,21 @@
|
|
|
314
314
|
);
|
|
315
315
|
} else {
|
|
316
316
|
if (dep.backend_fn) {
|
|
317
|
+
if (dep.js_implementation) {
|
|
318
|
+
let js_fn = new AsyncFunction(
|
|
319
|
+
`let result = await (${dep.js_implementation})(...arguments);
|
|
320
|
+
return (!Array.isArray(result)) ? [result] : result;`
|
|
321
|
+
);
|
|
322
|
+
js_fn(...payload.data)
|
|
323
|
+
.then((js_result) => {
|
|
324
|
+
handle_update(js_result, dep_index);
|
|
325
|
+
payload.js_implementation = true;
|
|
326
|
+
})
|
|
327
|
+
.catch((error) => {
|
|
328
|
+
console.error(error);
|
|
329
|
+
payload.js_implementation = false;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
317
332
|
trigger_prediction(dep, payload);
|
|
318
333
|
}
|
|
319
334
|
}
|
|
@@ -391,6 +406,9 @@
|
|
|
391
406
|
submit_map.set(dep_index, submission);
|
|
392
407
|
|
|
393
408
|
for await (const message of submission) {
|
|
409
|
+
if (payload.js_implementation) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
394
412
|
if (message.type === "data") {
|
|
395
413
|
handle_data(message);
|
|
396
414
|
} else if (message.type === "render") {
|
package/src/init.ts
CHANGED
|
@@ -478,12 +478,12 @@ export const AsyncFunction: new (
|
|
|
478
478
|
* @returns The function, or null if the source code is invalid or missing
|
|
479
479
|
*/
|
|
480
480
|
export function process_frontend_fn(
|
|
481
|
-
source: string | null | undefined |
|
|
481
|
+
source: string | null | undefined | boolean,
|
|
482
482
|
backend_fn: boolean,
|
|
483
483
|
input_length: number,
|
|
484
484
|
output_length: number
|
|
485
485
|
): ((...args: unknown[]) => Promise<unknown[]>) | null {
|
|
486
|
-
if (!source) return null;
|
|
486
|
+
if (!source || source === true) return null;
|
|
487
487
|
|
|
488
488
|
const wrap = backend_fn ? input_length === 1 : output_length === 1;
|
|
489
489
|
try {
|
package/src/types.ts
CHANGED
|
@@ -43,6 +43,7 @@ export interface Payload {
|
|
|
43
43
|
data: unknown[];
|
|
44
44
|
event_data?: unknown | null;
|
|
45
45
|
trigger_id?: number | null;
|
|
46
|
+
js_implementation?: boolean | null;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/** A dependency as received from the backend */
|
|
@@ -75,6 +76,7 @@ export interface Dependency {
|
|
|
75
76
|
stream_every: number;
|
|
76
77
|
like_user_message: boolean;
|
|
77
78
|
event_specific_args: string[];
|
|
79
|
+
js_implementation: string | null;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
interface TypeDescription {
|