@gradio/client 1.19.0 → 1.19.1
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 +6 -0
- package/dist/browser.js +186 -168
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/package.json +1 -1
- package/src/helpers/init_helpers.ts +23 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @gradio/client
|
|
2
2
|
|
|
3
|
+
## 1.19.1
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- [#11955](https://github.com/gradio-app/gradio/pull/11955) [`64046cc`](https://github.com/gradio-app/gradio/commit/64046ccd76a41f06ef9eed0e3aa1ec66348f55bd) - Fix Multi-page demo in Dev Mode. Thanks @ftoh!
|
|
8
|
+
|
|
3
9
|
## 1.19.0
|
|
4
10
|
|
|
5
11
|
### Features
|
package/dist/browser.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var st = Object.defineProperty;
|
|
2
|
+
var ke = (e) => {
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var u = (e, t, s) =>
|
|
7
|
-
var W = (e, t, s) => (
|
|
8
|
-
var
|
|
9
|
-
function
|
|
10
|
-
return e = e.split("."), t = t.split("."),
|
|
5
|
+
var nt = (e, t, s) => t in e ? st(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
6
|
+
var u = (e, t, s) => nt(e, typeof t != "symbol" ? t + "" : t, s), Re = (e, t, s) => t.has(e) || ke("Cannot " + s);
|
|
7
|
+
var W = (e, t, s) => (Re(e, t, "read from private field"), s ? s.call(e) : t.get(e)), Oe = (e, t, s) => t.has(e) ? ke("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), Ne = (e, t, s, n) => (Re(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s);
|
|
8
|
+
var fe = new Intl.Collator(0, { numeric: 1 }).compare;
|
|
9
|
+
function xe(e, t, s) {
|
|
10
|
+
return e = e.split("."), t = t.split("."), fe(e[0], t[0]) || fe(e[1], t[1]) || (t[2] = t.slice(2).join("."), s = /[.-]/.test(e[2] = e.slice(2).join(".")), s == /[.-]/.test(t[2]) ? fe(e[2], t[2]) : s ? -1 : 1);
|
|
11
11
|
}
|
|
12
|
-
const
|
|
13
|
-
function
|
|
12
|
+
const it = "host", Ie = "queue/data", ot = "queue/join", Te = "upload", rt = "login", ee = "config", at = "info", ct = "runtime", lt = "sleeptime", ut = "heartbeat", pt = "component_server", ft = "reset", ht = "cancel", dt = "app_id", _t = "https://gradio-space-api-fetcher-v2.hf.space/api", Ue = "This application is currently busy. Please try again. ", H = "Connection errored out. ", z = "Could not resolve app config. ", mt = "Could not get space status. ", gt = "Could not get API info. ", ge = "Space metadata could not be loaded. ", wt = "Invalid URL. A full URL path is required.", yt = "Not authorized to access this space. ", qe = "Invalid credentials. Could not login. ", bt = "Login credentials are required to access this space.", vt = "File system access is only available in Node.js environments", ze = "Root URL not found in client config", Et = "Error uploading file";
|
|
13
|
+
function St(e, t, s) {
|
|
14
14
|
return t.startsWith("http://") || t.startsWith("https://") ? s ? e : t : e + t;
|
|
15
15
|
}
|
|
16
|
-
async function
|
|
16
|
+
async function De(e, t, s) {
|
|
17
17
|
try {
|
|
18
18
|
return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, {
|
|
19
19
|
headers: {
|
|
@@ -25,53 +25,71 @@ async function Te(e, t, s) {
|
|
|
25
25
|
return !1;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function $t(e) {
|
|
29
29
|
let t = {};
|
|
30
30
|
return e.forEach(({ api_name: s, id: n }) => {
|
|
31
31
|
s && (t[s] = n);
|
|
32
32
|
}), t;
|
|
33
33
|
}
|
|
34
|
-
async function
|
|
34
|
+
async function kt(e) {
|
|
35
35
|
const t = this.options.hf_token ? { Authorization: `Bearer ${this.options.hf_token}` } : {};
|
|
36
|
-
if (t["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
if (t["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
37
|
+
if (window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.dev_mode) {
|
|
38
|
+
let s = _e(
|
|
39
|
+
e,
|
|
40
|
+
this.deep_link ? ee + "?deep_link=" + this.deep_link : ee
|
|
41
|
+
);
|
|
42
|
+
const n = await this.fetch(s, {
|
|
43
|
+
headers: t,
|
|
44
|
+
credentials: "include"
|
|
45
|
+
}), i = await Ce(
|
|
46
|
+
n,
|
|
47
|
+
e,
|
|
48
|
+
!!this.options.auth
|
|
49
|
+
);
|
|
50
|
+
window.gradio_config = {
|
|
51
|
+
...i,
|
|
52
|
+
current_page: window.gradio_config.current_page
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return window.gradio_config.root = e, { ...window.gradio_config };
|
|
56
|
+
} else if (e) {
|
|
57
|
+
let s = _e(
|
|
40
58
|
e,
|
|
41
|
-
this.deep_link ?
|
|
59
|
+
this.deep_link ? ee + "?deep_link=" + this.deep_link : ee
|
|
42
60
|
);
|
|
43
61
|
const n = await this.fetch(s, {
|
|
44
62
|
headers: t,
|
|
45
63
|
credentials: "include"
|
|
46
64
|
});
|
|
47
|
-
return
|
|
65
|
+
return Ce(n, e, !!this.options.auth);
|
|
48
66
|
}
|
|
49
67
|
throw new Error(z);
|
|
50
68
|
}
|
|
51
|
-
async function
|
|
69
|
+
async function Ce(e, t, s) {
|
|
52
70
|
var n, i;
|
|
53
71
|
if ((e == null ? void 0 : e.status) === 401 && !s) {
|
|
54
72
|
const r = await e.json(), o = (n = r == null ? void 0 : r.detail) == null ? void 0 : n.auth_message;
|
|
55
|
-
throw new Error(o ||
|
|
73
|
+
throw new Error(o || bt);
|
|
56
74
|
} else if ((e == null ? void 0 : e.status) === 401 && s)
|
|
57
|
-
throw new Error(
|
|
75
|
+
throw new Error(qe);
|
|
58
76
|
if ((e == null ? void 0 : e.status) === 200) {
|
|
59
77
|
let r = await e.json();
|
|
60
78
|
return r.root = t, (i = r.dependencies) == null || i.forEach((o, a) => {
|
|
61
79
|
o.id === void 0 && (o.id = a);
|
|
62
80
|
}), r;
|
|
63
81
|
} else if ((e == null ? void 0 : e.status) === 401)
|
|
64
|
-
throw new Error(
|
|
82
|
+
throw new Error(yt);
|
|
65
83
|
throw new Error(z);
|
|
66
84
|
}
|
|
67
85
|
async function Rt() {
|
|
68
|
-
const { http_protocol: e, host: t } = await
|
|
86
|
+
const { http_protocol: e, host: t } = await se(
|
|
69
87
|
this.app_reference,
|
|
70
88
|
this.options.hf_token
|
|
71
89
|
);
|
|
72
90
|
try {
|
|
73
91
|
if (this.options.auth) {
|
|
74
|
-
const s = await
|
|
92
|
+
const s = await Be(
|
|
75
93
|
e,
|
|
76
94
|
t,
|
|
77
95
|
this.options.auth,
|
|
@@ -84,12 +102,12 @@ async function Rt() {
|
|
|
84
102
|
throw Error(s.message);
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
|
-
async function
|
|
105
|
+
async function Be(e, t, s, n, i) {
|
|
88
106
|
const r = new FormData();
|
|
89
107
|
r.append("username", s == null ? void 0 : s[0]), r.append("password", s == null ? void 0 : s[1]);
|
|
90
108
|
let o = {};
|
|
91
109
|
i && (o.Authorization = `Bearer ${i}`);
|
|
92
|
-
const a = await n(`${e}//${t}/${
|
|
110
|
+
const a = await n(`${e}//${t}/${rt}`, {
|
|
93
111
|
headers: o,
|
|
94
112
|
method: "POST",
|
|
95
113
|
body: r,
|
|
@@ -97,9 +115,9 @@ async function qe(e, t, s, n, i) {
|
|
|
97
115
|
});
|
|
98
116
|
if (a.status === 200)
|
|
99
117
|
return a.headers.get("set-cookie");
|
|
100
|
-
throw a.status === 401 ? new Error(
|
|
118
|
+
throw a.status === 401 ? new Error(qe) : new Error(ge);
|
|
101
119
|
}
|
|
102
|
-
function
|
|
120
|
+
function he(e) {
|
|
103
121
|
if (e.startsWith("http")) {
|
|
104
122
|
const { protocol: t, host: s, pathname: n } = new URL(e);
|
|
105
123
|
return {
|
|
@@ -114,32 +132,32 @@ function fe(e) {
|
|
|
114
132
|
host: new URL(e).host
|
|
115
133
|
};
|
|
116
134
|
}
|
|
117
|
-
const
|
|
135
|
+
const Fe = (e) => {
|
|
118
136
|
let t = [];
|
|
119
137
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((n) => {
|
|
120
138
|
const [i, r] = n.split(";")[0].split("=");
|
|
121
139
|
i && r && t.push(`${i.trim()}=${r.trim()}`);
|
|
122
140
|
}), t;
|
|
123
|
-
},
|
|
124
|
-
async function
|
|
141
|
+
}, we = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, Ot = /.*hf\.space\/{0,1}.*$/;
|
|
142
|
+
async function se(e, t) {
|
|
125
143
|
const s = {};
|
|
126
144
|
t && (s.Authorization = `Bearer ${t}`);
|
|
127
145
|
const n = e.trim().replace(/\/$/, "");
|
|
128
|
-
if (
|
|
146
|
+
if (we.test(n))
|
|
129
147
|
try {
|
|
130
148
|
const r = (await (await fetch(
|
|
131
|
-
`https://huggingface.co/api/spaces/${n}/${
|
|
149
|
+
`https://huggingface.co/api/spaces/${n}/${it}`,
|
|
132
150
|
{ headers: s }
|
|
133
151
|
)).json()).host;
|
|
134
152
|
return {
|
|
135
153
|
space_id: e,
|
|
136
|
-
...
|
|
154
|
+
...he(r)
|
|
137
155
|
};
|
|
138
156
|
} catch {
|
|
139
|
-
throw new Error(
|
|
157
|
+
throw new Error(ge);
|
|
140
158
|
}
|
|
141
159
|
if (Ot.test(n)) {
|
|
142
|
-
const { ws_protocol: i, http_protocol: r, host: o } =
|
|
160
|
+
const { ws_protocol: i, http_protocol: r, host: o } = he(n);
|
|
143
161
|
return {
|
|
144
162
|
space_id: o.split("/")[0].replace(".hf.space", ""),
|
|
145
163
|
ws_protocol: i,
|
|
@@ -149,14 +167,14 @@ async function te(e, t) {
|
|
|
149
167
|
}
|
|
150
168
|
return {
|
|
151
169
|
space_id: !1,
|
|
152
|
-
...
|
|
170
|
+
...he(n)
|
|
153
171
|
};
|
|
154
172
|
}
|
|
155
|
-
const
|
|
173
|
+
const _e = (...e) => {
|
|
156
174
|
try {
|
|
157
175
|
return e.reduce((t, s) => (t = t.replace(/\/+$/, ""), s = s.replace(/^\/+/, ""), new URL(s, t + "/").toString()));
|
|
158
176
|
} catch {
|
|
159
|
-
throw new Error(
|
|
177
|
+
throw new Error(wt);
|
|
160
178
|
}
|
|
161
179
|
};
|
|
162
180
|
function Nt(e, t, s) {
|
|
@@ -238,7 +256,7 @@ function Tt(e, t, s, n) {
|
|
|
238
256
|
function Dt(e, t) {
|
|
239
257
|
return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e == null ? void 0 : e.description;
|
|
240
258
|
}
|
|
241
|
-
function
|
|
259
|
+
function de(e, t) {
|
|
242
260
|
switch (e.msg) {
|
|
243
261
|
case "send_data":
|
|
244
262
|
return { type: "data" };
|
|
@@ -249,7 +267,7 @@ function he(e, t) {
|
|
|
249
267
|
type: "update",
|
|
250
268
|
status: {
|
|
251
269
|
queue: !0,
|
|
252
|
-
message:
|
|
270
|
+
message: Ue,
|
|
253
271
|
stage: "error",
|
|
254
272
|
code: e.code,
|
|
255
273
|
success: e.success
|
|
@@ -411,8 +429,8 @@ async function At() {
|
|
|
411
429
|
if (typeof window < "u" && window.gradio_api_info)
|
|
412
430
|
i = window.gradio_api_info;
|
|
413
431
|
else {
|
|
414
|
-
if (
|
|
415
|
-
n = await this.fetch(
|
|
432
|
+
if (xe((t == null ? void 0 : t.version) || "2.0.0", "3.30") < 0)
|
|
433
|
+
n = await this.fetch(_t, {
|
|
416
434
|
method: "POST",
|
|
417
435
|
body: JSON.stringify({
|
|
418
436
|
serialize: !1,
|
|
@@ -422,7 +440,7 @@ async function At() {
|
|
|
422
440
|
credentials: "include"
|
|
423
441
|
});
|
|
424
442
|
else {
|
|
425
|
-
const r =
|
|
443
|
+
const r = _e(t.root, this.api_prefix, at);
|
|
426
444
|
n = await this.fetch(r, {
|
|
427
445
|
headers: s,
|
|
428
446
|
credentials: "include"
|
|
@@ -449,7 +467,7 @@ async function Lt(e, t, s) {
|
|
|
449
467
|
m.append("files", g);
|
|
450
468
|
});
|
|
451
469
|
try {
|
|
452
|
-
const g = s ? `${e}${this.api_prefix}/${
|
|
470
|
+
const g = s ? `${e}${this.api_prefix}/${Te}?upload_id=${s}` : `${e}${this.api_prefix}/${Te}`;
|
|
453
471
|
o = await this.fetch(g, {
|
|
454
472
|
method: "POST",
|
|
455
473
|
body: m,
|
|
@@ -484,7 +502,7 @@ async function Pt(e, t, s, n) {
|
|
|
484
502
|
async (o) => {
|
|
485
503
|
if (o.error)
|
|
486
504
|
throw new Error(o.error);
|
|
487
|
-
return o.files ? o.files.map((a, l) => new
|
|
505
|
+
return o.files ? o.files.map((a, l) => new ne({
|
|
488
506
|
...e[l],
|
|
489
507
|
path: a,
|
|
490
508
|
url: `${t}${this.api_prefix}/file=${a}`
|
|
@@ -495,7 +513,7 @@ async function Pt(e, t, s, n) {
|
|
|
495
513
|
}
|
|
496
514
|
async function cs(e, t) {
|
|
497
515
|
return e.map(
|
|
498
|
-
(s) => new
|
|
516
|
+
(s) => new ne({
|
|
499
517
|
path: s.name,
|
|
500
518
|
orig_name: s.name,
|
|
501
519
|
blob: s,
|
|
@@ -505,7 +523,7 @@ async function cs(e, t) {
|
|
|
505
523
|
})
|
|
506
524
|
);
|
|
507
525
|
}
|
|
508
|
-
class
|
|
526
|
+
class ne {
|
|
509
527
|
constructor({
|
|
510
528
|
path: t,
|
|
511
529
|
url: s,
|
|
@@ -530,7 +548,7 @@ class se {
|
|
|
530
548
|
this.path = t, this.url = s, this.orig_name = n, this.size = i, this.blob = s ? void 0 : r, this.is_stream = o, this.mime_type = a, this.alt_text = l, this.b64 = h;
|
|
531
549
|
}
|
|
532
550
|
}
|
|
533
|
-
class
|
|
551
|
+
class Ge {
|
|
534
552
|
constructor(t, s) {
|
|
535
553
|
u(this, "type");
|
|
536
554
|
u(this, "command");
|
|
@@ -540,7 +558,7 @@ class Fe {
|
|
|
540
558
|
}
|
|
541
559
|
}
|
|
542
560
|
const jt = typeof process < "u" && process.versions && process.versions.node;
|
|
543
|
-
function
|
|
561
|
+
function Ae(e, t, s) {
|
|
544
562
|
for (; s.length > 1; ) {
|
|
545
563
|
const i = s.shift();
|
|
546
564
|
if (typeof i == "string" || typeof i == "number")
|
|
@@ -554,7 +572,7 @@ function De(e, t, s) {
|
|
|
554
572
|
else
|
|
555
573
|
throw new Error("Invalid key type");
|
|
556
574
|
}
|
|
557
|
-
async function
|
|
575
|
+
async function me(e, t = void 0, s = [], n = !1, i = void 0) {
|
|
558
576
|
if (Array.isArray(e)) {
|
|
559
577
|
let r = [];
|
|
560
578
|
return await Promise.all(
|
|
@@ -562,7 +580,7 @@ async function de(e, t = void 0, s = [], n = !1, i = void 0) {
|
|
|
562
580
|
var m;
|
|
563
581
|
let l = s.slice();
|
|
564
582
|
l.push(String(a));
|
|
565
|
-
const h = await
|
|
583
|
+
const h = await me(
|
|
566
584
|
e[a],
|
|
567
585
|
n ? ((m = i == null ? void 0 : i.parameters[a]) == null ? void 0 : m.component) || void 0 : t,
|
|
568
586
|
l,
|
|
@@ -586,7 +604,7 @@ async function de(e, t = void 0, s = [], n = !1, i = void 0) {
|
|
|
586
604
|
for (const o of Object.keys(e)) {
|
|
587
605
|
const a = [...s, o], l = e[o];
|
|
588
606
|
r = r.concat(
|
|
589
|
-
await
|
|
607
|
+
await me(
|
|
590
608
|
l,
|
|
591
609
|
void 0,
|
|
592
610
|
a,
|
|
@@ -623,7 +641,7 @@ function ls(e) {
|
|
|
623
641
|
meta: { _type: "gradio.FileData" }
|
|
624
642
|
};
|
|
625
643
|
if (jt)
|
|
626
|
-
return new
|
|
644
|
+
return new Ge("upload_file", {
|
|
627
645
|
path: e,
|
|
628
646
|
name: e,
|
|
629
647
|
orig_path: e
|
|
@@ -671,7 +689,7 @@ function K(e, t, s, n, i = !1) {
|
|
|
671
689
|
async function Ut(e, t, s) {
|
|
672
690
|
const n = this;
|
|
673
691
|
await qt(n, t);
|
|
674
|
-
const i = await
|
|
692
|
+
const i = await me(
|
|
675
693
|
t,
|
|
676
694
|
void 0,
|
|
677
695
|
[],
|
|
@@ -691,46 +709,46 @@ async function Ut(e, t, s) {
|
|
|
691
709
|
})
|
|
692
710
|
)).forEach(({ path: o, file_url: a, type: l, name: h }) => {
|
|
693
711
|
if (l === "Gallery")
|
|
694
|
-
|
|
712
|
+
Ae(t, a, o);
|
|
695
713
|
else if (a) {
|
|
696
|
-
const m = new
|
|
697
|
-
|
|
714
|
+
const m = new ne({ path: a, orig_name: h });
|
|
715
|
+
Ae(t, m, o);
|
|
698
716
|
}
|
|
699
717
|
}), t;
|
|
700
718
|
}
|
|
701
719
|
async function qt(e, t) {
|
|
702
720
|
var n, i;
|
|
703
721
|
if (!(((n = e.config) == null ? void 0 : n.root) || ((i = e.config) == null ? void 0 : i.root_url)))
|
|
704
|
-
throw new Error(
|
|
705
|
-
await
|
|
722
|
+
throw new Error(ze);
|
|
723
|
+
await Me(e, t);
|
|
706
724
|
}
|
|
707
|
-
async function
|
|
725
|
+
async function Me(e, t, s = []) {
|
|
708
726
|
for (const n in t)
|
|
709
|
-
t[n] instanceof
|
|
727
|
+
t[n] instanceof Ge ? await zt(e, t, n) : typeof t[n] == "object" && t[n] !== null && await Me(e, t[n], [...s, n]);
|
|
710
728
|
}
|
|
711
729
|
async function zt(e, t, s) {
|
|
712
730
|
var r, o;
|
|
713
731
|
let n = t[s];
|
|
714
732
|
const i = ((r = e.config) == null ? void 0 : r.root) || ((o = e.config) == null ? void 0 : o.root_url);
|
|
715
733
|
if (!i)
|
|
716
|
-
throw new Error(
|
|
734
|
+
throw new Error(ze);
|
|
717
735
|
try {
|
|
718
736
|
let a, l;
|
|
719
737
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
720
738
|
const g = await import("./__vite-browser-external-DYxpcVy9.js");
|
|
721
739
|
l = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), a = await g.readFile(l);
|
|
722
740
|
} else
|
|
723
|
-
throw new Error(
|
|
741
|
+
throw new Error(vt);
|
|
724
742
|
const h = new Blob([a], { type: "application/octet-stream" }), m = await e.upload_files(i, [h]), p = m.files && m.files[0];
|
|
725
743
|
if (p) {
|
|
726
|
-
const g = new
|
|
744
|
+
const g = new ne({
|
|
727
745
|
path: p,
|
|
728
746
|
orig_name: n.meta.name || ""
|
|
729
747
|
});
|
|
730
748
|
t[s] = g;
|
|
731
749
|
}
|
|
732
750
|
} catch (a) {
|
|
733
|
-
console.error(
|
|
751
|
+
console.error(Et, a);
|
|
734
752
|
}
|
|
735
753
|
}
|
|
736
754
|
async function Bt(e, t, s) {
|
|
@@ -783,7 +801,7 @@ async function Q(e, t, s) {
|
|
|
783
801
|
s({
|
|
784
802
|
status: "error",
|
|
785
803
|
load_status: "error",
|
|
786
|
-
message:
|
|
804
|
+
message: mt,
|
|
787
805
|
detail: "NOT_FOUND"
|
|
788
806
|
});
|
|
789
807
|
return;
|
|
@@ -811,7 +829,7 @@ async function Q(e, t, s) {
|
|
|
811
829
|
load_status: "error",
|
|
812
830
|
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
|
813
831
|
detail: o,
|
|
814
|
-
discussions_enabled: await
|
|
832
|
+
discussions_enabled: await Le(a)
|
|
815
833
|
});
|
|
816
834
|
break;
|
|
817
835
|
case "RUNNING":
|
|
@@ -849,27 +867,27 @@ async function Q(e, t, s) {
|
|
|
849
867
|
load_status: "error",
|
|
850
868
|
message: "This space is experiencing an issue.",
|
|
851
869
|
detail: o,
|
|
852
|
-
discussions_enabled: await
|
|
870
|
+
discussions_enabled: await Le(a)
|
|
853
871
|
});
|
|
854
872
|
break;
|
|
855
873
|
}
|
|
856
874
|
}
|
|
857
|
-
const
|
|
875
|
+
const Je = async (e, t) => {
|
|
858
876
|
let s = 0;
|
|
859
877
|
const n = 12, i = 5e3;
|
|
860
878
|
return new Promise((r) => {
|
|
861
879
|
Q(
|
|
862
880
|
e,
|
|
863
|
-
|
|
881
|
+
we.test(e) ? "space_name" : "subdomain",
|
|
864
882
|
(o) => {
|
|
865
883
|
t(o), o.status === "running" || o.status === "error" || o.status === "paused" || o.status === "space_error" ? r() : (o.status === "sleeping" || o.status === "building") && (s < n ? (s++, setTimeout(() => {
|
|
866
|
-
|
|
884
|
+
Je(e, t).then(r);
|
|
867
885
|
}, i)) : r());
|
|
868
886
|
}
|
|
869
887
|
);
|
|
870
888
|
});
|
|
871
889
|
}, Gt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
|
872
|
-
async function
|
|
890
|
+
async function Le(e) {
|
|
873
891
|
try {
|
|
874
892
|
const t = await fetch(
|
|
875
893
|
`https://huggingface.co/api/spaces/${e}/discussions`,
|
|
@@ -887,7 +905,7 @@ async function Mt(e, t) {
|
|
|
887
905
|
t && (s.Authorization = `Bearer ${t}`);
|
|
888
906
|
try {
|
|
889
907
|
const n = await fetch(
|
|
890
|
-
`https://huggingface.co/api/spaces/${e}/${
|
|
908
|
+
`https://huggingface.co/api/spaces/${e}/${ct}`,
|
|
891
909
|
{ headers: s }
|
|
892
910
|
);
|
|
893
911
|
if (n.status !== 200)
|
|
@@ -906,7 +924,7 @@ async function Jt(e, t, s) {
|
|
|
906
924
|
};
|
|
907
925
|
try {
|
|
908
926
|
const r = await fetch(
|
|
909
|
-
`https://huggingface.co/api/spaces/${e}/${
|
|
927
|
+
`https://huggingface.co/api/spaces/${e}/${lt}`,
|
|
910
928
|
{
|
|
911
929
|
method: "POST",
|
|
912
930
|
headers: { "Content-Type": "application/json", ...n },
|
|
@@ -922,7 +940,7 @@ async function Jt(e, t, s) {
|
|
|
922
940
|
throw new Error(r.message);
|
|
923
941
|
}
|
|
924
942
|
}
|
|
925
|
-
const
|
|
943
|
+
const Pe = [
|
|
926
944
|
"cpu-basic",
|
|
927
945
|
"cpu-upgrade",
|
|
928
946
|
"cpu-xl",
|
|
@@ -939,23 +957,23 @@ const Ae = [
|
|
|
939
957
|
];
|
|
940
958
|
async function Wt(e, t) {
|
|
941
959
|
const { hf_token: s, private: n, hardware: i, timeout: r, auth: o } = t;
|
|
942
|
-
if (i && !
|
|
960
|
+
if (i && !Pe.includes(i))
|
|
943
961
|
throw new Error(
|
|
944
|
-
`Invalid hardware type provided. Valid types are: ${
|
|
962
|
+
`Invalid hardware type provided. Valid types are: ${Pe.map((_) => `"${_}"`).join(",")}.`
|
|
945
963
|
);
|
|
946
|
-
const { http_protocol: a, host: l } = await
|
|
964
|
+
const { http_protocol: a, host: l } = await se(
|
|
947
965
|
e,
|
|
948
966
|
s
|
|
949
967
|
);
|
|
950
968
|
let h = null;
|
|
951
969
|
if (o) {
|
|
952
|
-
const _ = await
|
|
970
|
+
const _ = await Be(
|
|
953
971
|
a,
|
|
954
972
|
l,
|
|
955
973
|
o,
|
|
956
974
|
fetch
|
|
957
975
|
);
|
|
958
|
-
_ && (h =
|
|
976
|
+
_ && (h = Fe(_));
|
|
959
977
|
}
|
|
960
978
|
const m = {
|
|
961
979
|
Authorization: `Bearer ${s}`,
|
|
@@ -971,7 +989,7 @@ async function Wt(e, t) {
|
|
|
971
989
|
try {
|
|
972
990
|
i || (B = await Mt(e, s));
|
|
973
991
|
} catch (_) {
|
|
974
|
-
throw Error(
|
|
992
|
+
throw Error(ge + _.message);
|
|
975
993
|
}
|
|
976
994
|
const c = i || B || "cpu-basic";
|
|
977
995
|
E.hardware = c;
|
|
@@ -986,14 +1004,14 @@ async function Wt(e, t) {
|
|
|
986
1004
|
);
|
|
987
1005
|
if (_.status === 409)
|
|
988
1006
|
try {
|
|
989
|
-
return await
|
|
1007
|
+
return await te.connect(`${p}/${g}`, t);
|
|
990
1008
|
} catch (C) {
|
|
991
1009
|
throw console.error("Failed to connect Client instance:", C), C;
|
|
992
1010
|
}
|
|
993
1011
|
else if (_.status !== 200)
|
|
994
1012
|
throw new Error(_.statusText);
|
|
995
1013
|
const N = await _.json();
|
|
996
|
-
return await Jt(`${p}/${g}`, r || 300, s), await
|
|
1014
|
+
return await Jt(`${p}/${g}`, r || 300, s), await te.connect(
|
|
997
1015
|
Ht(N.url),
|
|
998
1016
|
t
|
|
999
1017
|
);
|
|
@@ -1024,7 +1042,7 @@ class Vt extends TransformStream {
|
|
|
1024
1042
|
const a = n[r - 1] === "\r" ? r - 1 : r;
|
|
1025
1043
|
i.enqueue(n.slice(0, a)), n = n.slice(r + 1);
|
|
1026
1044
|
}
|
|
1027
|
-
|
|
1045
|
+
Ne(this, I, n);
|
|
1028
1046
|
},
|
|
1029
1047
|
flush: (n) => {
|
|
1030
1048
|
if (W(this, I) === "")
|
|
@@ -1033,7 +1051,7 @@ class Vt extends TransformStream {
|
|
|
1033
1051
|
n.enqueue(i);
|
|
1034
1052
|
}
|
|
1035
1053
|
});
|
|
1036
|
-
|
|
1054
|
+
Oe(this, I, "");
|
|
1037
1055
|
}
|
|
1038
1056
|
}
|
|
1039
1057
|
I = new WeakMap();
|
|
@@ -1049,7 +1067,7 @@ function Kt(e) {
|
|
|
1049
1067
|
e.substring(n + s[0].length)
|
|
1050
1068
|
];
|
|
1051
1069
|
}
|
|
1052
|
-
function
|
|
1070
|
+
function je(e, t, s) {
|
|
1053
1071
|
e.get(t) || e.set(t, s);
|
|
1054
1072
|
}
|
|
1055
1073
|
async function* Qt(e, t) {
|
|
@@ -1072,7 +1090,7 @@ async function* Qt(e, t) {
|
|
|
1072
1090
|
}
|
|
1073
1091
|
async function Xt(e, t) {
|
|
1074
1092
|
let s = new Request(e, t);
|
|
1075
|
-
|
|
1093
|
+
je(s.headers, "Accept", "text/event-stream"), je(s.headers, "Content-Type", "application/json");
|
|
1076
1094
|
let n = await fetch(s);
|
|
1077
1095
|
if (!n.ok)
|
|
1078
1096
|
throw n;
|
|
@@ -1093,7 +1111,7 @@ async function Yt() {
|
|
|
1093
1111
|
n.open = !0;
|
|
1094
1112
|
let a = null, l = new URLSearchParams({
|
|
1095
1113
|
session_hash: this.session_hash
|
|
1096
|
-
}).toString(), h = new URL(`${i.root}${this.api_prefix}/${
|
|
1114
|
+
}).toString(), h = new URL(`${i.root}${this.api_prefix}/${Ie}?${l}`);
|
|
1097
1115
|
if (r && h.searchParams.set("__sign", r), a = this.stream(h), !a) {
|
|
1098
1116
|
console.warn("Cannot connect to SSE endpoint: " + h.toString());
|
|
1099
1117
|
return;
|
|
@@ -1101,7 +1119,7 @@ async function Yt() {
|
|
|
1101
1119
|
a.onmessage = async function(m) {
|
|
1102
1120
|
let p = JSON.parse(m.data);
|
|
1103
1121
|
if (p.msg === "close_stream") {
|
|
1104
|
-
|
|
1122
|
+
ye(n, o.abort_controller);
|
|
1105
1123
|
return;
|
|
1106
1124
|
}
|
|
1107
1125
|
const g = p.event_id;
|
|
@@ -1130,7 +1148,7 @@ async function Yt() {
|
|
|
1130
1148
|
);
|
|
1131
1149
|
};
|
|
1132
1150
|
}
|
|
1133
|
-
function
|
|
1151
|
+
function ye(e, t) {
|
|
1134
1152
|
e && (e.open = !1, t == null || t.abort());
|
|
1135
1153
|
}
|
|
1136
1154
|
function es(e, t, s) {
|
|
@@ -1217,21 +1235,21 @@ function is(e, t = {}, s, n, i) {
|
|
|
1217
1235
|
var r;
|
|
1218
1236
|
try {
|
|
1219
1237
|
let o = function(w) {
|
|
1220
|
-
(i ||
|
|
1238
|
+
(i || Ke[w.type]) && m(w);
|
|
1221
1239
|
}, a = function() {
|
|
1222
|
-
for (
|
|
1240
|
+
for (Ye = !0; Z.length > 0; )
|
|
1223
1241
|
Z.shift()({
|
|
1224
1242
|
value: void 0,
|
|
1225
1243
|
done: !0
|
|
1226
1244
|
});
|
|
1227
1245
|
}, l = function(w) {
|
|
1228
|
-
Z.length > 0 ? Z.shift()(w) :
|
|
1246
|
+
Z.length > 0 ? Z.shift()(w) : ue.push(w);
|
|
1229
1247
|
}, h = function(w) {
|
|
1230
1248
|
l(os(w)), a();
|
|
1231
1249
|
}, m = function(w) {
|
|
1232
1250
|
l({ value: w, done: !1 });
|
|
1233
1251
|
}, p = function() {
|
|
1234
|
-
return
|
|
1252
|
+
return ue.length > 0 ? Promise.resolve(ue.shift()) : new Promise((w) => Z.push(w));
|
|
1235
1253
|
};
|
|
1236
1254
|
const { hf_token: g } = this.options, {
|
|
1237
1255
|
fetch: E,
|
|
@@ -1240,30 +1258,30 @@ function is(e, t = {}, s, n, i) {
|
|
|
1240
1258
|
session_hash: _,
|
|
1241
1259
|
api_info: N,
|
|
1242
1260
|
api_map: C,
|
|
1243
|
-
stream_status:
|
|
1244
|
-
pending_stream_messages:
|
|
1245
|
-
pending_diff_streams:
|
|
1246
|
-
event_callbacks:
|
|
1247
|
-
unclosed_events:
|
|
1248
|
-
post_data:
|
|
1261
|
+
stream_status: ie,
|
|
1262
|
+
pending_stream_messages: oe,
|
|
1263
|
+
pending_diff_streams: re,
|
|
1264
|
+
event_callbacks: ae,
|
|
1265
|
+
unclosed_events: We,
|
|
1266
|
+
post_data: ce,
|
|
1249
1267
|
options: F,
|
|
1250
1268
|
api_prefix: M
|
|
1251
|
-
} = this,
|
|
1269
|
+
} = this, He = this;
|
|
1252
1270
|
if (!N) throw new Error("No API found");
|
|
1253
1271
|
if (!c) throw new Error("Could not resolve app config");
|
|
1254
|
-
let { fn_index: f, endpoint_info:
|
|
1272
|
+
let { fn_index: f, endpoint_info: be, dependency: J } = rs(
|
|
1255
1273
|
N,
|
|
1256
1274
|
e,
|
|
1257
1275
|
C,
|
|
1258
1276
|
c
|
|
1259
|
-
),
|
|
1277
|
+
), Ve = Ct(t, be), R, T, j = c.protocol ?? "ws", ve = "", Ze = () => ve;
|
|
1260
1278
|
const d = typeof e == "number" ? "/predict" : e;
|
|
1261
|
-
let V, S = null, D = !1,
|
|
1262
|
-
const
|
|
1279
|
+
let V, S = null, D = !1, le = {}, G = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
|
|
1280
|
+
const Ke = ((r = F == null ? void 0 : F.events) == null ? void 0 : r.reduce(
|
|
1263
1281
|
(w, x) => (w[x] = !0, w),
|
|
1264
1282
|
{}
|
|
1265
1283
|
)) || {};
|
|
1266
|
-
async function
|
|
1284
|
+
async function Qe() {
|
|
1267
1285
|
let w = {}, x = {};
|
|
1268
1286
|
j === "ws" ? (R && R.readyState === 0 ? R.addEventListener("open", () => {
|
|
1269
1287
|
R.close();
|
|
@@ -1271,11 +1289,11 @@ function is(e, t = {}, s, n, i) {
|
|
|
1271
1289
|
try {
|
|
1272
1290
|
if (!c)
|
|
1273
1291
|
throw new Error("Could not resolve app config");
|
|
1274
|
-
"event_id" in x && await E(`${c.root}${M}/${
|
|
1292
|
+
"event_id" in x && await E(`${c.root}${M}/${ht}`, {
|
|
1275
1293
|
headers: { "Content-Type": "application/json" },
|
|
1276
1294
|
method: "POST",
|
|
1277
1295
|
body: JSON.stringify(x)
|
|
1278
|
-
}), await E(`${c.root}${M}/${
|
|
1296
|
+
}), await E(`${c.root}${M}/${ft}`, {
|
|
1279
1297
|
headers: { "Content-Type": "application/json" },
|
|
1280
1298
|
method: "POST",
|
|
1281
1299
|
body: JSON.stringify(w)
|
|
@@ -1286,10 +1304,10 @@ function is(e, t = {}, s, n, i) {
|
|
|
1286
1304
|
);
|
|
1287
1305
|
}
|
|
1288
1306
|
}
|
|
1289
|
-
const
|
|
1307
|
+
const Xe = async (w) => {
|
|
1290
1308
|
await this._resolve_heartbeat(w);
|
|
1291
1309
|
};
|
|
1292
|
-
async function
|
|
1310
|
+
async function Ee(w) {
|
|
1293
1311
|
if (!c) return;
|
|
1294
1312
|
let x = w.render_id;
|
|
1295
1313
|
c.components = [
|
|
@@ -1302,14 +1320,14 @@ function is(e, t = {}, s, n, i) {
|
|
|
1302
1320
|
const X = c.components.some((y) => y.type === "state"), Y = c.dependencies.some(
|
|
1303
1321
|
(y) => y.targets.some((U) => U[1] === "unload")
|
|
1304
1322
|
);
|
|
1305
|
-
c.connect_heartbeat = X || Y, await
|
|
1323
|
+
c.connect_heartbeat = X || Y, await Xe(c), o({
|
|
1306
1324
|
type: "render",
|
|
1307
1325
|
data: w,
|
|
1308
1326
|
endpoint: d,
|
|
1309
1327
|
fn_index: f
|
|
1310
1328
|
});
|
|
1311
1329
|
}
|
|
1312
|
-
this.handle_blob(c.root,
|
|
1330
|
+
this.handle_blob(c.root, Ve, be).then(
|
|
1313
1331
|
async (w) => {
|
|
1314
1332
|
var Y;
|
|
1315
1333
|
if (V = {
|
|
@@ -1331,7 +1349,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1331
1349
|
queue: !1,
|
|
1332
1350
|
fn_index: f,
|
|
1333
1351
|
time: /* @__PURE__ */ new Date()
|
|
1334
|
-
}),
|
|
1352
|
+
}), ce(
|
|
1335
1353
|
`${c.root}${M}/run${d.startsWith("/") ? d : `/${d}`}${G ? "?" + G : ""}`,
|
|
1336
1354
|
{
|
|
1337
1355
|
...V,
|
|
@@ -1353,7 +1371,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1353
1371
|
time: /* @__PURE__ */ new Date(),
|
|
1354
1372
|
event_data: s,
|
|
1355
1373
|
trigger_id: n
|
|
1356
|
-
}), y.render_config &&
|
|
1374
|
+
}), y.render_config && Ee(y.render_config), o({
|
|
1357
1375
|
type: "status",
|
|
1358
1376
|
endpoint: d,
|
|
1359
1377
|
fn_index: f,
|
|
@@ -1382,7 +1400,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1382
1400
|
});
|
|
1383
1401
|
});
|
|
1384
1402
|
else if (j == "ws") {
|
|
1385
|
-
const { ws_protocol: y, host: U } = await
|
|
1403
|
+
const { ws_protocol: y, host: U } = await se(
|
|
1386
1404
|
B,
|
|
1387
1405
|
g
|
|
1388
1406
|
);
|
|
@@ -1395,7 +1413,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1395
1413
|
time: /* @__PURE__ */ new Date()
|
|
1396
1414
|
});
|
|
1397
1415
|
let q = new URL(
|
|
1398
|
-
`${y}://${
|
|
1416
|
+
`${y}://${St(
|
|
1399
1417
|
U,
|
|
1400
1418
|
c.root,
|
|
1401
1419
|
!0
|
|
@@ -1413,9 +1431,9 @@ function is(e, t = {}, s, n, i) {
|
|
|
1413
1431
|
time: /* @__PURE__ */ new Date()
|
|
1414
1432
|
});
|
|
1415
1433
|
}, R.onmessage = function(A) {
|
|
1416
|
-
const k = JSON.parse(A.data), { type: $, status: v, data: O } =
|
|
1434
|
+
const k = JSON.parse(A.data), { type: $, status: v, data: O } = de(
|
|
1417
1435
|
k,
|
|
1418
|
-
|
|
1436
|
+
le[f]
|
|
1419
1437
|
);
|
|
1420
1438
|
if ($ === "update" && v && !D)
|
|
1421
1439
|
o({
|
|
@@ -1469,7 +1487,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1469
1487
|
endpoint: d,
|
|
1470
1488
|
fn_index: f
|
|
1471
1489
|
}), R.close()));
|
|
1472
|
-
},
|
|
1490
|
+
}, xe(c.version || "2.0.0", "3.6") < 0 && addEventListener(
|
|
1473
1491
|
"open",
|
|
1474
1492
|
() => R.send(JSON.stringify({ hash: _ }))
|
|
1475
1493
|
);
|
|
@@ -1487,16 +1505,16 @@ function is(e, t = {}, s, n, i) {
|
|
|
1487
1505
|
session_hash: _
|
|
1488
1506
|
}).toString();
|
|
1489
1507
|
let y = new URL(
|
|
1490
|
-
`${c.root}${M}/${
|
|
1508
|
+
`${c.root}${M}/${Ie}?${G ? G + "&" : ""}${X}`
|
|
1491
1509
|
);
|
|
1492
1510
|
if (this.jwt && y.searchParams.set("__sign", this.jwt), T = this.stream(y), !T)
|
|
1493
1511
|
return Promise.reject(
|
|
1494
1512
|
new Error("Cannot connect to SSE endpoint: " + y.toString())
|
|
1495
1513
|
);
|
|
1496
1514
|
T.onmessage = async function(U) {
|
|
1497
|
-
const q = JSON.parse(U.data), { type: A, status: k, data: $ } =
|
|
1515
|
+
const q = JSON.parse(U.data), { type: A, status: k, data: $ } = de(
|
|
1498
1516
|
q,
|
|
1499
|
-
|
|
1517
|
+
le[f]
|
|
1500
1518
|
);
|
|
1501
1519
|
if (A === "update" && k && !D)
|
|
1502
1520
|
o({
|
|
@@ -1507,7 +1525,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1507
1525
|
...k
|
|
1508
1526
|
}), k.stage === "error" && (T == null || T.close(), a());
|
|
1509
1527
|
else if (A === "data") {
|
|
1510
|
-
let [v, O] = await
|
|
1528
|
+
let [v, O] = await ce(
|
|
1511
1529
|
`${c.root}${M}/queue/data`,
|
|
1512
1530
|
{
|
|
1513
1531
|
...V,
|
|
@@ -1578,8 +1596,8 @@ function is(e, t = {}, s, n, i) {
|
|
|
1578
1596
|
let y = "";
|
|
1579
1597
|
typeof window < "u" && typeof document < "u" && (y = (Y = window == null ? void 0 : window.location) == null ? void 0 : Y.hostname);
|
|
1580
1598
|
const q = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
|
|
1581
|
-
(typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? It("zerogpu-headers", q) : Promise.resolve(null)).then((v) =>
|
|
1582
|
-
`${c.root}${M}/${
|
|
1599
|
+
(typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? It("zerogpu-headers", q) : Promise.resolve(null)).then((v) => ce(
|
|
1600
|
+
`${c.root}${M}/${ot}?${G}`,
|
|
1583
1601
|
{
|
|
1584
1602
|
...V,
|
|
1585
1603
|
session_hash: _
|
|
@@ -1590,7 +1608,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1590
1608
|
o({
|
|
1591
1609
|
type: "status",
|
|
1592
1610
|
stage: "error",
|
|
1593
|
-
message:
|
|
1611
|
+
message: Ue,
|
|
1594
1612
|
queue: !0,
|
|
1595
1613
|
endpoint: d,
|
|
1596
1614
|
fn_index: f,
|
|
@@ -1619,12 +1637,12 @@ function is(e, t = {}, s, n, i) {
|
|
|
1619
1637
|
time: /* @__PURE__ */ new Date()
|
|
1620
1638
|
});
|
|
1621
1639
|
else {
|
|
1622
|
-
S = v.event_id,
|
|
1623
|
-
let
|
|
1640
|
+
S = v.event_id, ve = S;
|
|
1641
|
+
let $e = async function(pe) {
|
|
1624
1642
|
try {
|
|
1625
|
-
const { type: L, status: b, data: P, original_msg:
|
|
1626
|
-
|
|
1627
|
-
|
|
1643
|
+
const { type: L, status: b, data: P, original_msg: et } = de(
|
|
1644
|
+
pe,
|
|
1645
|
+
le[f]
|
|
1628
1646
|
);
|
|
1629
1647
|
if (L == "heartbeat")
|
|
1630
1648
|
return;
|
|
@@ -1634,21 +1652,21 @@ function is(e, t = {}, s, n, i) {
|
|
|
1634
1652
|
endpoint: d,
|
|
1635
1653
|
fn_index: f,
|
|
1636
1654
|
time: /* @__PURE__ */ new Date(),
|
|
1637
|
-
original_msg:
|
|
1655
|
+
original_msg: et,
|
|
1638
1656
|
...b
|
|
1639
1657
|
});
|
|
1640
1658
|
else if (L === "complete")
|
|
1641
1659
|
D = b;
|
|
1642
1660
|
else if (L == "unexpected_error" || L == "broken_connection") {
|
|
1643
1661
|
console.error("Unexpected error", b == null ? void 0 : b.message);
|
|
1644
|
-
const
|
|
1662
|
+
const tt = L === "broken_connection";
|
|
1645
1663
|
o({
|
|
1646
1664
|
type: "status",
|
|
1647
1665
|
stage: "error",
|
|
1648
1666
|
message: (b == null ? void 0 : b.message) || "An Unexpected Error Occurred!",
|
|
1649
1667
|
queue: !0,
|
|
1650
1668
|
endpoint: d,
|
|
1651
|
-
broken:
|
|
1669
|
+
broken: tt,
|
|
1652
1670
|
session_not_found: b == null ? void 0 : b.session_not_found,
|
|
1653
1671
|
fn_index: f,
|
|
1654
1672
|
time: /* @__PURE__ */ new Date()
|
|
@@ -1673,7 +1691,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1673
1691
|
queue: !0,
|
|
1674
1692
|
endpoint: d,
|
|
1675
1693
|
fn_index: f
|
|
1676
|
-
}), P && J.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && es(
|
|
1694
|
+
}), P && J.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && es(re, S, P));
|
|
1677
1695
|
P && (o({
|
|
1678
1696
|
type: "data",
|
|
1679
1697
|
time: /* @__PURE__ */ new Date(),
|
|
@@ -1686,7 +1704,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1686
1704
|
),
|
|
1687
1705
|
endpoint: d,
|
|
1688
1706
|
fn_index: f
|
|
1689
|
-
}), P.render_config && await
|
|
1707
|
+
}), P.render_config && await Ee(P.render_config), D && (o({
|
|
1690
1708
|
type: "status",
|
|
1691
1709
|
time: /* @__PURE__ */ new Date(),
|
|
1692
1710
|
...D,
|
|
@@ -1694,7 +1712,7 @@ function is(e, t = {}, s, n, i) {
|
|
|
1694
1712
|
queue: !0,
|
|
1695
1713
|
endpoint: d,
|
|
1696
1714
|
fn_index: f
|
|
1697
|
-
}), a())), ((b == null ? void 0 : b.stage) === "complete" || (b == null ? void 0 : b.stage) === "error") && (
|
|
1715
|
+
}), a())), ((b == null ? void 0 : b.stage) === "complete" || (b == null ? void 0 : b.stage) === "error") && (ae[S] && delete ae[S], S in re && delete re[S]);
|
|
1698
1716
|
} catch (L) {
|
|
1699
1717
|
console.error("Unexpected client exception", L), o({
|
|
1700
1718
|
type: "status",
|
|
@@ -1704,27 +1722,27 @@ function is(e, t = {}, s, n, i) {
|
|
|
1704
1722
|
endpoint: d,
|
|
1705
1723
|
fn_index: f,
|
|
1706
1724
|
time: /* @__PURE__ */ new Date()
|
|
1707
|
-
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && (
|
|
1725
|
+
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && (ye(ie, He.abort_controller), ie.open = !1, a());
|
|
1708
1726
|
}
|
|
1709
1727
|
};
|
|
1710
|
-
S in
|
|
1711
|
-
(
|
|
1712
|
-
), delete
|
|
1728
|
+
S in oe && (oe[S].forEach(
|
|
1729
|
+
(pe) => $e(pe)
|
|
1730
|
+
), delete oe[S]), ae[S] = $e, We.add(S), ie.open || await this.open_stream();
|
|
1713
1731
|
}
|
|
1714
1732
|
});
|
|
1715
1733
|
}
|
|
1716
1734
|
}
|
|
1717
1735
|
);
|
|
1718
|
-
let
|
|
1719
|
-
const
|
|
1720
|
-
[Symbol.asyncIterator]: () =>
|
|
1736
|
+
let Ye = !1;
|
|
1737
|
+
const ue = [], Z = [], Se = {
|
|
1738
|
+
[Symbol.asyncIterator]: () => Se,
|
|
1721
1739
|
next: p,
|
|
1722
1740
|
throw: async (w) => (h(w), p()),
|
|
1723
1741
|
return: async () => (a(), p()),
|
|
1724
|
-
cancel:
|
|
1725
|
-
event_id:
|
|
1742
|
+
cancel: Qe,
|
|
1743
|
+
event_id: Ze
|
|
1726
1744
|
};
|
|
1727
|
-
return
|
|
1745
|
+
return Se;
|
|
1728
1746
|
} catch (o) {
|
|
1729
1747
|
throw console.error("Submit function encountered an error:", o), o;
|
|
1730
1748
|
}
|
|
@@ -1750,7 +1768,7 @@ function rs(e, t, s, n) {
|
|
|
1750
1768
|
);
|
|
1751
1769
|
return { fn_index: i, endpoint_info: r, dependency: o };
|
|
1752
1770
|
}
|
|
1753
|
-
class
|
|
1771
|
+
class te {
|
|
1754
1772
|
constructor(t, s = { events: ["data"] }) {
|
|
1755
1773
|
u(this, "app_reference");
|
|
1756
1774
|
u(this, "options");
|
|
@@ -1786,7 +1804,7 @@ class ee {
|
|
|
1786
1804
|
u(this, "resolve_config");
|
|
1787
1805
|
u(this, "resolve_cookies");
|
|
1788
1806
|
var n;
|
|
1789
|
-
this.app_reference = t, this.deep_link = ((n = s.query_params) == null ? void 0 : n.deep_link) || null, s.events || (s.events = ["data"]), this.options = s, this.current_payload = {}, this.view_api = At.bind(this), this.upload_files = Lt.bind(this), this.handle_blob = Ut.bind(this), this.post_data = Bt.bind(this), this.submit = is.bind(this), this.predict = Ft.bind(this), this.open_stream = Yt.bind(this), this.resolve_config =
|
|
1807
|
+
this.app_reference = t, this.deep_link = ((n = s.query_params) == null ? void 0 : n.deep_link) || null, s.events || (s.events = ["data"]), this.options = s, this.current_payload = {}, this.view_api = At.bind(this), this.upload_files = Lt.bind(this), this.handle_blob = Ut.bind(this), this.post_data = Bt.bind(this), this.submit = is.bind(this), this.predict = Ft.bind(this), this.open_stream = Yt.bind(this), this.resolve_config = kt.bind(this), this.resolve_cookies = Rt.bind(this), this.upload = Pt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
|
|
1790
1808
|
}
|
|
1791
1809
|
get_url_config(t = null) {
|
|
1792
1810
|
if (!this.config)
|
|
@@ -1834,16 +1852,16 @@ class ee {
|
|
|
1834
1852
|
var t;
|
|
1835
1853
|
this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
|
|
1836
1854
|
({ config: s }) => this._resolve_heartbeat(s)
|
|
1837
|
-
), this.api_info = await this.view_api(), this.api_map =
|
|
1855
|
+
), this.api_info = await this.view_api(), this.api_map = $t(((t = this.config) == null ? void 0 : t.dependencies) || []);
|
|
1838
1856
|
}
|
|
1839
1857
|
async _resolve_heartbeat(t) {
|
|
1840
|
-
if (t && (this.config = t, this.api_prefix = t.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.hf_token && (this.jwt = await
|
|
1858
|
+
if (t && (this.config = t, this.api_prefix = t.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.hf_token && (this.jwt = await De(
|
|
1841
1859
|
this.config.space_id,
|
|
1842
1860
|
this.options.hf_token,
|
|
1843
1861
|
this.cookies
|
|
1844
|
-
))), t.space_id && this.options.hf_token && (this.jwt = await
|
|
1862
|
+
))), t.space_id && this.options.hf_token && (this.jwt = await De(t.space_id, this.options.hf_token)), this.config && this.config.connect_heartbeat) {
|
|
1845
1863
|
const s = new URL(
|
|
1846
|
-
`${this.config.root}${this.api_prefix}/${
|
|
1864
|
+
`${this.config.root}${this.api_prefix}/${ut}/${this.session_hash}`
|
|
1847
1865
|
);
|
|
1848
1866
|
this.jwt && s.searchParams.set("__sign", this.jwt), this.heartbeat_event || (this.heartbeat_event = this.stream(s));
|
|
1849
1867
|
}
|
|
@@ -1856,7 +1874,7 @@ class ee {
|
|
|
1856
1874
|
}
|
|
1857
1875
|
async reconnect() {
|
|
1858
1876
|
const t = new URL(
|
|
1859
|
-
`${this.config.root}${this.api_prefix}/${
|
|
1877
|
+
`${this.config.root}${this.api_prefix}/${dt}`
|
|
1860
1878
|
);
|
|
1861
1879
|
let s;
|
|
1862
1880
|
try {
|
|
@@ -1870,7 +1888,7 @@ class ee {
|
|
|
1870
1888
|
return s !== this.config.app_id ? "changed" : "connected";
|
|
1871
1889
|
}
|
|
1872
1890
|
close() {
|
|
1873
|
-
this.closed = !0,
|
|
1891
|
+
this.closed = !0, ye(this.stream_status, this.abort_controller);
|
|
1874
1892
|
}
|
|
1875
1893
|
set_current_payload(t) {
|
|
1876
1894
|
this.current_payload = t;
|
|
@@ -1881,11 +1899,11 @@ class ee {
|
|
|
1881
1899
|
return Wt(t, s);
|
|
1882
1900
|
}
|
|
1883
1901
|
async _resolve_config() {
|
|
1884
|
-
const { http_protocol: t, host: s, space_id: n } = await
|
|
1902
|
+
const { http_protocol: t, host: s, space_id: n } = await se(
|
|
1885
1903
|
this.app_reference,
|
|
1886
1904
|
this.options.hf_token
|
|
1887
1905
|
), { status_callback: i } = this.options;
|
|
1888
|
-
n && i && await
|
|
1906
|
+
n && i && await Je(n, i);
|
|
1889
1907
|
let r;
|
|
1890
1908
|
try {
|
|
1891
1909
|
let o = `${t}//${s}`;
|
|
@@ -1896,7 +1914,7 @@ class ee {
|
|
|
1896
1914
|
if (n && i)
|
|
1897
1915
|
Q(
|
|
1898
1916
|
n,
|
|
1899
|
-
|
|
1917
|
+
we.test(n) ? "space_name" : "subdomain",
|
|
1900
1918
|
this.handle_space_success
|
|
1901
1919
|
);
|
|
1902
1920
|
else
|
|
@@ -1914,7 +1932,7 @@ class ee {
|
|
|
1914
1932
|
try {
|
|
1915
1933
|
this.api_info = await this.view_api();
|
|
1916
1934
|
} catch (s) {
|
|
1917
|
-
console.error(
|
|
1935
|
+
console.error(gt + s.message);
|
|
1918
1936
|
}
|
|
1919
1937
|
return this.prepare_return_obj();
|
|
1920
1938
|
}
|
|
@@ -1963,7 +1981,7 @@ class ee {
|
|
|
1963
1981
|
r && (i.Authorization = `Bearer ${r}`);
|
|
1964
1982
|
try {
|
|
1965
1983
|
const p = await this.fetch(
|
|
1966
|
-
`${a}${this.api_prefix}/${
|
|
1984
|
+
`${a}${this.api_prefix}/${pt}/`,
|
|
1967
1985
|
{
|
|
1968
1986
|
method: "POST",
|
|
1969
1987
|
body: h,
|
|
@@ -1981,7 +1999,7 @@ class ee {
|
|
|
1981
1999
|
}
|
|
1982
2000
|
}
|
|
1983
2001
|
set_cookies(t) {
|
|
1984
|
-
this.cookies =
|
|
2002
|
+
this.cookies = Fe(t).join("; ");
|
|
1985
2003
|
}
|
|
1986
2004
|
prepare_return_obj() {
|
|
1987
2005
|
return {
|
|
@@ -2029,15 +2047,15 @@ class ee {
|
|
|
2029
2047
|
async function us(e, t = {
|
|
2030
2048
|
events: ["data"]
|
|
2031
2049
|
}) {
|
|
2032
|
-
return await
|
|
2050
|
+
return await te.connect(e, t);
|
|
2033
2051
|
}
|
|
2034
2052
|
async function ps(e, t) {
|
|
2035
|
-
return await
|
|
2053
|
+
return await te.duplicate(e, t);
|
|
2036
2054
|
}
|
|
2037
2055
|
export {
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2056
|
+
te as Client,
|
|
2057
|
+
ne as FileData,
|
|
2058
|
+
bt as MISSING_CREDENTIALS_MSG,
|
|
2041
2059
|
us as client,
|
|
2042
2060
|
ps as duplicate,
|
|
2043
2061
|
ls as handle_file,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init_helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/init_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAUvC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAG5B;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,GACtB,MAAM,CAKR;AAED,wBAAsB,OAAO,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,MAAM,EAAE,EACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAezB;AAED,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"init_helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/init_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAUvC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAG5B;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,GACtB,MAAM,CAKR;AAED,wBAAsB,OAAO,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,MAAM,EAAE,EACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAezB;AAED,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B;AA+BD,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBjE;AAGD,wBAAsB,iBAAiB,CACtC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,EAAE,OAAO,KAAK,EACpB,QAAQ,CAAC,EAAE,MAAM,MAAM,EAAE,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyBxB;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACrD,WAAW,EAAE,IAAI,GAAG,KAAK,CAAC;IAC1B,aAAa,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACb,CAkBA;AAED,eAAO,MAAM,qBAAqB,kBAAmB,MAAM,KAAG,MAAM,EAUnE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -73,10 +73,29 @@ function map_names_to_ids(fns) {
|
|
|
73
73
|
async function resolve_config(endpoint) {
|
|
74
74
|
const headers = this.options.hf_token ? { Authorization: `Bearer ${this.options.hf_token}` } : {};
|
|
75
75
|
headers["Content-Type"] = "application/json";
|
|
76
|
-
if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876"
|
|
76
|
+
if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
77
77
|
if (window.gradio_config.current_page) {
|
|
78
78
|
endpoint = endpoint.substring(0, endpoint.lastIndexOf("/"));
|
|
79
79
|
}
|
|
80
|
+
if (window.gradio_config.dev_mode) {
|
|
81
|
+
let config_url = join_urls(
|
|
82
|
+
endpoint,
|
|
83
|
+
this.deep_link ? CONFIG_URL + "?deep_link=" + this.deep_link : CONFIG_URL
|
|
84
|
+
);
|
|
85
|
+
const response = await this.fetch(config_url, {
|
|
86
|
+
headers,
|
|
87
|
+
credentials: "include"
|
|
88
|
+
});
|
|
89
|
+
const config = await handleConfigResponse(
|
|
90
|
+
response,
|
|
91
|
+
endpoint,
|
|
92
|
+
!!this.options.auth
|
|
93
|
+
);
|
|
94
|
+
window.gradio_config = {
|
|
95
|
+
...config,
|
|
96
|
+
current_page: window.gradio_config.current_page
|
|
97
|
+
};
|
|
98
|
+
}
|
|
80
99
|
window.gradio_config.root = endpoint;
|
|
81
100
|
return { ...window.gradio_config };
|
|
82
101
|
} else if (endpoint) {
|
package/package.json
CHANGED
|
@@ -77,12 +77,33 @@ export async function resolve_config(
|
|
|
77
77
|
if (
|
|
78
78
|
typeof window !== "undefined" &&
|
|
79
79
|
window.gradio_config &&
|
|
80
|
-
location.origin !== "http://localhost:9876"
|
|
81
|
-
!window.gradio_config.dev_mode
|
|
80
|
+
location.origin !== "http://localhost:9876"
|
|
82
81
|
) {
|
|
83
82
|
if (window.gradio_config.current_page) {
|
|
84
83
|
endpoint = endpoint.substring(0, endpoint.lastIndexOf("/"));
|
|
85
84
|
}
|
|
85
|
+
if (window.gradio_config.dev_mode) {
|
|
86
|
+
let config_url = join_urls(
|
|
87
|
+
endpoint,
|
|
88
|
+
this.deep_link
|
|
89
|
+
? CONFIG_URL + "?deep_link=" + this.deep_link
|
|
90
|
+
: CONFIG_URL
|
|
91
|
+
);
|
|
92
|
+
const response = await this.fetch(config_url, {
|
|
93
|
+
headers,
|
|
94
|
+
credentials: "include"
|
|
95
|
+
});
|
|
96
|
+
const config = await handleConfigResponse(
|
|
97
|
+
response,
|
|
98
|
+
endpoint,
|
|
99
|
+
!!this.options.auth
|
|
100
|
+
);
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
window.gradio_config = {
|
|
103
|
+
...config,
|
|
104
|
+
current_page: window.gradio_config.current_page
|
|
105
|
+
};
|
|
106
|
+
}
|
|
86
107
|
window.gradio_config.root = endpoint;
|
|
87
108
|
// @ts-ignore
|
|
88
109
|
return { ...window.gradio_config } as Config;
|