@gradio/core 0.29.2 → 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 +103 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/Blocks.svelte +518 -999
- package/dist/src/Blocks.svelte.d.ts +31 -46
- 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 +338 -246
- 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 +8 -5
- 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 +29 -25
- package/index.ts +1 -1
- package/package.json +59 -59
- package/src/Blocks.svelte +344 -1059
- package/src/MountComponents.svelte +17 -27
- package/src/{init.ts → _init.ts} +49 -126
- package/src/api_docs/ApiDocs.svelte +67 -62
- 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/NoApi.svelte +1 -1
- 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,869 +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
|
-
|
|
225
|
-
let
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const
|
|
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
|
-
// @ts-ignore
|
|
400
|
-
`${app.config.root + app.config.api_prefix}/stream/${submit_map.get(dep_index).event_id()}`,
|
|
401
|
-
{ ...payload2, session_hash: app.session_hash }
|
|
402
|
-
);
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
try {
|
|
407
|
-
submission = app.submit(
|
|
408
|
-
payload2.fn_index,
|
|
409
|
-
payload2.data,
|
|
410
|
-
payload2.event_data,
|
|
411
|
-
payload2.trigger_id
|
|
412
|
-
);
|
|
413
|
-
} catch (e) {
|
|
414
|
-
const fn_index = 0;
|
|
415
|
-
if (app.closed) return;
|
|
416
|
-
messages = [
|
|
417
|
-
new_message("Error", String(e), fn_index, "error"),
|
|
418
|
-
...messages
|
|
419
|
-
];
|
|
420
|
-
loading_status.update({
|
|
421
|
-
status: "error",
|
|
422
|
-
fn_index,
|
|
423
|
-
eta: 0,
|
|
424
|
-
queue: false,
|
|
425
|
-
queue_position: null
|
|
426
|
-
});
|
|
427
|
-
set_status($loading_status);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
submit_map.set(dep_index, submission);
|
|
431
|
-
for await (const message of submission) {
|
|
432
|
-
if (payload2.js_implementation) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
if (message.type === "data") {
|
|
436
|
-
handle_data(message);
|
|
437
|
-
} else if (message.type === "render") {
|
|
438
|
-
handle_render(message);
|
|
439
|
-
} else if (message.type === "status") {
|
|
440
|
-
handle_status_update(message);
|
|
441
|
-
} else if (message.type === "log") {
|
|
442
|
-
handle_log(message);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
function handle_data(message) {
|
|
446
|
-
const { data, fn_index } = message;
|
|
447
|
-
if (dep.pending_request && dep.final_event) {
|
|
448
|
-
dep.pending_request = false;
|
|
449
|
-
make_prediction(dep.final_event, dep.connection == "stream");
|
|
450
|
-
}
|
|
451
|
-
dep.pending_request = false;
|
|
452
|
-
handle_update(data, fn_index);
|
|
453
|
-
set_status($loading_status);
|
|
454
|
-
}
|
|
455
|
-
function handle_render(message) {
|
|
456
|
-
const { data } = message;
|
|
457
|
-
let _components = data.components;
|
|
458
|
-
let render_layout = data.layout;
|
|
459
|
-
let _dependencies = data.dependencies;
|
|
460
|
-
let render_id = data.render_id;
|
|
461
|
-
let deps_to_remove = [];
|
|
462
|
-
dependencies.forEach((old_dep, i) => {
|
|
463
|
-
if (old_dep.rendered_in === dep.render_id) {
|
|
464
|
-
deps_to_remove.push(i);
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
deps_to_remove.reverse().forEach((i) => {
|
|
468
|
-
dependencies.splice(i, 1);
|
|
469
|
-
});
|
|
470
|
-
_dependencies.forEach((dep2) => {
|
|
471
|
-
dependencies.push(dep2);
|
|
472
|
-
});
|
|
473
|
-
rerender_layout({
|
|
474
|
-
components: _components,
|
|
475
|
-
layout: render_layout,
|
|
476
|
-
root: root + api_prefix,
|
|
477
|
-
dependencies,
|
|
478
|
-
render_id
|
|
479
|
-
});
|
|
480
|
-
_dependencies.forEach((dep2) => {
|
|
481
|
-
if (dep2.targets.some((dep3) => dep3[1] === "load")) {
|
|
482
|
-
wait_then_trigger_api_call(dep2.id);
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
function handle_log(msg) {
|
|
487
|
-
const { title: title2, log, fn_index, level, duration, visible } = msg;
|
|
488
|
-
messages = [
|
|
489
|
-
new_message(title2, log, fn_index, level, duration, visible),
|
|
490
|
-
...messages
|
|
491
|
-
];
|
|
492
|
-
}
|
|
493
|
-
function open_stream_events(status, id, dep2) {
|
|
494
|
-
if (status.original_msg === "process_starts" && dep2.connection === "stream") {
|
|
495
|
-
modify_stream(id, "open");
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function handle_status_update(message) {
|
|
499
|
-
if (message.code === "validation_error") {
|
|
500
|
-
const dep2 = dependencies.find((dep3) => dep3.id === message.fn_index);
|
|
501
|
-
if (dep2 === void 0 || message.message === void 0 || typeof message.message === "string") {
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
const validation_error_data = [];
|
|
505
|
-
message.message.forEach((message2, i) => {
|
|
506
|
-
if (message2.is_valid) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
validation_error_data.push({
|
|
510
|
-
id: dep2.inputs[i],
|
|
511
|
-
prop: "validation_error",
|
|
512
|
-
value: message2.message
|
|
513
|
-
});
|
|
514
|
-
validation_error_data.push({
|
|
515
|
-
id: dep2.inputs[i],
|
|
516
|
-
prop: "loading_status",
|
|
517
|
-
value: { validation_error: message2.message }
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
if (validation_error_data.length > 0) {
|
|
521
|
-
update_value(validation_error_data);
|
|
522
|
-
loading_status.update({
|
|
523
|
-
status: "complete",
|
|
524
|
-
fn_index: message.fn_index,
|
|
525
|
-
eta: 0,
|
|
526
|
-
queue: false,
|
|
527
|
-
queue_position: null
|
|
528
|
-
});
|
|
529
|
-
set_status($loading_status);
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (message.broken && !broken_connection) {
|
|
534
|
-
messages = [
|
|
535
|
-
new_message(
|
|
536
|
-
"Broken Connection",
|
|
537
|
-
LOST_CONNECTION_MESSAGE,
|
|
538
|
-
-1,
|
|
539
|
-
"error",
|
|
540
|
-
null,
|
|
541
|
-
true
|
|
542
|
-
),
|
|
543
|
-
...messages
|
|
544
|
-
];
|
|
545
|
-
broken_connection = true;
|
|
546
|
-
setTimeout(reconnect, 1e3);
|
|
547
|
-
}
|
|
548
|
-
if (message.session_not_found) {
|
|
549
|
-
messages = [
|
|
550
|
-
new_message(
|
|
551
|
-
"Session Not Found",
|
|
552
|
-
SESSION_NOT_FOUND_MESSAGE,
|
|
553
|
-
-1,
|
|
554
|
-
"error",
|
|
555
|
-
null,
|
|
556
|
-
true
|
|
557
|
-
),
|
|
558
|
-
...messages
|
|
559
|
-
];
|
|
560
|
-
}
|
|
561
|
-
const { fn_index, ...status } = message;
|
|
562
|
-
if (status.stage === "streaming" && status.time_limit) {
|
|
563
|
-
dep.inputs.forEach((id) => {
|
|
564
|
-
set_time_limit(id, status.time_limit);
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
dep.inputs.forEach((id) => {
|
|
568
|
-
open_stream_events(message, id, dep);
|
|
569
|
-
});
|
|
570
|
-
loading_status.update({
|
|
571
|
-
...status,
|
|
572
|
-
time_limit: status.time_limit,
|
|
573
|
-
status: status.stage,
|
|
574
|
-
progress: status.progress_data,
|
|
575
|
-
fn_index
|
|
576
|
-
});
|
|
577
|
-
set_status($loading_status);
|
|
578
|
-
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) {
|
|
579
|
-
showed_duplicate_message = true;
|
|
580
|
-
messages = [
|
|
581
|
-
new_message("Warning", DUPLICATE_MESSAGE, fn_index, "warning"),
|
|
582
|
-
...messages
|
|
583
|
-
];
|
|
584
|
-
}
|
|
585
|
-
if (!showed_mobile_warning && is_mobile_device && status.eta !== void 0 && status.eta > SHOW_MOBILE_QUEUE_WARNING_ON_ETA) {
|
|
586
|
-
showed_mobile_warning = true;
|
|
587
|
-
messages = [
|
|
588
|
-
new_message("Warning", MOBILE_QUEUE_WARNING, fn_index, "warning"),
|
|
589
|
-
...messages
|
|
590
|
-
];
|
|
591
|
-
}
|
|
592
|
-
if (status.stage === "complete" || status.stage === "generating") {
|
|
593
|
-
const deps_triggered_by_state = /* @__PURE__ */ new Set();
|
|
594
|
-
status.changed_state_ids?.forEach((id) => {
|
|
595
|
-
dependencies.filter((dep2) => dep2.targets.some(([_id, _2]) => _id === id)).forEach((dep2) => {
|
|
596
|
-
deps_triggered_by_state.add(dep2);
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
deps_triggered_by_state.forEach((dep2) => {
|
|
600
|
-
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
if (status.stage === "complete") {
|
|
604
|
-
dependencies.forEach(async (dep2) => {
|
|
605
|
-
if (dep2.trigger_after === fn_index && !dep2.trigger_only_on_failure) {
|
|
606
|
-
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
dep.inputs.forEach((id) => {
|
|
610
|
-
modify_stream(id, "closed");
|
|
611
|
-
});
|
|
612
|
-
submit_map.delete(dep_index);
|
|
613
|
-
}
|
|
614
|
-
if (status.stage === "error" && !broken_connection && !message.session_not_found) {
|
|
615
|
-
if (status.message && typeof status.message === "string") {
|
|
616
|
-
const _message = status.message.replace(
|
|
617
|
-
MESSAGE_QUOTE_RE,
|
|
618
|
-
(_2, b) => b
|
|
619
|
-
);
|
|
620
|
-
const _title = status.title ?? "Error";
|
|
621
|
-
messages = [
|
|
622
|
-
new_message(
|
|
623
|
-
_title,
|
|
624
|
-
_message,
|
|
625
|
-
fn_index,
|
|
626
|
-
"error",
|
|
627
|
-
status.duration,
|
|
628
|
-
status.visible
|
|
629
|
-
),
|
|
630
|
-
...messages
|
|
631
|
-
];
|
|
632
|
-
}
|
|
633
|
-
dependencies.map(async (dep2) => {
|
|
634
|
-
if (dep2.trigger_after === fn_index && (!dep2.trigger_only_on_success || dep2.trigger_only_on_failure)) {
|
|
635
|
-
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (allow_video_trim) {
|
|
641
|
-
screen_recorder.markRemoveSegmentEnd();
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
function trigger_share(title2, description) {
|
|
646
|
-
if (space_id === null) {
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
const discussion_url = new URL(
|
|
650
|
-
`https://huggingface.co/spaces/${space_id}/discussions/new`
|
|
651
|
-
);
|
|
652
|
-
if (title2 !== void 0 && title2.length > 0) {
|
|
653
|
-
discussion_url.searchParams.set("title", title2);
|
|
654
|
-
}
|
|
655
|
-
discussion_url.searchParams.set("description", description);
|
|
656
|
-
window.open(discussion_url.toString(), "_blank");
|
|
657
|
-
}
|
|
658
|
-
function handle_error_close(e) {
|
|
659
|
-
const _id = e.detail;
|
|
660
|
-
messages = messages.filter((m) => m.id !== _id);
|
|
661
|
-
}
|
|
662
|
-
const is_external_url = (link) => !!(link && new URL(link, location.href).origin !== location.origin);
|
|
663
|
-
async function handle_mount() {
|
|
664
|
-
if (js) {
|
|
665
|
-
let blocks_frontend_fn = new AsyncFunction(
|
|
666
|
-
`let result = await (${js})();
|
|
667
|
-
return (!Array.isArray(result)) ? [result] : result;`
|
|
668
|
-
);
|
|
669
|
-
await blocks_frontend_fn();
|
|
670
|
-
}
|
|
671
|
-
await tick();
|
|
672
|
-
var a = target.getElementsByTagName("a");
|
|
673
|
-
for (var i = 0; i < a.length; i++) {
|
|
674
|
-
const _target = a[i].getAttribute("target");
|
|
675
|
-
const _link = a[i].getAttribute("href");
|
|
676
|
-
if (is_external_url(_link) && _target !== "_blank")
|
|
677
|
-
a[i].setAttribute("target", "_blank");
|
|
678
|
-
}
|
|
679
|
-
handle_load_triggers();
|
|
680
|
-
if (!target || render_complete) return;
|
|
681
|
-
target.addEventListener("prop_change", (e) => {
|
|
682
|
-
if (!isCustomEvent(e)) throw new Error("not a custom event");
|
|
683
|
-
const { id, prop, value } = e.detail;
|
|
684
|
-
if (prop === "value") {
|
|
685
|
-
update_value([
|
|
686
|
-
{
|
|
687
|
-
id,
|
|
688
|
-
prop: "loading_status",
|
|
689
|
-
value: { validation_error: void 0 }
|
|
690
|
-
}
|
|
691
|
-
]);
|
|
692
|
-
}
|
|
693
|
-
update_value([{ id, prop, value }]);
|
|
694
|
-
if (prop === "input_ready" && value === false) {
|
|
695
|
-
inputs_waiting.push(id);
|
|
696
|
-
}
|
|
697
|
-
if (prop === "input_ready" && value === true) {
|
|
698
|
-
inputs_waiting = inputs_waiting.filter((item) => item !== id);
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
target.addEventListener("gradio", (e) => {
|
|
702
|
-
if (!isCustomEvent(e)) throw new Error("not a custom event");
|
|
703
|
-
const { id, event, data } = e.detail;
|
|
704
|
-
if (event === "share") {
|
|
705
|
-
const { title: title2, description } = data;
|
|
706
|
-
trigger_share(title2, description);
|
|
707
|
-
} else if (event === "error") {
|
|
708
|
-
messages = [new_message("Error", data, -1, event), ...messages];
|
|
709
|
-
} else if (event === "warning") {
|
|
710
|
-
messages = [new_message("Warning", data, -1, event), ...messages];
|
|
711
|
-
} else if (event === "info") {
|
|
712
|
-
messages = [new_message("Info", data, -1, event), ...messages];
|
|
713
|
-
} else if (event == "clear_status") {
|
|
714
|
-
update_status(id, "complete", data);
|
|
715
|
-
} else if (event == "close_stream") {
|
|
716
|
-
const deps = $targets[id]?.[data];
|
|
717
|
-
deps?.forEach((dep_id) => {
|
|
718
|
-
if (submit_map.has(dep_id)) {
|
|
719
|
-
const url = `${app.config.root + app.config.api_prefix}/stream/${submit_map.get(dep_id).event_id()}`;
|
|
720
|
-
app.post_data(`${url}/close`, {});
|
|
721
|
-
app.close_ws(url);
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
} else {
|
|
725
|
-
const deps = $targets[id]?.[event];
|
|
726
|
-
deps?.forEach((dep_id) => {
|
|
727
|
-
requestAnimationFrame(() => {
|
|
728
|
-
wait_then_trigger_api_call(dep_id, id, data);
|
|
729
|
-
});
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
render_complete = true;
|
|
734
|
-
}
|
|
735
|
-
value_change((id, value) => {
|
|
736
|
-
const deps = $targets[id]?.["change"];
|
|
737
|
-
deps?.forEach((dep_id) => {
|
|
738
|
-
requestAnimationFrame(() => {
|
|
739
|
-
wait_then_trigger_api_call(dep_id, id, value);
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
const handle_load_triggers = () => {
|
|
744
|
-
dependencies.forEach((dep) => {
|
|
745
|
-
if (dep.targets.some((dep2) => dep2[1] === "load")) {
|
|
746
|
-
wait_then_trigger_api_call(dep.id);
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
};
|
|
750
|
-
$: set_status($loading_status);
|
|
751
|
-
function update_status(id, status, data) {
|
|
752
|
-
data.status = status;
|
|
753
|
-
update_value([
|
|
754
|
-
{
|
|
755
|
-
id,
|
|
756
|
-
prop: "loading_status",
|
|
757
|
-
value: data
|
|
758
|
-
}
|
|
759
|
-
]);
|
|
760
|
-
}
|
|
761
|
-
function set_status(statuses) {
|
|
762
|
-
let updates = [];
|
|
763
|
-
Object.entries(statuses).forEach(([id, loading_status2]) => {
|
|
764
|
-
if (app.closed && loading_status2.status === "error") {
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
let dependency = dependencies.find(
|
|
768
|
-
(dep) => dep.id == loading_status2.fn_index
|
|
769
|
-
);
|
|
770
|
-
if (dependency === void 0) {
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
loading_status2.scroll_to_output = dependency.scroll_to_output;
|
|
774
|
-
loading_status2.show_progress = dependency.show_progress;
|
|
775
|
-
updates.push({
|
|
776
|
-
id: parseInt(id),
|
|
777
|
-
prop: "loading_status",
|
|
778
|
-
value: loading_status2
|
|
779
|
-
});
|
|
780
|
-
});
|
|
781
|
-
const inputs_to_update = loading_status.get_inputs_to_update();
|
|
782
|
-
const additional_updates = Array.from(inputs_to_update).map(
|
|
783
|
-
([id, pending_status]) => {
|
|
784
|
-
return {
|
|
785
|
-
id,
|
|
786
|
-
prop: "pending",
|
|
787
|
-
value: pending_status === "pending"
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
);
|
|
791
|
-
update_value([...updates, ...additional_updates]);
|
|
792
|
-
}
|
|
793
|
-
function isCustomEvent(event) {
|
|
794
|
-
return "detail" in event;
|
|
795
|
-
}
|
|
796
|
-
let is_screen_recording = writable(false);
|
|
797
|
-
onMount(() => {
|
|
798
|
-
is_mobile_device = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
799
|
-
navigator.userAgent
|
|
800
|
-
);
|
|
801
|
-
screen_recorder.initialize(
|
|
802
|
-
root,
|
|
803
|
-
(title2, message, type) => {
|
|
804
|
-
add_new_message(title2, message, type);
|
|
805
|
-
},
|
|
806
|
-
(isRecording) => {
|
|
807
|
-
$is_screen_recording = isRecording;
|
|
808
|
-
}
|
|
809
|
-
);
|
|
810
|
-
const handleVibeEditorResize = (event) => {
|
|
811
|
-
vibe_editor_width = event.detail.width;
|
|
812
|
-
};
|
|
813
|
-
window.addEventListener(
|
|
814
|
-
"vibeEditorResize",
|
|
815
|
-
handleVibeEditorResize
|
|
816
|
-
);
|
|
817
|
-
if (api_docs_visible) {
|
|
818
|
-
loadApiDocs();
|
|
819
|
-
}
|
|
820
|
-
if (api_recorder_visible) {
|
|
821
|
-
loadApiRecorder();
|
|
822
|
-
}
|
|
823
|
-
if (settings_visible) {
|
|
824
|
-
loadSettings();
|
|
825
|
-
}
|
|
826
|
-
if (vibe_mode) {
|
|
827
|
-
loadVibeEditor();
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
function screen_recording() {
|
|
831
|
-
if ($is_screen_recording) {
|
|
832
|
-
screen_recorder.stopRecording();
|
|
833
|
-
} else {
|
|
834
|
-
screen_recorder.startRecording();
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
let footer_height = 0;
|
|
838
|
-
let root_container;
|
|
839
|
-
function get_root_node(container) {
|
|
840
|
-
if (!container) return null;
|
|
841
|
-
return container.children[container.children.length - 1];
|
|
842
|
-
}
|
|
843
|
-
function handle_resize() {
|
|
844
|
-
if ("parentIFrame" in window) {
|
|
845
|
-
const box = root_container.children[0].getBoundingClientRect();
|
|
846
|
-
if (!box) return;
|
|
847
|
-
window.parentIFrame?.size(box.bottom + footer_height + 32);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
onMount(() => {
|
|
851
|
-
if ("parentIFrame" in window) {
|
|
852
|
-
window.parentIFrame?.autoResize(false);
|
|
853
|
-
}
|
|
854
|
-
const mut = new MutationObserver(handle_resize);
|
|
855
|
-
const res = new ResizeObserver(handle_resize);
|
|
856
|
-
mut.observe(root_container, {
|
|
857
|
-
childList: true,
|
|
858
|
-
subtree: true,
|
|
859
|
-
attributes: true
|
|
860
|
-
});
|
|
861
|
-
res.observe(root_container);
|
|
862
|
-
return () => {
|
|
863
|
-
mut.disconnect();
|
|
864
|
-
res.disconnect();
|
|
865
|
-
};
|
|
866
|
-
});
|
|
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
|
+
}
|
|
867
399
|
</script>
|
|
868
400
|
|
|
869
401
|
<svelte:head>
|
|
@@ -882,163 +414,150 @@ onMount(() => {
|
|
|
882
414
|
bind:this={root_container}
|
|
883
415
|
style:margin-right={vibe_mode ? `${vibe_editor_width}px` : "0"}
|
|
884
416
|
>
|
|
885
|
-
{
|
|
886
|
-
<MountComponents
|
|
887
|
-
rootNode={$_layout}
|
|
888
|
-
{root}
|
|
889
|
-
{target}
|
|
890
|
-
{theme_mode}
|
|
891
|
-
on:mount={handle_mount}
|
|
892
|
-
{version}
|
|
893
|
-
{autoscroll}
|
|
894
|
-
{max_file_size}
|
|
895
|
-
client={app}
|
|
896
|
-
/>
|
|
897
|
-
{/if}
|
|
898
|
-
</div>
|
|
417
|
+
<MountComponents node={app_tree.root} />
|
|
899
418
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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}
|
|
903
452
|
<button
|
|
453
|
+
class:hidden={!$is_screen_recording}
|
|
904
454
|
on:click={() => {
|
|
905
|
-
|
|
455
|
+
screen_recording();
|
|
906
456
|
}}
|
|
907
|
-
|
|
908
|
-
loadApiDocs();
|
|
909
|
-
loadApiRecorder();
|
|
910
|
-
}}
|
|
911
|
-
class="show-api"
|
|
457
|
+
class="record"
|
|
912
458
|
>
|
|
913
|
-
{
|
|
914
|
-
|
|
915
|
-
{:else}
|
|
916
|
-
{$_("errors.use_via_api")}
|
|
917
|
-
{/if}
|
|
918
|
-
<img src={api_logo} alt={$_("common.logo")} />
|
|
459
|
+
{$_("common.stop_recording")}
|
|
460
|
+
<img src={record_stop} alt={$_("common.stop_recording")} />
|
|
919
461
|
</button>
|
|
920
|
-
<div class="divider
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
>
|
|
939
|
-
{$_("common.stop_recording")}
|
|
940
|
-
<img src={record_stop} alt={$_("common.stop_recording")} />
|
|
941
|
-
</button>
|
|
942
|
-
<div class="divider">·</div>
|
|
943
|
-
<button
|
|
944
|
-
on:click={() => {
|
|
945
|
-
set_settings_visible(!settings_visible);
|
|
946
|
-
}}
|
|
947
|
-
on:mouseenter={() => {
|
|
948
|
-
loadSettings();
|
|
949
|
-
}}
|
|
950
|
-
class="settings"
|
|
951
|
-
>
|
|
952
|
-
{$_("common.settings")}
|
|
953
|
-
<img src={settings_logo} alt={$_("common.settings")} />
|
|
954
|
-
</button>
|
|
955
|
-
</footer>
|
|
956
|
-
{/if}
|
|
957
|
-
</div>
|
|
958
|
-
|
|
959
|
-
{#if api_recorder_visible && ApiRecorder}
|
|
960
|
-
<!-- TODO: fix -->
|
|
961
|
-
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
962
|
-
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
963
|
-
<div
|
|
964
|
-
id="api-recorder-container"
|
|
965
|
-
on:click={() => {
|
|
966
|
-
set_api_docs_visible(true);
|
|
967
|
-
api_recorder_visible = false;
|
|
968
|
-
}}
|
|
969
|
-
>
|
|
970
|
-
<svelte:component this={ApiRecorder} {api_calls} {dependencies} />
|
|
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}
|
|
971
480
|
</div>
|
|
972
|
-
{
|
|
973
|
-
|
|
974
|
-
{#if api_docs_visible && $_layout && ApiDocs}
|
|
975
|
-
<div class="api-docs">
|
|
481
|
+
{#if api_recorder_visible && ApiRecorder}
|
|
976
482
|
<!-- TODO: fix -->
|
|
977
483
|
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
978
484
|
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
979
485
|
<div
|
|
980
|
-
|
|
486
|
+
id="api-recorder-container"
|
|
981
487
|
on:click={() => {
|
|
982
|
-
set_api_docs_visible(
|
|
488
|
+
set_api_docs_visible(true);
|
|
489
|
+
api_recorder_visible = false;
|
|
983
490
|
}}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
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={() => {
|
|
990
504
|
set_api_docs_visible(false);
|
|
991
|
-
api_calls = [];
|
|
992
|
-
api_recorder_visible = api_recorder_visible =
|
|
993
|
-
event.detail?.api_recorder_visible;
|
|
994
505
|
}}
|
|
995
|
-
{dependencies}
|
|
996
|
-
{root}
|
|
997
|
-
{app}
|
|
998
|
-
{space_id}
|
|
999
|
-
{api_calls}
|
|
1000
|
-
{username}
|
|
1001
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>
|
|
1002
525
|
</div>
|
|
1003
|
-
|
|
1004
|
-
{/if}
|
|
526
|
+
{/if}
|
|
1005
527
|
|
|
1006
|
-
{#if settings_visible &&
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
set_settings_visible(false);
|
|
1015
|
-
}}
|
|
1016
|
-
/>
|
|
1017
|
-
<div class="api-docs-wrap">
|
|
1018
|
-
<svelte:component
|
|
1019
|
-
this={Settings}
|
|
1020
|
-
bind:allow_zoom
|
|
1021
|
-
bind:allow_video_trim
|
|
1022
|
-
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={() => {
|
|
1023
536
|
set_settings_visible(false);
|
|
1024
537
|
}}
|
|
1025
|
-
on:start_recording={() => {
|
|
1026
|
-
screen_recording();
|
|
1027
|
-
}}
|
|
1028
|
-
pwa_enabled={app.config.pwa}
|
|
1029
|
-
{root}
|
|
1030
|
-
{space_id}
|
|
1031
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>
|
|
1032
555
|
</div>
|
|
1033
|
-
|
|
1034
|
-
|
|
556
|
+
{/if}
|
|
557
|
+
</div>
|
|
1035
558
|
|
|
1036
559
|
{#if messages}
|
|
1037
|
-
<Toast {messages}
|
|
1038
|
-
{/if}
|
|
1039
|
-
|
|
1040
|
-
{#if vibe_mode && VibeEditor}
|
|
1041
|
-
<svelte:component this={VibeEditor} {app} {root} />
|
|
560
|
+
<Toast {messages} on_close={handle_close} />
|
|
1042
561
|
{/if}
|
|
1043
562
|
|
|
1044
563
|
<style>
|