@gradio/core 1.0.0-dev.3 → 1.0.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 +31 -0
- package/dist/src/Blocks.svelte +19 -3
- package/dist/src/Blocks.svelte.d.ts +2 -1
- package/dist/src/api_docs/ApiDocs.svelte +19 -2
- package/dist/src/api_docs/ApiDocs.svelte.d.ts +1 -0
- package/dist/src/api_docs/ApiRecorder.svelte +0 -3
- package/dist/src/api_docs/CodeSnippet.svelte +63 -19
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +2 -1
- package/dist/src/api_docs/EndpointDetail.svelte +73 -17
- package/dist/src/api_docs/EndpointDetail.svelte.d.ts +3 -0
- package/dist/src/api_docs/MCPSnippet.svelte +21 -28
- package/dist/src/api_docs/MCPSnippet.svelte.d.ts +1 -0
- package/dist/src/api_docs/PercentileChart.svelte +125 -0
- package/dist/src/api_docs/PercentileChart.svelte.d.ts +22 -0
- package/dist/src/dependency.d.ts +4 -1
- package/dist/src/dependency.js +33 -18
- package/dist/src/types.d.ts +1 -0
- package/package.json +60 -61
- package/src/Blocks.svelte +19 -3
- package/src/api_docs/ApiDocs.svelte +19 -2
- package/src/api_docs/ApiRecorder.svelte +0 -3
- package/src/api_docs/CodeSnippet.svelte +63 -19
- package/src/api_docs/EndpointDetail.svelte +73 -17
- package/src/api_docs/MCPSnippet.svelte +21 -28
- package/src/api_docs/PercentileChart.svelte +125 -0
- package/src/dependency.ts +78 -49
- package/src/types.ts +1 -0
package/src/dependency.ts
CHANGED
|
@@ -36,6 +36,8 @@ export class Dependency {
|
|
|
36
36
|
// in the case of chained events, it would be the id of the initial trigger
|
|
37
37
|
original_trigger_id: number | null = null;
|
|
38
38
|
show_progress_on: number[] | null = null;
|
|
39
|
+
component_prop_inputs: number[] = [];
|
|
40
|
+
show_progress: "full" | "minimal" | "hidden";
|
|
39
41
|
|
|
40
42
|
functions: {
|
|
41
43
|
frontend?: (...args: unknown[]) => Promise<unknown[]>;
|
|
@@ -49,6 +51,7 @@ export class Dependency {
|
|
|
49
51
|
this.inputs = dep_config.inputs;
|
|
50
52
|
this.outputs = dep_config.outputs;
|
|
51
53
|
this.connection_type = dep_config.connection;
|
|
54
|
+
this.show_progress = dep_config.show_progress;
|
|
52
55
|
this.functions = {
|
|
53
56
|
frontend: dep_config.js
|
|
54
57
|
? process_frontend_fn(
|
|
@@ -70,6 +73,7 @@ export class Dependency {
|
|
|
70
73
|
this.cancels = dep_config.cancels;
|
|
71
74
|
this.trigger_modes = dep_config.trigger_mode;
|
|
72
75
|
this.show_progress_on = dep_config.show_progress_on || null;
|
|
76
|
+
this.component_prop_inputs = dep_config.component_prop_inputs || [];
|
|
73
77
|
|
|
74
78
|
for (let i = 0; i < dep_config.event_specific_args?.length || 0; i++) {
|
|
75
79
|
const key = dep_config.event_specific_args[i];
|
|
@@ -205,12 +209,17 @@ export class DependencyManager {
|
|
|
205
209
|
add_to_api_calls: (payload: Payload) => void
|
|
206
210
|
) {
|
|
207
211
|
this.add_to_api_calls = add_to_api_calls;
|
|
208
|
-
this.client = client;
|
|
209
212
|
this.log_cb = log_cb;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.reload(
|
|
213
|
+
this.update_state_cb = update_state_cb;
|
|
214
|
+
this.get_state_cb = get_state_cb;
|
|
215
|
+
this.rerender_cb = rerender_cb;
|
|
216
|
+
this.reload(
|
|
217
|
+
dependencies,
|
|
218
|
+
update_state_cb,
|
|
219
|
+
get_state_cb,
|
|
220
|
+
rerender_cb,
|
|
221
|
+
client
|
|
222
|
+
);
|
|
214
223
|
}
|
|
215
224
|
|
|
216
225
|
reload(
|
|
@@ -223,15 +232,15 @@ export class DependencyManager {
|
|
|
223
232
|
const { by_id, by_event } = this.create(dependencies);
|
|
224
233
|
this.dependencies_by_event = by_event;
|
|
225
234
|
this.dependencies_by_fn = by_id;
|
|
235
|
+
this.client = client;
|
|
236
|
+
this.update_state_cb = update_state;
|
|
237
|
+
this.get_state_cb = get_state;
|
|
238
|
+
this.rerender_cb = rerender;
|
|
226
239
|
for (const [dep_id, dep] of this.dependencies_by_fn) {
|
|
227
240
|
for (const [output_id] of dep.targets) {
|
|
228
241
|
this.set_event_args(output_id, dep.event_args);
|
|
229
242
|
}
|
|
230
243
|
}
|
|
231
|
-
this.client = client;
|
|
232
|
-
this.update_state_cb = update_state;
|
|
233
|
-
this.get_state_cb = get_state;
|
|
234
|
-
this.rerender_cb = rerender;
|
|
235
244
|
this.register_loading_stati(by_id);
|
|
236
245
|
}
|
|
237
246
|
register_loading_stati(deps: Map<number, Dependency>): void {
|
|
@@ -239,7 +248,8 @@ export class DependencyManager {
|
|
|
239
248
|
this.loading_stati.register(
|
|
240
249
|
dep.id,
|
|
241
250
|
dep.show_progress_on || dep.outputs,
|
|
242
|
-
dep.inputs
|
|
251
|
+
dep.inputs,
|
|
252
|
+
dep.show_progress
|
|
243
253
|
);
|
|
244
254
|
}
|
|
245
255
|
}
|
|
@@ -324,7 +334,10 @@ export class DependencyManager {
|
|
|
324
334
|
this.update_loading_stati_state();
|
|
325
335
|
}
|
|
326
336
|
|
|
327
|
-
const data_payload = await this.gather_state(
|
|
337
|
+
const data_payload = await this.gather_state(
|
|
338
|
+
dep.inputs,
|
|
339
|
+
dep.component_prop_inputs
|
|
340
|
+
);
|
|
328
341
|
const unset_args = await Promise.all(
|
|
329
342
|
dep.targets.map(([output_id]) =>
|
|
330
343
|
this.set_event_args(output_id, dep.event_args)
|
|
@@ -375,7 +388,7 @@ export class DependencyManager {
|
|
|
375
388
|
if (dep_submission.type === "void") {
|
|
376
389
|
unset_args.forEach((fn) => fn());
|
|
377
390
|
} else if (dep_submission.type === "data") {
|
|
378
|
-
this.handle_data(dep.outputs, dep_submission.data);
|
|
391
|
+
await this.handle_data(dep.outputs, dep_submission.data);
|
|
379
392
|
unset_args.forEach((fn) => fn());
|
|
380
393
|
} else {
|
|
381
394
|
let stream_state: "open" | "closed" | "waiting" | null = null;
|
|
@@ -408,7 +421,7 @@ export class DependencyManager {
|
|
|
408
421
|
index += 1;
|
|
409
422
|
if (result === null) continue;
|
|
410
423
|
if (result.type === "data") {
|
|
411
|
-
this.handle_data(dep.outputs, result.data);
|
|
424
|
+
await this.handle_data(dep.outputs, result.data);
|
|
412
425
|
}
|
|
413
426
|
if (result.type === "status") {
|
|
414
427
|
if (
|
|
@@ -516,6 +529,12 @@ export class DependencyManager {
|
|
|
516
529
|
}
|
|
517
530
|
|
|
518
531
|
if (result.type === "render") {
|
|
532
|
+
this.loading_stati.update({
|
|
533
|
+
status: "complete",
|
|
534
|
+
fn_index: dep.id,
|
|
535
|
+
stream_state: null
|
|
536
|
+
});
|
|
537
|
+
this.update_loading_stati_state();
|
|
519
538
|
const { layout, components, render_id, dependencies } =
|
|
520
539
|
result.data;
|
|
521
540
|
|
|
@@ -660,52 +679,61 @@ export class DependencyManager {
|
|
|
660
679
|
* @param data the data to update the components with
|
|
661
680
|
* */
|
|
662
681
|
async handle_data(outputs: number[], data: unknown[]) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
682
|
+
await Promise.all(
|
|
683
|
+
outputs.map(async (output_id, i) => {
|
|
684
|
+
const _data = data[i] === undefined ? NOVALUE : data[i];
|
|
685
|
+
if (_data === NOVALUE) return;
|
|
686
|
+
|
|
687
|
+
if (is_prop_update(_data)) {
|
|
688
|
+
let pending_visibility_update = false;
|
|
689
|
+
let pending_visibility_value = null;
|
|
690
|
+
for (const [update_key, update_value] of Object.entries(_data)) {
|
|
691
|
+
if (update_key === "__type__") continue;
|
|
692
|
+
if (update_key === "visible") {
|
|
693
|
+
pending_visibility_update = true;
|
|
694
|
+
pending_visibility_value = update_value;
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
await this.update_state_cb(
|
|
698
|
+
outputs[i],
|
|
699
|
+
{
|
|
700
|
+
[update_key]: update_value
|
|
701
|
+
},
|
|
702
|
+
false
|
|
703
|
+
);
|
|
676
704
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
{
|
|
689
|
-
visible: pending_visibility_value
|
|
690
|
-
},
|
|
691
|
-
true
|
|
692
|
-
);
|
|
705
|
+
if (pending_visibility_update) {
|
|
706
|
+
await this.update_state_cb(
|
|
707
|
+
outputs[i],
|
|
708
|
+
{
|
|
709
|
+
visible: pending_visibility_value
|
|
710
|
+
},
|
|
711
|
+
true
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
} else {
|
|
715
|
+
await this.update_state_cb(output_id, { value: _data }, false);
|
|
693
716
|
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
});
|
|
717
|
+
})
|
|
718
|
+
);
|
|
698
719
|
}
|
|
699
720
|
|
|
700
721
|
/**
|
|
701
722
|
* Gathers the current state of the inputs
|
|
702
723
|
*
|
|
703
724
|
* @param ids the ids of the components to gather state from
|
|
725
|
+
* @param prop_indices the indices (relative to ids array) that should return all component props instead of just the value
|
|
704
726
|
* @returns an array of the current state of the components, in the same order as the ids
|
|
705
727
|
*/
|
|
706
|
-
async gather_state(
|
|
728
|
+
async gather_state(
|
|
729
|
+
ids: number[],
|
|
730
|
+
prop_indices: number[] = []
|
|
731
|
+
): Promise<(unknown | null)[]> {
|
|
707
732
|
return (await Promise.all(ids.map((id) => this.get_state_cb(id)))).map(
|
|
708
|
-
(state) => {
|
|
733
|
+
(state, index) => {
|
|
734
|
+
if (prop_indices.includes(index)) {
|
|
735
|
+
return state ?? null;
|
|
736
|
+
}
|
|
709
737
|
return state?.value ?? null;
|
|
710
738
|
}
|
|
711
739
|
);
|
|
@@ -722,7 +750,8 @@ export class DependencyManager {
|
|
|
722
750
|
args: Record<string, unknown>
|
|
723
751
|
): Promise<() => void> {
|
|
724
752
|
let current_args: Record<string, unknown> = {};
|
|
725
|
-
const current_state = await this.get_state_cb(id);
|
|
753
|
+
const current_state = await this.get_state_cb?.(id);
|
|
754
|
+
if (!current_state) return () => {};
|
|
726
755
|
for (const [key] of Object.entries(args)) {
|
|
727
756
|
current_args[key] = current_state?.[key] ?? null;
|
|
728
757
|
}
|
package/src/types.ts
CHANGED
|
@@ -82,6 +82,7 @@ export interface Dependency {
|
|
|
82
82
|
like_user_message: boolean; // dno, this shouldnt be here surely
|
|
83
83
|
event_specific_args: ("time_limit" | "stream_every" | "like_user_message")[]; // `click(fn, some_arg=val)`
|
|
84
84
|
js_implementation: string | null; // pythong -> js transpilation
|
|
85
|
+
component_prop_inputs: number[]; // inputs that request all component props
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
interface TypeDescription {
|