@gradio/client 0.0.1 → 0.1.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 +13 -0
- package/LICENSE +201 -0
- package/README.md +323 -30
- package/dist/client.d.ts +35 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1016 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/wrapper-b7460963.js +3468 -0
- package/package.json +26 -3
- package/src/client.node-test.ts +172 -0
- package/src/client.ts +785 -151
- package/src/globals.d.ts +31 -0
- package/src/index.ts +2 -2
- package/src/types.ts +9 -4
- package/src/utils.ts +121 -11
- package/tsconfig.json +14 -0
- package/vite.config.js +23 -0
package/package.json
CHANGED
@@ -1,9 +1,32 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/client",
|
3
|
-
"version": "0.0
|
3
|
+
"version": "0.1.0",
|
4
4
|
"description": "Gradio UI packages",
|
5
5
|
"type": "module",
|
6
|
-
"main": "
|
6
|
+
"main": "dist/index.js",
|
7
7
|
"author": "",
|
8
|
-
"license": "ISC"
|
8
|
+
"license": "ISC",
|
9
|
+
"exports": {
|
10
|
+
".": {
|
11
|
+
"import": "./dist/index.js"
|
12
|
+
},
|
13
|
+
"./package.json": "./package.json"
|
14
|
+
},
|
15
|
+
"dependencies": {
|
16
|
+
"bufferutil": "^4.0.7",
|
17
|
+
"semiver": "^1.1.0",
|
18
|
+
"ws": "^8.13.0"
|
19
|
+
},
|
20
|
+
"devDependencies": {
|
21
|
+
"@types/ws": "^8.5.4",
|
22
|
+
"esbuild": "^0.17.14"
|
23
|
+
},
|
24
|
+
"engines": {
|
25
|
+
"node": ">=18.0.0"
|
26
|
+
},
|
27
|
+
"scripts": {
|
28
|
+
"bundle": "vite build --ssr",
|
29
|
+
"generate_types": "tsc",
|
30
|
+
"build": "pnpm bundle && pnpm generate_types"
|
31
|
+
}
|
9
32
|
}
|
@@ -0,0 +1,172 @@
|
|
1
|
+
import { test, describe, assert } from "vitest";
|
2
|
+
import { readFileSync } from "fs";
|
3
|
+
import { join, dirname } from "path";
|
4
|
+
import { fileURLToPath } from "url";
|
5
|
+
import { Blob } from "node:buffer";
|
6
|
+
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
8
|
+
const image_path = join(
|
9
|
+
__dirname,
|
10
|
+
"..",
|
11
|
+
"..",
|
12
|
+
"..",
|
13
|
+
"demo",
|
14
|
+
"kitchen_sink",
|
15
|
+
"files",
|
16
|
+
"lion.jpg"
|
17
|
+
);
|
18
|
+
|
19
|
+
import { walk_and_store_blobs, client, handle_blob } from "./client";
|
20
|
+
|
21
|
+
describe.skip("extract blob parts", () => {
|
22
|
+
test("convert Buffer to Blob", async () => {
|
23
|
+
const image = readFileSync(image_path);
|
24
|
+
await client("gradio/hello_world_main");
|
25
|
+
const parts = walk_and_store_blobs({
|
26
|
+
data: {
|
27
|
+
image
|
28
|
+
}
|
29
|
+
});
|
30
|
+
|
31
|
+
assert.isTrue(parts[0].blob instanceof Blob);
|
32
|
+
});
|
33
|
+
|
34
|
+
test("leave node Blob as Blob", async () => {
|
35
|
+
const image = new Blob([readFileSync(image_path)]);
|
36
|
+
|
37
|
+
await client("gradio/hello_world_main");
|
38
|
+
const parts = walk_and_store_blobs({
|
39
|
+
data: {
|
40
|
+
image
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
44
|
+
assert.isTrue(parts[0].blob instanceof Blob);
|
45
|
+
});
|
46
|
+
|
47
|
+
test("handle deep structures", async () => {
|
48
|
+
const image = new Blob([readFileSync(image_path)]);
|
49
|
+
|
50
|
+
await client("gradio/hello_world_main");
|
51
|
+
const parts = walk_and_store_blobs({
|
52
|
+
a: {
|
53
|
+
b: {
|
54
|
+
data: {
|
55
|
+
image
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
});
|
60
|
+
|
61
|
+
assert.isTrue(parts[0].blob instanceof Blob);
|
62
|
+
});
|
63
|
+
|
64
|
+
test("handle deep structures with arrays", async () => {
|
65
|
+
const image = new Blob([readFileSync(image_path)]);
|
66
|
+
|
67
|
+
await client("gradio/hello_world_main");
|
68
|
+
const parts = walk_and_store_blobs({
|
69
|
+
a: [
|
70
|
+
{
|
71
|
+
b: [
|
72
|
+
{
|
73
|
+
data: [
|
74
|
+
{
|
75
|
+
image
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
]
|
80
|
+
}
|
81
|
+
]
|
82
|
+
});
|
83
|
+
|
84
|
+
assert.isTrue(parts[0].blob instanceof Blob);
|
85
|
+
});
|
86
|
+
|
87
|
+
test("handle deep structures with arrays 2", async () => {
|
88
|
+
const image = new Blob([readFileSync(image_path)]);
|
89
|
+
|
90
|
+
await client("gradio/hello_world_main");
|
91
|
+
const obj = {
|
92
|
+
a: [
|
93
|
+
{
|
94
|
+
b: [
|
95
|
+
{
|
96
|
+
data: [[image], image, [image, [image]]]
|
97
|
+
}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
]
|
101
|
+
};
|
102
|
+
const parts = walk_and_store_blobs(obj);
|
103
|
+
|
104
|
+
function map_path(
|
105
|
+
obj: Record<string, any>,
|
106
|
+
parts: { path: string[]; blob: any }[]
|
107
|
+
) {
|
108
|
+
const { path, blob } = parts[parts.length - 1];
|
109
|
+
let ref = obj;
|
110
|
+
path.forEach((p) => (ref = ref[p]));
|
111
|
+
|
112
|
+
return ref === blob;
|
113
|
+
}
|
114
|
+
|
115
|
+
assert.isTrue(parts[0].blob instanceof Blob);
|
116
|
+
// assert.isTrue(map_path(obj, parts));
|
117
|
+
});
|
118
|
+
});
|
119
|
+
|
120
|
+
describe("handle_blob", () => {
|
121
|
+
test("handle blobs", async () => {
|
122
|
+
const image = new Blob([readFileSync(image_path)]);
|
123
|
+
|
124
|
+
const app = await client("gradio/hello_world_main");
|
125
|
+
const obj = [
|
126
|
+
{
|
127
|
+
a: [
|
128
|
+
{
|
129
|
+
b: [
|
130
|
+
{
|
131
|
+
data: [[image], image, [image, [image]]]
|
132
|
+
}
|
133
|
+
]
|
134
|
+
}
|
135
|
+
]
|
136
|
+
}
|
137
|
+
];
|
138
|
+
|
139
|
+
const parts = await handle_blob(app.config.root, obj, undefined);
|
140
|
+
//@ts-ignore
|
141
|
+
// assert.isString(parts.data[0].a[0].b[0].data[0][0]);
|
142
|
+
});
|
143
|
+
});
|
144
|
+
|
145
|
+
describe.skip("private space", () => {
|
146
|
+
test("can access a private space", async () => {
|
147
|
+
const image = new Blob([readFileSync(image_path)]);
|
148
|
+
|
149
|
+
const app = await client("pngwn/hello_world", {
|
150
|
+
hf_token: "hf_"
|
151
|
+
});
|
152
|
+
|
153
|
+
console.log(app);
|
154
|
+
const obj = [
|
155
|
+
{
|
156
|
+
a: [
|
157
|
+
{
|
158
|
+
b: [
|
159
|
+
{
|
160
|
+
data: [[image], image, [image, [image]]]
|
161
|
+
}
|
162
|
+
]
|
163
|
+
}
|
164
|
+
]
|
165
|
+
}
|
166
|
+
];
|
167
|
+
|
168
|
+
const parts = await handle_blob(app.config.root, obj, "hf_");
|
169
|
+
//@ts-ignore
|
170
|
+
assert.isString(parts.data[0].a[0].b[0].data[0][0]);
|
171
|
+
});
|
172
|
+
});
|