@gradio/client 2.5.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/browser.js +544 -443
- package/dist/helpers/init_helpers.d.ts +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.cjs +145 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +139 -8
- package/dist/index.min.js +428 -327
- package/dist/types.d.ts +5 -5
- package/dist/upload.d.ts.map +1 -1
- package/dist/utils/bucket_sync.d.ts +38 -0
- package/dist/utils/bucket_sync.d.ts.map +1 -0
- package/dist/utils/run_history.d.ts +9 -0
- package/dist/utils/run_history.d.ts.map +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/helpers/init_helpers.ts +21 -4
- package/src/index.ts +12 -0
- package/src/test/bucket_sync.test.ts +138 -0
- package/src/test/run_history.test.ts +46 -0
- package/src/test/submit.test.ts +38 -1
- package/src/test/upload.test.ts +25 -0
- package/src/types.ts +5 -5
- package/src/upload.ts +5 -1
- package/src/utils/bucket_sync.ts +153 -0
- package/src/utils/run_history.ts +64 -1
- package/src/utils/submit.ts +11 -2
package/dist/index.min.js
CHANGED
|
@@ -8,10 +8,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
|
|
|
8
8
|
}, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
|
|
9
9
|
value: n,
|
|
10
10
|
enumerable: !0
|
|
11
|
-
}) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime",
|
|
11
|
+
}) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime", _ = "sleeptime", v = "heartbeat", ee = "component_server", te = "reset", ne = "cancel", re = "app_id", ie = "This application is currently busy. Please try again. ", y = "Connection errored out. ", b = "Could not resolve app config. ", x = "Could not get space status. ", ae = "Could not get API info. ", S = "Space metadata could not be loaded. ", C = "Invalid URL. A full URL path is required.", w = "Not authorized to access this space. ", T = "Invalid credentials. Could not login. ", oe = "Login credentials are required to access this space.", E = "Could not access this app (received a 401 response). If it is a private Hugging Face Space, pass a valid Hugging Face token to the `token` option of `Client.connect`. You can generate a token at https://huggingface.co/settings/tokens.", se = (e, t) => `Space "${e}" could not be accessed (received a ${t} response from the Hugging Face API). Check that the Space name is spelled correctly and that the Space exists. If the Space is private, pass a valid Hugging Face token to the \`token\` option of \`Client.connect\`. You can generate a token at https://huggingface.co/settings/tokens.`, ce = "No API information is available for this app. This can happen when the app's `/info` endpoint cannot be reached, or when the app is running a legacy version of Gradio that is not supported by this client. ", le = "This app appears to be running a legacy version of Gradio (3.x or earlier) that communicates over WebSockets, which is not supported by this version of @gradio/client. Please upgrade the app to a newer version of Gradio, or connect to it with @gradio/client version 0.x.", ue = "File system access is only available in Node.js environments", de = "Root URL not found in client config", fe = "Error uploading file";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/helpers/init_helpers.ts
|
|
14
|
-
async function
|
|
14
|
+
async function pe(e, t, n) {
|
|
15
15
|
try {
|
|
16
16
|
return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, { headers: {
|
|
17
17
|
Authorization: `Bearer ${t}`,
|
|
@@ -21,24 +21,24 @@ async function de(e, t, n) {
|
|
|
21
21
|
return !1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function D(e) {
|
|
25
25
|
e.hf_token && !e.token && (e.token = e.hf_token, console.warn("The `hf_token` option has been renamed to `token`. Support for `hf_token` will be removed in a future version of @gradio/client."));
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function me(e) {
|
|
28
28
|
let t = {};
|
|
29
29
|
return e.forEach(({ api_name: e, id: n }) => {
|
|
30
30
|
e && (t[e] = n);
|
|
31
31
|
}), t;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
let
|
|
35
|
-
return n.hostname === r.hostname ? (
|
|
33
|
+
function O(e, t, n = !1) {
|
|
34
|
+
let r = new URL(t), i = new URL(e, r), a = i.hostname.endsWith(".colab-user-runtimes.internal") || i.hostname.endsWith(".codatalab-user-runtimes.internal");
|
|
35
|
+
return n || a ? new URL(new URL(e, r).pathname, r).toString().replace(/\/$/, "") : i.hostname === r.hostname ? (i.protocol = r.protocol, i.host = r.host, i.toString().replace(/\/$/, "")) : e;
|
|
36
36
|
}
|
|
37
|
-
async function
|
|
37
|
+
async function he(e, t = !0) {
|
|
38
38
|
let n = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
|
|
39
39
|
if (typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
40
40
|
if (t && window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.dev_mode || typeof window < "u" && window?.BUILD_MODE === "dev") {
|
|
41
|
-
let t =
|
|
41
|
+
let t = I(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await k(await this.fetch(t, {
|
|
42
42
|
headers: n,
|
|
43
43
|
credentials: this.options.credentials ?? "same-origin"
|
|
44
44
|
}), !!this.options.auth);
|
|
@@ -48,9 +48,9 @@ async function j(e, t = !0) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
let r = { ...window.gradio_config };
|
|
51
|
-
return r.root =
|
|
51
|
+
return r.root = O(r.root, location.href, r.is_colab), r;
|
|
52
52
|
} else if (e) {
|
|
53
|
-
let t =
|
|
53
|
+
let t = I(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await k(await this.fetch(t, {
|
|
54
54
|
headers: n,
|
|
55
55
|
credentials: this.options.credentials ?? "same-origin"
|
|
56
56
|
}), !!this.options.auth);
|
|
@@ -58,37 +58,37 @@ async function j(e, t = !0) {
|
|
|
58
58
|
}
|
|
59
59
|
throw Error(b);
|
|
60
60
|
}
|
|
61
|
-
async function
|
|
61
|
+
async function k(e, t) {
|
|
62
62
|
if (e?.status === 401 && !t) {
|
|
63
63
|
let t = null;
|
|
64
64
|
try {
|
|
65
65
|
t = await e.json();
|
|
66
66
|
} catch {
|
|
67
|
-
throw Error(
|
|
67
|
+
throw Error(E);
|
|
68
68
|
}
|
|
69
69
|
let n = t?.detail?.auth_message;
|
|
70
70
|
throw Error(n || "Login credentials are required to access this space.");
|
|
71
|
-
} else if (e?.status === 401 && t) throw Error(
|
|
71
|
+
} else if (e?.status === 401 && t) throw Error(T);
|
|
72
72
|
if (e?.status === 200) {
|
|
73
73
|
let t = await e.json();
|
|
74
74
|
return t.dependencies?.forEach((e, t) => {
|
|
75
75
|
e.id === void 0 && (e.id = t);
|
|
76
76
|
}), t;
|
|
77
|
-
} else if (e?.status === 401) throw Error(
|
|
77
|
+
} else if (e?.status === 401) throw Error(w);
|
|
78
78
|
throw Error(`${b}(received status ${e?.status} when fetching the app config)`);
|
|
79
79
|
}
|
|
80
|
-
async function
|
|
81
|
-
let { http_protocol: e, host: t } = await
|
|
80
|
+
async function A() {
|
|
81
|
+
let { http_protocol: e, host: t } = await F(this.app_reference, this.options.token);
|
|
82
82
|
try {
|
|
83
83
|
if (this.options.auth) {
|
|
84
|
-
let n = await
|
|
84
|
+
let n = await j(e, t, this.options.auth, this.fetch, this.options.token, this.options.credentials);
|
|
85
85
|
n && this.set_cookies(n);
|
|
86
86
|
}
|
|
87
87
|
} catch (e) {
|
|
88
88
|
throw Error(e.message);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
async function
|
|
91
|
+
async function j(e, t, n, r, i, a) {
|
|
92
92
|
let o = new FormData();
|
|
93
93
|
o.append("username", n?.[0]), o.append("password", n?.[1]);
|
|
94
94
|
let s = {};
|
|
@@ -100,9 +100,9 @@ async function P(e, t, n, r, i, a) {
|
|
|
100
100
|
credentials: a ?? "same-origin"
|
|
101
101
|
});
|
|
102
102
|
if (c.status === 200) return c.headers.get("set-cookie");
|
|
103
|
-
throw c.status === 401 ? Error(
|
|
103
|
+
throw c.status === 401 ? Error(T) : Error(S);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function M(e) {
|
|
106
106
|
if (e.startsWith("http")) {
|
|
107
107
|
let { protocol: t, host: n, pathname: r } = new URL(e);
|
|
108
108
|
return {
|
|
@@ -117,39 +117,39 @@ function F(e) {
|
|
|
117
117
|
host: new URL(e).host
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
var
|
|
120
|
+
var N = (e) => {
|
|
121
121
|
let t = [];
|
|
122
122
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((e) => {
|
|
123
123
|
let [n, r] = e.split(";")[0].split("=");
|
|
124
124
|
n && r && t.push(`${n.trim()}=${r.trim()}`);
|
|
125
125
|
}), t;
|
|
126
|
-
},
|
|
127
|
-
async function
|
|
126
|
+
}, P = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, ge = /.*hf\.space\/{0,1}.*$/;
|
|
127
|
+
async function F(e, t) {
|
|
128
128
|
let n = {};
|
|
129
129
|
t && (n.Authorization = `Bearer ${t}`);
|
|
130
130
|
let r = e.trim().replace(/\/$/, "");
|
|
131
|
-
if (
|
|
131
|
+
if (P.test(r)) {
|
|
132
132
|
let e;
|
|
133
133
|
try {
|
|
134
134
|
e = await fetch(`https://huggingface.co/api/spaces/${r}/${l}`, { headers: n });
|
|
135
135
|
} catch {
|
|
136
|
-
throw Error(
|
|
136
|
+
throw Error(S);
|
|
137
137
|
}
|
|
138
|
-
if (e.status === 401 || e.status === 404) throw Error(
|
|
138
|
+
if (e.status === 401 || e.status === 404) throw Error(se(r, e.status));
|
|
139
139
|
let t;
|
|
140
140
|
try {
|
|
141
141
|
t = (await e.json()).host;
|
|
142
142
|
} catch {
|
|
143
|
-
throw Error(
|
|
143
|
+
throw Error(S);
|
|
144
144
|
}
|
|
145
|
-
if (!t) throw Error(
|
|
145
|
+
if (!t) throw Error(S);
|
|
146
146
|
return {
|
|
147
147
|
space_id: r,
|
|
148
|
-
...
|
|
148
|
+
...M(t)
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
-
if (
|
|
152
|
-
let { ws_protocol: e, http_protocol: t, host: n } =
|
|
151
|
+
if (ge.test(r)) {
|
|
152
|
+
let { ws_protocol: e, http_protocol: t, host: n } = M(r);
|
|
153
153
|
return {
|
|
154
154
|
space_id: n.split("/")[0].replace(".hf.space", ""),
|
|
155
155
|
ws_protocol: e,
|
|
@@ -159,17 +159,17 @@ async function R(e, t) {
|
|
|
159
159
|
}
|
|
160
160
|
return {
|
|
161
161
|
space_id: !1,
|
|
162
|
-
...
|
|
162
|
+
...M(r)
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
var
|
|
165
|
+
var I = (...e) => {
|
|
166
166
|
try {
|
|
167
167
|
return e.reduce((e, t) => (e = e.replace(/\/+$/, ""), t = t.replace(/^\/+/, ""), new URL(t, e + "/").toString()));
|
|
168
168
|
} catch {
|
|
169
|
-
throw Error(
|
|
169
|
+
throw Error(C);
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
function
|
|
172
|
+
function L(e, t, n) {
|
|
173
173
|
let r = {
|
|
174
174
|
named_endpoints: {},
|
|
175
175
|
unnamed_endpoints: {}
|
|
@@ -199,8 +199,8 @@ function he(e, t, n) {
|
|
|
199
199
|
}
|
|
200
200
|
let d = (e, t, n, r) => ({
|
|
201
201
|
...e,
|
|
202
|
-
description:
|
|
203
|
-
type:
|
|
202
|
+
description: ve(e?.type, n),
|
|
203
|
+
type: _e(e?.type, t, n, r) || ""
|
|
204
204
|
});
|
|
205
205
|
r[i][e] = {
|
|
206
206
|
parameters: o.map((e) => d(e, e?.component, e?.serializer, "parameter")),
|
|
@@ -211,7 +211,7 @@ function he(e, t, n) {
|
|
|
211
211
|
}));
|
|
212
212
|
}), r;
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function _e(e, t, n, r) {
|
|
215
215
|
if (t === "Api") return e.type;
|
|
216
216
|
switch (e?.type) {
|
|
217
217
|
case "string": return "string";
|
|
@@ -224,10 +224,10 @@ function ge(e, t, n, r) {
|
|
|
224
224
|
if (n === "FileSerializable") return e?.type === "array" ? r === "parameter" ? "(Blob | File | Buffer)[]" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]" : r === "parameter" ? "Blob | File | Buffer" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}";
|
|
225
225
|
if (n === "GallerySerializable") return r === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function ve(e, t) {
|
|
228
228
|
return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e?.description;
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function ye(e, t) {
|
|
231
231
|
switch (e.msg) {
|
|
232
232
|
case "send_data": return { type: "data" };
|
|
233
233
|
case "send_hash": return { type: "hash" };
|
|
@@ -363,7 +363,7 @@ function ve(e, t) {
|
|
|
363
363
|
}
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
|
-
var
|
|
366
|
+
var be = (e = [], t) => {
|
|
367
367
|
let n = t ? t.parameters : [];
|
|
368
368
|
if (Array.isArray(e)) return t && n.length > 0 && e.length > n.length && console.warn("Too many arguments provided for the endpoint."), e;
|
|
369
369
|
let r = [], i = Object.keys(e);
|
|
@@ -379,28 +379,28 @@ var ye = (e = [], t) => {
|
|
|
379
379
|
};
|
|
380
380
|
//#endregion
|
|
381
381
|
//#region src/utils/view_api.ts
|
|
382
|
-
async function
|
|
382
|
+
async function xe() {
|
|
383
383
|
if (this.api_info) return this.api_info;
|
|
384
384
|
let { token: e } = this.options, { config: t } = this, n = {};
|
|
385
385
|
if (e && (n.Authorization = `Bearer ${e}`), t) try {
|
|
386
386
|
let e, r;
|
|
387
387
|
if (typeof window < "u" && window.gradio_api_info) r = window.gradio_api_info;
|
|
388
388
|
else {
|
|
389
|
-
let i =
|
|
389
|
+
let i = I(t.root, this.api_prefix, h);
|
|
390
390
|
if (e = await this.fetch(i, {
|
|
391
391
|
headers: n,
|
|
392
392
|
credentials: this.options.credentials ?? "same-origin"
|
|
393
393
|
}), !e.ok) throw Error(y);
|
|
394
394
|
r = await e.json();
|
|
395
395
|
}
|
|
396
|
-
return "api" in r && (r = r.api), r.named_endpoints["/predict"] && !r.unnamed_endpoints[0] && (r.unnamed_endpoints[0] = r.named_endpoints["/predict"]),
|
|
396
|
+
return "api" in r && (r = r.api), r.named_endpoints["/predict"] && !r.unnamed_endpoints[0] && (r.unnamed_endpoints[0] = r.named_endpoints["/predict"]), L(r, t, this.api_map);
|
|
397
397
|
} catch (e) {
|
|
398
398
|
throw Error("Could not get API info. " + e.message);
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
//#endregion
|
|
402
402
|
//#region src/utils/upload_files.ts
|
|
403
|
-
async function
|
|
403
|
+
async function R(e, t, n) {
|
|
404
404
|
let r = {};
|
|
405
405
|
this?.options?.token && (r.Authorization = `Bearer ${this.options.token}`);
|
|
406
406
|
let i = 1e3, a = [], o;
|
|
@@ -429,7 +429,7 @@ async function z(e, t, n) {
|
|
|
429
429
|
}
|
|
430
430
|
return { files: a };
|
|
431
431
|
}
|
|
432
|
-
var
|
|
432
|
+
var z = {
|
|
433
433
|
si: {
|
|
434
434
|
radix: 1e3,
|
|
435
435
|
unit: [
|
|
@@ -473,27 +473,30 @@ var B = {
|
|
|
473
473
|
]
|
|
474
474
|
}
|
|
475
475
|
};
|
|
476
|
-
function
|
|
476
|
+
function B(e, t = 1, n = "jedec") {
|
|
477
477
|
e = Math.abs(e);
|
|
478
|
-
let { radix: r, unit: i } =
|
|
478
|
+
let { radix: r, unit: i } = z[n] || z.jedec, a = 0;
|
|
479
479
|
for (; e >= r;) e /= r, ++a;
|
|
480
480
|
return `${e.toFixed(t)} ${i[a]}`;
|
|
481
481
|
}
|
|
482
482
|
//#endregion
|
|
483
483
|
//#region src/upload.ts
|
|
484
|
-
async function
|
|
484
|
+
async function V(e, t, n, r) {
|
|
485
485
|
let i = (Array.isArray(e) ? e : [e]).map((e) => e.blob), a = i.filter((e) => e.size > (r ?? Infinity));
|
|
486
|
-
if (a.length) throw Error(`File(s) exceed the maximum allowed size of ${
|
|
486
|
+
if (a.length) throw Error(`File(s) exceed the maximum allowed size of ${B(r || Infinity)}: ${a.map((e) => `"${e.name}"`).join(", ")}`);
|
|
487
487
|
return await Promise.all(await this.upload_files(t, i, n).then(async (n) => {
|
|
488
488
|
if (n.error) throw Error(n.error);
|
|
489
|
-
return n.files ? n.files.map((n, r) =>
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
489
|
+
return n.files ? n.files.map((n, r) => {
|
|
490
|
+
let i = n.split("/").map((e) => encodeURIComponent(e)).join("/");
|
|
491
|
+
return new U({
|
|
492
|
+
...e[r],
|
|
493
|
+
path: n,
|
|
494
|
+
url: `${t}${this.api_prefix}/file=${i}`
|
|
495
|
+
});
|
|
496
|
+
}) : [];
|
|
494
497
|
}));
|
|
495
498
|
}
|
|
496
|
-
async function
|
|
499
|
+
async function H(e, t) {
|
|
497
500
|
return e.map((e) => new U({
|
|
498
501
|
path: e.name,
|
|
499
502
|
orig_name: e.name,
|
|
@@ -517,7 +520,7 @@ var U = class {
|
|
|
517
520
|
constructor({ path: e, url: t, orig_name: n, size: r, blob: i, is_stream: a, mime_type: o, alt_text: s, b64: c }) {
|
|
518
521
|
this.path = e, this.url = t, this.orig_name = n, this.size = r, this.blob = t ? void 0 : i, this.is_stream = a, this.mime_type = o, this.alt_text = s, this.b64 = c;
|
|
519
522
|
}
|
|
520
|
-
},
|
|
523
|
+
}, Se = class {
|
|
521
524
|
type;
|
|
522
525
|
command;
|
|
523
526
|
meta;
|
|
@@ -525,8 +528,8 @@ var U = class {
|
|
|
525
528
|
constructor(e, t) {
|
|
526
529
|
this.type = "command", this.command = e, this.meta = t;
|
|
527
530
|
}
|
|
528
|
-
},
|
|
529
|
-
function
|
|
531
|
+
}, Ce = typeof process < "u" && process.versions && process.versions.node;
|
|
532
|
+
function we(e, t, n) {
|
|
530
533
|
for (; n.length > 1;) {
|
|
531
534
|
let t = n.shift();
|
|
532
535
|
if (typeof t == "string" || typeof t == "number") e = e[t];
|
|
@@ -536,13 +539,13 @@ function Ce(e, t, n) {
|
|
|
536
539
|
if (typeof r == "string" || typeof r == "number") e[r] = t;
|
|
537
540
|
else throw Error("Invalid key type");
|
|
538
541
|
}
|
|
539
|
-
async function
|
|
542
|
+
async function W(e, t = void 0, n = [], r = !1, i = void 0) {
|
|
540
543
|
if (Array.isArray(e)) {
|
|
541
544
|
let a = [];
|
|
542
545
|
return await Promise.all(e.map(async (o, s) => {
|
|
543
546
|
let c = n.slice();
|
|
544
547
|
c.push(String(s));
|
|
545
|
-
let l = await
|
|
548
|
+
let l = await W(e[s], r ? i?.parameters[s]?.component || void 0 : t, c, !1, i);
|
|
546
549
|
a = a.concat(l);
|
|
547
550
|
})), a;
|
|
548
551
|
} else if (globalThis.Buffer && e instanceof globalThis.Buffer || e instanceof Blob) return [{
|
|
@@ -554,7 +557,7 @@ async function we(e, t = void 0, n = [], r = !1, i = void 0) {
|
|
|
554
557
|
let t = [];
|
|
555
558
|
for (let r of Object.keys(e)) {
|
|
556
559
|
let a = [...n, r], o = e[r];
|
|
557
|
-
t = t.concat(await
|
|
560
|
+
t = t.concat(await W(o, void 0, a, !1, i));
|
|
558
561
|
}
|
|
559
562
|
return t;
|
|
560
563
|
}
|
|
@@ -580,7 +583,7 @@ function De(e) {
|
|
|
580
583
|
orig_name: e.split("/").pop() ?? "unknown",
|
|
581
584
|
meta: { _type: "gradio.FileData" }
|
|
582
585
|
};
|
|
583
|
-
if (
|
|
586
|
+
if (Ce) return new Se("upload_file", {
|
|
584
587
|
path: e,
|
|
585
588
|
name: e,
|
|
586
589
|
orig_path: e
|
|
@@ -623,7 +626,7 @@ var Oe = /* @__PURE__ */ o(((e, t) => {
|
|
|
623
626
|
async function ke(e, t, n) {
|
|
624
627
|
let r = this;
|
|
625
628
|
await Ae(r, t);
|
|
626
|
-
let i = await
|
|
629
|
+
let i = await W(t, void 0, [], !0, n);
|
|
627
630
|
return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
|
|
628
631
|
if (!n) return {
|
|
629
632
|
path: t,
|
|
@@ -637,35 +640,35 @@ async function ke(e, t, n) {
|
|
|
637
640
|
name: typeof File < "u" && n instanceof File ? n?.name : void 0
|
|
638
641
|
};
|
|
639
642
|
}))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
|
|
640
|
-
r === "Gallery" ?
|
|
643
|
+
r === "Gallery" ? we(t, n, e) : n && we(t, new U({
|
|
641
644
|
path: n,
|
|
642
645
|
orig_name: i
|
|
643
646
|
}), e);
|
|
644
647
|
}), t;
|
|
645
648
|
}
|
|
646
649
|
async function Ae(e, t) {
|
|
647
|
-
if (!(e.config?.root || e.config?.root_url)) throw Error(
|
|
650
|
+
if (!(e.config?.root || e.config?.root_url)) throw Error(de);
|
|
648
651
|
await je(e, t);
|
|
649
652
|
}
|
|
650
653
|
async function je(e, t, n = []) {
|
|
651
|
-
for (let r in t) t[r] instanceof
|
|
654
|
+
for (let r in t) t[r] instanceof Se ? await Me(e, t, r) : typeof t[r] == "object" && t[r] !== null && await je(e, t[r], [...n, r]);
|
|
652
655
|
}
|
|
653
656
|
async function Me(e, t, n) {
|
|
654
657
|
let r = t[n], i = e.config?.root || e.config?.root_url;
|
|
655
|
-
if (!i) throw Error(
|
|
658
|
+
if (!i) throw Error(de);
|
|
656
659
|
try {
|
|
657
660
|
let a, o;
|
|
658
661
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
659
662
|
let e = await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1));
|
|
660
663
|
o = (await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
|
|
661
|
-
} else throw Error(
|
|
664
|
+
} else throw Error(ue);
|
|
662
665
|
let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
|
|
663
666
|
u && (t[n] = new U({
|
|
664
667
|
path: u,
|
|
665
668
|
orig_name: r.meta.name || ""
|
|
666
669
|
}));
|
|
667
670
|
} catch (e) {
|
|
668
|
-
console.error(
|
|
671
|
+
console.error(fe, e);
|
|
669
672
|
}
|
|
670
673
|
}
|
|
671
674
|
//#endregion
|
|
@@ -799,7 +802,7 @@ async function K(e, t, n) {
|
|
|
799
802
|
var Fe = async (e, t) => {
|
|
800
803
|
let n = 0;
|
|
801
804
|
return new Promise((r) => {
|
|
802
|
-
K(e,
|
|
805
|
+
K(e, P.test(e) ? "space_name" : "subdomain", (i) => {
|
|
803
806
|
t(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (n < 12 ? (n++, setTimeout(() => {
|
|
804
807
|
Fe(e, t).then(r);
|
|
805
808
|
}, 5e3)) : r());
|
|
@@ -831,7 +834,7 @@ async function ze(e, t, n) {
|
|
|
831
834
|
n && (r.Authorization = `Bearer ${n}`);
|
|
832
835
|
let i = { seconds: t };
|
|
833
836
|
try {
|
|
834
|
-
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${
|
|
837
|
+
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${_}`, {
|
|
835
838
|
method: "POST",
|
|
836
839
|
headers: {
|
|
837
840
|
"Content-Type": "application/json",
|
|
@@ -863,13 +866,13 @@ var Be = [
|
|
|
863
866
|
//#endregion
|
|
864
867
|
//#region src/utils/duplicate.ts
|
|
865
868
|
async function Ve(e, t) {
|
|
866
|
-
|
|
869
|
+
D(t);
|
|
867
870
|
let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
|
|
868
871
|
if (i && !Be.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Be.map((e) => `"${e}"`).join(",")}.`);
|
|
869
|
-
let { http_protocol: s, host: c } = await
|
|
872
|
+
let { http_protocol: s, host: c } = await F(e, n), l = null;
|
|
870
873
|
if (o) {
|
|
871
|
-
let e = await
|
|
872
|
-
e && (l =
|
|
874
|
+
let e = await j(s, c, o, fetch, void 0, t.credentials);
|
|
875
|
+
e && (l = N(e));
|
|
873
876
|
}
|
|
874
877
|
let u = {
|
|
875
878
|
Authorization: `Bearer ${n}`,
|
|
@@ -881,7 +884,7 @@ async function Ve(e, t) {
|
|
|
881
884
|
try {
|
|
882
885
|
i || (m = await Re(e, n));
|
|
883
886
|
} catch (e) {
|
|
884
|
-
throw Error(
|
|
887
|
+
throw Error(S + e.message);
|
|
885
888
|
}
|
|
886
889
|
p.hardware = i || m || "cpu-basic";
|
|
887
890
|
try {
|
|
@@ -1103,7 +1106,7 @@ function at(e, t = {}) {
|
|
|
1103
1106
|
}
|
|
1104
1107
|
//#endregion
|
|
1105
1108
|
//#region src/utils/run_history.ts
|
|
1106
|
-
var ot = "gradio:run-history:", q = `${ot}v2:`, st = `${ot}replay:v2:`, ct = 100,
|
|
1109
|
+
var ot = "gradio:run-history:", q = `${ot}v2:`, st = `${ot}replay:v2:`, ct = `${ot}destination:v1:`, lt = 100, ut = 8;
|
|
1107
1110
|
function J(e, t) {
|
|
1108
1111
|
try {
|
|
1109
1112
|
return e();
|
|
@@ -1111,7 +1114,7 @@ function J(e, t) {
|
|
|
1111
1114
|
return console.warn("Could not update the run history.", e), t;
|
|
1112
1115
|
}
|
|
1113
1116
|
}
|
|
1114
|
-
function
|
|
1117
|
+
function dt(e, t = "/gradio_api") {
|
|
1115
1118
|
return `${e.replace(/\/+$/, "")}${t}/runs`;
|
|
1116
1119
|
}
|
|
1117
1120
|
function Y(e) {
|
|
@@ -1124,11 +1127,35 @@ function Y(e) {
|
|
|
1124
1127
|
return null;
|
|
1125
1128
|
}
|
|
1126
1129
|
}
|
|
1127
|
-
function
|
|
1130
|
+
function ft(e) {
|
|
1128
1131
|
let t = Y(e);
|
|
1129
1132
|
return t ? t.replace(q, st) : null;
|
|
1130
1133
|
}
|
|
1131
|
-
function
|
|
1134
|
+
function pt(e) {
|
|
1135
|
+
let t = Y(e);
|
|
1136
|
+
return t ? t.replace(q, ct) : null;
|
|
1137
|
+
}
|
|
1138
|
+
function mt(e) {
|
|
1139
|
+
let t = pt(e);
|
|
1140
|
+
if (!t) return { type: "browser" };
|
|
1141
|
+
try {
|
|
1142
|
+
let e = JSON.parse(window.localStorage.getItem(t) || "null");
|
|
1143
|
+
return typeof e?.bucket_id == "string" ? e.type === "bucket" ? {
|
|
1144
|
+
type: "bucket",
|
|
1145
|
+
bucket_id: e.bucket_id
|
|
1146
|
+
} : {
|
|
1147
|
+
type: "browser",
|
|
1148
|
+
bucket_id: e.bucket_id
|
|
1149
|
+
} : { type: "browser" };
|
|
1150
|
+
} catch {
|
|
1151
|
+
return { type: "browser" };
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
function ht(e, t) {
|
|
1155
|
+
let n = pt(e);
|
|
1156
|
+
n && (t.type === "browser" && !t.bucket_id ? window.localStorage.removeItem(n) : window.localStorage.setItem(n, JSON.stringify(t)), Ct());
|
|
1157
|
+
}
|
|
1158
|
+
function gt(e) {
|
|
1132
1159
|
try {
|
|
1133
1160
|
let t = JSON.parse(window.localStorage.getItem(e) || "[]");
|
|
1134
1161
|
return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
|
|
@@ -1136,13 +1163,13 @@ function ft(e) {
|
|
|
1136
1163
|
return 0;
|
|
1137
1164
|
}
|
|
1138
1165
|
}
|
|
1139
|
-
function
|
|
1140
|
-
let t = Object.keys(window.localStorage).filter((e) => e.startsWith(ot)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(st)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) =>
|
|
1166
|
+
function _t(e) {
|
|
1167
|
+
let t = Object.keys(window.localStorage).filter((e) => e.startsWith(ot)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(st) && !e.startsWith(ct)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => gt(t) - gt(e)).slice(ut - 1)];
|
|
1141
1168
|
for (let e of n) try {
|
|
1142
1169
|
window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, st));
|
|
1143
1170
|
} catch {}
|
|
1144
1171
|
}
|
|
1145
|
-
function
|
|
1172
|
+
function vt() {
|
|
1146
1173
|
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1147
1174
|
}
|
|
1148
1175
|
function X(e) {
|
|
@@ -1170,16 +1197,16 @@ function Z(e) {
|
|
|
1170
1197
|
return [];
|
|
1171
1198
|
}
|
|
1172
1199
|
}
|
|
1173
|
-
function
|
|
1200
|
+
function yt(e, t) {
|
|
1174
1201
|
let n = Y(e);
|
|
1175
1202
|
if (!n) return;
|
|
1176
|
-
let r = t.slice(0,
|
|
1203
|
+
let r = t.slice(0, lt), i = !1;
|
|
1177
1204
|
for (; r.length > 0;) try {
|
|
1178
1205
|
window.localStorage.setItem(n, JSON.stringify(r));
|
|
1179
1206
|
return;
|
|
1180
1207
|
} catch {
|
|
1181
1208
|
if (!i) {
|
|
1182
|
-
i = !0,
|
|
1209
|
+
i = !0, _t(n);
|
|
1183
1210
|
continue;
|
|
1184
1211
|
}
|
|
1185
1212
|
r = r.slice(0, -1);
|
|
@@ -1188,37 +1215,37 @@ function ht(e, t) {
|
|
|
1188
1215
|
window.localStorage.removeItem(n);
|
|
1189
1216
|
} catch {}
|
|
1190
1217
|
}
|
|
1191
|
-
function
|
|
1218
|
+
function bt(e) {
|
|
1192
1219
|
let t = Y(e);
|
|
1193
1220
|
if (t) {
|
|
1194
1221
|
try {
|
|
1195
1222
|
window.localStorage.removeItem(t);
|
|
1196
1223
|
} catch {}
|
|
1197
|
-
|
|
1224
|
+
Ct();
|
|
1198
1225
|
}
|
|
1199
1226
|
}
|
|
1200
|
-
function
|
|
1201
|
-
|
|
1227
|
+
function xt(e, t) {
|
|
1228
|
+
yt(e, Z(e).filter((e) => e.id !== t)), Ct();
|
|
1202
1229
|
}
|
|
1203
|
-
var
|
|
1204
|
-
function
|
|
1230
|
+
var St = "gradio:run-history-change";
|
|
1231
|
+
function Ct() {
|
|
1205
1232
|
if (!(typeof window > "u")) try {
|
|
1206
|
-
window.dispatchEvent(new Event(
|
|
1233
|
+
window.dispatchEvent(new Event(St));
|
|
1207
1234
|
} catch {}
|
|
1208
1235
|
}
|
|
1209
|
-
function
|
|
1210
|
-
return typeof window > "u" ? () => {} : (window.addEventListener(
|
|
1211
|
-
window.removeEventListener(
|
|
1236
|
+
function wt(e) {
|
|
1237
|
+
return typeof window > "u" ? () => {} : (window.addEventListener(St, e), window.addEventListener("storage", e), () => {
|
|
1238
|
+
window.removeEventListener(St, e), window.removeEventListener("storage", e);
|
|
1212
1239
|
});
|
|
1213
1240
|
}
|
|
1214
|
-
function
|
|
1215
|
-
let n =
|
|
1241
|
+
function Tt(e, t) {
|
|
1242
|
+
let n = ft(e);
|
|
1216
1243
|
if (n) try {
|
|
1217
1244
|
window.sessionStorage.setItem(n, JSON.stringify(t));
|
|
1218
1245
|
} catch {}
|
|
1219
1246
|
}
|
|
1220
|
-
function
|
|
1221
|
-
let t =
|
|
1247
|
+
function Et(e) {
|
|
1248
|
+
let t = ft(e);
|
|
1222
1249
|
if (!t) return null;
|
|
1223
1250
|
try {
|
|
1224
1251
|
let e = window.sessionStorage.getItem(t);
|
|
@@ -1227,7 +1254,7 @@ function St(e) {
|
|
|
1227
1254
|
return null;
|
|
1228
1255
|
}
|
|
1229
1256
|
}
|
|
1230
|
-
function
|
|
1257
|
+
function Dt(e, t) {
|
|
1231
1258
|
let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
|
|
1232
1259
|
if (!n) return !1;
|
|
1233
1260
|
let r = Array.isArray(t.inputs) ? t.inputs : Object.values(t.inputs ?? {}), i = Array.isArray(t.outputs) ? t.outputs : t.outputs === null || t.outputs === void 0 ? [] : [t.outputs], a = (t, n) => {
|
|
@@ -1238,16 +1265,17 @@ function Ct(e, t) {
|
|
|
1238
1265
|
};
|
|
1239
1266
|
return a(n.inputs, r), a(n.outputs, i), !0;
|
|
1240
1267
|
}
|
|
1241
|
-
function
|
|
1242
|
-
let t =
|
|
1243
|
-
return t ?
|
|
1268
|
+
function Ot(e) {
|
|
1269
|
+
let t = Et(e);
|
|
1270
|
+
return t ? Dt(e, t) : !1;
|
|
1244
1271
|
}
|
|
1245
|
-
function
|
|
1272
|
+
function kt(e) {
|
|
1273
|
+
if (mt(e).type === "bucket") return null;
|
|
1246
1274
|
let t = Y(e);
|
|
1247
1275
|
if (!t) return null;
|
|
1248
|
-
|
|
1276
|
+
_t(t);
|
|
1249
1277
|
let n = {
|
|
1250
|
-
id:
|
|
1278
|
+
id: vt(),
|
|
1251
1279
|
endpoint: e.endpoint,
|
|
1252
1280
|
api_name: e.api_name,
|
|
1253
1281
|
fn_index: e.fn_index,
|
|
@@ -1259,116 +1287,125 @@ function Tt(e) {
|
|
|
1259
1287
|
status: "running",
|
|
1260
1288
|
started_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1261
1289
|
};
|
|
1262
|
-
return
|
|
1290
|
+
return yt(e, [n, ...Z(e)]), Ct(), n.id;
|
|
1263
1291
|
}
|
|
1264
|
-
function
|
|
1292
|
+
function At(e, t, n) {
|
|
1265
1293
|
if (!t) return;
|
|
1266
1294
|
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1267
|
-
i && (i.inputs = X(n),
|
|
1295
|
+
i && (i.inputs = X(n), yt(e, r));
|
|
1268
1296
|
}
|
|
1269
|
-
function
|
|
1297
|
+
function jt(e, t, n) {
|
|
1270
1298
|
if (!t) return;
|
|
1271
1299
|
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1272
1300
|
if (!i) return;
|
|
1273
1301
|
let a = !1;
|
|
1274
1302
|
if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
|
|
1275
|
-
else if (n.type === "status" && n.original_msg === "process_starts")
|
|
1303
|
+
else if (n.type === "status" && n.original_msg === "process_starts") Pt(i, n.time);
|
|
1276
1304
|
else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
|
|
1277
|
-
else if (n.type === "status" && n.stage === "complete") i.status = "completed",
|
|
1278
|
-
else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"),
|
|
1305
|
+
else if (n.type === "status" && n.stage === "complete") i.status = "completed", Ft(i, n), a = !0;
|
|
1306
|
+
else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"), Ft(i, n), a = !0;
|
|
1279
1307
|
else return;
|
|
1280
|
-
if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t),
|
|
1308
|
+
if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Nt.delete(t);
|
|
1281
1309
|
else if (i.streamed) {
|
|
1282
|
-
if (Date.now() - (
|
|
1283
|
-
|
|
1310
|
+
if (Date.now() - (Nt.get(t) ?? 0) < Mt) return;
|
|
1311
|
+
Nt.set(t, Date.now()), Q.delete(t);
|
|
1284
1312
|
}
|
|
1285
|
-
|
|
1313
|
+
yt(e, r);
|
|
1286
1314
|
}
|
|
1287
|
-
var
|
|
1288
|
-
function
|
|
1315
|
+
var Mt = 500, Nt = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
|
|
1316
|
+
function Pt(e, t) {
|
|
1289
1317
|
if (e.process_started_at) return;
|
|
1290
1318
|
let n = t || /* @__PURE__ */ new Date();
|
|
1291
1319
|
e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
|
|
1292
1320
|
}
|
|
1293
|
-
function
|
|
1321
|
+
function Ft(e, t) {
|
|
1294
1322
|
let n = t.time || /* @__PURE__ */ new Date();
|
|
1295
1323
|
e.completed_at = n.toISOString(), e.duration_ms = (!e.streamed && typeof t.cache_duration == "number" && t.cache_duration >= 0 ? t.cache_duration * 1e3 : null) ?? Math.max(0, n.getTime() - Date.parse(e.process_started_at || e.started_at));
|
|
1296
1324
|
}
|
|
1297
|
-
function
|
|
1325
|
+
function It(e) {
|
|
1298
1326
|
return J(() => Z(e), []);
|
|
1299
1327
|
}
|
|
1300
|
-
function
|
|
1301
|
-
J(() =>
|
|
1328
|
+
function Lt(e) {
|
|
1329
|
+
return J(() => mt(e), { type: "browser" });
|
|
1302
1330
|
}
|
|
1303
|
-
function
|
|
1304
|
-
J(() =>
|
|
1331
|
+
function Rt(e, t) {
|
|
1332
|
+
J(() => ht(e, t), void 0);
|
|
1305
1333
|
}
|
|
1306
|
-
function
|
|
1334
|
+
function zt(e) {
|
|
1335
|
+
J(() => bt(e), void 0);
|
|
1336
|
+
}
|
|
1337
|
+
function Bt(e, t) {
|
|
1307
1338
|
J(() => xt(e, t), void 0);
|
|
1308
1339
|
}
|
|
1309
|
-
function
|
|
1310
|
-
|
|
1340
|
+
function Vt(e, t) {
|
|
1341
|
+
J(() => Tt(e, t), void 0);
|
|
1311
1342
|
}
|
|
1312
|
-
function
|
|
1313
|
-
return J(() =>
|
|
1343
|
+
function Ht(e) {
|
|
1344
|
+
return J(() => Et(e), null);
|
|
1314
1345
|
}
|
|
1315
|
-
function
|
|
1316
|
-
return J(() =>
|
|
1346
|
+
function Ut(e) {
|
|
1347
|
+
return J(() => Ot(e), !1);
|
|
1317
1348
|
}
|
|
1318
|
-
function
|
|
1319
|
-
J(() =>
|
|
1349
|
+
function Wt(e) {
|
|
1350
|
+
return J(() => kt(e), null);
|
|
1320
1351
|
}
|
|
1321
|
-
function
|
|
1322
|
-
J(() =>
|
|
1352
|
+
function Gt(e, t, n) {
|
|
1353
|
+
J(() => At(e, t, n), void 0);
|
|
1323
1354
|
}
|
|
1324
|
-
function
|
|
1325
|
-
|
|
1355
|
+
function Kt(e, t, n) {
|
|
1356
|
+
J(() => jt(e, t, n), void 0);
|
|
1357
|
+
}
|
|
1358
|
+
function qt(e) {
|
|
1359
|
+
return J(() => wt(() => J(e, void 0)), () => {});
|
|
1326
1360
|
}
|
|
1327
1361
|
//#endregion
|
|
1328
1362
|
//#region src/utils/submit.ts
|
|
1329
|
-
function
|
|
1363
|
+
function Jt(e, t = {}, n, r, i, a) {
|
|
1330
1364
|
try {
|
|
1331
|
-
let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams:
|
|
1332
|
-
if (!p) throw Error(
|
|
1365
|
+
let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams: _, event_callbacks: v, unclosed_events: ee, post_data: re, options: b, api_prefix: x } = this, ae = a || { "x-gradio-user": "api" }, S = this;
|
|
1366
|
+
if (!p) throw Error(ce);
|
|
1333
1367
|
if (!l) throw Error("Could not resolve app config");
|
|
1334
|
-
let { fn_index:
|
|
1335
|
-
if (
|
|
1336
|
-
let
|
|
1368
|
+
let { fn_index: C, endpoint_info: w, dependency: T } = Xt(p, e, m, l), oe = be(t, w), E = l.protocol ?? "ws";
|
|
1369
|
+
if (E === "ws") throw Error(le);
|
|
1370
|
+
let se = typeof T.api_name == "string" ? `/${T.api_name}` : e, ue = typeof T.api_name == "string" ? `/${T.api_name}` : `Function ${C}`, de = (e) => {
|
|
1337
1371
|
let t = l.components.find((t) => t.id === e);
|
|
1338
1372
|
return t ? {
|
|
1339
1373
|
type: t.type,
|
|
1340
1374
|
component_class_id: t.component_class_id,
|
|
1341
1375
|
props: t.props
|
|
1342
1376
|
} : null;
|
|
1343
|
-
},
|
|
1377
|
+
}, fe = T.api_visibility === "public", pe = l.run_history !== !1 && this.options.record_history !== !1, D = {
|
|
1344
1378
|
app_id: l.app_id,
|
|
1345
1379
|
username: l.username
|
|
1346
|
-
},
|
|
1347
|
-
...
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1380
|
+
}, me = Lt(D), O = {
|
|
1381
|
+
...ae,
|
|
1382
|
+
...pe && me.type === "bucket" ? { "x-gradio-history-bucket": me.bucket_id } : {}
|
|
1383
|
+
}, he = !pe || !fe ? null : Wt({
|
|
1384
|
+
...D,
|
|
1385
|
+
endpoint: se,
|
|
1386
|
+
api_name: ue,
|
|
1387
|
+
fn_index: C,
|
|
1388
|
+
inputs: G(oe, T, l.components, "input", !0),
|
|
1389
|
+
input_components: T.inputs.map(de),
|
|
1390
|
+
output_components: T.outputs.map(de)
|
|
1391
|
+
}), k, A = "", j = typeof e == "number" ? "/predict" : e, M, N = null, P = !1, ge = {}, F = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", I = b?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
|
|
1392
|
+
function L(e) {
|
|
1393
|
+
Kt(D, he, e), (i || I[e.type]) && Ce(e);
|
|
1357
1394
|
}
|
|
1358
|
-
async function
|
|
1395
|
+
async function _e() {
|
|
1359
1396
|
let e = {}, t = {};
|
|
1360
|
-
e = { event_id:
|
|
1361
|
-
event_id:
|
|
1397
|
+
e = { event_id: N }, t = {
|
|
1398
|
+
event_id: N,
|
|
1362
1399
|
session_hash: f,
|
|
1363
|
-
fn_index:
|
|
1400
|
+
fn_index: C
|
|
1364
1401
|
};
|
|
1365
1402
|
try {
|
|
1366
1403
|
if (!l) throw Error("Could not resolve app config");
|
|
1367
|
-
"event_id" in t && await s(`${l.root}${x}/${
|
|
1404
|
+
"event_id" in t && await s(`${l.root}${x}/${ne}`, {
|
|
1368
1405
|
headers: { "Content-Type": "application/json" },
|
|
1369
1406
|
method: "POST",
|
|
1370
1407
|
body: JSON.stringify(t)
|
|
1371
|
-
}), await s(`${l.root}${x}/${
|
|
1408
|
+
}), await s(`${l.root}${x}/${te}`, {
|
|
1372
1409
|
headers: { "Content-Type": "application/json" },
|
|
1373
1410
|
method: "POST",
|
|
1374
1411
|
body: JSON.stringify(e)
|
|
@@ -1377,53 +1414,53 @@ function Ht(e, t = {}, n, r, i, a) {
|
|
|
1377
1414
|
console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
|
|
1378
1415
|
}
|
|
1379
1416
|
}
|
|
1380
|
-
let
|
|
1417
|
+
let ve = async (e) => {
|
|
1381
1418
|
await this._resolve_heartbeat(e);
|
|
1382
1419
|
};
|
|
1383
|
-
async function
|
|
1420
|
+
async function xe(e) {
|
|
1384
1421
|
if (!l) return;
|
|
1385
1422
|
let t = e.render_id;
|
|
1386
1423
|
l.components = [...l.components.filter((e) => e.props.rendered_in !== t), ...e.components], l.dependencies = [...l.dependencies.filter((e) => e.rendered_in !== t), ...e.dependencies];
|
|
1387
1424
|
let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
|
|
1388
|
-
l.connect_heartbeat = n || r, await
|
|
1425
|
+
l.connect_heartbeat = n || r, await ve(l), L({
|
|
1389
1426
|
type: "render",
|
|
1390
1427
|
data: e,
|
|
1391
|
-
endpoint:
|
|
1392
|
-
fn_index:
|
|
1428
|
+
endpoint: j,
|
|
1429
|
+
fn_index: C
|
|
1393
1430
|
});
|
|
1394
1431
|
}
|
|
1395
|
-
let
|
|
1396
|
-
let t = G(e,
|
|
1397
|
-
if (
|
|
1432
|
+
let R = this.handle_blob(l.root, oe, w).then(async (e) => {
|
|
1433
|
+
let t = G(e, T, l.components, "input", !0);
|
|
1434
|
+
if (Gt(D, he, t || []), M = {
|
|
1398
1435
|
data: t || [],
|
|
1399
1436
|
event_data: n,
|
|
1400
|
-
fn_index:
|
|
1437
|
+
fn_index: C,
|
|
1401
1438
|
trigger_id: r,
|
|
1402
|
-
...b.oauth_token &&
|
|
1403
|
-
}, Te(
|
|
1439
|
+
...b.oauth_token && w?.oauth_token ? { oauth_token: b.oauth_token } : {}
|
|
1440
|
+
}, Te(C, l)) L({
|
|
1404
1441
|
type: "status",
|
|
1405
|
-
endpoint:
|
|
1442
|
+
endpoint: j,
|
|
1406
1443
|
stage: "pending",
|
|
1407
1444
|
queue: !1,
|
|
1408
|
-
fn_index:
|
|
1445
|
+
fn_index: C,
|
|
1409
1446
|
time: /* @__PURE__ */ new Date()
|
|
1410
|
-
}),
|
|
1411
|
-
...
|
|
1447
|
+
}), re(`${l.root}${x}/run${j.startsWith("/") ? j : `/${j}`}${F ? "?" + F : ""}`, {
|
|
1448
|
+
...M,
|
|
1412
1449
|
session_hash: f
|
|
1413
|
-
},
|
|
1450
|
+
}, O).then(async ([e, t]) => {
|
|
1414
1451
|
let i = e.data;
|
|
1415
|
-
if (t == 200)
|
|
1452
|
+
if (t == 200) L({
|
|
1416
1453
|
type: "data",
|
|
1417
|
-
endpoint:
|
|
1418
|
-
fn_index:
|
|
1419
|
-
data: G(i,
|
|
1454
|
+
endpoint: j,
|
|
1455
|
+
fn_index: C,
|
|
1456
|
+
data: G(i, T, l.components, "output", b.with_null_state),
|
|
1420
1457
|
time: /* @__PURE__ */ new Date(),
|
|
1421
1458
|
event_data: n,
|
|
1422
1459
|
trigger_id: r
|
|
1423
|
-
}), e.render_config && await
|
|
1460
|
+
}), e.render_config && await xe(e.render_config), L({
|
|
1424
1461
|
type: "status",
|
|
1425
|
-
endpoint:
|
|
1426
|
-
fn_index:
|
|
1462
|
+
endpoint: j,
|
|
1463
|
+
fn_index: C,
|
|
1427
1464
|
stage: "complete",
|
|
1428
1465
|
eta: e.average_duration,
|
|
1429
1466
|
queue: !1,
|
|
@@ -1431,11 +1468,11 @@ function Ht(e, t = {}, n, r, i, a) {
|
|
|
1431
1468
|
});
|
|
1432
1469
|
else {
|
|
1433
1470
|
let t = e?.error === y;
|
|
1434
|
-
|
|
1471
|
+
L({
|
|
1435
1472
|
type: "status",
|
|
1436
1473
|
stage: "error",
|
|
1437
|
-
endpoint:
|
|
1438
|
-
fn_index:
|
|
1474
|
+
endpoint: j,
|
|
1475
|
+
fn_index: C,
|
|
1439
1476
|
message: e.error,
|
|
1440
1477
|
broken: t,
|
|
1441
1478
|
queue: !1,
|
|
@@ -1443,98 +1480,98 @@ function Ht(e, t = {}, n, r, i, a) {
|
|
|
1443
1480
|
});
|
|
1444
1481
|
}
|
|
1445
1482
|
}).catch((e) => {
|
|
1446
|
-
|
|
1483
|
+
L({
|
|
1447
1484
|
type: "status",
|
|
1448
1485
|
stage: "error",
|
|
1449
1486
|
message: e.message,
|
|
1450
|
-
endpoint:
|
|
1451
|
-
fn_index:
|
|
1487
|
+
endpoint: j,
|
|
1488
|
+
fn_index: C,
|
|
1452
1489
|
queue: !1,
|
|
1453
1490
|
time: /* @__PURE__ */ new Date()
|
|
1454
1491
|
});
|
|
1455
1492
|
});
|
|
1456
|
-
else if (
|
|
1457
|
-
|
|
1493
|
+
else if (E == "sse") {
|
|
1494
|
+
L({
|
|
1458
1495
|
type: "status",
|
|
1459
1496
|
stage: "pending",
|
|
1460
1497
|
queue: !0,
|
|
1461
|
-
endpoint:
|
|
1462
|
-
fn_index:
|
|
1498
|
+
endpoint: j,
|
|
1499
|
+
fn_index: C,
|
|
1463
1500
|
time: /* @__PURE__ */ new Date()
|
|
1464
1501
|
});
|
|
1465
1502
|
var i = new URLSearchParams({
|
|
1466
|
-
fn_index:
|
|
1503
|
+
fn_index: C.toString(),
|
|
1467
1504
|
session_hash: f
|
|
1468
1505
|
}).toString();
|
|
1469
|
-
let e = new URL(`${l.root}${x}/${u}?${
|
|
1470
|
-
if (this.jwt && e.searchParams.set("__sign", this.jwt),
|
|
1471
|
-
|
|
1472
|
-
let { type: t, status: i, data: a } =
|
|
1473
|
-
if (t === "update" && i && !
|
|
1506
|
+
let e = new URL(`${l.root}${x}/${u}?${F ? F + "&" : ""}${i}`);
|
|
1507
|
+
if (this.jwt && e.searchParams.set("__sign", this.jwt), k = this.stream(e), !k) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
|
|
1508
|
+
k.onmessage = async function(e) {
|
|
1509
|
+
let { type: t, status: i, data: a } = ye(JSON.parse(e.data), ge[C]);
|
|
1510
|
+
if (t === "update" && i && !P) L({
|
|
1474
1511
|
type: "status",
|
|
1475
|
-
endpoint:
|
|
1476
|
-
fn_index:
|
|
1512
|
+
endpoint: j,
|
|
1513
|
+
fn_index: C,
|
|
1477
1514
|
time: /* @__PURE__ */ new Date(),
|
|
1478
1515
|
...i
|
|
1479
|
-
}), i.stage === "error" && (
|
|
1516
|
+
}), i.stage === "error" && (k?.close(), H());
|
|
1480
1517
|
else if (t === "data") {
|
|
1481
|
-
let [e, t] = await
|
|
1482
|
-
...
|
|
1518
|
+
let [e, t] = await re(`${l.root}${x}/queue/data`, {
|
|
1519
|
+
...M,
|
|
1483
1520
|
session_hash: f,
|
|
1484
|
-
event_id:
|
|
1485
|
-
});
|
|
1486
|
-
t !== 200 && (
|
|
1521
|
+
event_id: N
|
|
1522
|
+
}, O);
|
|
1523
|
+
t !== 200 && (L({
|
|
1487
1524
|
type: "status",
|
|
1488
1525
|
stage: "error",
|
|
1489
1526
|
message: y,
|
|
1490
1527
|
queue: !0,
|
|
1491
|
-
endpoint:
|
|
1492
|
-
fn_index:
|
|
1528
|
+
endpoint: j,
|
|
1529
|
+
fn_index: C,
|
|
1493
1530
|
time: /* @__PURE__ */ new Date()
|
|
1494
|
-
}),
|
|
1495
|
-
} else t === "complete" ?
|
|
1531
|
+
}), k?.close(), H());
|
|
1532
|
+
} else t === "complete" ? P = i : t === "log" ? L({
|
|
1496
1533
|
type: "log",
|
|
1497
1534
|
title: a.title,
|
|
1498
1535
|
log: a.log,
|
|
1499
1536
|
level: a.level,
|
|
1500
|
-
endpoint:
|
|
1537
|
+
endpoint: j,
|
|
1501
1538
|
duration: a.duration,
|
|
1502
1539
|
visible: a.visible,
|
|
1503
|
-
fn_index:
|
|
1504
|
-
}) : (t === "generating" || t === "streaming") &&
|
|
1540
|
+
fn_index: C
|
|
1541
|
+
}) : (t === "generating" || t === "streaming") && L({
|
|
1505
1542
|
type: "status",
|
|
1506
1543
|
time: /* @__PURE__ */ new Date(),
|
|
1507
1544
|
...i,
|
|
1508
1545
|
stage: i?.stage,
|
|
1509
1546
|
queue: !0,
|
|
1510
|
-
endpoint:
|
|
1511
|
-
fn_index:
|
|
1547
|
+
endpoint: j,
|
|
1548
|
+
fn_index: C
|
|
1512
1549
|
});
|
|
1513
|
-
a && (
|
|
1550
|
+
a && (L({
|
|
1514
1551
|
type: "data",
|
|
1515
1552
|
time: /* @__PURE__ */ new Date(),
|
|
1516
|
-
data: G(a.data,
|
|
1517
|
-
endpoint:
|
|
1518
|
-
fn_index:
|
|
1553
|
+
data: G(a.data, T, l.components, "output", b.with_null_state),
|
|
1554
|
+
endpoint: j,
|
|
1555
|
+
fn_index: C,
|
|
1519
1556
|
event_data: n,
|
|
1520
1557
|
trigger_id: r
|
|
1521
|
-
}),
|
|
1558
|
+
}), P && (L({
|
|
1522
1559
|
type: "status",
|
|
1523
1560
|
time: /* @__PURE__ */ new Date(),
|
|
1524
|
-
...
|
|
1561
|
+
...P,
|
|
1525
1562
|
stage: i?.stage,
|
|
1526
1563
|
queue: !0,
|
|
1527
|
-
endpoint:
|
|
1528
|
-
fn_index:
|
|
1529
|
-
}),
|
|
1564
|
+
endpoint: j,
|
|
1565
|
+
fn_index: C
|
|
1566
|
+
}), k?.close(), H()));
|
|
1530
1567
|
};
|
|
1531
|
-
} else if (
|
|
1532
|
-
|
|
1568
|
+
} else if (E == "sse_v1" || E == "sse_v2" || E == "sse_v2.1" || E == "sse_v3") {
|
|
1569
|
+
L({
|
|
1533
1570
|
type: "status",
|
|
1534
1571
|
stage: "pending",
|
|
1535
1572
|
queue: !0,
|
|
1536
|
-
endpoint:
|
|
1537
|
-
fn_index:
|
|
1573
|
+
endpoint: j,
|
|
1574
|
+
fn_index: C,
|
|
1538
1575
|
time: /* @__PURE__ */ new Date()
|
|
1539
1576
|
});
|
|
1540
1577
|
let e = "";
|
|
@@ -1542,204 +1579,204 @@ function Ht(e, t = {}, n, r, i, a) {
|
|
|
1542
1579
|
let t = Ke(e);
|
|
1543
1580
|
return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
|
|
1544
1581
|
let t = {
|
|
1545
|
-
...
|
|
1582
|
+
...O,
|
|
1546
1583
|
...e || {}
|
|
1547
1584
|
};
|
|
1548
|
-
return
|
|
1549
|
-
...
|
|
1585
|
+
return re(`${l.root}${x}/${d}?${F}`, {
|
|
1586
|
+
...M,
|
|
1550
1587
|
session_hash: f
|
|
1551
1588
|
}, t);
|
|
1552
1589
|
}).then(async ([e, t]) => {
|
|
1553
|
-
if (e.event_id && (
|
|
1590
|
+
if (e.event_id && (A = e.event_id), t === 503) L({
|
|
1554
1591
|
type: "status",
|
|
1555
1592
|
stage: "error",
|
|
1556
1593
|
message: ie,
|
|
1557
1594
|
queue: !0,
|
|
1558
|
-
endpoint:
|
|
1559
|
-
fn_index:
|
|
1595
|
+
endpoint: j,
|
|
1596
|
+
fn_index: C,
|
|
1560
1597
|
time: /* @__PURE__ */ new Date(),
|
|
1561
1598
|
visible: !0
|
|
1562
|
-
}),
|
|
1563
|
-
else if (t === 422)
|
|
1599
|
+
}), H();
|
|
1600
|
+
else if (t === 422) L({
|
|
1564
1601
|
type: "status",
|
|
1565
1602
|
stage: "error",
|
|
1566
1603
|
message: e.detail,
|
|
1567
1604
|
queue: !0,
|
|
1568
|
-
endpoint:
|
|
1569
|
-
fn_index:
|
|
1605
|
+
endpoint: j,
|
|
1606
|
+
fn_index: C,
|
|
1570
1607
|
code: "validation_error",
|
|
1571
1608
|
time: /* @__PURE__ */ new Date(),
|
|
1572
1609
|
visible: !0
|
|
1573
|
-
}),
|
|
1610
|
+
}), H();
|
|
1574
1611
|
else if (t !== 200) {
|
|
1575
1612
|
let t = e?.error === y;
|
|
1576
|
-
|
|
1613
|
+
L({
|
|
1577
1614
|
type: "status",
|
|
1578
1615
|
stage: "error",
|
|
1579
1616
|
broken: t,
|
|
1580
1617
|
message: t ? y : e.detail || e.error,
|
|
1581
1618
|
queue: !0,
|
|
1582
|
-
endpoint:
|
|
1583
|
-
fn_index:
|
|
1619
|
+
endpoint: j,
|
|
1620
|
+
fn_index: C,
|
|
1584
1621
|
time: /* @__PURE__ */ new Date(),
|
|
1585
1622
|
visible: !0
|
|
1586
|
-
}),
|
|
1623
|
+
}), H();
|
|
1587
1624
|
} else {
|
|
1588
|
-
|
|
1625
|
+
N = e.event_id, A = N;
|
|
1589
1626
|
let t = async function(e) {
|
|
1590
1627
|
try {
|
|
1591
|
-
let { type: t, status: n, data: r, original_msg: i } =
|
|
1628
|
+
let { type: t, status: n, data: r, original_msg: i } = ye(e, ge[C]);
|
|
1592
1629
|
if (t == "heartbeat") return;
|
|
1593
|
-
if (t === "update" && n && !
|
|
1630
|
+
if (t === "update" && n && !P) L({
|
|
1594
1631
|
type: "status",
|
|
1595
|
-
endpoint:
|
|
1596
|
-
fn_index:
|
|
1632
|
+
endpoint: j,
|
|
1633
|
+
fn_index: C,
|
|
1597
1634
|
time: /* @__PURE__ */ new Date(),
|
|
1598
1635
|
original_msg: i,
|
|
1599
1636
|
...n
|
|
1600
1637
|
});
|
|
1601
|
-
else if (t === "complete")
|
|
1638
|
+
else if (t === "complete") P = n;
|
|
1602
1639
|
else if (t == "unexpected_error" || t == "broken_connection") {
|
|
1603
1640
|
console.error("Unexpected error", n?.message);
|
|
1604
1641
|
let e = t === "broken_connection";
|
|
1605
|
-
|
|
1642
|
+
L({
|
|
1606
1643
|
type: "status",
|
|
1607
1644
|
stage: "error",
|
|
1608
1645
|
message: n?.message || "An Unexpected Error Occurred!",
|
|
1609
1646
|
queue: !0,
|
|
1610
|
-
endpoint:
|
|
1647
|
+
endpoint: j,
|
|
1611
1648
|
broken: e,
|
|
1612
1649
|
session_not_found: n?.session_not_found,
|
|
1613
|
-
fn_index:
|
|
1650
|
+
fn_index: C,
|
|
1614
1651
|
time: /* @__PURE__ */ new Date()
|
|
1615
1652
|
});
|
|
1616
1653
|
} else if (t === "log") {
|
|
1617
|
-
|
|
1654
|
+
L({
|
|
1618
1655
|
type: "log",
|
|
1619
1656
|
title: r.title,
|
|
1620
1657
|
log: r.log,
|
|
1621
1658
|
level: r.level,
|
|
1622
|
-
endpoint:
|
|
1659
|
+
endpoint: j,
|
|
1623
1660
|
duration: r.duration,
|
|
1624
1661
|
visible: r.visible,
|
|
1625
|
-
fn_index:
|
|
1662
|
+
fn_index: C
|
|
1626
1663
|
});
|
|
1627
1664
|
return;
|
|
1628
|
-
} else (t === "generating" || t === "streaming") && (
|
|
1665
|
+
} else (t === "generating" || t === "streaming") && (L({
|
|
1629
1666
|
type: "status",
|
|
1630
1667
|
time: /* @__PURE__ */ new Date(),
|
|
1631
1668
|
...n,
|
|
1632
1669
|
stage: n?.stage,
|
|
1633
1670
|
queue: !0,
|
|
1634
|
-
endpoint:
|
|
1635
|
-
fn_index:
|
|
1636
|
-
}), r &&
|
|
1671
|
+
endpoint: j,
|
|
1672
|
+
fn_index: C
|
|
1673
|
+
}), r && T.connection !== "stream" && [
|
|
1637
1674
|
"sse_v2",
|
|
1638
1675
|
"sse_v2.1",
|
|
1639
1676
|
"sse_v3"
|
|
1640
|
-
].includes(
|
|
1641
|
-
r && (
|
|
1677
|
+
].includes(E) && nt(_, N, r));
|
|
1678
|
+
r && (L({
|
|
1642
1679
|
type: "data",
|
|
1643
1680
|
time: /* @__PURE__ */ new Date(),
|
|
1644
|
-
data: G(r.data,
|
|
1645
|
-
endpoint:
|
|
1646
|
-
fn_index:
|
|
1647
|
-
}), r.render_config && await
|
|
1681
|
+
data: G(r.data, T, l.components, "output", b.with_null_state),
|
|
1682
|
+
endpoint: j,
|
|
1683
|
+
fn_index: C
|
|
1684
|
+
}), r.render_config && await xe(r.render_config), P && (L({
|
|
1648
1685
|
type: "status",
|
|
1649
1686
|
time: /* @__PURE__ */ new Date(),
|
|
1650
|
-
...
|
|
1687
|
+
...P,
|
|
1651
1688
|
stage: n?.stage,
|
|
1652
1689
|
queue: !0,
|
|
1653
|
-
endpoint:
|
|
1654
|
-
fn_index:
|
|
1655
|
-
}),
|
|
1690
|
+
endpoint: j,
|
|
1691
|
+
fn_index: C
|
|
1692
|
+
}), H())), (n?.stage === "complete" || n?.stage === "error") && (v[N] && delete v[N], N in _ && delete _[N], H());
|
|
1656
1693
|
} catch (e) {
|
|
1657
|
-
console.error("Unexpected client exception", e),
|
|
1694
|
+
console.error("Unexpected client exception", e), L({
|
|
1658
1695
|
type: "status",
|
|
1659
1696
|
stage: "error",
|
|
1660
1697
|
message: "An Unexpected Error Occurred!",
|
|
1661
1698
|
queue: !0,
|
|
1662
|
-
endpoint:
|
|
1663
|
-
fn_index:
|
|
1699
|
+
endpoint: j,
|
|
1700
|
+
fn_index: C,
|
|
1664
1701
|
time: /* @__PURE__ */ new Date()
|
|
1665
1702
|
}), [
|
|
1666
1703
|
"sse_v2",
|
|
1667
1704
|
"sse_v2.1",
|
|
1668
1705
|
"sse_v3"
|
|
1669
|
-
].includes(
|
|
1706
|
+
].includes(E) && (tt(h, S.abort_controller), h.open = !1, H());
|
|
1670
1707
|
}
|
|
1671
1708
|
};
|
|
1672
|
-
|
|
1709
|
+
N in g && (g[N].forEach((e) => t(e)), delete g[N]), v[N] = t, ee.add(N), h.open || await this.open_stream();
|
|
1673
1710
|
}
|
|
1674
1711
|
});
|
|
1675
1712
|
}
|
|
1676
1713
|
});
|
|
1677
|
-
|
|
1678
|
-
|
|
1714
|
+
R.catch((e) => {
|
|
1715
|
+
L({
|
|
1679
1716
|
type: "status",
|
|
1680
1717
|
stage: "error",
|
|
1681
1718
|
message: e instanceof Error ? e.message : String(e),
|
|
1682
|
-
queue: !Te(
|
|
1683
|
-
endpoint:
|
|
1684
|
-
fn_index:
|
|
1719
|
+
queue: !Te(C, l),
|
|
1720
|
+
endpoint: j,
|
|
1721
|
+
fn_index: C,
|
|
1685
1722
|
time: /* @__PURE__ */ new Date()
|
|
1686
|
-
}),
|
|
1723
|
+
}), H();
|
|
1687
1724
|
});
|
|
1688
|
-
let
|
|
1689
|
-
function
|
|
1690
|
-
for (
|
|
1725
|
+
let z = !1, B = [], V = [];
|
|
1726
|
+
function H() {
|
|
1727
|
+
for (z = !0; V.length > 0;) V.shift()({
|
|
1691
1728
|
value: void 0,
|
|
1692
1729
|
done: !0
|
|
1693
1730
|
});
|
|
1694
1731
|
}
|
|
1695
|
-
function
|
|
1696
|
-
|
|
1732
|
+
function U(e) {
|
|
1733
|
+
V.length > 0 ? V.shift()(e) : B.push(e);
|
|
1697
1734
|
}
|
|
1698
|
-
function
|
|
1699
|
-
|
|
1735
|
+
function Se(e) {
|
|
1736
|
+
U(Yt(e)), H();
|
|
1700
1737
|
}
|
|
1701
|
-
function
|
|
1702
|
-
|
|
1738
|
+
function Ce(e) {
|
|
1739
|
+
U({
|
|
1703
1740
|
value: e,
|
|
1704
1741
|
done: !1
|
|
1705
1742
|
});
|
|
1706
1743
|
}
|
|
1707
|
-
function
|
|
1708
|
-
return
|
|
1744
|
+
function we() {
|
|
1745
|
+
return B.length > 0 ? Promise.resolve(B.shift()) : z ? Promise.resolve({
|
|
1709
1746
|
value: void 0,
|
|
1710
1747
|
done: !0
|
|
1711
|
-
}) : new Promise((e) =>
|
|
1748
|
+
}) : new Promise((e) => V.push(e));
|
|
1712
1749
|
}
|
|
1713
|
-
let
|
|
1714
|
-
[Symbol.asyncIterator]: () =>
|
|
1715
|
-
next:
|
|
1716
|
-
throw: async (e) => (
|
|
1717
|
-
return: async () => (
|
|
1750
|
+
let W = {
|
|
1751
|
+
[Symbol.asyncIterator]: () => W,
|
|
1752
|
+
next: we,
|
|
1753
|
+
throw: async (e) => (Se(e), we()),
|
|
1754
|
+
return: async () => (H(), {
|
|
1718
1755
|
value: void 0,
|
|
1719
1756
|
done: !0
|
|
1720
1757
|
}),
|
|
1721
|
-
cancel:
|
|
1758
|
+
cancel: _e,
|
|
1722
1759
|
send_chunk: (e) => {
|
|
1723
|
-
this.post_data(`${l.root}${x}/stream/${
|
|
1760
|
+
this.post_data(`${l.root}${x}/stream/${A}`, {
|
|
1724
1761
|
...e,
|
|
1725
1762
|
session_hash: this.session_hash
|
|
1726
1763
|
});
|
|
1727
1764
|
},
|
|
1728
1765
|
close_stream: () => {
|
|
1729
|
-
this.post_data(`${l.root}${x}/stream/${
|
|
1766
|
+
this.post_data(`${l.root}${x}/stream/${A}/close`, {}), H();
|
|
1730
1767
|
},
|
|
1731
|
-
event_id: () =>
|
|
1732
|
-
wait_for_id: async () => (await
|
|
1768
|
+
event_id: () => A,
|
|
1769
|
+
wait_for_id: async () => (await R, N)
|
|
1733
1770
|
};
|
|
1734
|
-
return
|
|
1771
|
+
return W;
|
|
1735
1772
|
} catch (e) {
|
|
1736
1773
|
throw console.error("Submit function encountered an error:", e), e;
|
|
1737
1774
|
}
|
|
1738
1775
|
}
|
|
1739
|
-
function
|
|
1776
|
+
function Yt(e) {
|
|
1740
1777
|
return { then: (t, n) => n(e) };
|
|
1741
1778
|
}
|
|
1742
|
-
function
|
|
1779
|
+
function Xt(e, t, n, r) {
|
|
1743
1780
|
let i, a, o;
|
|
1744
1781
|
if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
|
|
1745
1782
|
else {
|
|
@@ -1827,7 +1864,7 @@ var $ = class {
|
|
|
1827
1864
|
resolve_config;
|
|
1828
1865
|
resolve_cookies;
|
|
1829
1866
|
constructor(e, t = { events: ["data"] }) {
|
|
1830
|
-
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"],
|
|
1867
|
+
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], D(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = xe.bind(this), this.upload_files = R.bind(this), this.handle_blob = ke.bind(this), this.post_data = Ne.bind(this), this.submit = Jt.bind(this), this.predict = Pe.bind(this), this.open_stream = et.bind(this), this.resolve_config = he.bind(this), this.resolve_cookies = A.bind(this), this.upload = V.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
|
|
1831
1868
|
}
|
|
1832
1869
|
async init() {
|
|
1833
1870
|
qe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
|
|
@@ -1836,11 +1873,11 @@ var $ = class {
|
|
|
1836
1873
|
} catch (e) {
|
|
1837
1874
|
console.error(e.message);
|
|
1838
1875
|
}
|
|
1839
|
-
this.api_map =
|
|
1876
|
+
this.api_map = me(this.config?.dependencies || []);
|
|
1840
1877
|
}
|
|
1841
1878
|
async _resolve_heartbeat(e) {
|
|
1842
|
-
if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await
|
|
1843
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1879
|
+
if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await pe(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await pe(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
|
|
1880
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${v}/${this.session_hash}`);
|
|
1844
1881
|
this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
|
|
1845
1882
|
}
|
|
1846
1883
|
}
|
|
@@ -1849,7 +1886,7 @@ var $ = class {
|
|
|
1849
1886
|
return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
|
|
1850
1887
|
}
|
|
1851
1888
|
async reconnect() {
|
|
1852
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1889
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${re}`), t;
|
|
1853
1890
|
try {
|
|
1854
1891
|
let n = await this.fetch(e);
|
|
1855
1892
|
if (!n.ok) throw Error();
|
|
@@ -1866,11 +1903,11 @@ var $ = class {
|
|
|
1866
1903
|
if (!this.config) throw Error(b);
|
|
1867
1904
|
let e = await this.resolve_config(this.config.root, !1);
|
|
1868
1905
|
if (!e) throw Error(b);
|
|
1869
|
-
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map =
|
|
1906
|
+
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = me(e.dependencies || []);
|
|
1870
1907
|
try {
|
|
1871
1908
|
this.api_info = await this.view_api();
|
|
1872
1909
|
} catch (e) {
|
|
1873
|
-
console.error(
|
|
1910
|
+
console.error(ae + e.message);
|
|
1874
1911
|
}
|
|
1875
1912
|
return this.get_url_config();
|
|
1876
1913
|
}
|
|
@@ -1881,7 +1918,7 @@ var $ = class {
|
|
|
1881
1918
|
return Ve(e, t);
|
|
1882
1919
|
}
|
|
1883
1920
|
async _resolve_config() {
|
|
1884
|
-
let { http_protocol: e, host: t, space_id: n } = await
|
|
1921
|
+
let { http_protocol: e, host: t, space_id: n } = await F(this.app_reference, this.options.token), { status_callback: r } = this.options;
|
|
1885
1922
|
n && r && await Fe(n, r);
|
|
1886
1923
|
let i;
|
|
1887
1924
|
try {
|
|
@@ -1889,7 +1926,7 @@ var $ = class {
|
|
|
1889
1926
|
if (i = await this.resolve_config(n), !i) throw Error(b);
|
|
1890
1927
|
return this.config_success(i);
|
|
1891
1928
|
} catch (e) {
|
|
1892
|
-
if (n && r) K(n,
|
|
1929
|
+
if (n && r) K(n, P.test(n) ? "space_name" : "subdomain", this.handle_space_success);
|
|
1893
1930
|
else throw r && r({
|
|
1894
1931
|
status: "error",
|
|
1895
1932
|
message: "Could not load this space.",
|
|
@@ -1899,14 +1936,14 @@ var $ = class {
|
|
|
1899
1936
|
}
|
|
1900
1937
|
}
|
|
1901
1938
|
async config_success(e) {
|
|
1902
|
-
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 &&
|
|
1939
|
+
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && zt({
|
|
1903
1940
|
app_id: e.app_id,
|
|
1904
1941
|
username: e.username
|
|
1905
1942
|
}), this.config.auth_required) return this.prepare_return_obj();
|
|
1906
1943
|
try {
|
|
1907
1944
|
this.api_info = await this.view_api();
|
|
1908
1945
|
} catch (e) {
|
|
1909
|
-
console.error(
|
|
1946
|
+
console.error(ae + e.message);
|
|
1910
1947
|
}
|
|
1911
1948
|
return this.prepare_return_obj();
|
|
1912
1949
|
}
|
|
@@ -1945,7 +1982,7 @@ var $ = class {
|
|
|
1945
1982
|
}), r["Content-Type"] = "application/json";
|
|
1946
1983
|
i && (r.Authorization = `Bearer ${i}`);
|
|
1947
1984
|
try {
|
|
1948
|
-
let e = await this.fetch(`${o}${this.api_prefix}/${
|
|
1985
|
+
let e = await this.fetch(`${o}${this.api_prefix}/${ee}/`, {
|
|
1949
1986
|
method: "POST",
|
|
1950
1987
|
body: c,
|
|
1951
1988
|
headers: r,
|
|
@@ -1958,7 +1995,7 @@ var $ = class {
|
|
|
1958
1995
|
}
|
|
1959
1996
|
}
|
|
1960
1997
|
set_cookies(e) {
|
|
1961
|
-
this.cookies =
|
|
1998
|
+
this.cookies = N(e).join("; ");
|
|
1962
1999
|
}
|
|
1963
2000
|
prepare_return_obj() {
|
|
1964
2001
|
return {
|
|
@@ -1970,11 +2007,75 @@ var $ = class {
|
|
|
1970
2007
|
};
|
|
1971
2008
|
}
|
|
1972
2009
|
};
|
|
1973
|
-
async function
|
|
2010
|
+
async function Zt(e, t = { events: ["data"] }) {
|
|
1974
2011
|
return await $.connect(e, t);
|
|
1975
2012
|
}
|
|
1976
|
-
async function
|
|
2013
|
+
async function Qt(e, t) {
|
|
1977
2014
|
return await $.duplicate(e, t);
|
|
1978
2015
|
}
|
|
1979
2016
|
//#endregion
|
|
1980
|
-
|
|
2017
|
+
//#region src/utils/bucket_sync.ts
|
|
2018
|
+
var $t = /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-][a-zA-Z0-9_./-]*$/;
|
|
2019
|
+
function en(e) {
|
|
2020
|
+
return $t.test(e) ? !e.split("/").some((e) => e === "" || e === "." || e === "..") : !1;
|
|
2021
|
+
}
|
|
2022
|
+
function tn(e, t, n) {
|
|
2023
|
+
let r = n ? `?${new URLSearchParams(n)}` : "", i = e.replace(/\/+$/, "");
|
|
2024
|
+
return i ? `${i}/gradio_api/run-history/${t}${r}` : typeof document < "u" && document.baseURI ? new URL(`gradio_api/run-history/${t}${r}`, document.baseURI).toString() : `gradio_api/run-history/${t}${r}`;
|
|
2025
|
+
}
|
|
2026
|
+
async function nn(e) {
|
|
2027
|
+
try {
|
|
2028
|
+
let t = await e.json();
|
|
2029
|
+
return typeof t?.detail == "string" ? t.detail : `${e.status}`;
|
|
2030
|
+
} catch {
|
|
2031
|
+
return `${e.status}`;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
async function rn(e, t, n, r) {
|
|
2035
|
+
try {
|
|
2036
|
+
let i = await fetch(e, {
|
|
2037
|
+
credentials: "include",
|
|
2038
|
+
...t
|
|
2039
|
+
});
|
|
2040
|
+
return i.ok ? {
|
|
2041
|
+
ok: !0,
|
|
2042
|
+
status: i.status,
|
|
2043
|
+
data: r(await i.json())
|
|
2044
|
+
} : {
|
|
2045
|
+
ok: !1,
|
|
2046
|
+
status: i.status,
|
|
2047
|
+
data: n,
|
|
2048
|
+
detail: await nn(i)
|
|
2049
|
+
};
|
|
2050
|
+
} catch (e) {
|
|
2051
|
+
return {
|
|
2052
|
+
ok: !1,
|
|
2053
|
+
status: 0,
|
|
2054
|
+
data: n,
|
|
2055
|
+
detail: String(e)
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
async function an(e, t) {
|
|
2060
|
+
return en(t) ? rn(tn(e, "connect"), {
|
|
2061
|
+
method: "POST",
|
|
2062
|
+
headers: { "Content-Type": "application/json" },
|
|
2063
|
+
body: JSON.stringify({ bucket_id: t })
|
|
2064
|
+
}, null, () => null) : {
|
|
2065
|
+
ok: !1,
|
|
2066
|
+
status: 422,
|
|
2067
|
+
data: null,
|
|
2068
|
+
detail: "invalid bucket id"
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
async function on(e) {
|
|
2072
|
+
return rn(tn(e, "buckets"), {}, [], (e) => Array.isArray(e?.buckets) ? e.buckets : []);
|
|
2073
|
+
}
|
|
2074
|
+
async function sn(e, t) {
|
|
2075
|
+
return rn(tn(e, "records", { bucket: t }), {}, [], (e) => Array.isArray(e?.records) ? e.records : []);
|
|
2076
|
+
}
|
|
2077
|
+
function cn(e, t, n, r, i) {
|
|
2078
|
+
return tn(e, `records/${encodeURIComponent(n)}/${encodeURIComponent(r)}/assets/${encodeURIComponent(i)}`, { bucket: t });
|
|
2079
|
+
}
|
|
2080
|
+
//#endregion
|
|
2081
|
+
export { $ as Client, U as FileData, oe as MISSING_CREDENTIALS_MSG, Ut as apply_run_history_replay, cn as asset_url, zt as clear_run_history, Zt as client, an as connect_bucket, Ht as consume_run_history_replay, Bt as delete_run_history, Qt as duplicate, De as handle_file, en as is_valid_bucket_id, sn as list_bucket_records, on as list_user_buckets, qt as on_run_history_change, Pe as predict, H as prepare_files, It as read_run_history, Lt as read_run_history_storage, dt as run_history_url, Rt as set_run_history_storage, Vt as stage_run_history_replay, Jt as submit, V as upload, R as upload_files };
|