@gradio/client 0.17.0 → 0.19.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 +27 -0
- package/README.md +10 -6
- package/dist/client.d.ts +18 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/constants.d.ts +8 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers/api_info.d.ts +22 -0
- package/dist/helpers/api_info.d.ts.map +1 -1
- package/dist/helpers/data.d.ts +2 -2
- package/dist/helpers/data.d.ts.map +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/helpers/spaces.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +275 -183
- package/dist/test/handlers.d.ts +3 -0
- package/dist/test/handlers.d.ts.map +1 -0
- package/dist/test/mock_eventsource.d.ts +2 -0
- package/dist/test/mock_eventsource.d.ts.map +1 -0
- package/dist/test/server.d.ts +2 -0
- package/dist/test/server.d.ts.map +1 -0
- package/dist/test/test_data.d.ts +76 -0
- package/dist/test/test_data.d.ts.map +1 -0
- package/dist/types.d.ts +23 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/upload.d.ts +2 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/utils/duplicate.d.ts.map +1 -1
- package/dist/utils/predict.d.ts +1 -1
- package/dist/utils/predict.d.ts.map +1 -1
- package/dist/utils/stream.d.ts +2 -2
- package/dist/utils/stream.d.ts.map +1 -1
- package/dist/utils/submit.d.ts +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/dist/utils/upload_files.d.ts.map +1 -1
- package/dist/utils/view_api.d.ts.map +1 -1
- package/package.json +8 -2
- package/src/client.ts +53 -28
- package/src/constants.ts +9 -2
- package/src/helpers/api_info.ts +75 -4
- package/src/helpers/data.ts +46 -28
- package/src/helpers/init_helpers.ts +7 -11
- package/src/helpers/spaces.ts +8 -3
- package/src/index.ts +1 -1
- package/src/test/api_info.test.ts +567 -0
- package/src/test/data.test.ts +281 -0
- package/src/test/handlers.ts +438 -0
- package/src/test/init.test.ts +139 -0
- package/src/test/init_helpers.test.ts +94 -0
- package/src/test/mock_eventsource.ts +13 -0
- package/src/test/post_data.test.ts +45 -0
- package/src/test/server.ts +6 -0
- package/src/test/spaces.test.ts +145 -0
- package/src/test/stream.test.ts +79 -0
- package/src/test/test_data.ts +557 -0
- package/src/test/upload_files.test.ts +42 -0
- package/src/test/view_api.test.ts +53 -0
- package/src/types.ts +36 -17
- package/src/upload.ts +4 -8
- package/src/utils/duplicate.ts +20 -3
- package/src/utils/handle_blob.ts +1 -1
- package/src/utils/post_data.ts +1 -1
- package/src/utils/predict.ts +2 -2
- package/src/utils/stream.ts +30 -21
- package/src/utils/submit.ts +42 -19
- package/src/utils/upload_files.ts +11 -6
- package/src/utils/view_api.ts +4 -7
- package/vite.config.js +7 -0
- package/src/utils/client.node-test.ts +0 -173
package/src/helpers/data.ts
CHANGED
@@ -5,7 +5,7 @@ import type {
|
|
5
5
|
Config,
|
6
6
|
EndpointInfo,
|
7
7
|
JsApiData,
|
8
|
-
|
8
|
+
DataType
|
9
9
|
} from "../types";
|
10
10
|
|
11
11
|
export function update_object(
|
@@ -31,22 +31,22 @@ export function update_object(
|
|
31
31
|
}
|
32
32
|
|
33
33
|
export async function walk_and_store_blobs(
|
34
|
-
|
34
|
+
data: DataType,
|
35
35
|
type: string | undefined = undefined,
|
36
36
|
path: string[] = [],
|
37
37
|
root = false,
|
38
38
|
endpoint_info: EndpointInfo<ApiData | JsApiData> | undefined = undefined
|
39
39
|
): Promise<BlobRef[]> {
|
40
|
-
if (Array.isArray(
|
40
|
+
if (Array.isArray(data)) {
|
41
41
|
let blob_refs: BlobRef[] = [];
|
42
42
|
|
43
43
|
await Promise.all(
|
44
|
-
|
44
|
+
data.map(async (item) => {
|
45
45
|
let new_path = path.slice();
|
46
46
|
new_path.push(item);
|
47
47
|
|
48
48
|
const array_refs = await walk_and_store_blobs(
|
49
|
-
|
49
|
+
data[item],
|
50
50
|
root ? endpoint_info?.parameters[item]?.component || undefined : type,
|
51
51
|
new_path,
|
52
52
|
false,
|
@@ -58,44 +58,62 @@ export async function walk_and_store_blobs(
|
|
58
58
|
);
|
59
59
|
|
60
60
|
return blob_refs;
|
61
|
-
} else if (
|
61
|
+
} else if (
|
62
|
+
(globalThis.Buffer && data instanceof globalThis.Buffer) ||
|
63
|
+
data instanceof Blob
|
64
|
+
) {
|
62
65
|
const is_image = type === "Image";
|
63
66
|
return [
|
64
67
|
{
|
65
68
|
path: path,
|
66
|
-
blob: is_image ? false : new NodeBlob([
|
69
|
+
blob: is_image ? false : new NodeBlob([data]),
|
67
70
|
type
|
68
71
|
}
|
69
72
|
];
|
70
|
-
} else if (typeof
|
73
|
+
} else if (typeof data === "object" && data !== null) {
|
71
74
|
let blob_refs: BlobRef[] = [];
|
72
|
-
for (
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
75
|
+
for (const key of Object.keys(data) as (keyof typeof data)[]) {
|
76
|
+
const new_path = [...path, key];
|
77
|
+
const value = data[key];
|
78
|
+
|
79
|
+
blob_refs = blob_refs.concat(
|
80
|
+
await walk_and_store_blobs(
|
81
|
+
value,
|
82
|
+
undefined,
|
83
|
+
new_path,
|
84
|
+
false,
|
85
|
+
endpoint_info
|
86
|
+
)
|
87
|
+
);
|
88
|
+
}
|
89
|
+
|
90
|
+
if (
|
91
|
+
!blob_refs.length &&
|
92
|
+
!(
|
93
|
+
data instanceof Blob ||
|
94
|
+
data instanceof ArrayBuffer ||
|
95
|
+
data instanceof Uint8Array
|
96
|
+
)
|
97
|
+
) {
|
98
|
+
return [
|
99
|
+
{
|
100
|
+
path: path,
|
101
|
+
blob: new NodeBlob([JSON.stringify(data)]),
|
102
|
+
type: typeof data
|
103
|
+
}
|
104
|
+
];
|
87
105
|
}
|
88
106
|
return blob_refs;
|
89
107
|
}
|
108
|
+
|
90
109
|
return [];
|
91
110
|
}
|
92
111
|
|
93
112
|
export function skip_queue(id: number, config: Config): boolean {
|
94
|
-
|
95
|
-
!
|
96
|
-
|
97
|
-
|
98
|
-
);
|
113
|
+
if (config?.dependencies?.[id]?.queue !== null) {
|
114
|
+
return !config.dependencies[id].queue;
|
115
|
+
}
|
116
|
+
return !config.enable_queue;
|
99
117
|
}
|
100
118
|
|
101
119
|
// todo: add jsdoc for this function
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Config } from "../types";
|
2
|
-
import { CONFIG_URL } from "../constants";
|
2
|
+
import { CONFIG_ERROR_MSG, CONFIG_URL } from "../constants";
|
3
3
|
import { Client } from "..";
|
4
4
|
|
5
5
|
/**
|
@@ -38,7 +38,6 @@ export async function get_jwt(
|
|
38
38
|
|
39
39
|
return jwt || false;
|
40
40
|
} catch (e) {
|
41
|
-
console.error(e);
|
42
41
|
return false;
|
43
42
|
}
|
44
43
|
}
|
@@ -74,14 +73,11 @@ export async function resolve_config(
|
|
74
73
|
const config = window.gradio_config;
|
75
74
|
let config_root = resolve_root(endpoint, config.root, false);
|
76
75
|
config.root = config_root;
|
77
|
-
return { ...config, path };
|
76
|
+
return { ...config, path } as Config;
|
78
77
|
} else if (endpoint) {
|
79
|
-
const response = await this.
|
80
|
-
|
81
|
-
|
82
|
-
headers
|
83
|
-
}
|
84
|
-
);
|
78
|
+
const response = await this.fetch(`${endpoint}/${CONFIG_URL}`, {
|
79
|
+
headers
|
80
|
+
});
|
85
81
|
|
86
82
|
if (response?.status === 200) {
|
87
83
|
let config = await response.json();
|
@@ -89,10 +85,10 @@ export async function resolve_config(
|
|
89
85
|
config.root = endpoint;
|
90
86
|
return config;
|
91
87
|
}
|
92
|
-
throw new Error(
|
88
|
+
throw new Error(CONFIG_ERROR_MSG);
|
93
89
|
}
|
94
90
|
|
95
|
-
throw new Error(
|
91
|
+
throw new Error(CONFIG_ERROR_MSG);
|
96
92
|
}
|
97
93
|
|
98
94
|
export function determine_protocol(endpoint: string): {
|
package/src/helpers/spaces.ts
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
import {
|
2
|
+
RUNTIME_URL,
|
3
|
+
SLEEPTIME_URL,
|
4
|
+
SPACE_STATUS_ERROR_MSG
|
5
|
+
} from "../constants";
|
1
6
|
import type { SpaceStatusCallback } from "../types";
|
2
7
|
|
3
8
|
export async function check_space_status(
|
@@ -22,7 +27,7 @@ export async function check_space_status(
|
|
22
27
|
status_callback({
|
23
28
|
status: "error",
|
24
29
|
load_status: "error",
|
25
|
-
message:
|
30
|
+
message: SPACE_STATUS_ERROR_MSG,
|
26
31
|
detail: "NOT_FOUND"
|
27
32
|
});
|
28
33
|
return;
|
@@ -121,7 +126,7 @@ export async function get_space_hardware(
|
|
121
126
|
|
122
127
|
try {
|
123
128
|
const res = await fetch(
|
124
|
-
`https://huggingface.co/api/spaces/${space_id}
|
129
|
+
`https://huggingface.co/api/spaces/${space_id}/${RUNTIME_URL}`,
|
125
130
|
{ headers }
|
126
131
|
);
|
127
132
|
|
@@ -154,7 +159,7 @@ export async function set_space_timeout(
|
|
154
159
|
|
155
160
|
try {
|
156
161
|
const res = await fetch(
|
157
|
-
`https://huggingface.co/api/spaces/${space_id}
|
162
|
+
`https://huggingface.co/api/spaces/${space_id}/${SLEEPTIME_URL}`,
|
158
163
|
{
|
159
164
|
method: "POST",
|
160
165
|
headers: { "Content-Type": "application/json", ...headers },
|
package/src/index.ts
CHANGED