@gradio/client 2.5.0 → 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 +17 -0
- package/dist/browser.js +557 -438
- package/dist/helpers/init_helpers.d.ts +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.cjs +177 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +170 -8
- package/dist/index.min.js +440 -321
- 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 +35 -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 +14 -0
- package/src/test/bucket_sync.test.ts +138 -0
- package/src/test/run_history.test.ts +113 -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 +133 -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,12 +1254,28 @@ function St(e) {
|
|
|
1227
1254
|
return null;
|
|
1228
1255
|
}
|
|
1229
1256
|
}
|
|
1230
|
-
function
|
|
1257
|
+
function Dt(e, t) {
|
|
1258
|
+
let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
|
|
1259
|
+
if (!n) return !1;
|
|
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) => {
|
|
1261
|
+
for (let [r, i] of t.entries()) {
|
|
1262
|
+
let t = e.components.find((e) => e.id === i);
|
|
1263
|
+
!t || r >= n.length || t.type !== "state" && (t.props.value = n[r]);
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
return a(n.inputs, r), a(n.outputs, i), !0;
|
|
1267
|
+
}
|
|
1268
|
+
function Ot(e) {
|
|
1269
|
+
let t = Et(e);
|
|
1270
|
+
return t ? Dt(e, t) : !1;
|
|
1271
|
+
}
|
|
1272
|
+
function kt(e) {
|
|
1273
|
+
if (mt(e).type === "bucket") return null;
|
|
1231
1274
|
let t = Y(e);
|
|
1232
1275
|
if (!t) return null;
|
|
1233
|
-
|
|
1276
|
+
_t(t);
|
|
1234
1277
|
let n = {
|
|
1235
|
-
id:
|
|
1278
|
+
id: vt(),
|
|
1236
1279
|
endpoint: e.endpoint,
|
|
1237
1280
|
api_name: e.api_name,
|
|
1238
1281
|
fn_index: e.fn_index,
|
|
@@ -1244,113 +1287,125 @@ function Ct(e) {
|
|
|
1244
1287
|
status: "running",
|
|
1245
1288
|
started_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1246
1289
|
};
|
|
1247
|
-
return
|
|
1290
|
+
return yt(e, [n, ...Z(e)]), Ct(), n.id;
|
|
1248
1291
|
}
|
|
1249
|
-
function
|
|
1292
|
+
function At(e, t, n) {
|
|
1250
1293
|
if (!t) return;
|
|
1251
1294
|
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1252
|
-
i && (i.inputs = X(n),
|
|
1295
|
+
i && (i.inputs = X(n), yt(e, r));
|
|
1253
1296
|
}
|
|
1254
|
-
function
|
|
1297
|
+
function jt(e, t, n) {
|
|
1255
1298
|
if (!t) return;
|
|
1256
1299
|
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1257
1300
|
if (!i) return;
|
|
1258
1301
|
let a = !1;
|
|
1259
1302
|
if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
|
|
1260
|
-
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);
|
|
1261
1304
|
else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
|
|
1262
|
-
else if (n.type === "status" && n.stage === "complete") i.status = "completed",
|
|
1263
|
-
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;
|
|
1264
1307
|
else return;
|
|
1265
|
-
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);
|
|
1266
1309
|
else if (i.streamed) {
|
|
1267
|
-
if (Date.now() - (
|
|
1268
|
-
|
|
1310
|
+
if (Date.now() - (Nt.get(t) ?? 0) < Mt) return;
|
|
1311
|
+
Nt.set(t, Date.now()), Q.delete(t);
|
|
1269
1312
|
}
|
|
1270
|
-
|
|
1313
|
+
yt(e, r);
|
|
1271
1314
|
}
|
|
1272
|
-
var
|
|
1273
|
-
function
|
|
1315
|
+
var Mt = 500, Nt = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
|
|
1316
|
+
function Pt(e, t) {
|
|
1274
1317
|
if (e.process_started_at) return;
|
|
1275
1318
|
let n = t || /* @__PURE__ */ new Date();
|
|
1276
1319
|
e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
|
|
1277
1320
|
}
|
|
1278
|
-
function
|
|
1321
|
+
function Ft(e, t) {
|
|
1279
1322
|
let n = t.time || /* @__PURE__ */ new Date();
|
|
1280
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));
|
|
1281
1324
|
}
|
|
1282
|
-
function
|
|
1325
|
+
function It(e) {
|
|
1283
1326
|
return J(() => Z(e), []);
|
|
1284
1327
|
}
|
|
1285
|
-
function
|
|
1286
|
-
J(() =>
|
|
1328
|
+
function Lt(e) {
|
|
1329
|
+
return J(() => mt(e), { type: "browser" });
|
|
1330
|
+
}
|
|
1331
|
+
function Rt(e, t) {
|
|
1332
|
+
J(() => ht(e, t), void 0);
|
|
1287
1333
|
}
|
|
1288
|
-
function
|
|
1289
|
-
J(() =>
|
|
1334
|
+
function zt(e) {
|
|
1335
|
+
J(() => bt(e), void 0);
|
|
1290
1336
|
}
|
|
1291
|
-
function
|
|
1337
|
+
function Bt(e, t) {
|
|
1292
1338
|
J(() => xt(e, t), void 0);
|
|
1293
1339
|
}
|
|
1294
|
-
function
|
|
1295
|
-
|
|
1340
|
+
function Vt(e, t) {
|
|
1341
|
+
J(() => Tt(e, t), void 0);
|
|
1342
|
+
}
|
|
1343
|
+
function Ht(e) {
|
|
1344
|
+
return J(() => Et(e), null);
|
|
1296
1345
|
}
|
|
1297
|
-
function
|
|
1298
|
-
return J(() =>
|
|
1346
|
+
function Ut(e) {
|
|
1347
|
+
return J(() => Ot(e), !1);
|
|
1299
1348
|
}
|
|
1300
|
-
function
|
|
1301
|
-
J(() =>
|
|
1349
|
+
function Wt(e) {
|
|
1350
|
+
return J(() => kt(e), null);
|
|
1302
1351
|
}
|
|
1303
|
-
function
|
|
1304
|
-
J(() =>
|
|
1352
|
+
function Gt(e, t, n) {
|
|
1353
|
+
J(() => At(e, t, n), void 0);
|
|
1305
1354
|
}
|
|
1306
|
-
function
|
|
1307
|
-
|
|
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)), () => {});
|
|
1308
1360
|
}
|
|
1309
1361
|
//#endregion
|
|
1310
1362
|
//#region src/utils/submit.ts
|
|
1311
|
-
function
|
|
1363
|
+
function Jt(e, t = {}, n, r, i, a) {
|
|
1312
1364
|
try {
|
|
1313
|
-
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:
|
|
1314
|
-
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);
|
|
1315
1367
|
if (!l) throw Error("Could not resolve app config");
|
|
1316
|
-
let { fn_index:
|
|
1317
|
-
if (
|
|
1318
|
-
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) => {
|
|
1319
1371
|
let t = l.components.find((t) => t.id === e);
|
|
1320
1372
|
return t ? {
|
|
1321
1373
|
type: t.type,
|
|
1322
1374
|
component_class_id: t.component_class_id,
|
|
1323
1375
|
props: t.props
|
|
1324
1376
|
} : null;
|
|
1325
|
-
},
|
|
1377
|
+
}, fe = T.api_visibility === "public", pe = l.run_history !== !1 && this.options.record_history !== !1, D = {
|
|
1326
1378
|
app_id: l.app_id,
|
|
1327
1379
|
username: l.username
|
|
1328
|
-
},
|
|
1329
|
-
...
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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);
|
|
1339
1394
|
}
|
|
1340
|
-
async function
|
|
1395
|
+
async function _e() {
|
|
1341
1396
|
let e = {}, t = {};
|
|
1342
|
-
e = { event_id:
|
|
1343
|
-
event_id:
|
|
1397
|
+
e = { event_id: N }, t = {
|
|
1398
|
+
event_id: N,
|
|
1344
1399
|
session_hash: f,
|
|
1345
|
-
fn_index:
|
|
1400
|
+
fn_index: C
|
|
1346
1401
|
};
|
|
1347
1402
|
try {
|
|
1348
1403
|
if (!l) throw Error("Could not resolve app config");
|
|
1349
|
-
"event_id" in t && await s(`${l.root}${x}/${
|
|
1404
|
+
"event_id" in t && await s(`${l.root}${x}/${ne}`, {
|
|
1350
1405
|
headers: { "Content-Type": "application/json" },
|
|
1351
1406
|
method: "POST",
|
|
1352
1407
|
body: JSON.stringify(t)
|
|
1353
|
-
}), await s(`${l.root}${x}/${
|
|
1408
|
+
}), await s(`${l.root}${x}/${te}`, {
|
|
1354
1409
|
headers: { "Content-Type": "application/json" },
|
|
1355
1410
|
method: "POST",
|
|
1356
1411
|
body: JSON.stringify(e)
|
|
@@ -1359,53 +1414,53 @@ function zt(e, t = {}, n, r, i, a) {
|
|
|
1359
1414
|
console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
|
|
1360
1415
|
}
|
|
1361
1416
|
}
|
|
1362
|
-
let
|
|
1417
|
+
let ve = async (e) => {
|
|
1363
1418
|
await this._resolve_heartbeat(e);
|
|
1364
1419
|
};
|
|
1365
|
-
async function
|
|
1420
|
+
async function xe(e) {
|
|
1366
1421
|
if (!l) return;
|
|
1367
1422
|
let t = e.render_id;
|
|
1368
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];
|
|
1369
1424
|
let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
|
|
1370
|
-
l.connect_heartbeat = n || r, await
|
|
1425
|
+
l.connect_heartbeat = n || r, await ve(l), L({
|
|
1371
1426
|
type: "render",
|
|
1372
1427
|
data: e,
|
|
1373
|
-
endpoint:
|
|
1374
|
-
fn_index:
|
|
1428
|
+
endpoint: j,
|
|
1429
|
+
fn_index: C
|
|
1375
1430
|
});
|
|
1376
1431
|
}
|
|
1377
|
-
let
|
|
1378
|
-
let t = G(e,
|
|
1379
|
-
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 = {
|
|
1380
1435
|
data: t || [],
|
|
1381
1436
|
event_data: n,
|
|
1382
|
-
fn_index:
|
|
1437
|
+
fn_index: C,
|
|
1383
1438
|
trigger_id: r,
|
|
1384
|
-
...b.oauth_token &&
|
|
1385
|
-
}, Te(
|
|
1439
|
+
...b.oauth_token && w?.oauth_token ? { oauth_token: b.oauth_token } : {}
|
|
1440
|
+
}, Te(C, l)) L({
|
|
1386
1441
|
type: "status",
|
|
1387
|
-
endpoint:
|
|
1442
|
+
endpoint: j,
|
|
1388
1443
|
stage: "pending",
|
|
1389
1444
|
queue: !1,
|
|
1390
|
-
fn_index:
|
|
1445
|
+
fn_index: C,
|
|
1391
1446
|
time: /* @__PURE__ */ new Date()
|
|
1392
|
-
}),
|
|
1393
|
-
...
|
|
1447
|
+
}), re(`${l.root}${x}/run${j.startsWith("/") ? j : `/${j}`}${F ? "?" + F : ""}`, {
|
|
1448
|
+
...M,
|
|
1394
1449
|
session_hash: f
|
|
1395
|
-
},
|
|
1450
|
+
}, O).then(async ([e, t]) => {
|
|
1396
1451
|
let i = e.data;
|
|
1397
|
-
if (t == 200)
|
|
1452
|
+
if (t == 200) L({
|
|
1398
1453
|
type: "data",
|
|
1399
|
-
endpoint:
|
|
1400
|
-
fn_index:
|
|
1401
|
-
data: G(i,
|
|
1454
|
+
endpoint: j,
|
|
1455
|
+
fn_index: C,
|
|
1456
|
+
data: G(i, T, l.components, "output", b.with_null_state),
|
|
1402
1457
|
time: /* @__PURE__ */ new Date(),
|
|
1403
1458
|
event_data: n,
|
|
1404
1459
|
trigger_id: r
|
|
1405
|
-
}), e.render_config && await
|
|
1460
|
+
}), e.render_config && await xe(e.render_config), L({
|
|
1406
1461
|
type: "status",
|
|
1407
|
-
endpoint:
|
|
1408
|
-
fn_index:
|
|
1462
|
+
endpoint: j,
|
|
1463
|
+
fn_index: C,
|
|
1409
1464
|
stage: "complete",
|
|
1410
1465
|
eta: e.average_duration,
|
|
1411
1466
|
queue: !1,
|
|
@@ -1413,11 +1468,11 @@ function zt(e, t = {}, n, r, i, a) {
|
|
|
1413
1468
|
});
|
|
1414
1469
|
else {
|
|
1415
1470
|
let t = e?.error === y;
|
|
1416
|
-
|
|
1471
|
+
L({
|
|
1417
1472
|
type: "status",
|
|
1418
1473
|
stage: "error",
|
|
1419
|
-
endpoint:
|
|
1420
|
-
fn_index:
|
|
1474
|
+
endpoint: j,
|
|
1475
|
+
fn_index: C,
|
|
1421
1476
|
message: e.error,
|
|
1422
1477
|
broken: t,
|
|
1423
1478
|
queue: !1,
|
|
@@ -1425,98 +1480,98 @@ function zt(e, t = {}, n, r, i, a) {
|
|
|
1425
1480
|
});
|
|
1426
1481
|
}
|
|
1427
1482
|
}).catch((e) => {
|
|
1428
|
-
|
|
1483
|
+
L({
|
|
1429
1484
|
type: "status",
|
|
1430
1485
|
stage: "error",
|
|
1431
1486
|
message: e.message,
|
|
1432
|
-
endpoint:
|
|
1433
|
-
fn_index:
|
|
1487
|
+
endpoint: j,
|
|
1488
|
+
fn_index: C,
|
|
1434
1489
|
queue: !1,
|
|
1435
1490
|
time: /* @__PURE__ */ new Date()
|
|
1436
1491
|
});
|
|
1437
1492
|
});
|
|
1438
|
-
else if (
|
|
1439
|
-
|
|
1493
|
+
else if (E == "sse") {
|
|
1494
|
+
L({
|
|
1440
1495
|
type: "status",
|
|
1441
1496
|
stage: "pending",
|
|
1442
1497
|
queue: !0,
|
|
1443
|
-
endpoint:
|
|
1444
|
-
fn_index:
|
|
1498
|
+
endpoint: j,
|
|
1499
|
+
fn_index: C,
|
|
1445
1500
|
time: /* @__PURE__ */ new Date()
|
|
1446
1501
|
});
|
|
1447
1502
|
var i = new URLSearchParams({
|
|
1448
|
-
fn_index:
|
|
1503
|
+
fn_index: C.toString(),
|
|
1449
1504
|
session_hash: f
|
|
1450
1505
|
}).toString();
|
|
1451
|
-
let e = new URL(`${l.root}${x}/${u}?${
|
|
1452
|
-
if (this.jwt && e.searchParams.set("__sign", this.jwt),
|
|
1453
|
-
|
|
1454
|
-
let { type: t, status: i, data: a } =
|
|
1455
|
-
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({
|
|
1456
1511
|
type: "status",
|
|
1457
|
-
endpoint:
|
|
1458
|
-
fn_index:
|
|
1512
|
+
endpoint: j,
|
|
1513
|
+
fn_index: C,
|
|
1459
1514
|
time: /* @__PURE__ */ new Date(),
|
|
1460
1515
|
...i
|
|
1461
|
-
}), i.stage === "error" && (
|
|
1516
|
+
}), i.stage === "error" && (k?.close(), H());
|
|
1462
1517
|
else if (t === "data") {
|
|
1463
|
-
let [e, t] = await
|
|
1464
|
-
...
|
|
1518
|
+
let [e, t] = await re(`${l.root}${x}/queue/data`, {
|
|
1519
|
+
...M,
|
|
1465
1520
|
session_hash: f,
|
|
1466
|
-
event_id:
|
|
1467
|
-
});
|
|
1468
|
-
t !== 200 && (
|
|
1521
|
+
event_id: N
|
|
1522
|
+
}, O);
|
|
1523
|
+
t !== 200 && (L({
|
|
1469
1524
|
type: "status",
|
|
1470
1525
|
stage: "error",
|
|
1471
1526
|
message: y,
|
|
1472
1527
|
queue: !0,
|
|
1473
|
-
endpoint:
|
|
1474
|
-
fn_index:
|
|
1528
|
+
endpoint: j,
|
|
1529
|
+
fn_index: C,
|
|
1475
1530
|
time: /* @__PURE__ */ new Date()
|
|
1476
|
-
}),
|
|
1477
|
-
} else t === "complete" ?
|
|
1531
|
+
}), k?.close(), H());
|
|
1532
|
+
} else t === "complete" ? P = i : t === "log" ? L({
|
|
1478
1533
|
type: "log",
|
|
1479
1534
|
title: a.title,
|
|
1480
1535
|
log: a.log,
|
|
1481
1536
|
level: a.level,
|
|
1482
|
-
endpoint:
|
|
1537
|
+
endpoint: j,
|
|
1483
1538
|
duration: a.duration,
|
|
1484
1539
|
visible: a.visible,
|
|
1485
|
-
fn_index:
|
|
1486
|
-
}) : (t === "generating" || t === "streaming") &&
|
|
1540
|
+
fn_index: C
|
|
1541
|
+
}) : (t === "generating" || t === "streaming") && L({
|
|
1487
1542
|
type: "status",
|
|
1488
1543
|
time: /* @__PURE__ */ new Date(),
|
|
1489
1544
|
...i,
|
|
1490
1545
|
stage: i?.stage,
|
|
1491
1546
|
queue: !0,
|
|
1492
|
-
endpoint:
|
|
1493
|
-
fn_index:
|
|
1547
|
+
endpoint: j,
|
|
1548
|
+
fn_index: C
|
|
1494
1549
|
});
|
|
1495
|
-
a && (
|
|
1550
|
+
a && (L({
|
|
1496
1551
|
type: "data",
|
|
1497
1552
|
time: /* @__PURE__ */ new Date(),
|
|
1498
|
-
data: G(a.data,
|
|
1499
|
-
endpoint:
|
|
1500
|
-
fn_index:
|
|
1553
|
+
data: G(a.data, T, l.components, "output", b.with_null_state),
|
|
1554
|
+
endpoint: j,
|
|
1555
|
+
fn_index: C,
|
|
1501
1556
|
event_data: n,
|
|
1502
1557
|
trigger_id: r
|
|
1503
|
-
}),
|
|
1558
|
+
}), P && (L({
|
|
1504
1559
|
type: "status",
|
|
1505
1560
|
time: /* @__PURE__ */ new Date(),
|
|
1506
|
-
...
|
|
1561
|
+
...P,
|
|
1507
1562
|
stage: i?.stage,
|
|
1508
1563
|
queue: !0,
|
|
1509
|
-
endpoint:
|
|
1510
|
-
fn_index:
|
|
1511
|
-
}),
|
|
1564
|
+
endpoint: j,
|
|
1565
|
+
fn_index: C
|
|
1566
|
+
}), k?.close(), H()));
|
|
1512
1567
|
};
|
|
1513
|
-
} else if (
|
|
1514
|
-
|
|
1568
|
+
} else if (E == "sse_v1" || E == "sse_v2" || E == "sse_v2.1" || E == "sse_v3") {
|
|
1569
|
+
L({
|
|
1515
1570
|
type: "status",
|
|
1516
1571
|
stage: "pending",
|
|
1517
1572
|
queue: !0,
|
|
1518
|
-
endpoint:
|
|
1519
|
-
fn_index:
|
|
1573
|
+
endpoint: j,
|
|
1574
|
+
fn_index: C,
|
|
1520
1575
|
time: /* @__PURE__ */ new Date()
|
|
1521
1576
|
});
|
|
1522
1577
|
let e = "";
|
|
@@ -1524,204 +1579,204 @@ function zt(e, t = {}, n, r, i, a) {
|
|
|
1524
1579
|
let t = Ke(e);
|
|
1525
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) => {
|
|
1526
1581
|
let t = {
|
|
1527
|
-
...
|
|
1582
|
+
...O,
|
|
1528
1583
|
...e || {}
|
|
1529
1584
|
};
|
|
1530
|
-
return
|
|
1531
|
-
...
|
|
1585
|
+
return re(`${l.root}${x}/${d}?${F}`, {
|
|
1586
|
+
...M,
|
|
1532
1587
|
session_hash: f
|
|
1533
1588
|
}, t);
|
|
1534
1589
|
}).then(async ([e, t]) => {
|
|
1535
|
-
if (e.event_id && (
|
|
1590
|
+
if (e.event_id && (A = e.event_id), t === 503) L({
|
|
1536
1591
|
type: "status",
|
|
1537
1592
|
stage: "error",
|
|
1538
1593
|
message: ie,
|
|
1539
1594
|
queue: !0,
|
|
1540
|
-
endpoint:
|
|
1541
|
-
fn_index:
|
|
1595
|
+
endpoint: j,
|
|
1596
|
+
fn_index: C,
|
|
1542
1597
|
time: /* @__PURE__ */ new Date(),
|
|
1543
1598
|
visible: !0
|
|
1544
|
-
}),
|
|
1545
|
-
else if (t === 422)
|
|
1599
|
+
}), H();
|
|
1600
|
+
else if (t === 422) L({
|
|
1546
1601
|
type: "status",
|
|
1547
1602
|
stage: "error",
|
|
1548
1603
|
message: e.detail,
|
|
1549
1604
|
queue: !0,
|
|
1550
|
-
endpoint:
|
|
1551
|
-
fn_index:
|
|
1605
|
+
endpoint: j,
|
|
1606
|
+
fn_index: C,
|
|
1552
1607
|
code: "validation_error",
|
|
1553
1608
|
time: /* @__PURE__ */ new Date(),
|
|
1554
1609
|
visible: !0
|
|
1555
|
-
}),
|
|
1610
|
+
}), H();
|
|
1556
1611
|
else if (t !== 200) {
|
|
1557
1612
|
let t = e?.error === y;
|
|
1558
|
-
|
|
1613
|
+
L({
|
|
1559
1614
|
type: "status",
|
|
1560
1615
|
stage: "error",
|
|
1561
1616
|
broken: t,
|
|
1562
1617
|
message: t ? y : e.detail || e.error,
|
|
1563
1618
|
queue: !0,
|
|
1564
|
-
endpoint:
|
|
1565
|
-
fn_index:
|
|
1619
|
+
endpoint: j,
|
|
1620
|
+
fn_index: C,
|
|
1566
1621
|
time: /* @__PURE__ */ new Date(),
|
|
1567
1622
|
visible: !0
|
|
1568
|
-
}),
|
|
1623
|
+
}), H();
|
|
1569
1624
|
} else {
|
|
1570
|
-
|
|
1625
|
+
N = e.event_id, A = N;
|
|
1571
1626
|
let t = async function(e) {
|
|
1572
1627
|
try {
|
|
1573
|
-
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]);
|
|
1574
1629
|
if (t == "heartbeat") return;
|
|
1575
|
-
if (t === "update" && n && !
|
|
1630
|
+
if (t === "update" && n && !P) L({
|
|
1576
1631
|
type: "status",
|
|
1577
|
-
endpoint:
|
|
1578
|
-
fn_index:
|
|
1632
|
+
endpoint: j,
|
|
1633
|
+
fn_index: C,
|
|
1579
1634
|
time: /* @__PURE__ */ new Date(),
|
|
1580
1635
|
original_msg: i,
|
|
1581
1636
|
...n
|
|
1582
1637
|
});
|
|
1583
|
-
else if (t === "complete")
|
|
1638
|
+
else if (t === "complete") P = n;
|
|
1584
1639
|
else if (t == "unexpected_error" || t == "broken_connection") {
|
|
1585
1640
|
console.error("Unexpected error", n?.message);
|
|
1586
1641
|
let e = t === "broken_connection";
|
|
1587
|
-
|
|
1642
|
+
L({
|
|
1588
1643
|
type: "status",
|
|
1589
1644
|
stage: "error",
|
|
1590
1645
|
message: n?.message || "An Unexpected Error Occurred!",
|
|
1591
1646
|
queue: !0,
|
|
1592
|
-
endpoint:
|
|
1647
|
+
endpoint: j,
|
|
1593
1648
|
broken: e,
|
|
1594
1649
|
session_not_found: n?.session_not_found,
|
|
1595
|
-
fn_index:
|
|
1650
|
+
fn_index: C,
|
|
1596
1651
|
time: /* @__PURE__ */ new Date()
|
|
1597
1652
|
});
|
|
1598
1653
|
} else if (t === "log") {
|
|
1599
|
-
|
|
1654
|
+
L({
|
|
1600
1655
|
type: "log",
|
|
1601
1656
|
title: r.title,
|
|
1602
1657
|
log: r.log,
|
|
1603
1658
|
level: r.level,
|
|
1604
|
-
endpoint:
|
|
1659
|
+
endpoint: j,
|
|
1605
1660
|
duration: r.duration,
|
|
1606
1661
|
visible: r.visible,
|
|
1607
|
-
fn_index:
|
|
1662
|
+
fn_index: C
|
|
1608
1663
|
});
|
|
1609
1664
|
return;
|
|
1610
|
-
} else (t === "generating" || t === "streaming") && (
|
|
1665
|
+
} else (t === "generating" || t === "streaming") && (L({
|
|
1611
1666
|
type: "status",
|
|
1612
1667
|
time: /* @__PURE__ */ new Date(),
|
|
1613
1668
|
...n,
|
|
1614
1669
|
stage: n?.stage,
|
|
1615
1670
|
queue: !0,
|
|
1616
|
-
endpoint:
|
|
1617
|
-
fn_index:
|
|
1618
|
-
}), r &&
|
|
1671
|
+
endpoint: j,
|
|
1672
|
+
fn_index: C
|
|
1673
|
+
}), r && T.connection !== "stream" && [
|
|
1619
1674
|
"sse_v2",
|
|
1620
1675
|
"sse_v2.1",
|
|
1621
1676
|
"sse_v3"
|
|
1622
|
-
].includes(
|
|
1623
|
-
r && (
|
|
1677
|
+
].includes(E) && nt(_, N, r));
|
|
1678
|
+
r && (L({
|
|
1624
1679
|
type: "data",
|
|
1625
1680
|
time: /* @__PURE__ */ new Date(),
|
|
1626
|
-
data: G(r.data,
|
|
1627
|
-
endpoint:
|
|
1628
|
-
fn_index:
|
|
1629
|
-
}), 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({
|
|
1630
1685
|
type: "status",
|
|
1631
1686
|
time: /* @__PURE__ */ new Date(),
|
|
1632
|
-
...
|
|
1687
|
+
...P,
|
|
1633
1688
|
stage: n?.stage,
|
|
1634
1689
|
queue: !0,
|
|
1635
|
-
endpoint:
|
|
1636
|
-
fn_index:
|
|
1637
|
-
}),
|
|
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());
|
|
1638
1693
|
} catch (e) {
|
|
1639
|
-
console.error("Unexpected client exception", e),
|
|
1694
|
+
console.error("Unexpected client exception", e), L({
|
|
1640
1695
|
type: "status",
|
|
1641
1696
|
stage: "error",
|
|
1642
1697
|
message: "An Unexpected Error Occurred!",
|
|
1643
1698
|
queue: !0,
|
|
1644
|
-
endpoint:
|
|
1645
|
-
fn_index:
|
|
1699
|
+
endpoint: j,
|
|
1700
|
+
fn_index: C,
|
|
1646
1701
|
time: /* @__PURE__ */ new Date()
|
|
1647
1702
|
}), [
|
|
1648
1703
|
"sse_v2",
|
|
1649
1704
|
"sse_v2.1",
|
|
1650
1705
|
"sse_v3"
|
|
1651
|
-
].includes(
|
|
1706
|
+
].includes(E) && (tt(h, S.abort_controller), h.open = !1, H());
|
|
1652
1707
|
}
|
|
1653
1708
|
};
|
|
1654
|
-
|
|
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();
|
|
1655
1710
|
}
|
|
1656
1711
|
});
|
|
1657
1712
|
}
|
|
1658
1713
|
});
|
|
1659
|
-
|
|
1660
|
-
|
|
1714
|
+
R.catch((e) => {
|
|
1715
|
+
L({
|
|
1661
1716
|
type: "status",
|
|
1662
1717
|
stage: "error",
|
|
1663
1718
|
message: e instanceof Error ? e.message : String(e),
|
|
1664
|
-
queue: !Te(
|
|
1665
|
-
endpoint:
|
|
1666
|
-
fn_index:
|
|
1719
|
+
queue: !Te(C, l),
|
|
1720
|
+
endpoint: j,
|
|
1721
|
+
fn_index: C,
|
|
1667
1722
|
time: /* @__PURE__ */ new Date()
|
|
1668
|
-
}),
|
|
1723
|
+
}), H();
|
|
1669
1724
|
});
|
|
1670
|
-
let
|
|
1671
|
-
function
|
|
1672
|
-
for (
|
|
1725
|
+
let z = !1, B = [], V = [];
|
|
1726
|
+
function H() {
|
|
1727
|
+
for (z = !0; V.length > 0;) V.shift()({
|
|
1673
1728
|
value: void 0,
|
|
1674
1729
|
done: !0
|
|
1675
1730
|
});
|
|
1676
1731
|
}
|
|
1677
|
-
function
|
|
1678
|
-
|
|
1732
|
+
function U(e) {
|
|
1733
|
+
V.length > 0 ? V.shift()(e) : B.push(e);
|
|
1679
1734
|
}
|
|
1680
|
-
function
|
|
1681
|
-
|
|
1735
|
+
function Se(e) {
|
|
1736
|
+
U(Yt(e)), H();
|
|
1682
1737
|
}
|
|
1683
|
-
function
|
|
1684
|
-
|
|
1738
|
+
function Ce(e) {
|
|
1739
|
+
U({
|
|
1685
1740
|
value: e,
|
|
1686
1741
|
done: !1
|
|
1687
1742
|
});
|
|
1688
1743
|
}
|
|
1689
|
-
function
|
|
1690
|
-
return
|
|
1744
|
+
function we() {
|
|
1745
|
+
return B.length > 0 ? Promise.resolve(B.shift()) : z ? Promise.resolve({
|
|
1691
1746
|
value: void 0,
|
|
1692
1747
|
done: !0
|
|
1693
|
-
}) : new Promise((e) =>
|
|
1748
|
+
}) : new Promise((e) => V.push(e));
|
|
1694
1749
|
}
|
|
1695
|
-
let
|
|
1696
|
-
[Symbol.asyncIterator]: () =>
|
|
1697
|
-
next:
|
|
1698
|
-
throw: async (e) => (
|
|
1699
|
-
return: async () => (
|
|
1750
|
+
let W = {
|
|
1751
|
+
[Symbol.asyncIterator]: () => W,
|
|
1752
|
+
next: we,
|
|
1753
|
+
throw: async (e) => (Se(e), we()),
|
|
1754
|
+
return: async () => (H(), {
|
|
1700
1755
|
value: void 0,
|
|
1701
1756
|
done: !0
|
|
1702
1757
|
}),
|
|
1703
|
-
cancel:
|
|
1758
|
+
cancel: _e,
|
|
1704
1759
|
send_chunk: (e) => {
|
|
1705
|
-
this.post_data(`${l.root}${x}/stream/${
|
|
1760
|
+
this.post_data(`${l.root}${x}/stream/${A}`, {
|
|
1706
1761
|
...e,
|
|
1707
1762
|
session_hash: this.session_hash
|
|
1708
1763
|
});
|
|
1709
1764
|
},
|
|
1710
1765
|
close_stream: () => {
|
|
1711
|
-
this.post_data(`${l.root}${x}/stream/${
|
|
1766
|
+
this.post_data(`${l.root}${x}/stream/${A}/close`, {}), H();
|
|
1712
1767
|
},
|
|
1713
|
-
event_id: () =>
|
|
1714
|
-
wait_for_id: async () => (await
|
|
1768
|
+
event_id: () => A,
|
|
1769
|
+
wait_for_id: async () => (await R, N)
|
|
1715
1770
|
};
|
|
1716
|
-
return
|
|
1771
|
+
return W;
|
|
1717
1772
|
} catch (e) {
|
|
1718
1773
|
throw console.error("Submit function encountered an error:", e), e;
|
|
1719
1774
|
}
|
|
1720
1775
|
}
|
|
1721
|
-
function
|
|
1776
|
+
function Yt(e) {
|
|
1722
1777
|
return { then: (t, n) => n(e) };
|
|
1723
1778
|
}
|
|
1724
|
-
function
|
|
1779
|
+
function Xt(e, t, n, r) {
|
|
1725
1780
|
let i, a, o;
|
|
1726
1781
|
if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
|
|
1727
1782
|
else {
|
|
@@ -1809,7 +1864,7 @@ var $ = class {
|
|
|
1809
1864
|
resolve_config;
|
|
1810
1865
|
resolve_cookies;
|
|
1811
1866
|
constructor(e, t = { events: ["data"] }) {
|
|
1812
|
-
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);
|
|
1813
1868
|
}
|
|
1814
1869
|
async init() {
|
|
1815
1870
|
qe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
|
|
@@ -1818,11 +1873,11 @@ var $ = class {
|
|
|
1818
1873
|
} catch (e) {
|
|
1819
1874
|
console.error(e.message);
|
|
1820
1875
|
}
|
|
1821
|
-
this.api_map =
|
|
1876
|
+
this.api_map = me(this.config?.dependencies || []);
|
|
1822
1877
|
}
|
|
1823
1878
|
async _resolve_heartbeat(e) {
|
|
1824
|
-
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
|
|
1825
|
-
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}`);
|
|
1826
1881
|
this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
|
|
1827
1882
|
}
|
|
1828
1883
|
}
|
|
@@ -1831,7 +1886,7 @@ var $ = class {
|
|
|
1831
1886
|
return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
|
|
1832
1887
|
}
|
|
1833
1888
|
async reconnect() {
|
|
1834
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1889
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${re}`), t;
|
|
1835
1890
|
try {
|
|
1836
1891
|
let n = await this.fetch(e);
|
|
1837
1892
|
if (!n.ok) throw Error();
|
|
@@ -1848,11 +1903,11 @@ var $ = class {
|
|
|
1848
1903
|
if (!this.config) throw Error(b);
|
|
1849
1904
|
let e = await this.resolve_config(this.config.root, !1);
|
|
1850
1905
|
if (!e) throw Error(b);
|
|
1851
|
-
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 || []);
|
|
1852
1907
|
try {
|
|
1853
1908
|
this.api_info = await this.view_api();
|
|
1854
1909
|
} catch (e) {
|
|
1855
|
-
console.error(
|
|
1910
|
+
console.error(ae + e.message);
|
|
1856
1911
|
}
|
|
1857
1912
|
return this.get_url_config();
|
|
1858
1913
|
}
|
|
@@ -1863,7 +1918,7 @@ var $ = class {
|
|
|
1863
1918
|
return Ve(e, t);
|
|
1864
1919
|
}
|
|
1865
1920
|
async _resolve_config() {
|
|
1866
|
-
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;
|
|
1867
1922
|
n && r && await Fe(n, r);
|
|
1868
1923
|
let i;
|
|
1869
1924
|
try {
|
|
@@ -1871,7 +1926,7 @@ var $ = class {
|
|
|
1871
1926
|
if (i = await this.resolve_config(n), !i) throw Error(b);
|
|
1872
1927
|
return this.config_success(i);
|
|
1873
1928
|
} catch (e) {
|
|
1874
|
-
if (n && r) K(n,
|
|
1929
|
+
if (n && r) K(n, P.test(n) ? "space_name" : "subdomain", this.handle_space_success);
|
|
1875
1930
|
else throw r && r({
|
|
1876
1931
|
status: "error",
|
|
1877
1932
|
message: "Could not load this space.",
|
|
@@ -1881,14 +1936,14 @@ var $ = class {
|
|
|
1881
1936
|
}
|
|
1882
1937
|
}
|
|
1883
1938
|
async config_success(e) {
|
|
1884
|
-
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({
|
|
1885
1940
|
app_id: e.app_id,
|
|
1886
1941
|
username: e.username
|
|
1887
1942
|
}), this.config.auth_required) return this.prepare_return_obj();
|
|
1888
1943
|
try {
|
|
1889
1944
|
this.api_info = await this.view_api();
|
|
1890
1945
|
} catch (e) {
|
|
1891
|
-
console.error(
|
|
1946
|
+
console.error(ae + e.message);
|
|
1892
1947
|
}
|
|
1893
1948
|
return this.prepare_return_obj();
|
|
1894
1949
|
}
|
|
@@ -1927,7 +1982,7 @@ var $ = class {
|
|
|
1927
1982
|
}), r["Content-Type"] = "application/json";
|
|
1928
1983
|
i && (r.Authorization = `Bearer ${i}`);
|
|
1929
1984
|
try {
|
|
1930
|
-
let e = await this.fetch(`${o}${this.api_prefix}/${
|
|
1985
|
+
let e = await this.fetch(`${o}${this.api_prefix}/${ee}/`, {
|
|
1931
1986
|
method: "POST",
|
|
1932
1987
|
body: c,
|
|
1933
1988
|
headers: r,
|
|
@@ -1940,7 +1995,7 @@ var $ = class {
|
|
|
1940
1995
|
}
|
|
1941
1996
|
}
|
|
1942
1997
|
set_cookies(e) {
|
|
1943
|
-
this.cookies =
|
|
1998
|
+
this.cookies = N(e).join("; ");
|
|
1944
1999
|
}
|
|
1945
2000
|
prepare_return_obj() {
|
|
1946
2001
|
return {
|
|
@@ -1952,11 +2007,75 @@ var $ = class {
|
|
|
1952
2007
|
};
|
|
1953
2008
|
}
|
|
1954
2009
|
};
|
|
1955
|
-
async function
|
|
2010
|
+
async function Zt(e, t = { events: ["data"] }) {
|
|
1956
2011
|
return await $.connect(e, t);
|
|
1957
2012
|
}
|
|
1958
|
-
async function
|
|
2013
|
+
async function Qt(e, t) {
|
|
1959
2014
|
return await $.duplicate(e, t);
|
|
1960
2015
|
}
|
|
1961
2016
|
//#endregion
|
|
1962
|
-
|
|
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 };
|