@gradio/client 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +2 -2
- package/dist/client.d.ts +29 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/index.js +96 -78
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/{wrapper-b7460963.js → wrapper-6f348d45.js} +16 -27
- package/package.json +1 -1
- package/src/client.ts +124 -97
- package/src/types.ts +7 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# @gradio/client
|
2
2
|
|
3
|
+
## 0.1.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#4357](https://github.com/gradio-app/gradio/pull/4357) [`0dbd8f7f`](https://github.com/gradio-app/gradio/commit/0dbd8f7fee4b4877f783fa7bc493f98bbfc3d01d) Thanks [@pngwn](https://github.com/pngwn)! - Various internal refactors and cleanups.
|
8
|
+
|
9
|
+
## 0.1.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- [#4273](https://github.com/gradio-app/gradio/pull/4273) [`1d0f0a9d`](https://github.com/gradio-app/gradio/commit/1d0f0a9db096552e67eb2197c932342587e9e61e) Thanks [@pngwn](https://github.com/pngwn)! - Ensure websocket error messages are correctly handled.
|
14
|
+
|
15
|
+
- [#4315](https://github.com/gradio-app/gradio/pull/4315) [`b525b122`](https://github.com/gradio-app/gradio/commit/b525b122dd8569bbaf7e06db5b90d622d2e9073d) Thanks [@whitphx](https://github.com/whitphx)! - Refacor types.
|
16
|
+
|
17
|
+
- [#4271](https://github.com/gradio-app/gradio/pull/4271) [`1151c525`](https://github.com/gradio-app/gradio/commit/1151c5253554cb87ebd4a44a8a470ac215ff782b) Thanks [@pngwn](https://github.com/pngwn)! - Ensure the full root path is always respected when making requests to a gradio app server.
|
18
|
+
|
3
19
|
## 0.1.1
|
4
20
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
@@ -206,7 +206,7 @@ submission.off("/predict", handle_data);
|
|
206
206
|
|
207
207
|
##### `destroy`
|
208
208
|
|
209
|
-
The `destroy` method will remove all subscriptions to a job, regardless of whether or not they are `"data"` or `"status"` events. This is a convenience method for when you do not
|
209
|
+
The `destroy` method will remove all subscriptions to a job, regardless of whether or not they are `"data"` or `"status"` events. This is a convenience method for when you do not want to unsubscribe use the `off` method.
|
210
210
|
|
211
211
|
```js
|
212
212
|
import { client } from "@gradio/client";
|
@@ -239,7 +239,7 @@ submission.cancel();
|
|
239
239
|
|
240
240
|
#### `view_api`
|
241
241
|
|
242
|
-
The `view_api` method provides details about the API you are connected
|
242
|
+
The `view_api` method provides details about the API you are connected to. It returns a JavaScript object of all named endpoints, unnamed endpoints and what values they accept and return. This method does not accept arguments.
|
243
243
|
|
244
244
|
```ts
|
245
245
|
import { client } from "@gradio/client";
|
package/dist/client.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { hardware_types } from "./utils.js";
|
2
|
-
import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatusCallback
|
2
|
+
import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatusCallback } from "./types.js";
|
3
3
|
import type { Config } from "./types.js";
|
4
4
|
declare type event = <K extends EventType>(eventType: K, listener: EventListener<K>) => SubmitReturn;
|
5
5
|
declare type predict = (endpoint: string | number, data?: unknown[], event_data?: unknown) => Promise<unknown>;
|
@@ -7,7 +7,7 @@ declare type client_return = {
|
|
7
7
|
predict: predict;
|
8
8
|
config: Config;
|
9
9
|
submit: (endpoint: string | number, data?: unknown[], event_data?: unknown) => SubmitReturn;
|
10
|
-
view_api: (c?: Config) => Promise<
|
10
|
+
view_api: (c?: Config) => Promise<ApiInfo<JsApiData>>;
|
11
11
|
};
|
12
12
|
declare type SubmitReturn = {
|
13
13
|
on: event;
|
@@ -30,7 +30,33 @@ export declare function client(app_reference: string, options?: {
|
|
30
30
|
status_callback?: SpaceStatusCallback;
|
31
31
|
normalise_files?: boolean;
|
32
32
|
}): Promise<client_return>;
|
33
|
-
|
33
|
+
interface ApiData {
|
34
|
+
label: string;
|
35
|
+
type: {
|
36
|
+
type: any;
|
37
|
+
description: string;
|
38
|
+
};
|
39
|
+
component: string;
|
40
|
+
example_input?: any;
|
41
|
+
}
|
42
|
+
interface JsApiData {
|
43
|
+
label: string;
|
44
|
+
type: string;
|
45
|
+
component: string;
|
46
|
+
example_input: any;
|
47
|
+
}
|
48
|
+
interface EndpointInfo<T extends ApiData | JsApiData> {
|
49
|
+
parameters: T[];
|
50
|
+
returns: T[];
|
51
|
+
}
|
52
|
+
interface ApiInfo<T extends ApiData | JsApiData> {
|
53
|
+
named_endpoints: {
|
54
|
+
[key: string]: EndpointInfo<T>;
|
55
|
+
};
|
56
|
+
unnamed_endpoints: {
|
57
|
+
[key: string]: EndpointInfo<T>;
|
58
|
+
};
|
59
|
+
}
|
34
60
|
export declare function handle_blob(endpoint: string, data: unknown[], api_info: any, token?: `hf_${string}`): Promise<unknown[]>;
|
35
61
|
export declare function walk_and_store_blobs(param: any, type?: any, path?: any[], root?: boolean, api_info?: any): Promise<any[]>;
|
36
62
|
export {};
|
package/dist/client.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAQN,cAAc,EACd,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EAIb,YAAY,EACZ,cAAc,EAGd,mBAAmB,
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAQN,cAAc,EACd,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EAIb,YAAY,EACZ,cAAc,EAGd,mBAAmB,EAEnB,MAAM,YAAY,CAAC;AAE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,CAAC,CAAC;KAC/B,CAAC;CACF;AA2HD,wBAAsB,WAAW,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EAAE,EACf,QAAQ,KAAA,EACR,KAAK,CAAC,EAAE,MAAM,MAAM,EAAE,GACpB,OAAO,CAAC,OAAO,EAAE,CAAC,CAqCpB;AAUD,wBAAsB,oBAAoB,CACzC,KAAK,KAAA,EACL,IAAI,MAAY,EAChB,IAAI,QAAK,EACT,IAAI,UAAQ,EACZ,QAAQ,MAAY,kBAyEpB"}
|
package/dist/index.js
CHANGED
@@ -263,9 +263,9 @@ async function client(app_reference, options = { normalise_files: true }) {
|
|
263
263
|
view_api
|
264
264
|
// duplicate
|
265
265
|
};
|
266
|
-
|
266
|
+
const transform_files = normalise_files ?? true;
|
267
267
|
if (typeof window === "undefined" || !("WebSocket" in window)) {
|
268
|
-
const ws = await import("./wrapper-
|
268
|
+
const ws = await import("./wrapper-6f348d45.js");
|
269
269
|
NodeBlob = (await import("node:buffer")).Blob;
|
270
270
|
global.WebSocket = ws.WebSocket;
|
271
271
|
}
|
@@ -400,7 +400,7 @@ async function client(app_reference, options = { normalise_files: true }) {
|
|
400
400
|
},
|
401
401
|
hf_token
|
402
402
|
).then(([output, status_code]) => {
|
403
|
-
transform_files ? transform_output(
|
403
|
+
const data2 = transform_files ? transform_output(
|
404
404
|
output.data,
|
405
405
|
api_info,
|
406
406
|
config.root,
|
@@ -411,7 +411,7 @@ async function client(app_reference, options = { normalise_files: true }) {
|
|
411
411
|
type: "data",
|
412
412
|
endpoint: _endpoint,
|
413
413
|
fn_index,
|
414
|
-
data:
|
414
|
+
data: data2,
|
415
415
|
time: /* @__PURE__ */ new Date()
|
416
416
|
});
|
417
417
|
fire_event({
|
@@ -545,12 +545,12 @@ async function client(app_reference, options = { normalise_files: true }) {
|
|
545
545
|
});
|
546
546
|
function fire_event(event) {
|
547
547
|
const narrowed_listener_map = listener_map;
|
548
|
-
|
548
|
+
const listeners = narrowed_listener_map[event.type] || [];
|
549
549
|
listeners == null ? void 0 : listeners.forEach((l) => l(event));
|
550
550
|
}
|
551
551
|
function on(eventType, listener) {
|
552
552
|
const narrowed_listener_map = listener_map;
|
553
|
-
|
553
|
+
const listeners = narrowed_listener_map[eventType] || [];
|
554
554
|
narrowed_listener_map[eventType] = listeners;
|
555
555
|
listeners == null ? void 0 : listeners.push(listener);
|
556
556
|
return { on, off, cancel, destroy };
|
@@ -615,42 +615,41 @@ async function client(app_reference, options = { normalise_files: true }) {
|
|
615
615
|
if (hf_token) {
|
616
616
|
headers.Authorization = `Bearer ${hf_token}`;
|
617
617
|
}
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
}),
|
629
|
-
headers
|
630
|
-
}
|
631
|
-
);
|
632
|
-
} else {
|
633
|
-
response = await fetch(`${http_protocol}//${host}/info`, {
|
618
|
+
let response;
|
619
|
+
if (semiver(config2.version || "2.0.0", "3.30") < 0) {
|
620
|
+
response = await fetch(
|
621
|
+
"https://gradio-space-api-fetcher-v2.hf.space/api",
|
622
|
+
{
|
623
|
+
method: "POST",
|
624
|
+
body: JSON.stringify({
|
625
|
+
serialize: false,
|
626
|
+
config: JSON.stringify(config2)
|
627
|
+
}),
|
634
628
|
headers
|
635
|
-
}
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
}
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
629
|
+
}
|
630
|
+
);
|
631
|
+
} else {
|
632
|
+
response = await fetch(`${config2.root}/info`, {
|
633
|
+
headers
|
634
|
+
});
|
635
|
+
}
|
636
|
+
if (!response.ok) {
|
637
|
+
throw new Error(BROKEN_CONNECTION_MSG);
|
638
|
+
}
|
639
|
+
let api_info = await response.json();
|
640
|
+
if ("api" in api_info) {
|
641
|
+
api_info = api_info.api;
|
642
|
+
}
|
643
|
+
if (api_info.named_endpoints["/predict"] && !api_info.unnamed_endpoints["0"]) {
|
644
|
+
api_info.unnamed_endpoints[0] = api_info.named_endpoints["/predict"];
|
648
645
|
}
|
646
|
+
const x = transform_api_info(api_info, config2, api_map);
|
647
|
+
return x;
|
649
648
|
}
|
650
649
|
});
|
651
650
|
}
|
652
651
|
function transform_output(data, api_info, root_url, remote_url) {
|
653
|
-
|
652
|
+
return data.map((d, i) => {
|
654
653
|
var _a, _b, _c, _d;
|
655
654
|
if (((_b = (_a = api_info.returns) == null ? void 0 : _a[i]) == null ? void 0 : _b.component) === "File") {
|
656
655
|
return normalise_file(d, root_url, remote_url);
|
@@ -664,7 +663,6 @@ function transform_output(data, api_info, root_url, remote_url) {
|
|
664
663
|
return d;
|
665
664
|
}
|
666
665
|
});
|
667
|
-
return transformed_data;
|
668
666
|
}
|
669
667
|
function normalise_file(file, root, root_url) {
|
670
668
|
if (file == null)
|
@@ -688,7 +686,7 @@ function normalise_file(file, root, root_url) {
|
|
688
686
|
if (!root_url) {
|
689
687
|
file.data = root + "/file=" + file.name;
|
690
688
|
} else {
|
691
|
-
file.data = "/proxy=" + root_url + "
|
689
|
+
file.data = "/proxy=" + root_url + "file=" + file.name;
|
692
690
|
}
|
693
691
|
}
|
694
692
|
return file;
|
@@ -785,34 +783,32 @@ async function handle_blob(endpoint, data, api_info, token) {
|
|
785
783
|
true,
|
786
784
|
api_info
|
787
785
|
);
|
788
|
-
return
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
res(data);
|
815
|
-
}).catch(console.log);
|
786
|
+
return Promise.all(
|
787
|
+
blob_refs.map(async ({ path, blob, data: data2, type }) => {
|
788
|
+
if (blob) {
|
789
|
+
const file_url = (await upload_files(endpoint, [blob], token)).files[0];
|
790
|
+
return { path, file_url, type };
|
791
|
+
} else {
|
792
|
+
return { path, base64: data2, type };
|
793
|
+
}
|
794
|
+
})
|
795
|
+
).then((r) => {
|
796
|
+
r.forEach(({ path, file_url, base64, type }) => {
|
797
|
+
if (base64) {
|
798
|
+
update_object(data, base64, path);
|
799
|
+
} else if (type === "Gallery") {
|
800
|
+
update_object(data, file_url, path);
|
801
|
+
} else if (file_url) {
|
802
|
+
const o = {
|
803
|
+
is_file: true,
|
804
|
+
name: `${file_url}`,
|
805
|
+
data: null
|
806
|
+
// orig_name: "file.csv"
|
807
|
+
};
|
808
|
+
update_object(data, o, path);
|
809
|
+
}
|
810
|
+
});
|
811
|
+
return data;
|
816
812
|
});
|
817
813
|
}
|
818
814
|
function update_object(object, newValue, stack) {
|
@@ -958,6 +954,15 @@ async function check_space_status(id, type, status_callback) {
|
|
958
954
|
check_space_status(id, type, status_callback);
|
959
955
|
}, 1e3);
|
960
956
|
break;
|
957
|
+
case "PAUSED":
|
958
|
+
status_callback({
|
959
|
+
status: "paused",
|
960
|
+
load_status: "error",
|
961
|
+
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
962
|
+
detail: stage,
|
963
|
+
discussions_enabled: await discussions_enabled(space_name)
|
964
|
+
});
|
965
|
+
break;
|
961
966
|
case "RUNNING":
|
962
967
|
case "RUNNING_BUILDING":
|
963
968
|
status_callback({
|
@@ -1045,18 +1050,31 @@ function handle_message(data, last_status) {
|
|
1045
1050
|
data: data.success ? data.output : null
|
1046
1051
|
};
|
1047
1052
|
case "process_completed":
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
}
|
1053
|
+
if ("error" in data.output) {
|
1054
|
+
return {
|
1055
|
+
type: "update",
|
1056
|
+
status: {
|
1057
|
+
queue,
|
1058
|
+
message: data.output.error,
|
1059
|
+
stage: "error",
|
1060
|
+
code: data.code,
|
1061
|
+
success: data.success
|
1062
|
+
}
|
1063
|
+
};
|
1064
|
+
} else {
|
1065
|
+
return {
|
1066
|
+
type: "complete",
|
1067
|
+
status: {
|
1068
|
+
queue,
|
1069
|
+
message: !data.success ? data.output.error : void 0,
|
1070
|
+
stage: data.success ? "complete" : "error",
|
1071
|
+
code: data.code,
|
1072
|
+
progress_data: data.progress_data,
|
1073
|
+
eta: data.output.average_duration
|
1074
|
+
},
|
1075
|
+
data: data.success ? data.output : null
|
1076
|
+
};
|
1077
|
+
}
|
1060
1078
|
case "process_starts":
|
1061
1079
|
return {
|
1062
1080
|
type: "update",
|
package/dist/types.d.ts
CHANGED
@@ -58,8 +58,8 @@ export interface SpaceStatusNormal {
|
|
58
58
|
message: string;
|
59
59
|
}
|
60
60
|
export interface SpaceStatusError {
|
61
|
-
status: "space_error";
|
62
|
-
detail: "NO_APP_FILE" | "CONFIG_ERROR" | "BUILD_ERROR" | "RUNTIME_ERROR";
|
61
|
+
status: "space_error" | "paused";
|
62
|
+
detail: "NO_APP_FILE" | "CONFIG_ERROR" | "BUILD_ERROR" | "RUNTIME_ERROR" | "PAUSED";
|
63
63
|
load_status: "error";
|
64
64
|
message: string;
|
65
65
|
discussions_enabled: boolean;
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACtB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,EAAE,GAAG,EAAE,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;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F,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
@@ -8,6 +8,9 @@ import require$$0$3 from "events";
|
|
8
8
|
import require$$1$1 from "https";
|
9
9
|
import require$$2 from "http";
|
10
10
|
import require$$7 from "url";
|
11
|
+
function getDefaultExportFromCjs(x) {
|
12
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
13
|
+
}
|
11
14
|
function getAugmentedNamespace(n) {
|
12
15
|
if (n.__esModule)
|
13
16
|
return n;
|
@@ -135,16 +138,8 @@ function createWebSocketStream(ws, options) {
|
|
135
138
|
return duplex;
|
136
139
|
}
|
137
140
|
var stream = createWebSocketStream;
|
138
|
-
const stream$1 = stream;
|
139
|
-
var
|
140
|
-
var bufferUtil$1 = {
|
141
|
-
get exports() {
|
142
|
-
return bufferUtilExports;
|
143
|
-
},
|
144
|
-
set exports(v) {
|
145
|
-
bufferUtilExports = v;
|
146
|
-
}
|
147
|
-
};
|
141
|
+
const stream$1 = /* @__PURE__ */ getDefaultExportFromCjs(stream);
|
142
|
+
var bufferUtil$1 = { exports: {} };
|
148
143
|
var constants = {
|
149
144
|
BINARY_TYPES: ["nodebuffer", "arraybuffer", "fragments"],
|
150
145
|
EMPTY_BUFFER: Buffer.alloc(0),
|
@@ -218,13 +213,13 @@ bufferUtil$1.exports = {
|
|
218
213
|
if (!process.env.WS_NO_BUFFER_UTIL) {
|
219
214
|
try {
|
220
215
|
const bufferUtil2 = require("bufferutil");
|
221
|
-
mask =
|
216
|
+
mask = bufferUtil$1.exports.mask = function(source, mask2, output, offset, length) {
|
222
217
|
if (length < 48)
|
223
218
|
_mask(source, mask2, output, offset, length);
|
224
219
|
else
|
225
220
|
bufferUtil2.mask(source, mask2, output, offset, length);
|
226
221
|
};
|
227
|
-
unmask$1 =
|
222
|
+
unmask$1 = bufferUtil$1.exports.unmask = function(buffer, mask2) {
|
228
223
|
if (buffer.length < 32)
|
229
224
|
_unmask(buffer, mask2);
|
230
225
|
else
|
@@ -233,6 +228,7 @@ if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
233
228
|
} catch (e) {
|
234
229
|
}
|
235
230
|
}
|
231
|
+
var bufferUtilExports = bufferUtil$1.exports;
|
236
232
|
const kDone = Symbol("kDone");
|
237
233
|
const kRun = Symbol("kRun");
|
238
234
|
let Limiter$1 = class Limiter {
|
@@ -650,15 +646,7 @@ function inflateOnError(err) {
|
|
650
646
|
err[kStatusCode$2] = 1007;
|
651
647
|
this[kCallback](err);
|
652
648
|
}
|
653
|
-
var
|
654
|
-
var validation = {
|
655
|
-
get exports() {
|
656
|
-
return validationExports;
|
657
|
-
},
|
658
|
-
set exports(v) {
|
659
|
-
validationExports = v;
|
660
|
-
}
|
661
|
-
};
|
649
|
+
var validation = { exports: {} };
|
662
650
|
const __viteOptionalPeerDep_utf8Validate_ws = {};
|
663
651
|
const __viteOptionalPeerDep_utf8Validate_ws$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
664
652
|
__proto__: null,
|
@@ -843,18 +831,19 @@ validation.exports = {
|
|
843
831
|
tokenChars: tokenChars$2
|
844
832
|
};
|
845
833
|
if (isUtf8) {
|
846
|
-
isValidUTF8_1 =
|
834
|
+
isValidUTF8_1 = validation.exports.isValidUTF8 = function(buf) {
|
847
835
|
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
848
836
|
};
|
849
837
|
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
850
838
|
try {
|
851
839
|
const isValidUTF82 = require$$1;
|
852
|
-
isValidUTF8_1 =
|
840
|
+
isValidUTF8_1 = validation.exports.isValidUTF8 = function(buf) {
|
853
841
|
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF82(buf);
|
854
842
|
};
|
855
843
|
} catch (e) {
|
856
844
|
}
|
857
845
|
}
|
846
|
+
var validationExports = validation.exports;
|
858
847
|
const { Writable } = require$$0;
|
859
848
|
const PerMessageDeflate$3 = permessageDeflate;
|
860
849
|
const {
|
@@ -1380,7 +1369,7 @@ function error(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
1380
1369
|
err[kStatusCode$1] = statusCode;
|
1381
1370
|
return err;
|
1382
1371
|
}
|
1383
|
-
const receiver$1 = receiver;
|
1372
|
+
const receiver$1 = /* @__PURE__ */ getDefaultExportFromCjs(receiver);
|
1384
1373
|
const { randomFillSync } = require$$5;
|
1385
1374
|
const PerMessageDeflate$2 = permessageDeflate;
|
1386
1375
|
const { EMPTY_BUFFER: EMPTY_BUFFER$1 } = constants;
|
@@ -1784,7 +1773,7 @@ let Sender$1 = class Sender {
|
|
1784
1773
|
}
|
1785
1774
|
};
|
1786
1775
|
var sender = Sender$1;
|
1787
|
-
const sender$1 = sender;
|
1776
|
+
const sender$1 = /* @__PURE__ */ getDefaultExportFromCjs(sender);
|
1788
1777
|
const { kForOnEventAttribute: kForOnEventAttribute$1, kListener: kListener$1 } = constants;
|
1789
1778
|
const kCode = Symbol("kCode");
|
1790
1779
|
const kData = Symbol("kData");
|
@@ -3034,7 +3023,7 @@ function socketOnError$1() {
|
|
3034
3023
|
this.destroy();
|
3035
3024
|
}
|
3036
3025
|
}
|
3037
|
-
const WebSocket$2 = websocket;
|
3026
|
+
const WebSocket$2 = /* @__PURE__ */ getDefaultExportFromCjs(websocket);
|
3038
3027
|
const { tokenChars } = validationExports;
|
3039
3028
|
function parse(header) {
|
3040
3029
|
const protocols = /* @__PURE__ */ new Set();
|
@@ -3457,7 +3446,7 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
3457
3446
|
abortHandshake(socket, code, message);
|
3458
3447
|
}
|
3459
3448
|
}
|
3460
|
-
const websocketServer$1 = websocketServer;
|
3449
|
+
const websocketServer$1 = /* @__PURE__ */ getDefaultExportFromCjs(websocketServer);
|
3461
3450
|
export {
|
3462
3451
|
receiver$1 as Receiver,
|
3463
3452
|
sender$1 as Sender,
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
@@ -45,7 +45,7 @@ type client_return = {
|
|
45
45
|
data?: unknown[],
|
46
46
|
event_data?: unknown
|
47
47
|
) => SubmitReturn;
|
48
|
-
view_api: (c?: Config) => Promise<
|
48
|
+
view_api: (c?: Config) => Promise<ApiInfo<JsApiData>>;
|
49
49
|
};
|
50
50
|
|
51
51
|
type SubmitReturn = {
|
@@ -214,7 +214,7 @@ export async function client(
|
|
214
214
|
// duplicate
|
215
215
|
};
|
216
216
|
|
217
|
-
|
217
|
+
const transform_files = normalise_files ?? true;
|
218
218
|
if (typeof window === "undefined" || !("WebSocket" in window)) {
|
219
219
|
const ws = await import("ws");
|
220
220
|
NodeBlob = (await import("node:buffer")).Blob;
|
@@ -250,7 +250,7 @@ export async function client(
|
|
250
250
|
...return_obj
|
251
251
|
};
|
252
252
|
}
|
253
|
-
let api
|
253
|
+
let api: ApiInfo<JsApiData>;
|
254
254
|
async function handle_space_sucess(status: SpaceStatus) {
|
255
255
|
if (status_callback) status_callback(status);
|
256
256
|
if (status.status === "running")
|
@@ -357,7 +357,6 @@ export async function client(
|
|
357
357
|
let complete: false | Record<string, any> = false;
|
358
358
|
const listener_map: ListenerMap<EventType> = {};
|
359
359
|
|
360
|
-
//@ts-ignore
|
361
360
|
handle_blob(
|
362
361
|
`${http_protocol}//${host + config.path}`,
|
363
362
|
data,
|
@@ -399,7 +398,7 @@ export async function client(
|
|
399
398
|
type: "data",
|
400
399
|
endpoint: _endpoint,
|
401
400
|
fn_index,
|
402
|
-
data:
|
401
|
+
data: data,
|
403
402
|
time: new Date()
|
404
403
|
});
|
405
404
|
|
@@ -548,7 +547,7 @@ export async function client(
|
|
548
547
|
|
549
548
|
function fire_event<K extends EventType>(event: Event<K>) {
|
550
549
|
const narrowed_listener_map: ListenerMap<K> = listener_map;
|
551
|
-
|
550
|
+
const listeners = narrowed_listener_map[event.type] || [];
|
552
551
|
listeners?.forEach((l) => l(event));
|
553
552
|
}
|
554
553
|
|
@@ -557,7 +556,7 @@ export async function client(
|
|
557
556
|
listener: EventListener<K>
|
558
557
|
) {
|
559
558
|
const narrowed_listener_map: ListenerMap<K> = listener_map;
|
560
|
-
|
559
|
+
const listeners = narrowed_listener_map[eventType] || [];
|
561
560
|
narrowed_listener_map[eventType] = listeners;
|
562
561
|
listeners?.push(listener);
|
563
562
|
|
@@ -627,9 +626,7 @@ export async function client(
|
|
627
626
|
};
|
628
627
|
}
|
629
628
|
|
630
|
-
async function view_api(
|
631
|
-
config?: Config
|
632
|
-
): Promise<ApiInfo<JsApiData> | [{ error: string }, 500]> {
|
629
|
+
async function view_api(config?: Config): Promise<ApiInfo<JsApiData>> {
|
633
630
|
if (api) return api;
|
634
631
|
|
635
632
|
const headers: {
|
@@ -639,46 +636,46 @@ export async function client(
|
|
639
636
|
if (hf_token) {
|
640
637
|
headers.Authorization = `Bearer ${hf_token}`;
|
641
638
|
}
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
}),
|
654
|
-
headers
|
655
|
-
}
|
656
|
-
);
|
657
|
-
} else {
|
658
|
-
response = await fetch(`${http_protocol}//${host}/info`, {
|
639
|
+
let response: Response;
|
640
|
+
// @ts-ignore
|
641
|
+
if (semiver(config.version || "2.0.0", "3.30") < 0) {
|
642
|
+
response = await fetch(
|
643
|
+
"https://gradio-space-api-fetcher-v2.hf.space/api",
|
644
|
+
{
|
645
|
+
method: "POST",
|
646
|
+
body: JSON.stringify({
|
647
|
+
serialize: false,
|
648
|
+
config: JSON.stringify(config)
|
649
|
+
}),
|
659
650
|
headers
|
660
|
-
}
|
661
|
-
|
651
|
+
}
|
652
|
+
);
|
653
|
+
} else {
|
654
|
+
response = await fetch(`${config.root}/info`, {
|
655
|
+
headers
|
656
|
+
});
|
657
|
+
}
|
662
658
|
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
if ("api" in api_info) {
|
667
|
-
api_info = api_info.api;
|
668
|
-
}
|
659
|
+
if (!response.ok) {
|
660
|
+
throw new Error(BROKEN_CONNECTION_MSG);
|
661
|
+
}
|
669
662
|
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
663
|
+
let api_info = (await response.json()) as
|
664
|
+
| ApiInfo<ApiData>
|
665
|
+
| { api: ApiInfo<ApiData> };
|
666
|
+
if ("api" in api_info) {
|
667
|
+
api_info = api_info.api;
|
668
|
+
}
|
676
669
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
670
|
+
if (
|
671
|
+
api_info.named_endpoints["/predict"] &&
|
672
|
+
!api_info.unnamed_endpoints["0"]
|
673
|
+
) {
|
674
|
+
api_info.unnamed_endpoints[0] = api_info.named_endpoints["/predict"];
|
681
675
|
}
|
676
|
+
|
677
|
+
const x = transform_api_info(api_info, config, api_map);
|
678
|
+
return x;
|
682
679
|
}
|
683
680
|
});
|
684
681
|
}
|
@@ -689,7 +686,7 @@ function transform_output(
|
|
689
686
|
root_url: string,
|
690
687
|
remote_url?: string
|
691
688
|
): unknown[] {
|
692
|
-
|
689
|
+
return data.map((d, i) => {
|
693
690
|
if (api_info.returns?.[i]?.component === "File") {
|
694
691
|
return normalise_file(d, root_url, remote_url);
|
695
692
|
} else if (api_info.returns?.[i]?.component === "Gallery") {
|
@@ -704,14 +701,27 @@ function transform_output(
|
|
704
701
|
return d;
|
705
702
|
}
|
706
703
|
});
|
707
|
-
|
708
|
-
return transformed_data;
|
709
704
|
}
|
710
705
|
|
711
|
-
|
712
|
-
file: Array<FileData
|
706
|
+
function normalise_file(
|
707
|
+
file: Array<FileData>,
|
713
708
|
root: string,
|
714
709
|
root_url: string | null
|
710
|
+
): Array<FileData>;
|
711
|
+
function normalise_file(
|
712
|
+
file: FileData | string,
|
713
|
+
root: string,
|
714
|
+
root_url: string | null
|
715
|
+
): FileData;
|
716
|
+
function normalise_file(
|
717
|
+
file: null,
|
718
|
+
root: string,
|
719
|
+
root_url: string | null
|
720
|
+
): null;
|
721
|
+
function normalise_file(
|
722
|
+
file,
|
723
|
+
root,
|
724
|
+
root_url
|
715
725
|
): Array<FileData> | FileData | null {
|
716
726
|
if (file == null) return null;
|
717
727
|
if (typeof file === "string") {
|
@@ -726,7 +736,6 @@ export function normalise_file(
|
|
726
736
|
if (x === null) {
|
727
737
|
normalized_file.push(null);
|
728
738
|
} else {
|
729
|
-
//@ts-ignore
|
730
739
|
normalized_file.push(normalise_file(x, root, root_url));
|
731
740
|
}
|
732
741
|
}
|
@@ -736,7 +745,7 @@ export function normalise_file(
|
|
736
745
|
if (!root_url) {
|
737
746
|
file.data = root + "/file=" + file.name;
|
738
747
|
} else {
|
739
|
-
file.data = "/proxy=" + root_url + "
|
748
|
+
file.data = "/proxy=" + root_url + "file=" + file.name;
|
740
749
|
}
|
741
750
|
}
|
742
751
|
return file;
|
@@ -907,38 +916,33 @@ export async function handle_blob(
|
|
907
916
|
api_info
|
908
917
|
);
|
909
918
|
|
910
|
-
return
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
update_object(data, o, path);
|
936
|
-
}
|
937
|
-
});
|
919
|
+
return Promise.all(
|
920
|
+
blob_refs.map(async ({ path, blob, data, type }) => {
|
921
|
+
if (blob) {
|
922
|
+
const file_url = (await upload_files(endpoint, [blob], token)).files[0];
|
923
|
+
return { path, file_url, type };
|
924
|
+
} else {
|
925
|
+
return { path, base64: data, type };
|
926
|
+
}
|
927
|
+
})
|
928
|
+
).then((r) => {
|
929
|
+
r.forEach(({ path, file_url, base64, type }) => {
|
930
|
+
if (base64) {
|
931
|
+
update_object(data, base64, path);
|
932
|
+
} else if (type === "Gallery") {
|
933
|
+
update_object(data, file_url, path);
|
934
|
+
} else if (file_url) {
|
935
|
+
const o = {
|
936
|
+
is_file: true,
|
937
|
+
name: `${file_url}`,
|
938
|
+
data: null
|
939
|
+
// orig_name: "file.csv"
|
940
|
+
};
|
941
|
+
update_object(data, o, path);
|
942
|
+
}
|
943
|
+
});
|
938
944
|
|
939
|
-
|
940
|
-
})
|
941
|
-
.catch(console.log);
|
945
|
+
return data;
|
942
946
|
});
|
943
947
|
}
|
944
948
|
|
@@ -1125,9 +1129,18 @@ async function check_space_status(
|
|
1125
1129
|
|
1126
1130
|
setTimeout(() => {
|
1127
1131
|
check_space_status(id, type, status_callback);
|
1128
|
-
}, 1000);
|
1132
|
+
}, 1000); // poll for status
|
1133
|
+
break;
|
1134
|
+
case "PAUSED":
|
1135
|
+
status_callback({
|
1136
|
+
status: "paused",
|
1137
|
+
load_status: "error",
|
1138
|
+
message:
|
1139
|
+
"This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
1140
|
+
detail: stage,
|
1141
|
+
discussions_enabled: await discussions_enabled(space_name)
|
1142
|
+
});
|
1129
1143
|
break;
|
1130
|
-
// poll for status
|
1131
1144
|
case "RUNNING":
|
1132
1145
|
case "RUNNING_BUILDING":
|
1133
1146
|
status_callback({
|
@@ -1226,18 +1239,32 @@ function handle_message(
|
|
1226
1239
|
data: data.success ? data.output : null
|
1227
1240
|
};
|
1228
1241
|
case "process_completed":
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
}
|
1242
|
+
if ("error" in data.output) {
|
1243
|
+
return {
|
1244
|
+
type: "update",
|
1245
|
+
status: {
|
1246
|
+
queue,
|
1247
|
+
message: data.output.error as string,
|
1248
|
+
stage: "error",
|
1249
|
+
code: data.code,
|
1250
|
+
success: data.success
|
1251
|
+
}
|
1252
|
+
};
|
1253
|
+
} else {
|
1254
|
+
return {
|
1255
|
+
type: "complete",
|
1256
|
+
status: {
|
1257
|
+
queue,
|
1258
|
+
message: !data.success ? data.output.error : undefined,
|
1259
|
+
stage: data.success ? "complete" : "error",
|
1260
|
+
code: data.code,
|
1261
|
+
progress_data: data.progress_data,
|
1262
|
+
eta: data.output.average_duration
|
1263
|
+
},
|
1264
|
+
data: data.success ? data.output : null
|
1265
|
+
};
|
1266
|
+
}
|
1267
|
+
|
1241
1268
|
case "process_starts":
|
1242
1269
|
return {
|
1243
1270
|
type: "update",
|
package/src/types.ts
CHANGED
@@ -67,8 +67,13 @@ export interface SpaceStatusNormal {
|
|
67
67
|
message: string;
|
68
68
|
}
|
69
69
|
export interface SpaceStatusError {
|
70
|
-
status: "space_error";
|
71
|
-
detail:
|
70
|
+
status: "space_error" | "paused";
|
71
|
+
detail:
|
72
|
+
| "NO_APP_FILE"
|
73
|
+
| "CONFIG_ERROR"
|
74
|
+
| "BUILD_ERROR"
|
75
|
+
| "RUNTIME_ERROR"
|
76
|
+
| "PAUSED";
|
72
77
|
load_status: "error";
|
73
78
|
message: string;
|
74
79
|
discussions_enabled: boolean;
|