@gradio/core 0.0.2 → 0.0.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 +30 -0
- package/dist/blocks.d.ts +1 -0
- package/dist/blocks.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/login.d.ts +1 -0
- package/dist/login.js +1 -0
- package/dist/src/Blocks.svelte +671 -0
- package/dist/src/Blocks.svelte.d.ts +41 -0
- package/dist/src/Embed.svelte +195 -0
- package/dist/src/Embed.svelte.d.ts +26 -0
- package/dist/src/Login.svelte +107 -0
- package/dist/src/Login.svelte.d.ts +19 -0
- package/dist/src/MountComponents.svelte +26 -0
- package/dist/src/MountComponents.svelte.d.ts +26 -0
- package/dist/src/Render.svelte +91 -0
- package/dist/src/Render.svelte.d.ts +29 -0
- package/dist/src/RenderComponent.svelte +51 -0
- package/dist/src/RenderComponent.svelte.d.ts +32 -0
- package/dist/src/api_docs/ApiBanner.svelte +115 -0
- package/dist/src/api_docs/ApiBanner.svelte.d.ts +19 -0
- package/dist/src/api_docs/ApiDocs.svelte +388 -0
- package/dist/src/api_docs/ApiDocs.svelte.d.ts +27 -0
- package/dist/src/api_docs/ApiRecorder.svelte +72 -0
- package/dist/src/api_docs/ApiRecorder.svelte.d.ts +18 -0
- package/dist/src/api_docs/CodeSnippet.svelte +184 -0
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +24 -0
- package/dist/src/api_docs/CopyButton.svelte +15 -0
- package/dist/src/api_docs/CopyButton.svelte.d.ts +16 -0
- package/dist/src/api_docs/EndpointDetail.svelte +36 -0
- package/dist/src/api_docs/EndpointDetail.svelte.d.ts +18 -0
- package/dist/src/api_docs/InputPayload.svelte +149 -0
- package/dist/src/api_docs/InputPayload.svelte.d.ts +24 -0
- package/dist/src/api_docs/InstallSnippet.svelte +56 -0
- package/dist/src/api_docs/InstallSnippet.svelte.d.ts +16 -0
- package/dist/src/api_docs/NoApi.svelte +71 -0
- package/dist/src/api_docs/NoApi.svelte.d.ts +18 -0
- package/dist/src/api_docs/ParametersSnippet.svelte +104 -0
- package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +19 -0
- package/dist/src/api_docs/RecordingSnippet.svelte +210 -0
- package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +22 -0
- package/dist/src/api_docs/ResponseSnippet.svelte +95 -0
- package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +19 -0
- package/dist/src/api_docs/TryButton.svelte +17 -0
- package/dist/src/api_docs/TryButton.svelte.d.ts +17 -0
- package/dist/src/api_docs/img/api-logo.svg +4 -0
- package/dist/src/api_docs/img/bash.svg +8 -0
- package/dist/src/api_docs/img/clear.svelte +19 -0
- package/dist/src/api_docs/img/clear.svelte.d.ts +23 -0
- package/dist/src/api_docs/img/javascript.svg +16 -0
- package/dist/src/api_docs/img/python.svg +20 -0
- package/dist/src/api_docs/index.d.ts +2 -0
- package/dist/src/api_docs/index.js +2 -0
- package/dist/src/api_docs/utils.d.ts +2 -0
- package/dist/src/api_docs/utils.js +135 -0
- package/dist/src/css.d.ts +2 -0
- package/dist/src/css.js +93 -0
- package/dist/src/gradio_helper.js +4 -0
- package/dist/src/i18n.d.ts +6 -0
- package/dist/src/i18n.js +22 -0
- package/dist/src/images/lightning.svg +2 -0
- package/dist/src/images/logo.svg +19 -0
- package/dist/src/images/play.svg +2 -0
- package/dist/src/images/spaces.svg +7 -0
- package/dist/src/init.d.ts +107 -0
- package/dist/src/init.js +377 -0
- package/dist/src/lang/BCP47_codes.d.ts +2 -0
- package/dist/src/lang/BCP47_codes.js +58 -0
- package/dist/src/lang/ar.json +16 -0
- package/dist/src/lang/ca.json +19 -0
- package/dist/src/lang/ckb.json +108 -0
- package/dist/src/lang/de.json +16 -0
- package/dist/src/lang/en.json +118 -0
- package/dist/src/lang/es.json +17 -0
- package/dist/src/lang/eu.json +16 -0
- package/dist/src/lang/fa.json +16 -0
- package/dist/src/lang/fr.json +30 -0
- package/dist/src/lang/he.json +16 -0
- package/dist/src/lang/hi.json +16 -0
- package/dist/src/lang/ja.json +16 -0
- package/dist/src/lang/ko.json +16 -0
- package/dist/src/lang/lt.json +16 -0
- package/dist/src/lang/nl.json +16 -0
- package/dist/src/lang/pl.json +16 -0
- package/dist/src/lang/pt-BR.json +19 -0
- package/dist/src/lang/ru.json +118 -0
- package/dist/src/lang/ta.json +16 -0
- package/dist/src/lang/tr.json +16 -0
- package/dist/src/lang/uk.json +16 -0
- package/dist/src/lang/ur.json +16 -0
- package/dist/src/lang/uz.json +15 -0
- package/dist/src/lang/zh-CN.json +115 -0
- package/dist/src/lang/zh-TW.json +16 -0
- package/dist/src/s-blocks.d.ts +1 -0
- package/dist/src/s-blocks.js +1 -0
- package/dist/src/s-login.d.ts +1 -0
- package/dist/src/s-login.js +1 -0
- package/dist/src/stores.d.ts +30 -0
- package/dist/src/stores.js +93 -0
- package/dist/src/types.d.ts +95 -0
- package/dist/src/types.js +1 -0
- package/dist/src/vite-env-override.d.ts +20 -0
- package/package.json +71 -60
- package/src/Render.svelte +3 -1
- package/src/api_docs/ApiDocs.svelte +1 -1
- package/src/api_docs/ApiRecorder.svelte +1 -1
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
<script>import { tick } from "svelte";
|
|
2
|
+
import { _ } from "svelte-i18n";
|
|
3
|
+
import { Client } from "@gradio/client";
|
|
4
|
+
import { setupi18n } from "./i18n";
|
|
5
|
+
import { ApiDocs, ApiRecorder } from "./api_docs/";
|
|
6
|
+
import { Toast } from "@gradio/statustracker";
|
|
7
|
+
import MountComponents from "./MountComponents.svelte";
|
|
8
|
+
import logo from "./images/logo.svg";
|
|
9
|
+
import api_logo from "./api_docs/img/api-logo.svg";
|
|
10
|
+
import { create_components, AsyncFunction } from "./init";
|
|
11
|
+
setupi18n();
|
|
12
|
+
export let root;
|
|
13
|
+
export let components;
|
|
14
|
+
export let layout;
|
|
15
|
+
export let dependencies;
|
|
16
|
+
export let title = "Gradio";
|
|
17
|
+
export let target;
|
|
18
|
+
export let autoscroll;
|
|
19
|
+
export let show_api = true;
|
|
20
|
+
export let show_footer = true;
|
|
21
|
+
export let control_page_title = false;
|
|
22
|
+
export let app_mode;
|
|
23
|
+
export let theme_mode;
|
|
24
|
+
export let app;
|
|
25
|
+
export let space_id;
|
|
26
|
+
export let version;
|
|
27
|
+
export let js;
|
|
28
|
+
export let fill_height = false;
|
|
29
|
+
export let ready;
|
|
30
|
+
export let username;
|
|
31
|
+
const {
|
|
32
|
+
layout: _layout,
|
|
33
|
+
targets,
|
|
34
|
+
update_value,
|
|
35
|
+
get_data,
|
|
36
|
+
loading_status,
|
|
37
|
+
scheduled_updates,
|
|
38
|
+
create_layout,
|
|
39
|
+
rerender_layout
|
|
40
|
+
} = create_components();
|
|
41
|
+
$:
|
|
42
|
+
create_layout({
|
|
43
|
+
components,
|
|
44
|
+
layout,
|
|
45
|
+
dependencies,
|
|
46
|
+
root,
|
|
47
|
+
app,
|
|
48
|
+
options: {
|
|
49
|
+
fill_height
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
$: {
|
|
53
|
+
ready = !!$_layout;
|
|
54
|
+
}
|
|
55
|
+
let params = new URLSearchParams(window.location.search);
|
|
56
|
+
let api_docs_visible = params.get("view") === "api" && show_api;
|
|
57
|
+
let api_recorder_visible = params.get("view") === "api-recorder" && show_api;
|
|
58
|
+
function set_api_docs_visible(visible) {
|
|
59
|
+
api_recorder_visible = false;
|
|
60
|
+
api_docs_visible = visible;
|
|
61
|
+
let params2 = new URLSearchParams(window.location.search);
|
|
62
|
+
if (visible) {
|
|
63
|
+
params2.set("view", "api");
|
|
64
|
+
} else {
|
|
65
|
+
params2.delete("view");
|
|
66
|
+
}
|
|
67
|
+
history.replaceState(null, "", "?" + params2.toString());
|
|
68
|
+
}
|
|
69
|
+
let api_calls = [];
|
|
70
|
+
export let render_complete = false;
|
|
71
|
+
async function handle_update(data, fn_index) {
|
|
72
|
+
const outputs = dependencies.find((dep) => dep.id == fn_index).outputs;
|
|
73
|
+
const meta_updates = data?.map((value, i) => {
|
|
74
|
+
return {
|
|
75
|
+
id: outputs[i],
|
|
76
|
+
prop: "value_is_output",
|
|
77
|
+
value: true
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
update_value(meta_updates);
|
|
81
|
+
await tick();
|
|
82
|
+
const updates = [];
|
|
83
|
+
data?.forEach((value, i) => {
|
|
84
|
+
if (typeof value === "object" && value !== null && value.__type__ === "update") {
|
|
85
|
+
for (const [update_key, update_value2] of Object.entries(value)) {
|
|
86
|
+
if (update_key === "__type__") {
|
|
87
|
+
continue;
|
|
88
|
+
} else {
|
|
89
|
+
updates.push({
|
|
90
|
+
id: outputs[i],
|
|
91
|
+
prop: update_key,
|
|
92
|
+
value: update_value2
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
updates.push({
|
|
98
|
+
id: outputs[i],
|
|
99
|
+
prop: "value",
|
|
100
|
+
value
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
update_value(updates);
|
|
105
|
+
await tick();
|
|
106
|
+
}
|
|
107
|
+
let submit_map = /* @__PURE__ */ new Map();
|
|
108
|
+
let messages = [];
|
|
109
|
+
function new_message(message, fn_index, type, duration = 10, visible = true) {
|
|
110
|
+
return {
|
|
111
|
+
message,
|
|
112
|
+
fn_index,
|
|
113
|
+
type,
|
|
114
|
+
id: ++_error_id,
|
|
115
|
+
duration,
|
|
116
|
+
visible
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export function add_new_message(message, type) {
|
|
120
|
+
messages = [new_message(message, -1, type), ...messages];
|
|
121
|
+
}
|
|
122
|
+
let _error_id = -1;
|
|
123
|
+
let user_left_page = false;
|
|
124
|
+
document.addEventListener("visibilitychange", function() {
|
|
125
|
+
if (document.visibilityState === "hidden") {
|
|
126
|
+
user_left_page = true;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const MESSAGE_QUOTE_RE = /^'([^]+)'$/;
|
|
130
|
+
const DUPLICATE_MESSAGE = $_("blocks.long_requests_queue");
|
|
131
|
+
const MOBILE_QUEUE_WARNING = $_("blocks.connection_can_break");
|
|
132
|
+
const MOBILE_RECONNECT_MESSAGE = $_("blocks.lost_connection");
|
|
133
|
+
const SHOW_DUPLICATE_MESSAGE_ON_ETA = 15;
|
|
134
|
+
const SHOW_MOBILE_QUEUE_WARNING_ON_ETA = 10;
|
|
135
|
+
const is_mobile_device = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
136
|
+
navigator.userAgent
|
|
137
|
+
);
|
|
138
|
+
let showed_duplicate_message = false;
|
|
139
|
+
let showed_mobile_warning = false;
|
|
140
|
+
function wait_then_trigger_api_call(dep_index, trigger_id = null, event_data = null) {
|
|
141
|
+
let _unsub = () => {
|
|
142
|
+
};
|
|
143
|
+
function unsub() {
|
|
144
|
+
_unsub();
|
|
145
|
+
}
|
|
146
|
+
if ($scheduled_updates) {
|
|
147
|
+
_unsub = scheduled_updates.subscribe((updating) => {
|
|
148
|
+
if (!updating) {
|
|
149
|
+
trigger_api_call(dep_index, trigger_id, event_data);
|
|
150
|
+
unsub();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
trigger_api_call(dep_index, trigger_id, event_data);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function trigger_api_call(dep_index, trigger_id = null, event_data = null) {
|
|
158
|
+
let dep = dependencies.find((dep2) => dep2.id === dep_index);
|
|
159
|
+
const current_status = loading_status.get_status_for_fn(dep_index);
|
|
160
|
+
messages = messages.filter(({ fn_index }) => fn_index !== dep_index);
|
|
161
|
+
if (current_status === "pending" || current_status === "generating") {
|
|
162
|
+
dep.pending_request = true;
|
|
163
|
+
}
|
|
164
|
+
let payload = {
|
|
165
|
+
fn_index: dep_index,
|
|
166
|
+
data: await Promise.all(dep.inputs.map((id) => get_data(id))),
|
|
167
|
+
event_data: dep.collects_event_data ? event_data : null,
|
|
168
|
+
trigger_id
|
|
169
|
+
};
|
|
170
|
+
if (dep.frontend_fn) {
|
|
171
|
+
dep.frontend_fn(
|
|
172
|
+
payload.data.concat(
|
|
173
|
+
await Promise.all(dep.outputs.map((id) => get_data(id)))
|
|
174
|
+
)
|
|
175
|
+
).then((v) => {
|
|
176
|
+
if (dep.backend_fn) {
|
|
177
|
+
payload.data = v;
|
|
178
|
+
make_prediction(payload);
|
|
179
|
+
} else {
|
|
180
|
+
handle_update(v, dep_index);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} else if (dep.types.cancel && dep.cancels) {
|
|
184
|
+
await Promise.all(
|
|
185
|
+
dep.cancels.map(async (fn_index) => {
|
|
186
|
+
const submission = submit_map.get(fn_index);
|
|
187
|
+
submission?.cancel();
|
|
188
|
+
return submission;
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
} else {
|
|
192
|
+
if (dep.backend_fn) {
|
|
193
|
+
if (dep.trigger_mode === "once") {
|
|
194
|
+
if (!dep.pending_request)
|
|
195
|
+
make_prediction(payload);
|
|
196
|
+
} else if (dep.trigger_mode === "multiple") {
|
|
197
|
+
make_prediction(payload);
|
|
198
|
+
} else if (dep.trigger_mode === "always_last") {
|
|
199
|
+
if (!dep.pending_request) {
|
|
200
|
+
make_prediction(payload);
|
|
201
|
+
} else {
|
|
202
|
+
dep.final_event = payload;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function make_prediction(payload2) {
|
|
208
|
+
if (api_recorder_visible) {
|
|
209
|
+
api_calls = [...api_calls, JSON.parse(JSON.stringify(payload2))];
|
|
210
|
+
}
|
|
211
|
+
let submission;
|
|
212
|
+
try {
|
|
213
|
+
submission = app.submit(
|
|
214
|
+
payload2.fn_index,
|
|
215
|
+
payload2.data,
|
|
216
|
+
payload2.event_data,
|
|
217
|
+
payload2.trigger_id
|
|
218
|
+
);
|
|
219
|
+
} catch (e) {
|
|
220
|
+
const fn_index = 0;
|
|
221
|
+
messages = [new_message(String(e), fn_index, "error"), ...messages];
|
|
222
|
+
loading_status.update({
|
|
223
|
+
status: "error",
|
|
224
|
+
fn_index,
|
|
225
|
+
eta: 0,
|
|
226
|
+
queue: false,
|
|
227
|
+
queue_position: null
|
|
228
|
+
});
|
|
229
|
+
set_status($loading_status);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
submit_map.set(dep_index, submission);
|
|
233
|
+
for await (const message of submission) {
|
|
234
|
+
if (message.type === "data") {
|
|
235
|
+
handle_data(message);
|
|
236
|
+
} else if (message.type === "render") {
|
|
237
|
+
handle_render(message);
|
|
238
|
+
} else if (message.type === "status") {
|
|
239
|
+
handle_status_update(message);
|
|
240
|
+
} else if (message.type === "log") {
|
|
241
|
+
handle_log(message);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function handle_data(message) {
|
|
245
|
+
const { data, fn_index } = message;
|
|
246
|
+
if (dep.pending_request && dep.final_event) {
|
|
247
|
+
dep.pending_request = false;
|
|
248
|
+
make_prediction(dep.final_event);
|
|
249
|
+
}
|
|
250
|
+
dep.pending_request = false;
|
|
251
|
+
handle_update(data, fn_index);
|
|
252
|
+
set_status($loading_status);
|
|
253
|
+
}
|
|
254
|
+
function handle_render(message) {
|
|
255
|
+
const { data } = message;
|
|
256
|
+
let _components = data.components;
|
|
257
|
+
let render_layout = data.layout;
|
|
258
|
+
let _dependencies = data.dependencies;
|
|
259
|
+
let render_id = data.render_id;
|
|
260
|
+
let deps_to_remove = [];
|
|
261
|
+
dependencies.forEach((dep2, i) => {
|
|
262
|
+
if (dep2.rendered_in === render_id) {
|
|
263
|
+
deps_to_remove.push(i);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
deps_to_remove.reverse().forEach((i) => {
|
|
267
|
+
dependencies.splice(i, 1);
|
|
268
|
+
});
|
|
269
|
+
_dependencies.forEach((dep2) => {
|
|
270
|
+
dependencies.push(dep2);
|
|
271
|
+
});
|
|
272
|
+
rerender_layout({
|
|
273
|
+
components: _components,
|
|
274
|
+
layout: render_layout,
|
|
275
|
+
root,
|
|
276
|
+
dependencies,
|
|
277
|
+
render_id
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function handle_log(msg) {
|
|
281
|
+
const { log, fn_index, level, duration, visible } = msg;
|
|
282
|
+
messages = [
|
|
283
|
+
new_message(log, fn_index, level, duration, visible),
|
|
284
|
+
...messages
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
function handle_status_update(message) {
|
|
288
|
+
const { fn_index, ...status } = message;
|
|
289
|
+
loading_status.update({
|
|
290
|
+
...status,
|
|
291
|
+
status: status.stage,
|
|
292
|
+
progress: status.progress_data,
|
|
293
|
+
fn_index
|
|
294
|
+
});
|
|
295
|
+
set_status($loading_status);
|
|
296
|
+
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) {
|
|
297
|
+
showed_duplicate_message = true;
|
|
298
|
+
messages = [
|
|
299
|
+
new_message(DUPLICATE_MESSAGE, fn_index, "warning"),
|
|
300
|
+
...messages
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
if (!showed_mobile_warning && is_mobile_device && status.eta !== void 0 && status.eta > SHOW_MOBILE_QUEUE_WARNING_ON_ETA) {
|
|
304
|
+
showed_mobile_warning = true;
|
|
305
|
+
messages = [
|
|
306
|
+
new_message(MOBILE_QUEUE_WARNING, fn_index, "warning"),
|
|
307
|
+
...messages
|
|
308
|
+
];
|
|
309
|
+
}
|
|
310
|
+
if (status.stage === "complete") {
|
|
311
|
+
status.changed_state_ids?.forEach((id) => {
|
|
312
|
+
dependencies.filter((dep2) => dep2.targets.some(([_id, _2]) => _id === id)).forEach((dep2) => {
|
|
313
|
+
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
dependencies.forEach(async (dep2) => {
|
|
317
|
+
if (dep2.trigger_after === fn_index) {
|
|
318
|
+
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (status.broken && is_mobile_device && user_left_page) {
|
|
323
|
+
window.setTimeout(() => {
|
|
324
|
+
messages = [
|
|
325
|
+
new_message(MOBILE_RECONNECT_MESSAGE, fn_index, "error"),
|
|
326
|
+
...messages
|
|
327
|
+
];
|
|
328
|
+
}, 0);
|
|
329
|
+
wait_then_trigger_api_call(dep.id, payload2.trigger_id, event_data);
|
|
330
|
+
user_left_page = false;
|
|
331
|
+
} else if (status.stage === "error") {
|
|
332
|
+
if (status.message) {
|
|
333
|
+
const _message = status.message.replace(
|
|
334
|
+
MESSAGE_QUOTE_RE,
|
|
335
|
+
(_2, b) => b
|
|
336
|
+
);
|
|
337
|
+
messages = [
|
|
338
|
+
new_message(
|
|
339
|
+
_message,
|
|
340
|
+
fn_index,
|
|
341
|
+
"error",
|
|
342
|
+
status.duration,
|
|
343
|
+
status.visible
|
|
344
|
+
),
|
|
345
|
+
...messages
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
dependencies.map(async (dep2) => {
|
|
349
|
+
if (dep2.trigger_after === fn_index && !dep2.trigger_only_on_success) {
|
|
350
|
+
wait_then_trigger_api_call(dep2.id, payload2.trigger_id);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function trigger_share(title2, description) {
|
|
358
|
+
if (space_id === null) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const discussion_url = new URL(
|
|
362
|
+
`https://huggingface.co/spaces/${space_id}/discussions/new`
|
|
363
|
+
);
|
|
364
|
+
if (title2 !== void 0 && title2.length > 0) {
|
|
365
|
+
discussion_url.searchParams.set("title", title2);
|
|
366
|
+
}
|
|
367
|
+
discussion_url.searchParams.set("description", description);
|
|
368
|
+
window.open(discussion_url.toString(), "_blank");
|
|
369
|
+
}
|
|
370
|
+
function handle_error_close(e) {
|
|
371
|
+
const _id = e.detail;
|
|
372
|
+
messages = messages.filter((m) => m.id !== _id);
|
|
373
|
+
}
|
|
374
|
+
const is_external_url = (link) => !!(link && new URL(link, location.href).origin !== location.origin);
|
|
375
|
+
async function handle_mount() {
|
|
376
|
+
if (js) {
|
|
377
|
+
let blocks_frontend_fn = new AsyncFunction(
|
|
378
|
+
`let result = await (${js})();
|
|
379
|
+
return (!Array.isArray(result)) ? [result] : result;`
|
|
380
|
+
);
|
|
381
|
+
await blocks_frontend_fn();
|
|
382
|
+
}
|
|
383
|
+
await tick();
|
|
384
|
+
var a = target.getElementsByTagName("a");
|
|
385
|
+
for (var i = 0; i < a.length; i++) {
|
|
386
|
+
const _target = a[i].getAttribute("target");
|
|
387
|
+
const _link = a[i].getAttribute("href");
|
|
388
|
+
if (is_external_url(_link) && _target !== "_blank")
|
|
389
|
+
a[i].setAttribute("target", "_blank");
|
|
390
|
+
}
|
|
391
|
+
dependencies.forEach((dep) => {
|
|
392
|
+
if (dep.targets.some((dep2) => dep2[1] === "load")) {
|
|
393
|
+
wait_then_trigger_api_call(dep.id);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
if (render_complete)
|
|
397
|
+
return;
|
|
398
|
+
target.addEventListener("prop_change", (e) => {
|
|
399
|
+
if (!isCustomEvent(e))
|
|
400
|
+
throw new Error("not a custom event");
|
|
401
|
+
const { id, prop, value } = e.detail;
|
|
402
|
+
update_value([{ id, prop, value }]);
|
|
403
|
+
});
|
|
404
|
+
target.addEventListener("gradio", (e) => {
|
|
405
|
+
if (!isCustomEvent(e))
|
|
406
|
+
throw new Error("not a custom event");
|
|
407
|
+
const { id, event, data } = e.detail;
|
|
408
|
+
if (event === "share") {
|
|
409
|
+
const { title: title2, description } = data;
|
|
410
|
+
trigger_share(title2, description);
|
|
411
|
+
} else if (event === "error" || event === "warning") {
|
|
412
|
+
messages = [new_message(data, -1, event), ...messages];
|
|
413
|
+
} else if (event == "clear_status") {
|
|
414
|
+
update_status(id, "complete", data);
|
|
415
|
+
} else {
|
|
416
|
+
const deps = $targets[id]?.[event];
|
|
417
|
+
deps?.forEach((dep_id) => {
|
|
418
|
+
requestAnimationFrame(() => {
|
|
419
|
+
wait_then_trigger_api_call(dep_id, id, data);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
render_complete = true;
|
|
425
|
+
}
|
|
426
|
+
$:
|
|
427
|
+
set_status($loading_status);
|
|
428
|
+
function update_status(id, status, data) {
|
|
429
|
+
data.status = status;
|
|
430
|
+
update_value([
|
|
431
|
+
{
|
|
432
|
+
id,
|
|
433
|
+
prop: "loading_status",
|
|
434
|
+
value: data
|
|
435
|
+
}
|
|
436
|
+
]);
|
|
437
|
+
}
|
|
438
|
+
function set_status(statuses) {
|
|
439
|
+
let updates = [];
|
|
440
|
+
Object.entries(statuses).forEach(([id, loading_status2]) => {
|
|
441
|
+
let dependency = dependencies.find(
|
|
442
|
+
(dep) => dep.id == loading_status2.fn_index
|
|
443
|
+
);
|
|
444
|
+
if (dependency === void 0) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
loading_status2.scroll_to_output = dependency.scroll_to_output;
|
|
448
|
+
loading_status2.show_progress = dependency.show_progress;
|
|
449
|
+
updates.push({
|
|
450
|
+
id: parseInt(id),
|
|
451
|
+
prop: "loading_status",
|
|
452
|
+
value: loading_status2
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
const inputs_to_update = loading_status.get_inputs_to_update();
|
|
456
|
+
const additional_updates = Array.from(inputs_to_update).map(
|
|
457
|
+
([id, pending_status]) => {
|
|
458
|
+
return {
|
|
459
|
+
id,
|
|
460
|
+
prop: "pending",
|
|
461
|
+
value: pending_status === "pending"
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
);
|
|
465
|
+
update_value([...updates, ...additional_updates]);
|
|
466
|
+
}
|
|
467
|
+
function isCustomEvent(event) {
|
|
468
|
+
return "detail" in event;
|
|
469
|
+
}
|
|
470
|
+
</script>
|
|
471
|
+
|
|
472
|
+
<svelte:head>
|
|
473
|
+
{#if control_page_title}
|
|
474
|
+
<title>{title}</title>
|
|
475
|
+
{/if}
|
|
476
|
+
</svelte:head>
|
|
477
|
+
|
|
478
|
+
<div class="wrap" style:min-height={app_mode ? "100%" : "auto"}>
|
|
479
|
+
<div class="contain" style:flex-grow={app_mode ? "1" : "auto"}>
|
|
480
|
+
{#if $_layout && app.config}
|
|
481
|
+
<MountComponents
|
|
482
|
+
rootNode={$_layout}
|
|
483
|
+
{root}
|
|
484
|
+
{target}
|
|
485
|
+
{theme_mode}
|
|
486
|
+
on:mount={handle_mount}
|
|
487
|
+
{version}
|
|
488
|
+
{autoscroll}
|
|
489
|
+
max_file_size={app.config.max_file_size}
|
|
490
|
+
client={app}
|
|
491
|
+
/>
|
|
492
|
+
{/if}
|
|
493
|
+
</div>
|
|
494
|
+
|
|
495
|
+
{#if show_footer}
|
|
496
|
+
<footer>
|
|
497
|
+
{#if show_api}
|
|
498
|
+
<button
|
|
499
|
+
on:click={() => {
|
|
500
|
+
set_api_docs_visible(!api_docs_visible);
|
|
501
|
+
}}
|
|
502
|
+
class="show-api"
|
|
503
|
+
>
|
|
504
|
+
{$_("errors.use_via_api")}
|
|
505
|
+
<img src={api_logo} alt={$_("common.logo")} />
|
|
506
|
+
</button>
|
|
507
|
+
<div>·</div>
|
|
508
|
+
{/if}
|
|
509
|
+
<a
|
|
510
|
+
href="https://gradio.app"
|
|
511
|
+
class="built-with"
|
|
512
|
+
target="_blank"
|
|
513
|
+
rel="noreferrer"
|
|
514
|
+
>
|
|
515
|
+
{$_("common.built_with_gradio")}
|
|
516
|
+
<img src={logo} alt={$_("common.logo")} />
|
|
517
|
+
</a>
|
|
518
|
+
</footer>
|
|
519
|
+
{/if}
|
|
520
|
+
</div>
|
|
521
|
+
|
|
522
|
+
{#if api_recorder_visible}
|
|
523
|
+
<!-- TODO: fix -->
|
|
524
|
+
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
525
|
+
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
526
|
+
<div
|
|
527
|
+
id="api-recorder-container"
|
|
528
|
+
on:click={() => {
|
|
529
|
+
set_api_docs_visible(true);
|
|
530
|
+
api_recorder_visible = false;
|
|
531
|
+
}}
|
|
532
|
+
>
|
|
533
|
+
<ApiRecorder {api_calls} {dependencies} />
|
|
534
|
+
</div>
|
|
535
|
+
{/if}
|
|
536
|
+
|
|
537
|
+
{#if api_docs_visible && $_layout}
|
|
538
|
+
<div class="api-docs">
|
|
539
|
+
<!-- TODO: fix -->
|
|
540
|
+
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
|
541
|
+
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
|
542
|
+
<div
|
|
543
|
+
class="backdrop"
|
|
544
|
+
on:click={() => {
|
|
545
|
+
set_api_docs_visible(false);
|
|
546
|
+
}}
|
|
547
|
+
/>
|
|
548
|
+
<div class="api-docs-wrap">
|
|
549
|
+
<ApiDocs
|
|
550
|
+
root_node={$_layout}
|
|
551
|
+
on:close={(event) => {
|
|
552
|
+
set_api_docs_visible(false);
|
|
553
|
+
api_calls = [];
|
|
554
|
+
api_recorder_visible = event.detail.api_recorder_visible;
|
|
555
|
+
}}
|
|
556
|
+
{dependencies}
|
|
557
|
+
{root}
|
|
558
|
+
{app}
|
|
559
|
+
{space_id}
|
|
560
|
+
{api_calls}
|
|
561
|
+
{username}
|
|
562
|
+
/>
|
|
563
|
+
</div>
|
|
564
|
+
</div>
|
|
565
|
+
{/if}
|
|
566
|
+
|
|
567
|
+
{#if messages}
|
|
568
|
+
<Toast {messages} on:close={handle_error_close} />
|
|
569
|
+
{/if}
|
|
570
|
+
|
|
571
|
+
<style>
|
|
572
|
+
.wrap {
|
|
573
|
+
display: flex;
|
|
574
|
+
flex-grow: 1;
|
|
575
|
+
flex-direction: column;
|
|
576
|
+
width: var(--size-full);
|
|
577
|
+
font-weight: var(--body-text-weight);
|
|
578
|
+
font-size: var(--body-text-size);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.contain {
|
|
582
|
+
display: flex;
|
|
583
|
+
flex-direction: column;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
footer {
|
|
587
|
+
display: flex;
|
|
588
|
+
justify-content: center;
|
|
589
|
+
margin-top: var(--size-4);
|
|
590
|
+
color: var(--body-text-color-subdued);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
footer > * + * {
|
|
594
|
+
margin-left: var(--size-2);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
.show-api {
|
|
598
|
+
display: flex;
|
|
599
|
+
align-items: center;
|
|
600
|
+
}
|
|
601
|
+
.show-api:hover {
|
|
602
|
+
color: var(--body-text-color);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
.show-api img {
|
|
606
|
+
margin-right: var(--size-1);
|
|
607
|
+
margin-left: var(--size-2);
|
|
608
|
+
width: var(--size-3);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
.built-with {
|
|
612
|
+
display: flex;
|
|
613
|
+
align-items: center;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
.built-with:hover {
|
|
617
|
+
color: var(--body-text-color);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
.built-with img {
|
|
621
|
+
margin-right: var(--size-1);
|
|
622
|
+
margin-left: var(--size-1);
|
|
623
|
+
margin-bottom: 1px;
|
|
624
|
+
width: var(--size-4);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
.api-docs {
|
|
628
|
+
display: flex;
|
|
629
|
+
position: fixed;
|
|
630
|
+
top: 0;
|
|
631
|
+
right: 0;
|
|
632
|
+
z-index: var(--layer-top);
|
|
633
|
+
background: rgba(0, 0, 0, 0.5);
|
|
634
|
+
width: var(--size-screen);
|
|
635
|
+
height: var(--size-screen-h);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
.backdrop {
|
|
639
|
+
flex: 1 1 0%;
|
|
640
|
+
-webkit-backdrop-filter: blur(4px);
|
|
641
|
+
backdrop-filter: blur(4px);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
.api-docs-wrap {
|
|
645
|
+
box-shadow: var(--shadow-drop-lg);
|
|
646
|
+
background: var(--background-fill-primary);
|
|
647
|
+
overflow-x: hidden;
|
|
648
|
+
overflow-y: auto;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
@media (--screen-md) {
|
|
652
|
+
.api-docs-wrap {
|
|
653
|
+
border-top-left-radius: var(--radius-lg);
|
|
654
|
+
border-bottom-left-radius: var(--radius-lg);
|
|
655
|
+
width: 950px;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
@media (--screen-xxl) {
|
|
660
|
+
.api-docs-wrap {
|
|
661
|
+
width: 1150px;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
#api-recorder-container {
|
|
666
|
+
position: fixed;
|
|
667
|
+
left: 10px;
|
|
668
|
+
bottom: 10px;
|
|
669
|
+
z-index: 1000;
|
|
670
|
+
}
|
|
671
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { Client } from "@gradio/client";
|
|
3
|
+
import type { ComponentMeta, Dependency, LayoutNode } from "./types";
|
|
4
|
+
import type { ThemeMode } from "./types";
|
|
5
|
+
import type { ToastMessage } from "@gradio/statustracker";
|
|
6
|
+
declare const __propDef: {
|
|
7
|
+
props: {
|
|
8
|
+
root: string;
|
|
9
|
+
components: ComponentMeta[];
|
|
10
|
+
layout: LayoutNode;
|
|
11
|
+
dependencies: Dependency[];
|
|
12
|
+
title?: string | undefined;
|
|
13
|
+
target: HTMLElement;
|
|
14
|
+
autoscroll: boolean;
|
|
15
|
+
show_api?: boolean | undefined;
|
|
16
|
+
show_footer?: boolean | undefined;
|
|
17
|
+
control_page_title?: boolean | undefined;
|
|
18
|
+
app_mode: boolean;
|
|
19
|
+
theme_mode: ThemeMode;
|
|
20
|
+
app: Awaited<ReturnType<typeof Client.connect>>;
|
|
21
|
+
space_id: string | null;
|
|
22
|
+
version: string;
|
|
23
|
+
js: string | null;
|
|
24
|
+
fill_height?: boolean | undefined;
|
|
25
|
+
ready: boolean;
|
|
26
|
+
username: string | null;
|
|
27
|
+
render_complete?: boolean | undefined;
|
|
28
|
+
add_new_message?: ((message: string, type: ToastMessage["type"]) => void) | undefined;
|
|
29
|
+
};
|
|
30
|
+
events: {
|
|
31
|
+
[evt: string]: CustomEvent<any>;
|
|
32
|
+
};
|
|
33
|
+
slots: {};
|
|
34
|
+
};
|
|
35
|
+
export type BlocksProps = typeof __propDef.props;
|
|
36
|
+
export type BlocksEvents = typeof __propDef.events;
|
|
37
|
+
export type BlocksSlots = typeof __propDef.slots;
|
|
38
|
+
export default class Blocks extends SvelteComponent<BlocksProps, BlocksEvents, BlocksSlots> {
|
|
39
|
+
get add_new_message(): (message: string, type: ToastMessage["type"]) => void;
|
|
40
|
+
}
|
|
41
|
+
export {};
|