@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.
Files changed (69) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +10 -6
  3. package/dist/client.d.ts +18 -7
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/constants.d.ts +8 -2
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/helpers/api_info.d.ts +22 -0
  8. package/dist/helpers/api_info.d.ts.map +1 -1
  9. package/dist/helpers/data.d.ts +2 -2
  10. package/dist/helpers/data.d.ts.map +1 -1
  11. package/dist/helpers/init_helpers.d.ts.map +1 -1
  12. package/dist/helpers/spaces.d.ts.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +275 -183
  16. package/dist/test/handlers.d.ts +3 -0
  17. package/dist/test/handlers.d.ts.map +1 -0
  18. package/dist/test/mock_eventsource.d.ts +2 -0
  19. package/dist/test/mock_eventsource.d.ts.map +1 -0
  20. package/dist/test/server.d.ts +2 -0
  21. package/dist/test/server.d.ts.map +1 -0
  22. package/dist/test/test_data.d.ts +76 -0
  23. package/dist/test/test_data.d.ts.map +1 -0
  24. package/dist/types.d.ts +23 -7
  25. package/dist/types.d.ts.map +1 -1
  26. package/dist/upload.d.ts +2 -2
  27. package/dist/upload.d.ts.map +1 -1
  28. package/dist/utils/duplicate.d.ts.map +1 -1
  29. package/dist/utils/predict.d.ts +1 -1
  30. package/dist/utils/predict.d.ts.map +1 -1
  31. package/dist/utils/stream.d.ts +2 -2
  32. package/dist/utils/stream.d.ts.map +1 -1
  33. package/dist/utils/submit.d.ts +1 -1
  34. package/dist/utils/submit.d.ts.map +1 -1
  35. package/dist/utils/upload_files.d.ts.map +1 -1
  36. package/dist/utils/view_api.d.ts.map +1 -1
  37. package/package.json +8 -2
  38. package/src/client.ts +53 -28
  39. package/src/constants.ts +9 -2
  40. package/src/helpers/api_info.ts +75 -4
  41. package/src/helpers/data.ts +46 -28
  42. package/src/helpers/init_helpers.ts +7 -11
  43. package/src/helpers/spaces.ts +8 -3
  44. package/src/index.ts +1 -1
  45. package/src/test/api_info.test.ts +567 -0
  46. package/src/test/data.test.ts +281 -0
  47. package/src/test/handlers.ts +438 -0
  48. package/src/test/init.test.ts +139 -0
  49. package/src/test/init_helpers.test.ts +94 -0
  50. package/src/test/mock_eventsource.ts +13 -0
  51. package/src/test/post_data.test.ts +45 -0
  52. package/src/test/server.ts +6 -0
  53. package/src/test/spaces.test.ts +145 -0
  54. package/src/test/stream.test.ts +79 -0
  55. package/src/test/test_data.ts +557 -0
  56. package/src/test/upload_files.test.ts +42 -0
  57. package/src/test/view_api.test.ts +53 -0
  58. package/src/types.ts +36 -17
  59. package/src/upload.ts +4 -8
  60. package/src/utils/duplicate.ts +20 -3
  61. package/src/utils/handle_blob.ts +1 -1
  62. package/src/utils/post_data.ts +1 -1
  63. package/src/utils/predict.ts +2 -2
  64. package/src/utils/stream.ts +30 -21
  65. package/src/utils/submit.ts +42 -19
  66. package/src/utils/upload_files.ts +11 -6
  67. package/src/utils/view_api.ts +4 -7
  68. package/vite.config.js +7 -0
  69. package/src/utils/client.node-test.ts +0 -173
