@gradio/core 1.0.0-dev.0 → 1.0.0-dev.3
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 +79 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/Blocks.svelte +518 -1001
- package/dist/src/Blocks.svelte.d.ts +31 -45
- package/dist/src/Embed.svelte +82 -55
- package/dist/src/Embed.svelte.d.ts +39 -30
- package/dist/src/Login.svelte +33 -29
- package/dist/src/Login.svelte.d.ts +21 -19
- package/dist/src/MountComponents.svelte +19 -25
- package/dist/src/MountComponents.svelte.d.ts +5 -28
- package/dist/src/{init.d.ts → _init.d.ts} +5 -4
- package/dist/src/{init.js → _init.js} +31 -108
- package/dist/src/api_docs/ApiBanner.svelte +12 -8
- package/dist/src/api_docs/ApiBanner.svelte.d.ts +22 -20
- package/dist/src/api_docs/ApiDocs.svelte +337 -245
- package/dist/src/api_docs/ApiDocs.svelte.d.ts +26 -24
- package/dist/src/api_docs/ApiRecorder.svelte +9 -3
- package/dist/src/api_docs/ApiRecorder.svelte.d.ts +19 -17
- package/dist/src/api_docs/CodeSnippet.svelte +60 -30
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +27 -24
- package/dist/src/api_docs/CopyButton.svelte +69 -13
- package/dist/src/api_docs/CopyButton.svelte.d.ts +18 -16
- package/dist/src/api_docs/CopyMarkdown.svelte +734 -0
- package/dist/src/api_docs/CopyMarkdown.svelte.d.ts +37 -0
- package/dist/src/api_docs/EndpointDetail.svelte +8 -6
- package/dist/src/api_docs/EndpointDetail.svelte.d.ts +20 -18
- package/dist/src/api_docs/IconArrowUpRight.svelte +34 -0
- package/dist/src/api_docs/IconArrowUpRight.svelte.d.ts +20 -0
- package/dist/src/api_docs/IconCaret.svelte +39 -0
- package/dist/src/api_docs/IconCaret.svelte.d.ts +20 -0
- package/dist/src/api_docs/IconHuggingChat.svelte +62 -0
- package/dist/src/api_docs/IconHuggingChat.svelte.d.ts +20 -0
- package/dist/src/api_docs/InputPayload.svelte +17 -11
- package/dist/src/api_docs/InputPayload.svelte.d.ts +25 -23
- package/dist/src/api_docs/InstallSnippet.svelte +9 -6
- package/dist/src/api_docs/InstallSnippet.svelte.d.ts +18 -16
- package/dist/src/api_docs/MCPSnippet.svelte +119 -99
- package/dist/src/api_docs/MCPSnippet.svelte.d.ts +59 -58
- package/dist/src/api_docs/NoApi.svelte +7 -4
- package/dist/src/api_docs/NoApi.svelte.d.ts +20 -18
- package/dist/src/api_docs/ParametersSnippet.svelte +8 -6
- package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +21 -19
- package/dist/src/api_docs/RecordingSnippet.svelte +124 -110
- package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +24 -22
- package/dist/src/api_docs/ResponseSnippet.svelte +7 -5
- package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +21 -19
- package/dist/src/api_docs/Settings.svelte +73 -62
- package/dist/src/api_docs/Settings.svelte.d.ts +25 -23
- package/dist/src/api_docs/SettingsBanner.svelte +11 -8
- package/dist/src/api_docs/SettingsBanner.svelte.d.ts +20 -18
- package/dist/src/api_docs/TryButton.svelte +5 -3
- package/dist/src/api_docs/TryButton.svelte.d.ts +19 -17
- package/dist/src/api_docs/img/IconCheck.svelte +33 -0
- package/dist/src/api_docs/img/IconCheck.svelte.d.ts +26 -0
- package/dist/src/api_docs/img/IconCopy.svelte +40 -0
- package/dist/src/api_docs/img/IconCopy.svelte.d.ts +26 -0
- package/dist/src/api_docs/img/clear.svelte.d.ts +22 -21
- package/dist/src/dependency.d.ts +142 -0
- package/dist/src/dependency.js +653 -0
- package/dist/src/init.svelte.d.ts +78 -0
- package/dist/src/init.svelte.js +469 -0
- package/dist/src/init_utils.d.ts +32 -0
- package/dist/src/init_utils.js +73 -0
- package/dist/src/lang/en.json +10 -1
- package/dist/src/lang/get_lang_names.js +0 -3
- package/dist/src/lang/ru.json +10 -1
- package/dist/src/stores.d.ts +0 -21
- package/dist/src/stories/I18nMultiLanguageTestComponent.svelte +5 -3
- package/dist/src/stories/I18nMultiLanguageTestComponent.svelte.d.ts +16 -14
- package/dist/src/stories/I18nTestSetup.svelte +14 -10
- package/dist/src/stories/I18nTestSetup.svelte.d.ts +18 -16
- package/dist/src/types.d.ts +30 -26
- package/index.ts +1 -1
- package/package.json +59 -59
- package/src/Blocks.svelte +344 -1063
- package/src/MountComponents.svelte +17 -27
- package/src/{init.ts → _init.ts} +49 -126
- package/src/api_docs/ApiDocs.svelte +65 -60
- package/src/api_docs/ApiRecorder.svelte +3 -0
- package/src/api_docs/CodeSnippet.svelte +20 -5
- package/src/api_docs/CopyButton.svelte +61 -7
- package/src/api_docs/CopyMarkdown.svelte +734 -0
- package/src/api_docs/IconArrowUpRight.svelte +34 -0
- package/src/api_docs/IconCaret.svelte +39 -0
- package/src/api_docs/IconHuggingChat.svelte +62 -0
- package/src/api_docs/MCPSnippet.svelte +24 -46
- package/src/api_docs/ParametersSnippet.svelte +1 -1
- package/src/api_docs/ResponseSnippet.svelte +1 -1
- package/src/api_docs/Settings.svelte +11 -11
- package/src/api_docs/img/IconCheck.svelte +33 -0
- package/src/api_docs/img/IconCopy.svelte +40 -0
- package/src/dependency.ts +880 -0
- package/src/init.svelte.ts +717 -0
- package/src/init_utils.ts +99 -0
- package/src/lang/en.json +10 -1
- package/src/lang/get_lang_names.js +0 -3
- package/src/lang/ru.json +10 -1
- package/src/stores.ts +22 -22
- package/src/types.ts +54 -43
- package/dist/src/Render.svelte +0 -105
- package/dist/src/Render.svelte.d.ts +0 -31
- package/dist/src/RenderComponent.svelte +0 -72
- package/dist/src/RenderComponent.svelte.d.ts +0 -33
- package/src/Render.svelte +0 -126
- package/src/RenderComponent.svelte +0 -91
package/dist/src/Blocks.svelte
CHANGED
|
@@ -1,867 +1,401 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
`${app.config.root + app.config.api_prefix}/stream/${submit_map.get(dep_index).event_id()}`,
|
|
400
|
-
{ ...payload2, session_hash: app.session_hash }
|
|
401
|
-
);
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
try {
|
|
406
|
-
submission = app.submit(
|
|
407
|
-
payload2.fn_index,
|
|
408
|
-
payload2.data,
|
|
409
|
-
payload2.event_data,
|
|
410
|
-
payload2.trigger_id
|
|
411
|
-
);
|
|
412
|
-
} catch (e) {
|
|
413
|
-
const fn_index = 0;
|
|
414
|
-
if (app.closed) return;
|
|
415
|
-
messages = [
|
|
416
|
-
new_message("Error", String(e), fn_index, "error"),
|
|
417
|
-
...messages
|
|
418
|
-
];
|
|
419
|
-
loading_status.update({
|
|
420
|
-
status: "error",
|
|
421
|
-
fn_index,
|
|
422
|
-
eta: 0,
|
|
423
|
-
queue: false,
|
|
424
|
-
queue_position: null
|
|
425
|
-
});
|
|
426
|
-
set_status($loading_status);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
submit_map.set(dep_index, submission);
|
|
430
|
-
for await (const message of submission) {
|
|
431
|
-
if (payload2.js_implementation) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
if (message.type === "data") {
|
|
435
|
-
handle_data(message);
|
|
436
|
-
} else if (message.type === "render") {
|
|
437
|
-
handle_render(message);
|
|
438
|
-
} else if (message.type === "status") {
|
|
439
|
-
handle_status_update(message);
|
|
440
|
-
} else if (message.type === "log") {
|
|
441
|
-
handle_log(message);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
function handle_data(message) {
|
|
445
|
-
const { data, fn_index } = message;
|
|
446
|
-
if (dep.pending_request && dep.final_event) {
|
|
447
|
-
dep.pending_request = false;
|
|
448
|
-
make_prediction(dep.final_event, dep.connection == "stream");
|
|
449
|
-
}
|
|
450
|
-
dep.pending_request = false;
|
|
451
|
-
handle_update(data, fn_index);
|
|
452
|
-
set_status($loading_status);
|
|
453
|
-
}
|
|
454
|
-
function handle_render(message) {
|
|
455
|
-
const { data } = message;
|
|
456
|
-
let _components = data.components;
|
|
457
|
-
let render_layout = data.layout;
|
|
458
|
-
let _dependencies = data.dependencies;
|
|
459
|
-
let render_id = data.render_id;
|
|
460
|
-
let deps_to_remove = [];
|
|
461
|
-
dependencies.forEach((old_dep, i) => {
|
|
462
|
-
if (old_dep.rendered_in === dep.render_id) {
|
|
463
|
-
deps_to_remove.push(i);
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
deps_to_remove.reverse().forEach((i) => {
|
|
467
|
-
dependencies.splice(i, 1);
|
|
468
|
-
});
|
|
469
|
-
_dependencies.forEach((dep2) => {
|
|
470
|
-
dependencies.push(dep2);
|
|
471
|
-
});
|
|
472
|
-
rerender_layout({
|
|
473
|
-
components: _components,
|
|
474
|
-
layout: render_layout,
|
|
475
|
-
root: root + api_prefix,
|
|
476
|
-
dependencies,
|
|
477
|
-
render_id
|
|
478
|
-
});
|
|
479
|
-
_dependencies.forEach((dep2) => {
|
|
480
|
-
if (dep2.targets.some((dep3) => dep3[1] === "load")) {
|
|
481
|
-
wait_then_trigger_api_call(dep2.id);
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
function handle_log(msg) {
|
|
486
|
-
const { title: title2, log, fn_index, level, duration, visible } = msg;
|
|
487
|
-
messages = [
|
|
488
|
-
new_message(title2, log, fn_index, level, duration, visible),
|
|
489
|
-
...messages
|
|
490
|
-
];
|
|
491
|
-
}
|
|
492
|
-
function open_stream_events(status, id, dep2) {
|
|
493
|
-
if (status.original_msg === "process_starts" && dep2.connection === "stream") {
|
|
494
|
-
modify_stream(id, "open");
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
function handle_status_update(message) {
|
|
498
|
-
if (message.code === "validation_error") {
|
|
499
|
-
const dep2 = dependencies.find((dep3) => dep3.id === message.fn_index);
|
|
500
|
-
if (dep2 === void 0 || message.message === void 0 || typeof message.message === "string") {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const validation_error_data = [];
|
|
504
|
-
message.message.forEach((message2, i) => {
|
|
505
|
-
if (message2.is_valid) {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
validation_error_data.push({
|
|
509
|
-
id: dep2.inputs[i],
|
|
510
|
-
prop: "validation_error",
|
|
511
|
-
value: message2.message
|
|
512
|
-
});
|
|
513
|
-
validation_error_data.push({
|
|
514
|
-
id: dep2.inputs[i],
|
|
515
|
-
prop: "loading_status",
|
|
516
|
-
value: { validation_error: message2.message }
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
if (validation_error_data.length > 0) {
|
|
520
|
-
update_value(validation_error_data);
|
|
521
|
-
loading_status.update({
|
|
522
|
-
status: "complete",
|
|
523
|
-
fn_index: message.fn_index,
|
|
524
|
-
eta: 0,
|
|
525
|
-
queue: false,
|
|
526
|
-
queue_position: null
|
|
527
|
-
});
|
|
528
|
-
set_status($loading_status);
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
if (message.broken && !broken_connection) {
|
|
533
|
-
messages = [
|
|
534
|
-
new_message(
|
|
535
|
-
"Broken Connection",
|
|
536
|
-
LOST_CONNECTION_MESSAGE,
|
|
537
|
-
-1,
|
|
538
|
-
"error",
|
|
539
|
-
null,
|
|
540
|
-
true
|
|
541
|
-
),
|
|
542
|
-
...messages
|
|
543
|
-
];
|
|
544
|
-
broken_connection = true;
|
|
545
|
-
setTimeout(reconnect, 1e3);
|
|
546
|
-
}
|
|
547
|
-
if (message.session_not_found) {
|
|
548
|
-
messages = [
|
|
549
|
-
new_message(
|
|
550
|
-
"Session Not Found",
|
|
551
|
-
SESSION_NOT_FOUND_MESSAGE,
|
|
552
|
-
-1,
|
|
553
|
-
"error",
|
|
554
|
-
null,
|
|
555
|
-
true
|
|
556
|
-
),
|
|
557
|
-
...messages
|
|
558
|
-
];
|
|
559
|
-
}
|
|
560
|
-
const { fn_index, ...status } = message;
|
|
561
|
-
if (status.stage === "streaming" && status.time_limit) {
|
|
562
|
-
dep.inputs.forEach((id) => {
|
|
563
|
-
set_time_limit(id, status.time_limit);
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
dep.inputs.forEach((id) => {
|
|
567
|
-
open_stream_events(message, id, dep);
|
|
568
|
-
});
|
|
569
|
-
loading_status.update({
|
|
570
|
-
...status,
|
|
571
|
-
time_limit: status.time_limit,
|
|
572
|
-
status: status.stage,
|
|
573
|
-
progress: status.progress_data,
|
|
574
|
-
fn_index
|
|
575
|
-
});
|
|
576
|
-
set_status($loading_status);
|
|
577
|
-
if (!showed_duplicate_message && space_id !== null && status.position !== void 0 && status.position >= 2 && status.eta !== void 0 && status.eta > SHOW_DUPLICATE_MESSAGE_ON_ETA) {
|
|
578
|
-
showed_duplicate_message = true;
|
|
579
|
-
messages = [
|
|
580
|
-
new_message("Warning", DUPLICATE_MESSAGE, fn_index, "warning"),
|
|
581
|
-
...messages
|
|
582
|
-
];
|
|
583
|
-
}
|
|
584
|
-
if (!showed_mobile_warning && is_mobile_device && status.eta !== void 0 && status.eta > SHOW_MOBILE_QUEUE_WARNING_ON_ETA) {
|
|
585
|
-
showed_mobile_warning = true;
|
|
586
|
-
messages = [
|
|
587
|
-
new_message("Warning", MOBILE_QUEUE_WARNING, fn_index, "warning"),
|
|
588
|
-
...messages
|
|
589
|
-
];
|
|
590
|
-
}
|
|
591
|
-
if (status.stage === "complete" || status.stage === "generating") {
|
|
592
|
-
const deps_triggered_by_state = /* @__PURE__ */ new Set();
|
|
593
|
-
status.changed_state_ids?.forEach((id) => {
|
|
594
|
-
dependencies.filter((dep2) => dep2.targets.some(([_id, _2]) => _id === id)).forEach((dep2) => {
|
|
595
|
-
deps_triggered_by_state.add(dep2);
|
|
596
|
-
});
|
|
597
|
-
});
|
|
598
|
-
deps_triggered_by_state.forEach((dep2) => {
|
|
599
|
-
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
if (status.stage === "complete") {
|
|
603
|
-
dependencies.forEach(async (dep2) => {
|
|
604
|
-
if (dep2.trigger_after === fn_index && !dep2.trigger_only_on_failure) {
|
|
605
|
-
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
dep.inputs.forEach((id) => {
|
|
609
|
-
modify_stream(id, "closed");
|
|
610
|
-
});
|
|
611
|
-
submit_map.delete(dep_index);
|
|
612
|
-
}
|
|
613
|
-
if (status.stage === "error" && !broken_connection && !message.session_not_found) {
|
|
614
|
-
if (status.message && typeof status.message === "string") {
|
|
615
|
-
const _message = status.message.replace(
|
|
616
|
-
MESSAGE_QUOTE_RE,
|
|
617
|
-
(_2, b) => b
|
|
618
|
-
);
|
|
619
|
-
const _title = status.title ?? "Error";
|
|
620
|
-
messages = [
|
|
621
|
-
new_message(
|
|
622
|
-
_title,
|
|
623
|
-
_message,
|
|
624
|
-
fn_index,
|
|
625
|
-
"error",
|
|
626
|
-
status.duration,
|
|
627
|
-
status.visible
|
|
628
|
-
),
|
|
629
|
-
...messages
|
|
630
|
-
];
|
|
631
|
-
}
|
|
632
|
-
dependencies.map(async (dep2) => {
|
|
633
|
-
if (dep2.trigger_after === fn_index && (!dep2.trigger_only_on_success || dep2.trigger_only_on_failure)) {
|
|
634
|
-
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
if (allow_video_trim) {
|
|
640
|
-
screen_recorder.markRemoveSegmentEnd();
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function trigger_share(title2, description) {
|
|
645
|
-
if (space_id === null) {
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
const discussion_url = new URL(
|
|
649
|
-
`https://huggingface.co/spaces/${space_id}/discussions/new`
|
|
650
|
-
);
|
|
651
|
-
if (title2 !== void 0 && title2.length > 0) {
|
|
652
|
-
discussion_url.searchParams.set("title", title2);
|
|
653
|
-
}
|
|
654
|
-
discussion_url.searchParams.set("description", description);
|
|
655
|
-
window.open(discussion_url.toString(), "_blank");
|
|
656
|
-
}
|
|
657
|
-
function handle_error_close(e) {
|
|
658
|
-
const _id = e.detail;
|
|
659
|
-
messages = messages.filter((m) => m.id !== _id);
|
|
660
|
-
}
|
|
661
|
-
const is_external_url = (link) => !!(link && new URL(link, location.href).origin !== location.origin);
|
|
662
|
-
async function handle_mount() {
|
|
663
|
-
if (js) {
|
|
664
|
-
let blocks_frontend_fn = new AsyncFunction(
|
|
665
|
-
`let result = await (${js})();
|
|
666
|
-
return (!Array.isArray(result)) ? [result] : result;`
|
|
667
|
-
);
|
|
668
|
-
await blocks_frontend_fn();
|
|
669
|
-
}
|
|
670
|
-
await tick();
|
|
671
|
-
var a = target.getElementsByTagName("a");
|
|
672
|
-
for (var i = 0; i < a.length; i++) {
|
|
673
|
-
const _target = a[i].getAttribute("target");
|
|
674
|
-
const _link = a[i].getAttribute("href");
|
|
675
|
-
if (is_external_url(_link) && _target !== "_blank")
|
|
676
|
-
a[i].setAttribute("target", "_blank");
|
|
677
|
-
}
|
|
678
|
-
handle_load_triggers();
|
|
679
|
-
if (!target || render_complete) return;
|
|
680
|
-
target.addEventListener("prop_change", (e) => {
|
|
681
|
-
if (!isCustomEvent(e)) throw new Error("not a custom event");
|
|
682
|
-
const { id, prop, value } = e.detail;
|
|
683
|
-
if (prop === "value") {
|
|
684
|
-
update_value([
|
|
685
|
-
{
|
|
686
|
-
id,
|
|
687
|
-
prop: "loading_status",
|
|
688
|
-
value: { validation_error: void 0 }
|
|
689
|
-
}
|
|
690
|
-
]);
|
|
691
|
-
}
|
|
692
|
-
update_value([{ id, prop, value }]);
|
|
693
|
-
if (prop === "input_ready" && value === false) {
|
|
694
|
-
inputs_waiting.push(id);
|
|
695
|
-
}
|
|
696
|
-
if (prop === "input_ready" && value === true) {
|
|
697
|
-
inputs_waiting = inputs_waiting.filter((item) => item !== id);
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
target.addEventListener("gradio", (e) => {
|
|
701
|
-
if (!isCustomEvent(e)) throw new Error("not a custom event");
|
|
702
|
-
const { id, event, data } = e.detail;
|
|
703
|
-
if (event === "share") {
|
|
704
|
-
const { title: title2, description } = data;
|
|
705
|
-
trigger_share(title2, description);
|
|
706
|
-
} else if (event === "error") {
|
|
707
|
-
messages = [new_message("Error", data, -1, event), ...messages];
|
|
708
|
-
} else if (event === "warning") {
|
|
709
|
-
messages = [new_message("Warning", data, -1, event), ...messages];
|
|
710
|
-
} else if (event === "info") {
|
|
711
|
-
messages = [new_message("Info", data, -1, event), ...messages];
|
|
712
|
-
} else if (event == "clear_status") {
|
|
713
|
-
update_status(id, "complete", data);
|
|
714
|
-
} else if (event == "close_stream") {
|
|
715
|
-
const deps = $targets[id]?.[data];
|
|
716
|
-
deps?.forEach((dep_id) => {
|
|
717
|
-
if (submit_map.has(dep_id)) {
|
|
718
|
-
const url = `${app.config.root + app.config.api_prefix}/stream/${submit_map.get(dep_id).event_id()}`;
|
|
719
|
-
app.post_data(`${url}/close`, {});
|
|
720
|
-
}
|
|
721
|
-
});
|
|
722
|
-
} else {
|
|
723
|
-
const deps = $targets[id]?.[event];
|
|
724
|
-
deps?.forEach((dep_id) => {
|
|
725
|
-
requestAnimationFrame(() => {
|
|
726
|
-
wait_then_trigger_api_call(dep_id, id, data);
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
render_complete = true;
|
|
732
|
-
}
|
|
733
|
-
value_change((id, value) => {
|
|
734
|
-
const deps = $targets[id]?.["change"];
|
|
735
|
-
deps?.forEach((dep_id) => {
|
|
736
|
-
requestAnimationFrame(() => {
|
|
737
|
-
wait_then_trigger_api_call(dep_id, id, value);
|
|
738
|
-
});
|
|
739
|
-
});
|
|
740
|
-
});
|
|
741
|
-
const handle_load_triggers = () => {
|
|
742
|
-
dependencies.forEach((dep) => {
|
|
743
|
-
if (dep.targets.some((dep2) => dep2[1] === "load")) {
|
|
744
|
-
wait_then_trigger_api_call(dep.id);
|
|
745
|
-
}
|
|
746
|
-
});
|
|
747
|
-
};
|
|
748
|
-
$: set_status($loading_status);
|
|
749
|
-
function update_status(id, status, data) {
|
|
750
|
-
data.status = status;
|
|
751
|
-
update_value([
|
|
752
|
-
{
|
|
753
|
-
id,
|
|
754
|
-
prop: "loading_status",
|
|
755
|
-
value: data
|
|
756
|
-
}
|
|
757
|
-
]);
|
|
758
|
-
}
|
|
759
|
-
function set_status(statuses) {
|
|
760
|
-
let updates = [];
|
|
761
|
-
Object.entries(statuses).forEach(([id, loading_status2]) => {
|
|
762
|
-
if (app.closed && loading_status2.status === "error") {
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
let dependency = dependencies.find(
|
|
766
|
-
(dep) => dep.id == loading_status2.fn_index
|
|
767
|
-
);
|
|
768
|
-
if (dependency === void 0) {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
loading_status2.scroll_to_output = dependency.scroll_to_output;
|
|
772
|
-
loading_status2.show_progress = dependency.show_progress;
|
|
773
|
-
updates.push({
|
|
774
|
-
id: parseInt(id),
|
|
775
|
-
prop: "loading_status",
|
|
776
|
-
value: loading_status2
|
|
777
|
-
});
|
|
778
|
-
});
|
|
779
|
-
const inputs_to_update = loading_status.get_inputs_to_update();
|
|
780
|
-
const additional_updates = Array.from(inputs_to_update).map(
|
|
781
|
-
([id, pending_status]) => {
|
|
782
|
-
return {
|
|
783
|
-
id,
|
|
784
|
-
prop: "pending",
|
|
785
|
-
value: pending_status === "pending"
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
);
|
|
789
|
-
update_value([...updates, ...additional_updates]);
|
|
790
|
-
}
|
|
791
|
-
function isCustomEvent(event) {
|
|
792
|
-
return "detail" in event;
|
|
793
|
-
}
|
|
794
|
-
let is_screen_recording = writable(false);
|
|
795
|
-
onMount(() => {
|
|
796
|
-
is_mobile_device = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
797
|
-
navigator.userAgent
|
|
798
|
-
);
|
|
799
|
-
screen_recorder.initialize(
|
|
800
|
-
root,
|
|
801
|
-
(title2, message, type) => {
|
|
802
|
-
add_new_message(title2, message, type);
|
|
803
|
-
},
|
|
804
|
-
(isRecording) => {
|
|
805
|
-
$is_screen_recording = isRecording;
|
|
806
|
-
}
|
|
807
|
-
);
|
|
808
|
-
const handleVibeEditorResize = (event) => {
|
|
809
|
-
vibe_editor_width = event.detail.width;
|
|
810
|
-
};
|
|
811
|
-
window.addEventListener(
|
|
812
|
-
"vibeEditorResize",
|
|
813
|
-
handleVibeEditorResize
|
|
814
|
-
);
|
|
815
|
-
if (api_docs_visible) {
|
|
816
|
-
loadApiDocs();
|
|
817
|
-
}
|
|
818
|
-
if (api_recorder_visible) {
|
|
819
|
-
loadApiRecorder();
|
|
820
|
-
}
|
|
821
|
-
if (settings_visible) {
|
|
822
|
-
loadSettings();
|
|
823
|
-
}
|
|
824
|
-
if (vibe_mode) {
|
|
825
|
-
loadVibeEditor();
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
function screen_recording() {
|
|
829
|
-
if ($is_screen_recording) {
|
|
830
|
-
screen_recorder.stopRecording();
|
|
831
|
-
} else {
|
|
832
|
-
screen_recorder.startRecording();
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
let footer_height = 0;
|
|
836
|
-
let root_container;
|
|
837
|
-
function get_root_node(container) {
|
|
838
|
-
if (!container) return null;
|
|
839
|
-
return container.children[container.children.length - 1];
|
|
840
|
-
}
|
|
841
|
-
function handle_resize() {
|
|
842
|
-
if ("parentIFrame" in window) {
|
|
843
|
-
const box = root_container.children[0].getBoundingClientRect();
|
|
844
|
-
if (!box) return;
|
|
845
|
-
window.parentIFrame?.size(box.bottom + footer_height + 32);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
onMount(() => {
|
|
849
|
-
if ("parentIFrame" in window) {
|
|
850
|
-
window.parentIFrame?.autoResize(false);
|
|
851
|
-
}
|
|
852
|
-
const mut = new MutationObserver(handle_resize);
|
|
853
|
-
const res = new ResizeObserver(handle_resize);
|
|
854
|
-
mut.observe(root_container, {
|
|
855
|
-
childList: true,
|
|
856
|
-
subtree: true,
|
|
857
|
-
attributes: true
|
|
858
|
-
});
|
|
859
|
-
res.observe(root_container);
|
|
860
|
-
return () => {
|
|
861
|
-
mut.disconnect();
|
|
862
|
-
res.disconnect();
|
|
863
|
-
};
|
|
864
|
-
});
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick, onMount, setContext, settled, untrack } from "svelte";
|
|
3
|
+
import { _ } from "svelte-i18n";
|
|
4
|
+
import { Client } from "@gradio/client";
|
|
5
|
+
import { writable } from "svelte/store";
|
|
6
|
+
|
|
7
|
+
// import type { LoadingStatus, LoadingStatusCollection } from "./stores";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
ComponentMeta,
|
|
11
|
+
Dependency as IDependency,
|
|
12
|
+
LayoutNode
|
|
13
|
+
} from "./types";
|
|
14
|
+
// import type { UpdateTransaction } from "./_init";
|
|
15
|
+
import { setupi18n } from "./i18n";
|
|
16
|
+
import type { ThemeMode, Payload } from "./types";
|
|
17
|
+
import { Toast } from "@gradio/statustracker";
|
|
18
|
+
import type { ToastMessage } from "@gradio/statustracker";
|
|
19
|
+
import { type ShareData, type ValueData, GRADIO_ROOT } from "@gradio/utils";
|
|
20
|
+
|
|
21
|
+
import MountComponents from "./MountComponents.svelte";
|
|
22
|
+
import { prefix_css } from "./css";
|
|
23
|
+
import { reactive_formatter } from "./gradio_helper";
|
|
24
|
+
|
|
25
|
+
import type ApiDocsInterface from "./api_docs/ApiDocs.svelte";
|
|
26
|
+
import type ApiRecorderInterface from "./api_docs/ApiRecorder.svelte";
|
|
27
|
+
import type SettingsInterface from "./api_docs/Settings.svelte";
|
|
28
|
+
// import type { ComponentType } from "svelte";
|
|
29
|
+
|
|
30
|
+
import logo from "./images/logo.svg";
|
|
31
|
+
import api_logo from "./api_docs/img/api-logo.svg";
|
|
32
|
+
import settings_logo from "./api_docs/img/settings-logo.svg";
|
|
33
|
+
import record_stop from "./api_docs/img/record-stop.svg";
|
|
34
|
+
import { AppTree } from "./init.svelte";
|
|
35
|
+
// import type {
|
|
36
|
+
// LogMessage,
|
|
37
|
+
// RenderMessage,
|
|
38
|
+
// StatusMessage,
|
|
39
|
+
// } from "@gradio/client";
|
|
40
|
+
import * as screen_recorder from "./screen_recorder";
|
|
41
|
+
|
|
42
|
+
import { DependencyManager } from "./dependency";
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
root,
|
|
46
|
+
components,
|
|
47
|
+
layout,
|
|
48
|
+
dependencies,
|
|
49
|
+
title,
|
|
50
|
+
target,
|
|
51
|
+
autoscroll,
|
|
52
|
+
footer_links,
|
|
53
|
+
control_page_title,
|
|
54
|
+
app_mode,
|
|
55
|
+
theme_mode,
|
|
56
|
+
app,
|
|
57
|
+
space_id,
|
|
58
|
+
version,
|
|
59
|
+
js,
|
|
60
|
+
fill_height,
|
|
61
|
+
username,
|
|
62
|
+
api_prefix,
|
|
63
|
+
max_file_size,
|
|
64
|
+
initial_layout,
|
|
65
|
+
css,
|
|
66
|
+
vibe_mode,
|
|
67
|
+
search_params,
|
|
68
|
+
render_complete = false,
|
|
69
|
+
ready = $bindable(false),
|
|
70
|
+
reload_count = $bindable(0)
|
|
71
|
+
}: {
|
|
72
|
+
root: string;
|
|
73
|
+
components: ComponentMeta[];
|
|
74
|
+
layout: LayoutNode;
|
|
75
|
+
dependencies: IDependency[];
|
|
76
|
+
title: string;
|
|
77
|
+
target: HTMLElement;
|
|
78
|
+
autoscroll: boolean;
|
|
79
|
+
footer_links: string[];
|
|
80
|
+
control_page_title: boolean;
|
|
81
|
+
app_mode: boolean;
|
|
82
|
+
theme_mode: ThemeMode;
|
|
83
|
+
app: Awaited<ReturnType<typeof Client.connect>>;
|
|
84
|
+
space_id: string | null;
|
|
85
|
+
version: string;
|
|
86
|
+
js: string | null;
|
|
87
|
+
fill_height: boolean;
|
|
88
|
+
username: string | null;
|
|
89
|
+
api_prefix: string;
|
|
90
|
+
max_file_size: number | undefined;
|
|
91
|
+
initial_layout: ComponentMeta | undefined;
|
|
92
|
+
css: string | null | undefined;
|
|
93
|
+
vibe_mode: boolean;
|
|
94
|
+
search_params: URLSearchParams;
|
|
95
|
+
render_complete: boolean;
|
|
96
|
+
ready: boolean;
|
|
97
|
+
reload_count: number;
|
|
98
|
+
} = $props();
|
|
99
|
+
|
|
100
|
+
components.forEach((comp) => {
|
|
101
|
+
if (!comp.props.i18n) {
|
|
102
|
+
comp.props.i18n = $reactive_formatter;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
let app_tree = new AppTree(
|
|
107
|
+
components,
|
|
108
|
+
layout,
|
|
109
|
+
dependencies,
|
|
110
|
+
{
|
|
111
|
+
root,
|
|
112
|
+
theme: theme_mode,
|
|
113
|
+
version,
|
|
114
|
+
api_prefix,
|
|
115
|
+
max_file_size,
|
|
116
|
+
autoscroll
|
|
117
|
+
},
|
|
118
|
+
app,
|
|
119
|
+
$reactive_formatter
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
setContext(GRADIO_ROOT, {
|
|
123
|
+
register: app_tree.register_component.bind(app_tree),
|
|
124
|
+
dispatcher: gradio_event_dispatcher
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
let messages: (ToastMessage & { fn_index: number })[] = $state([]);
|
|
128
|
+
|
|
129
|
+
function gradio_event_dispatcher(
|
|
130
|
+
id: number,
|
|
131
|
+
event: string,
|
|
132
|
+
data: unknown
|
|
133
|
+
): void {
|
|
134
|
+
if (event === "share") {
|
|
135
|
+
const { title, description } = data as ShareData;
|
|
136
|
+
// trigger_share(title, description);
|
|
137
|
+
// TODO: lets combine all of the into a log type with levels
|
|
138
|
+
} else if (event === "error") {
|
|
139
|
+
new_message("Error", data, -1, event, 10, true);
|
|
140
|
+
} else if (event === "warning") {
|
|
141
|
+
new_message("Warning", data, -1, event, 10, true);
|
|
142
|
+
} else if (event === "info") {
|
|
143
|
+
new_message("Info", data, -1, event, 10, true);
|
|
144
|
+
} else if (event == "clear_status") {
|
|
145
|
+
app_tree.update_state(
|
|
146
|
+
id,
|
|
147
|
+
{
|
|
148
|
+
loading_status: {}
|
|
149
|
+
},
|
|
150
|
+
false
|
|
151
|
+
);
|
|
152
|
+
dep_manager.clear_loading_status(id);
|
|
153
|
+
// TODO: the loading_status store should handle this via a method
|
|
154
|
+
// update_status(id, "complete", data);
|
|
155
|
+
} else if (event == "close_stream") {
|
|
156
|
+
dep_manager.close_stream(id);
|
|
157
|
+
} else {
|
|
158
|
+
// Tabs are a bit weird. The Tabs component dispatches 'select' events
|
|
159
|
+
// but the target id corresponds to the child Tab component that was selected.
|
|
160
|
+
// So the id we get from the dispatcher belongs to the Tabs,
|
|
161
|
+
// so we need to pull out the correct id here.
|
|
162
|
+
if (event === "select" && id in app_tree.initial_tabs) {
|
|
163
|
+
// this is the id of the selected tab
|
|
164
|
+
id = data.id;
|
|
165
|
+
}
|
|
166
|
+
dep_manager.dispatch({
|
|
167
|
+
type: "event",
|
|
168
|
+
event_name: event,
|
|
169
|
+
target_id: id,
|
|
170
|
+
event_data: data
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let api_calls: Payload[] = $state([]);
|
|
176
|
+
// We need a callback to add to api_calls from the DependencyManager
|
|
177
|
+
// We can't update a state variable from inside the DependencyManager because
|
|
178
|
+
// svelte won't see it and won't update the UI.
|
|
179
|
+
let add_to_api_calls = (payload: Payload): void => {
|
|
180
|
+
api_calls = [...api_calls, payload];
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
let dep_manager = new DependencyManager(
|
|
184
|
+
dependencies,
|
|
185
|
+
app,
|
|
186
|
+
app_tree.update_state.bind(app_tree),
|
|
187
|
+
app_tree.get_state.bind(app_tree),
|
|
188
|
+
app_tree.rerender.bind(app_tree),
|
|
189
|
+
new_message,
|
|
190
|
+
add_to_api_calls
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
$effect(() => {
|
|
194
|
+
reload_count;
|
|
195
|
+
untrack(() => {
|
|
196
|
+
app_tree.reload(components, layout, dependencies, {
|
|
197
|
+
root,
|
|
198
|
+
theme: theme_mode,
|
|
199
|
+
version,
|
|
200
|
+
api_prefix,
|
|
201
|
+
max_file_size,
|
|
202
|
+
autoscroll
|
|
203
|
+
});
|
|
204
|
+
dep_manager.reload(
|
|
205
|
+
dependencies,
|
|
206
|
+
app_tree.update_state.bind(app_tree),
|
|
207
|
+
app_tree.get_state.bind(app_tree),
|
|
208
|
+
app_tree.rerender.bind(app_tree),
|
|
209
|
+
app
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
let vibe_editor_width = 350;
|
|
215
|
+
|
|
216
|
+
// export let
|
|
217
|
+
let api_docs_visible = $derived(
|
|
218
|
+
search_params.get("view") === "api" && footer_links.includes("api")
|
|
219
|
+
);
|
|
220
|
+
let settings_visible = $derived(search_params.get("view") === "settings");
|
|
221
|
+
let api_recorder_visible = $derived(
|
|
222
|
+
search_params.get("view") === "api-recorder" && footer_links.includes("api")
|
|
223
|
+
);
|
|
224
|
+
let allow_zoom = true;
|
|
225
|
+
let allow_video_trim = true;
|
|
226
|
+
|
|
227
|
+
// Lazy component loading state
|
|
228
|
+
let ApiDocs: ComponentType<ApiDocsInterface> | null = null;
|
|
229
|
+
let ApiRecorder: ComponentType<ApiRecorderInterface> | null = null;
|
|
230
|
+
let Settings: ComponentType<SettingsInterface> | null = null;
|
|
231
|
+
let VibeEditor: ComponentType | null = null;
|
|
232
|
+
|
|
233
|
+
async function loadApiDocs(): Promise<void> {
|
|
234
|
+
if (!ApiDocs || !ApiRecorder) {
|
|
235
|
+
const api_docs_module = await import("./api_docs/ApiDocs.svelte");
|
|
236
|
+
const api_recorder_module = await import("./api_docs/ApiRecorder.svelte");
|
|
237
|
+
if (!ApiDocs) ApiDocs = api_docs_module.default;
|
|
238
|
+
if (!ApiRecorder) ApiRecorder = api_recorder_module.default;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function loadApiRecorder(): Promise<void> {
|
|
243
|
+
if (!ApiRecorder) {
|
|
244
|
+
const api_recorder_module = await import("./api_docs/ApiRecorder.svelte");
|
|
245
|
+
ApiRecorder = api_recorder_module.default;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async function loadSettings(): Promise<void> {
|
|
250
|
+
if (!Settings) {
|
|
251
|
+
const settings_module = await import("./api_docs/Settings.svelte");
|
|
252
|
+
Settings = settings_module.default;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function loadVibeEditor(): Promise<void> {
|
|
257
|
+
if (!VibeEditor) {
|
|
258
|
+
const vibe_editor_module = await import("@gradio/vibeeditor");
|
|
259
|
+
VibeEditor = vibe_editor_module.default;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function set_api_docs_visible(visible: boolean): Promise<void> {
|
|
264
|
+
api_recorder_visible = false;
|
|
265
|
+
if (visible) {
|
|
266
|
+
await loadApiDocs();
|
|
267
|
+
}
|
|
268
|
+
api_docs_visible = visible;
|
|
269
|
+
let params = new URLSearchParams(window.location.search);
|
|
270
|
+
if (visible) {
|
|
271
|
+
params.set("view", "api");
|
|
272
|
+
} else {
|
|
273
|
+
params.delete("view");
|
|
274
|
+
}
|
|
275
|
+
history.replaceState(null, "", "?" + params.toString());
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async function set_settings_visible(visible: boolean): Promise<void> {
|
|
279
|
+
if (visible) {
|
|
280
|
+
await loadSettings();
|
|
281
|
+
}
|
|
282
|
+
let params = new URLSearchParams(window.location.search);
|
|
283
|
+
if (visible) {
|
|
284
|
+
params.set("view", "settings");
|
|
285
|
+
} else {
|
|
286
|
+
params.delete("view");
|
|
287
|
+
}
|
|
288
|
+
history.replaceState(null, "", "?" + params.toString());
|
|
289
|
+
settings_visible = !settings_visible;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let layout_creating = false;
|
|
293
|
+
//
|
|
294
|
+
|
|
295
|
+
function new_message(
|
|
296
|
+
title: string,
|
|
297
|
+
message: string,
|
|
298
|
+
fn_index: number,
|
|
299
|
+
type: ToastMessage["type"],
|
|
300
|
+
duration: number | null = 10,
|
|
301
|
+
visible = false
|
|
302
|
+
): void {
|
|
303
|
+
if (!visible) return;
|
|
304
|
+
messages.push({
|
|
305
|
+
title,
|
|
306
|
+
message,
|
|
307
|
+
fn_index,
|
|
308
|
+
type,
|
|
309
|
+
id: ++_error_id,
|
|
310
|
+
duration,
|
|
311
|
+
visible
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let _error_id = -1;
|
|
316
|
+
|
|
317
|
+
const MESSAGE_QUOTE_RE = /^'([^]+)'$/;
|
|
318
|
+
|
|
319
|
+
const DUPLICATE_MESSAGE = $_("blocks.long_requests_queue");
|
|
320
|
+
const MOBILE_QUEUE_WARNING = $_("blocks.connection_can_break");
|
|
321
|
+
const LOST_CONNECTION_MESSAGE =
|
|
322
|
+
"Connection to the server was lost. Attempting reconnection...";
|
|
323
|
+
const CHANGED_CONNECTION_MESSAGE =
|
|
324
|
+
"Reconnected to server, but the server has changed. You may need to <a href=''>refresh the page</a>.";
|
|
325
|
+
const RECONNECTION_MESSAGE = "Connection re-established.";
|
|
326
|
+
const SESSION_NOT_FOUND_MESSAGE =
|
|
327
|
+
"Session not found - this is likely because the machine you were connected to has changed. <a href=''>Refresh the page</a> to continue.";
|
|
328
|
+
const WAITING_FOR_INPUTS_MESSAGE = $_("blocks.waiting_for_inputs");
|
|
329
|
+
const SHOW_DUPLICATE_MESSAGE_ON_ETA = 15;
|
|
330
|
+
const SHOW_MOBILE_QUEUE_WARNING_ON_ETA = 10;
|
|
331
|
+
let is_mobile_device = false;
|
|
332
|
+
let showed_duplicate_message = false;
|
|
333
|
+
let showed_mobile_warning = false;
|
|
334
|
+
let inputs_waiting: number[] = [];
|
|
335
|
+
|
|
336
|
+
// as state updates are not synchronous, we need to ensure updates are flushed before triggering any requests
|
|
337
|
+
|
|
338
|
+
let is_screen_recording = writable(false);
|
|
339
|
+
|
|
340
|
+
let footer_height = 0;
|
|
341
|
+
|
|
342
|
+
let root_container: HTMLElement;
|
|
343
|
+
|
|
344
|
+
function get_root_node(container: HTMLElement | null): HTMLElement | null {
|
|
345
|
+
if (!container) return null;
|
|
346
|
+
return container.children[container.children.length - 1] as HTMLElement;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function handle_resize(): void {
|
|
350
|
+
if ("parentIFrame" in window) {
|
|
351
|
+
const box = root_container.children[0].getBoundingClientRect();
|
|
352
|
+
if (!box) return;
|
|
353
|
+
window.parentIFrame?.size(box.bottom + footer_height + 32);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function screen_recording(): void {
|
|
358
|
+
if ($is_screen_recording) {
|
|
359
|
+
screen_recorder.stopRecording();
|
|
360
|
+
} else {
|
|
361
|
+
screen_recorder.startRecording();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
onMount(() => {
|
|
366
|
+
is_mobile_device =
|
|
367
|
+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
368
|
+
navigator.userAgent
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
if ("parentIFrame" in window) {
|
|
372
|
+
window.parentIFrame?.autoResize(false);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const mut = new MutationObserver(handle_resize);
|
|
376
|
+
const res = new ResizeObserver(handle_resize);
|
|
377
|
+
|
|
378
|
+
mut.observe(root_container, {
|
|
379
|
+
childList: true,
|
|
380
|
+
subtree: true,
|
|
381
|
+
attributes: true
|
|
382
|
+
});
|
|
383
|
+
res.observe(root_container);
|
|
384
|
+
|
|
385
|
+
app_tree.ready.then(() => {
|
|
386
|
+
ready = true;
|
|
387
|
+
dep_manager.dispatch_load_events();
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
return () => {
|
|
391
|
+
mut.disconnect();
|
|
392
|
+
res.disconnect();
|
|
393
|
+
};
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
function handle_close(id: number): void {
|
|
397
|
+
messages = messages.filter((m) => m.id !== id);
|
|
398
|
+
}
|
|
865
399
|
</script>
|
|
866
400
|
|
|
867
401
|
<svelte:head>
|
|
@@ -880,167 +414,150 @@ onMount(() => {
|
|
|
880
414
|
bind:this={root_container}
|
|
881
415
|
style:margin-right={vibe_mode ? `${vibe_editor_width}px` : "0"}
|
|
882
416
|
>
|
|
883
|
-
{
|
|
884
|
-
<MountComponents
|
|
885
|
-
rootNode={$_layout}
|
|
886
|
-
{root}
|
|
887
|
-
{target}
|
|
888
|
-
{theme_mode}
|
|
889
|
-
on:mount={handle_mount}
|
|
890
|
-
{version}
|
|
891
|
-
{autoscroll}
|
|
892
|
-
{max_file_size}
|
|
893
|
-
client={app}
|
|
894
|
-
/>
|
|
895
|
-
{/if}
|
|
896
|
-
</div>
|
|
417
|
+
<MountComponents node={app_tree.root} />
|
|
897
418
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
419
|
+
{#if footer_links.length > 0}
|
|
420
|
+
<footer bind:clientHeight={footer_height}>
|
|
421
|
+
{#if footer_links.includes("api")}
|
|
422
|
+
<button
|
|
423
|
+
on:click={() => {
|
|
424
|
+
set_api_docs_visible(!api_docs_visible);
|
|
425
|
+
}}
|
|
426
|
+
on:mouseenter={() => {
|
|
427
|
+
loadApiDocs();
|
|
428
|
+
loadApiRecorder();
|
|
429
|
+
}}
|
|
430
|
+
class="show-api"
|
|
431
|
+
>
|
|
432
|
+
{#if app.config?.mcp_server}
|
|
433
|
+
{$_("errors.use_via_api_or_mcp")}
|
|
434
|
+
{:else}
|
|
435
|
+
{$_("errors.use_via_api")}
|
|
436
|
+
{/if}
|
|
437
|
+
<img src={api_logo} alt={$_("common.logo")} />
|
|
438
|
+
</button>
|
|
439
|
+
{/if}
|
|
440
|
+
{#if footer_links.includes("gradio")}
|
|
441
|
+
<div class="divider show-api-divider">·</div>
|
|
442
|
+
<a
|
|
443
|
+
href="https://gradio.app"
|
|
444
|
+
class="built-with"
|
|
445
|
+
target="_blank"
|
|
446
|
+
rel="noreferrer"
|
|
447
|
+
>
|
|
448
|
+
{$_("common.built_with_gradio")}
|
|
449
|
+
<img src={logo} alt={$_("common.logo")} />
|
|
450
|
+
</a>
|
|
451
|
+
{/if}
|
|
901
452
|
<button
|
|
453
|
+
class:hidden={!$is_screen_recording}
|
|
902
454
|
on:click={() => {
|
|
903
|
-
|
|
455
|
+
screen_recording();
|
|
904
456
|
}}
|
|
905
|
-
|
|
906
|
-
loadApiDocs();
|
|
907
|
-
loadApiRecorder();
|
|
908
|
-
}}
|
|
909
|
-
class="show-api"
|
|
910
|
-
>
|
|
911
|
-
{#if app.config?.mcp_server}
|
|
912
|
-
{$_("errors.use_via_api_or_mcp")}
|
|
913
|
-
{:else}
|
|
914
|
-
{$_("errors.use_via_api")}
|
|
915
|
-
{/if}
|
|
916
|
-
<img src={api_logo} alt={$_("common.logo")} />
|
|
917
|
-
</button>
|
|
918
|
-
{/if}
|
|
919
|
-
{#if footer_links.includes("gradio")}
|
|
920
|
-
<div class="divider show-api-divider">·</div>
|
|
921
|
-
<a
|
|
922
|
-
href="https://gradio.app"
|
|
923
|
-
class="built-with"
|
|
924
|
-
target="_blank"
|
|
925
|
-
rel="noreferrer"
|
|
926
|
-
>
|
|
927
|
-
{$_("common.built_with_gradio")}
|
|
928
|
-
<img src={logo} alt={$_("common.logo")} />
|
|
929
|
-
</a>
|
|
930
|
-
{/if}
|
|
931
|
-
<button
|
|
932
|
-
class:hidden={!$is_screen_recording}
|
|
933
|
-
on:click={() => {
|
|
934
|
-
screen_recording();
|
|
935
|
-
}}
|
|
936
|
-
class="record"
|
|
937
|
-
>
|
|
938
|
-
{$_("common.stop_recording")}
|
|
939
|
-
<img src={record_stop} alt={$_("common.stop_recording")} />
|
|
940
|
-
</button>
|
|
941
|
-
<div class="divider">·</div>
|
|
942
|
-
{#if footer_links.includes("settings")}
|
|
943
|
-
<div class="divider" class:hidden={!$is_screen_recording}>·</div>
|
|
944
|
-
<button
|
|
945
|
-
on:click={() => {
|
|
946
|
-
set_settings_visible(!settings_visible);
|
|
947
|
-
}}
|
|
948
|
-
on:mouseenter={() => {
|
|
949
|
-
loadSettings();
|
|
950
|
-
}}
|
|
951
|
-
class="settings"
|
|
457
|
+
class="record"
|
|
952
458
|
>
|
|
953
|
-
{$_("common.
|
|
954
|
-
<img src={
|
|
459
|
+
{$_("common.stop_recording")}
|
|
460
|
+
<img src={record_stop} alt={$_("common.stop_recording")} />
|
|
955
461
|
</button>
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
462
|
+
<div class="divider">·</div>
|
|
463
|
+
{#if footer_links.includes("settings")}
|
|
464
|
+
<div class="divider" class:hidden={!$is_screen_recording}>·</div>
|
|
465
|
+
<button
|
|
466
|
+
on:click={() => {
|
|
467
|
+
set_settings_visible(!settings_visible);
|
|
468
|
+
}}
|
|
469
|
+
on:mouseenter={() => {
|
|
470
|
+
loadSettings();
|
|
471
|
+
}}
|
|
472
|
+
class="settings"
|
|
473
|
+
>
|
|
474
|
+
{$_("common.settings")}
|
|
475
|
+
<img src={settings_logo} alt={$_("common.settings")} />
|
|
476
|
+
</button>
|
|
477
|
+
{/if}
|
|
478
|
+
</footer>
|
|
479
|
+
{/if}
|
|
973
480
|
</div>
|
|
974
|
-
{
|
|
975
|
-
|
|
976
|
-
{#if api_docs_visible && $_layout && ApiDocs}
|
|
977
|
-
<div class="api-docs">
|
|
481
|
+
{#if api_recorder_visible && ApiRecorder}
|
|
978
482
|
<!-- TODO: fix -->
|
|
979
483
|
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
980
484
|
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
981
485
|
<div
|
|
982
|
-
|
|
486
|
+
id="api-recorder-container"
|
|
983
487
|
on:click={() => {
|
|
984
|
-
set_api_docs_visible(
|
|
488
|
+
set_api_docs_visible(true);
|
|
489
|
+
api_recorder_visible = false;
|
|
985
490
|
}}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
491
|
+
>
|
|
492
|
+
<svelte:component this={ApiRecorder} {api_calls} {dependencies} />
|
|
493
|
+
</div>
|
|
494
|
+
{/if}
|
|
495
|
+
|
|
496
|
+
{#if api_docs_visible && app_tree.root && ApiDocs}
|
|
497
|
+
<div class="api-docs">
|
|
498
|
+
<!-- TODO: fix -->
|
|
499
|
+
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
500
|
+
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
501
|
+
<div
|
|
502
|
+
class="backdrop"
|
|
503
|
+
on:click={() => {
|
|
992
504
|
set_api_docs_visible(false);
|
|
993
|
-
api_calls = [];
|
|
994
|
-
api_recorder_visible = api_recorder_visible =
|
|
995
|
-
event.detail?.api_recorder_visible;
|
|
996
505
|
}}
|
|
997
|
-
{dependencies}
|
|
998
|
-
{root}
|
|
999
|
-
{app}
|
|
1000
|
-
{space_id}
|
|
1001
|
-
{api_calls}
|
|
1002
|
-
{username}
|
|
1003
506
|
/>
|
|
507
|
+
<div class="api-docs-wrap">
|
|
508
|
+
<svelte:component
|
|
509
|
+
this={ApiDocs}
|
|
510
|
+
root_node={app_tree.root}
|
|
511
|
+
on:close={(event) => {
|
|
512
|
+
set_api_docs_visible(false);
|
|
513
|
+
api_calls = [];
|
|
514
|
+
api_recorder_visible = api_recorder_visible =
|
|
515
|
+
event.detail?.api_recorder_visible;
|
|
516
|
+
}}
|
|
517
|
+
{dependencies}
|
|
518
|
+
{root}
|
|
519
|
+
{app}
|
|
520
|
+
{space_id}
|
|
521
|
+
{api_calls}
|
|
522
|
+
{username}
|
|
523
|
+
/>
|
|
524
|
+
</div>
|
|
1004
525
|
</div>
|
|
1005
|
-
|
|
1006
|
-
{/if}
|
|
526
|
+
{/if}
|
|
1007
527
|
|
|
1008
|
-
{#if settings_visible &&
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
set_settings_visible(false);
|
|
1017
|
-
}}
|
|
1018
|
-
/>
|
|
1019
|
-
<div class="api-docs-wrap">
|
|
1020
|
-
<svelte:component
|
|
1021
|
-
this={Settings}
|
|
1022
|
-
bind:allow_zoom
|
|
1023
|
-
bind:allow_video_trim
|
|
1024
|
-
on:close={() => {
|
|
528
|
+
{#if settings_visible && app.config && app_tree.root && Settings}
|
|
529
|
+
<div class="api-docs">
|
|
530
|
+
<!-- TODO: fix -->
|
|
531
|
+
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
532
|
+
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
533
|
+
<div
|
|
534
|
+
class="backdrop"
|
|
535
|
+
on:click={() => {
|
|
1025
536
|
set_settings_visible(false);
|
|
1026
537
|
}}
|
|
1027
|
-
on:start_recording={() => {
|
|
1028
|
-
screen_recording();
|
|
1029
|
-
}}
|
|
1030
|
-
pwa_enabled={app.config.pwa}
|
|
1031
|
-
{root}
|
|
1032
|
-
{space_id}
|
|
1033
538
|
/>
|
|
539
|
+
<div class="api-docs-wrap">
|
|
540
|
+
<svelte:component
|
|
541
|
+
this={Settings}
|
|
542
|
+
bind:allow_zoom
|
|
543
|
+
bind:allow_video_trim
|
|
544
|
+
on:close={() => {
|
|
545
|
+
set_settings_visible(false);
|
|
546
|
+
}}
|
|
547
|
+
on:start_recording={() => {
|
|
548
|
+
screen_recording();
|
|
549
|
+
}}
|
|
550
|
+
pwa_enabled={app.config.pwa}
|
|
551
|
+
{root}
|
|
552
|
+
{space_id}
|
|
553
|
+
/>
|
|
554
|
+
</div>
|
|
1034
555
|
</div>
|
|
1035
|
-
|
|
1036
|
-
|
|
556
|
+
{/if}
|
|
557
|
+
</div>
|
|
1037
558
|
|
|
1038
559
|
{#if messages}
|
|
1039
|
-
<Toast {messages}
|
|
1040
|
-
{/if}
|
|
1041
|
-
|
|
1042
|
-
{#if vibe_mode && VibeEditor}
|
|
1043
|
-
<svelte:component this={VibeEditor} {app} {root} />
|
|
560
|
+
<Toast {messages} on_close={handle_close} />
|
|
1044
561
|
{/if}
|
|
1045
562
|
|
|
1046
563
|
<style>
|