@@ -1,173 +0,0 @@
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 } from "../helpers/data";
20
- import { Client } from "..";
21
-
22
- describe.skip("extract blob parts", () => {
23
- test("convert Buffer to Blob", async () => {
24
- const image = readFileSync(image_path);
25
- await Client.connect("gradio/hello_world_main");
26
- const parts = walk_and_store_blobs({
27
- data: {
28
- image
29
- }
30
- });
31
-
32
- assert.isTrue(parts[0].blob instanceof Blob);
33
- });
34
-
35
- test("leave node Blob as Blob", async () => {
36
- const image = new Blob([readFileSync(image_path)]);
37
-
38
- await Client.connect("gradio/hello_world_main");
39
- const parts = walk_and_store_blobs({
40
- data: {
41
- image
42
- }
43
- });
44
-
45
- assert.isTrue(parts[0].blob instanceof Blob);
46
- });
47
-
48
- test("handle deep structures", async () => {
49
- const image = new Blob([readFileSync(image_path)]);
50
-
51
- await Client.connect("gradio/hello_world_main");
52
- const parts = walk_and_store_blobs({
53
- a: {
54
- b: {
55
- data: {
56
- image
57
- }
58
- }
59
- }
60
- });
61
-
62
- assert.isTrue(parts[0].blob instanceof Blob);
63
- });
64
-
65
- test("handle deep structures with arrays", async () => {
66
- const image = new Blob([readFileSync(image_path)]);
67
-
68
- await Client.connect("gradio/hello_world_main");
69
- const parts = walk_and_store_blobs({
70
- a: [
71
- {
72
- b: [
73
- {
74
- data: [
75
- {
76
- image
77
- }
78
- ]
79
- }
80
- ]
81
- }
82
- ]
83
- });
84
-
85
- assert.isTrue(parts[0].blob instanceof Blob);
86
- });
87
-
88
- test("handle deep structures with arrays 2", async () => {
89
- const image = new Blob([readFileSync(image_path)]);
90
-
91
- await Client.connect("gradio/hello_world_main");
92
- const obj = {
93
- a: [
94
- {
95
- b: [
96
- {
97
- data: [[image], image, [image, [image]]]
98
- }
99
- ]
100
- }
101
- ]
102
- };
103
- const parts = walk_and_store_blobs(obj);
104
-
105
- function map_path(
106
- obj: Record<string, any>,
107
- parts: { path: string[]; blob: any }[]
108
- ) {
109
- const { path, blob } = parts[parts.length - 1];
110
- let ref = obj;
111
- path.forEach((p) => (ref = ref[p]));
112
-
113
- return ref === blob;
114
- }
115
-
116
- assert.isTrue(parts[0].blob instanceof Blob);
117
- // assert.isTrue(map_path(obj, parts));
118
- });
119
- });
120
-
121
- describe("handle_blob", () => {
122
- test("handle blobs", async () => {
123
- const image = new Blob([readFileSync(image_path)]);
124
-
125
- const app = await Client.connect("gradio/hello_world_main");
126
- const obj = [
127
- {
128
- a: [
129
- {
130
- b: [
131
- {
132
- data: [[image], image, [image, [image]]]
133
- }
134
- ]
135
- }
136
- ]
137
- }
138
- ];
139
-
140
- const parts = await app.handle_blob(app.config.root, obj, undefined);
141
- //@ts-ignore
142
- // assert.isString(parts.data[0].a[0].b[0].data[0][0]);
143
- });
144
- });
145
-
146
- describe.skip("private space", () => {
147
- test("can access a private space", async () => {
148
- const image = new Blob([readFileSync(image_path)]);
149
-
150
- const app = await Client.connect("pngwn/hello_world", {
151
- hf_token: "hf_"
152
- });
153
-
154
- console.log(app);
155
- const obj = [
156
- {
157
- a: [
158
- {
159
- b: [
160
- {
161
- data: [[image], image, [image, [image]]]
162
- }
163
- ]
164
- }
165
- ]
166
- }
167
- ];
168
-
169
- const parts = await app.handle_blob(app.config.root, obj, undefined);
170
- //@ts-ignore
171
- assert.isString(parts.data[0].a[0].b[0].data[0][0]);
172
- });
173
- });