@gradio/client 0.16.0 → 0.18.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 (84) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +49 -43
  3. package/dist/client.d.ts +63 -70
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/constants.d.ts +23 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/helpers/api_info.d.ts +25 -0
  8. package/dist/helpers/api_info.d.ts.map +1 -0
  9. package/dist/helpers/data.d.ts +8 -0
  10. package/dist/helpers/data.d.ts.map +1 -0
  11. package/dist/{utils.d.ts → helpers/init_helpers.d.ts} +6 -18
  12. package/dist/helpers/init_helpers.d.ts.map +1 -0
  13. package/dist/helpers/spaces.d.ts +7 -0
  14. package/dist/helpers/spaces.d.ts.map +1 -0
  15. package/dist/index.d.ts +8 -4
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1628 -1398
  18. package/dist/test/handlers.d.ts +3 -0
  19. package/dist/test/handlers.d.ts.map +1 -0
  20. package/dist/test/mock_eventsource.d.ts +2 -0
  21. package/dist/test/mock_eventsource.d.ts.map +1 -0
  22. package/dist/test/server.d.ts +2 -0
  23. package/dist/test/server.d.ts.map +1 -0
  24. package/dist/test/test_data.d.ts +76 -0
  25. package/dist/test/test_data.d.ts.map +1 -0
  26. package/dist/types.d.ts +153 -49
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/upload.d.ts +2 -2
  29. package/dist/upload.d.ts.map +1 -1
  30. package/dist/utils/duplicate.d.ts +4 -0
  31. package/dist/utils/duplicate.d.ts.map +1 -0
  32. package/dist/utils/handle_blob.d.ts +4 -0
  33. package/dist/utils/handle_blob.d.ts.map +1 -0
  34. package/dist/utils/post_data.d.ts +4 -0
  35. package/dist/utils/post_data.d.ts.map +1 -0
  36. package/dist/utils/predict.d.ts +4 -0
  37. package/dist/utils/predict.d.ts.map +1 -0
  38. package/dist/utils/stream.d.ts +8 -0
  39. package/dist/utils/stream.d.ts.map +1 -0
  40. package/dist/utils/submit.d.ts +4 -0
  41. package/dist/utils/submit.d.ts.map +1 -0
  42. package/dist/utils/upload_files.d.ts +4 -0
  43. package/dist/utils/upload_files.d.ts.map +1 -0
  44. package/dist/utils/view_api.d.ts +3 -0
  45. package/dist/utils/view_api.d.ts.map +1 -0
  46. package/dist/{wrapper-6f348d45.js → wrapper-CviSselG.js} +259 -17
  47. package/package.json +10 -3
  48. package/src/client.ts +314 -1691
  49. package/src/constants.ts +27 -0
  50. package/src/globals.d.ts +2 -21
  51. package/src/helpers/api_info.ts +300 -0
  52. package/src/helpers/data.ts +133 -0
  53. package/src/helpers/init_helpers.ts +130 -0
  54. package/src/helpers/spaces.ts +197 -0
  55. package/src/index.ts +16 -10
  56. package/src/test/api_info.test.ts +456 -0
  57. package/src/test/data.test.ts +281 -0
  58. package/src/test/handlers.ts +438 -0
  59. package/src/test/init.test.ts +139 -0
  60. package/src/test/init_helpers.test.ts +94 -0
  61. package/src/test/mock_eventsource.ts +11 -0
  62. package/src/test/post_data.test.ts +45 -0
  63. package/src/test/server.ts +6 -0
  64. package/src/test/spaces.test.ts +145 -0
  65. package/src/test/stream.test.ts +67 -0
  66. package/src/test/test_data.ts +557 -0
  67. package/src/test/upload_files.test.ts +42 -0
  68. package/src/test/view_api.test.ts +53 -0
  69. package/src/types.ts +201 -59
  70. package/src/upload.ts +19 -15
  71. package/src/utils/duplicate.ts +104 -0
  72. package/src/utils/handle_blob.ts +47 -0
  73. package/src/utils/post_data.ts +37 -0
  74. package/src/utils/predict.ts +56 -0
  75. package/src/utils/stream.ts +175 -0
  76. package/src/utils/submit.ts +697 -0
  77. package/src/utils/upload_files.ts +51 -0
  78. package/src/utils/view_api.ts +67 -0
  79. package/src/vite-env.d.ts +1 -0
  80. package/tsconfig.json +15 -2
  81. package/vite.config.js +11 -17
  82. package/dist/utils.d.ts.map +0 -1
  83. package/src/client.node-test.ts +0 -172
  84. package/src/utils.ts +0 -314
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # @gradio/client
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Features
6
+
7
+ - [#8121](https://github.com/gradio-app/gradio/pull/8121) [`f5b710c`](https://github.com/gradio-app/gradio/commit/f5b710c919b0ce604ea955f0d5f4faa91095ca4a) - chore(deps): update dependency eslint to v9. Thanks @renovate!
8
+ - [#8209](https://github.com/gradio-app/gradio/pull/8209) [`b9afe93`](https://github.com/gradio-app/gradio/commit/b9afe93915401df5bd6737c89395c2477acfa585) - Rename `eventSource_Factory` and `fetch_implementation`. Thanks @hannahblair!
9
+ - [#8109](https://github.com/gradio-app/gradio/pull/8109) [`bed2f82`](https://github.com/gradio-app/gradio/commit/bed2f82e2297b50f7b59423a3de05af0b9910724) - Implement JS Client tests. Thanks @hannahblair!
10
+ - [#8211](https://github.com/gradio-app/gradio/pull/8211) [`91b5cd6`](https://github.com/gradio-app/gradio/commit/91b5cd6132fb8903c92f70fce0800324836a1fc3) - remove redundant event source logic. Thanks @hannahblair!
11
+
12
+ ### Fixes
13
+
14
+ - [#8179](https://github.com/gradio-app/gradio/pull/8179) [`6a218b4`](https://github.com/gradio-app/gradio/commit/6a218b4148095aaa0c58d8c20973ba01c8764fc2) - rework upload to be a class method + pass client into each component. Thanks @pngwn!
15
+ - [#8181](https://github.com/gradio-app/gradio/pull/8181) [`cf52ca6`](https://github.com/gradio-app/gradio/commit/cf52ca6a51320ece97f009a177792840b5fbc785) - Ensure connectivity to private HF spaces with SSE protocol. Thanks @hannahblair!
16
+ - [#8169](https://github.com/gradio-app/gradio/pull/8169) [`3a6f1a5`](https://github.com/gradio-app/gradio/commit/3a6f1a50b263e0a733f609a08019fc4d05480e1a) - Only connect to heartbeat if needed. Thanks @freddyaboulton!
17
+ - [#8118](https://github.com/gradio-app/gradio/pull/8118) [`7aca673`](https://github.com/gradio-app/gradio/commit/7aca673b38a087533524b2fd8dd3a03e0e4bacfe) - Add eventsource polyfill for Node.js and browser environments. Thanks @hannahblair!
18
+
19
+ ## 0.17.0
20
+
21
+ ### Highlights
22
+
23
+ #### Setting File Upload Limits ([#7909](https://github.com/gradio-app/gradio/pull/7909) [`2afca65`](https://github.com/gradio-app/gradio/commit/2afca6541912b37dc84f447c7ad4af21607d7c72))
24
+
25
+ We have added a `max_file_size` size parameter to `launch()` that limits to size of files uploaded to the server. This limit applies to each individual file. This parameter can be specified as a string or an integer (corresponding to the size in bytes).
26
+
27
+ The following code snippet sets a max file size of 5 megabytes.
28
+
29
+ ```python
30
+ import gradio as gr
31
+
32
+ demo = gr.Interface(lambda x: x, "image", "image")
33
+
34
+ demo.launch(max_file_size="5mb")
35
+ # or
36
+ demo.launch(max_file_size=5 * gr.FileSize.MB)
37
+ ```
38
+
39
+ ![max_file_size_upload](https://github.com/gradio-app/gradio/assets/41651716/7547330c-a082-4901-a291-3f150a197e45)
40
+
41
+
42
+ #### Error states can now be cleared
43
+
44
+ When a component encounters an error, the error state shown in the UI can now be cleared by clicking on the `x` icon in the top right of the component. This applies to all types of errors, whether it's raised in the UI or the server.
45
+
46
+ ![error_modal_calculator](https://github.com/gradio-app/gradio/assets/41651716/16cb071c-accd-45a6-9c18-0dea27d4bd98)
47
+
48
+ Thanks @freddyaboulton!
49
+
50
+ ### Features
51
+
52
+ - [#8056](https://github.com/gradio-app/gradio/pull/8056) [`2e469a5`](https://github.com/gradio-app/gradio/commit/2e469a5f99e52a5011a010f46e47dde7bb0c7140) - Using keys to preserve values between reloads. Thanks @aliabid94!
53
+ - [#7646](https://github.com/gradio-app/gradio/pull/7646) [`450b8cc`](https://github.com/gradio-app/gradio/commit/450b8cc898f130f15caa3742f65c17b9f7a8f398) - Refactor JS Client. Thanks @hannahblair!
54
+ - [#8061](https://github.com/gradio-app/gradio/pull/8061) [`17e83c9`](https://github.com/gradio-app/gradio/commit/17e83c958ebb35b3e122ca486067d1bd5ce33a22) - Docs Reorg and Intro Page. Thanks @aliabd!
55
+
56
+ ### Fixes
57
+
58
+ - [#8066](https://github.com/gradio-app/gradio/pull/8066) [`624f9b9`](https://github.com/gradio-app/gradio/commit/624f9b9477f74a581a6c14119234f9efdfcda398) - make gradio dev tools a local dependency rather than bundling. Thanks @pngwn!
59
+
3
60
  ## 0.16.0
4
61
 
5
62
  ### Features
package/README.md CHANGED
@@ -1,29 +1,29 @@
1
1
  ## JavaScript Client Library
2
2
 
3
- A javascript (and typescript) client to call Gradio APIs.
3
+ A JavaScript (and TypeScript) Client to call Gradio APIs.
4
4
 
5
5
  ## Installation
6
6
 
7
- The Gradio JavaScript client is available on npm as `@gradio/client`. You can install it as below:
7
+ The Gradio JavaScript Client is available on npm as `@gradio/client`. You can install it as below:
8
8
 
9
- ```sh
9
+ ```shell
10
10
  npm i @gradio/client
11
11
  ```
12
12
 
13
13
  ## Usage
14
14
 
15
- The JavaScript Gradio Client exposes two named imports, `client` and `duplicate`.
15
+ The JavaScript Gradio Client exposes the Client class, `Client`, along with various other utility functions. `Client` is used to initialise and establish a connection to, or duplicate, a Gradio app.
16
16
 
17
- ### `client`
17
+ ### `Client`
18
18
 
19
- The client function connects to the API of a hosted Gradio space and returns an object that allows you to make calls to that API.
19
+ The Client function connects to the API of a hosted Gradio space and returns an object that allows you to make calls to that API.
20
20
 
21
21
  The simplest example looks like this:
22
22
 
23
23
  ```ts
24
- import { client } from "@gradio/client";
24
+ import { Client } from "@gradio/client";
25
25
 
26
- const app = await client("user/space-name");
26
+ const app = await Client.connect("user/space-name");
27
27
  const result = await app.predict("/predict");
28
28
  ```
29
29
 
@@ -34,7 +34,7 @@ This function accepts two arguments: `source` and `options`:
34
34
  This is the url or name of the gradio app whose API you wish to connect to. This parameter is required and should always be a string. For example:
35
35
 
36
36
  ```ts
37
- client("user/space-name");
37
+ Client.connect("user/space-name");
38
38
  ```
39
39
 
40
40
  #### `options`
@@ -48,23 +48,23 @@ This should be a Hugging Face personal access token and is required if you wish
48
48
  Example:
49
49
 
50
50
  ```ts
51
- import { client } from "@gradio/client";
51
+ import { Client } from "@gradio/client";
52
52
 
53
- const app = await client("user/space-name", { hf_token: "hf_..." });
53
+ const app = await Client.connect("user/space-name", { hf_token: "hf_..." });
54
54
  ```
55
55
 
56
56
  ##### `status_callback`
57
57
 
58
- This should be a function which will notify your of the status of a space if it is not running. If the gradio API you are connecting to is awake and running or is not hosted on Hugging Face space then this function will do nothing.
58
+ This should be a function which will notify you of the status of a space if it is not running. If the gradio API you are connecting to is not awake and running or is not hosted on Hugging Face space then this function will do nothing.
59
59
 
60
60
  **Additional context**
61
61
 
62
62
  Applications hosted on Hugging Face spaces can be in a number of different states. As spaces are a GitOps tool and will rebuild when new changes are pushed to the repository, they have various building, running and error states. If a space is not 'running' then the function passed as the `status_callback` will notify you of the current state of the space and the status of the space as it changes. Spaces that are building or sleeping can take longer than usual to respond, so you can use this information to give users feedback about the progress of their action.
63
63
 
64
64
  ```ts
65
- import { client, type SpaceStatus } from "@gradio/client";
65
+ import { Client, type SpaceStatus } from "@gradio/client";
66
66
 
67
- const app = await client("user/space-name", {
67
+ const app = await Client.connect("user/space-name", {
68
68
  // The space_status parameter does not need to be manually annotated, this is just for illustration.
69
69
  space_status: (space_status: SpaceStatus) => console.log(space_status)
70
70
  });
@@ -100,9 +100,9 @@ The gradio client returns an object with a number of methods and properties:
100
100
  The `predict` method allows you to call an api endpoint and get a prediction result:
101
101
 
102
102
  ```ts
103
- import { client } from "@gradio/client";
103
+ import { Client } from "@gradio/client";
104
104
 
105
- const app = await client("user/space-name");
105
+ const app = await Client.connect("user/space-name");
106
106
  const result = await app.predict("/predict");
107
107
  ```
108
108
 
@@ -113,20 +113,20 @@ const result = await app.predict("/predict");
113
113
  This is the endpoint for an api request and is required. The default endpoint for a `gradio.Interface` is `"/predict"`. Explicitly named endpoints have a custom name. The endpoint names can be found on the "View API" page of a space.
114
114
 
115
115
  ```ts
116
- import { client } from "@gradio/client";
116
+ import { Client } from "@gradio/client";
117
117
 
118
- const app = await client("user/space-name");
118
+ const app = await Client.connect("user/space-name");
119
119
  const result = await app.predict("/predict");
120
120
  ```
121
121
 
122
122
  ##### `payload`
123
123
 
124
- The `payload` argument is generally optional but this depends on the API itself. If the API endpoint depends on values being passed in then it is required for the API request to succeed. The data that should be passed in is detailed on the "View API" page of a space, or accessible via the `view_api()` method of the client.
124
+ The `payload` argument is generally required but this depends on the API itself. If the API endpoint depends on values being passed in then the argument is required for the API request to succeed. The data that should be passed in is detailed on the "View API" page of a space, or accessible via the `view_api()` method of the client.
125
125
 
126
126
  ```ts
127
- import { client } from "@gradio/client";
127
+ import { Client } from "@gradio/client";
128
128
 
129
- const app = await client("user/space-name");
129
+ const app = await Client.connect("user/space-name");
130
130
  const result = await app.predict("/predict", [1, "Hello", "friends"]);
131
131
  ```
132
132
 
@@ -135,9 +135,9 @@ const result = await app.predict("/predict", [1, "Hello", "friends"]);
135
135
  The `submit` method provides a more flexible way to call an API endpoint, providing you with status updates about the current progress of the prediction as well as supporting more complex endpoint types.
136
136
 
137
137
  ```ts
138
- import { client } from "@gradio/client";
138
+ import { Client } from "@gradio/client";
139
139
 
140
- const app = await client("user/space-name");
140
+ const app = await Client.connect("user/space-name");
141
141
  const submission = app.submit("/predict", payload);
142
142
  ```
143
143
 
@@ -179,9 +179,9 @@ interface Status {
179
179
  Usage of these subscribe callback looks like this:
180
180
 
181
181
  ```ts
182
- import { client } from "@gradio/client";
182
+ import { Client } from "@gradio/client";
183
183
 
184
- const app = await client("user/space-name");
184
+ const app = await Client.connect("user/space-name");
185
185
  const submission = app
186
186
  .submit("/predict", payload)
187
187
  .on("data", (data) => console.log(data))
@@ -193,9 +193,9 @@ const submission = app
193
193
  The `off` method unsubscribes from a specific event of the submitted job and works similarly to `document.removeEventListener`; both the event name and the original callback must be passed in to successfully unsubscribe:
194
194
 
195
195
  ```ts
196
- import { client } from "@gradio/client";
196
+ import { Client } from "@gradio/client";
197
197
 
198
- const app = await client("user/space-name");
198
+ const app = await Client.connect("user/space-name");
199
199
  const handle_data = (data) => console.log(data);
200
200
 
201
201
  const submission = app.submit("/predict", payload).on("data", handle_data);
@@ -209,9 +209,9 @@ submission.off("/predict", handle_data);
209
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
- import { client } from "@gradio/client";
212
+ import { Client } from "@gradio/client";
213
213
 
214
- const app = await client("user/space-name");
214
+ const app = await Client.connect("user/space-name");
215
215
  const handle_data = (data) => console.log(data);
216
216
 
217
217
  const submission = app.submit("/predict", payload).on("data", handle_data);
@@ -225,9 +225,9 @@ submission.destroy();
225
225
  Certain types of gradio function can run repeatedly and in some cases indefinitely. the `cancel` method will stop such an endpoints and prevent the API from issuing additional updates.
226
226
 
227
227
  ```ts
228
- import { client } from "@gradio/client";
228
+ import { Client } from "@gradio/client";
229
229
 
230
- const app = await client("user/space-name");
230
+ const app = await Client.connect("user/space-name");
231
231
  const submission = app
232
232
  .submit("/predict", payload)
233
233
  .on("data", (data) => console.log(data));
@@ -242,9 +242,9 @@ submission.cancel();
242
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
- import { client } from "@gradio/client";
245
+ import { Client } from "@gradio/client";
246
246
 
247
- const app = await client("user/space-name");
247
+ const app = await Client.connect("user/space-name");
248
248
  const api_info = await app.view_api();
249
249
 
250
250
  console.log(api_info);
@@ -255,9 +255,9 @@ console.log(api_info);
255
255
  The `config` property contains the configuration for the gradio application you are connected to. This object may contain useful meta information about the application.
256
256
 
257
257
  ```ts
258
- import { client } from "@gradio/client";
258
+ import { Client } from "@gradio/client";
259
259
 
260
- const app = await client("user/space-name");
260
+ const app = await Client.connect("user/space-name");
261
261
  console.log(app.config);
262
262
  ```
263
263
 
@@ -268,9 +268,9 @@ The duplicate function will attempt to duplicate the space that is referenced an
268
268
  `duplicate` accepts the same arguments as `client` with the addition of a `private` options property dictating whether the duplicated space should be private or public. A huggingface token is required for duplication to work.
269
269
 
270
270
  ```ts
271
- import { duplicate } from "@gradio/client";
271
+ import { Client } from "@gradio/client";
272
272
 
273
- const app = await duplicate("user/space-name", {
273
+ const app = await Client.duplicate("user/space-name", {
274
274
  hf_token: "hf_..."
275
275
  });
276
276
  ```
@@ -292,9 +292,9 @@ Accepts all options that `client` accepts, except `hf_token` is required. [See `
292
292
  This is an optional property specific to `duplicate`'s options object and will determine whether the space should be public or private. Spaces duplicated via the `duplicate` method are public by default.
293
293
 
294
294
  ```ts
295
- import { duplicate } from "@gradio/client";
295
+ import { Client } from "@gradio/client";
296
296
 
297
- const app = await duplicate("user/space-name", {
297
+ const app = await Client.duplicate("user/space-name", {
298
298
  hf_token: "hf_...",
299
299
  private: true
300
300
  });
@@ -305,9 +305,9 @@ const app = await duplicate("user/space-name", {
305
305
  This is an optional property specific to `duplicate`'s options object and will set the timeout in minutes before the duplicated space will go to sleep.
306
306
 
307
307
  ```ts
308
- import { duplicate } from "@gradio/client";
308
+ import { Client } from "@gradio/client";
309
309
 
310
- const app = await duplicate("user/space-name", {
310
+ const app = await Client.duplicate("user/space-name", {
311
311
  hf_token: "hf_...",
312
312
  private: true,
313
313
  timeout: 5
@@ -322,16 +322,22 @@ Possible hardware options are:
322
322
 
323
323
  - `"cpu-basic"`
324
324
  - `"cpu-upgrade"`
325
+ - `"cpu-xl"`
325
326
  - `"t4-small"`
326
327
  - `"t4-medium"`
327
328
  - `"a10g-small"`
328
329
  - `"a10g-large"`
330
+ - `"a10g-largex2"`
331
+ - `"a10g-largex4"`
329
332
  - `"a100-large"`
333
+ - `"zero-a10g"`
334
+ - `"h100"`
335
+ - `"h100x8"`
330
336
 
331
337
  ```ts
332
- import { duplicate } from "@gradio/client";
338
+ import { Client } from "@gradio/client";
333
339
 
334
- const app = await duplicate("user/space-name", {
340
+ const app = await Client.duplicate("user/space-name", {
335
341
  hf_token: "hf_...",
336
342
  private: true,
337
343
  hardware: "a10g-small"
package/dist/client.d.ts CHANGED
@@ -1,74 +1,67 @@
1
- import { hardware_types } from "./utils.js";
2
- import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatusCallback } from "./types.js";
3
- import type { Config } from "./types.js";
4
- type event = <K extends EventType>(eventType: K, listener: EventListener<K>) => SubmitReturn;
5
- type predict = (endpoint: string | number, data?: unknown[], event_data?: unknown) => Promise<unknown>;
6
- export type client_return = {
7
- predict: predict;
8
- config: Config;
9
- submit: (endpoint: string | number, data?: unknown[], event_data?: unknown, trigger_id?: number | null) => SubmitReturn;
10
- component_server: (component_id: number, fn_name: string, data: unknown[]) => any;
11
- view_api: (c?: Config) => Promise<ApiInfo<JsApiData>>;
12
- };
13
- type SubmitReturn = {
14
- on: event;
15
- off: event;
16
- cancel: () => Promise<void>;
17
- destroy: () => void;
18
- };
19
- export declare let NodeBlob: any;
20
- export declare function duplicate(app_reference: string, options: {
21
- hf_token: `hf_${string}`;
22
- private?: boolean;
23
- status_callback: SpaceStatusCallback;
24
- hardware?: (typeof hardware_types)[number];
25
- timeout?: number;
26
- }): Promise<client_return>;
27
- interface Client {
28
- post_data: (url: string, body: unknown, token?: `hf_${string}`) => Promise<[PostResponse, number]>;
29
- upload_files: (root: string, files: File[], token?: `hf_${string}`, upload_id?: string) => Promise<UploadResponse>;
30
- client: (app_reference: string, options: {
31
- hf_token?: `hf_${string}`;
32
- status_callback?: SpaceStatusCallback;
33
- }) => Promise<client_return>;
34
- handle_blob: (endpoint: string, data: unknown[], api_info: ApiInfo<JsApiData>, token?: `hf_${string}`) => Promise<unknown[]>;
1
+ import type { ApiData, ApiInfo, ClientOptions, Config, DuplicateOptions, EndpointInfo, JsApiData, SpaceStatus, Status, SubmitReturn, UploadResponse } from "./types";
2
+ import { FileData } from "./upload";
3
+ export declare class NodeBlob extends Blob {
4
+ constructor(blobParts?: BlobPart[], options?: BlobPropertyBag);
35
5
  }
36
- export declare function api_factory(fetch_implementation: typeof fetch, EventSource_factory: (url: URL) => EventSource): Client;
37
- export declare const post_data: (url: string, body: unknown, token?: `hf_${string}`) => Promise<[PostResponse, number]>, upload_files: (root: string, files: File[], token?: `hf_${string}`, upload_id?: string) => Promise<UploadResponse>, client: (app_reference: string, options: {
38
- hf_token?: `hf_${string}`;
39
- status_callback?: SpaceStatusCallback;
40
- }) => Promise<client_return>, handle_blob: (endpoint: string, data: unknown[], api_info: ApiInfo<JsApiData>, token?: `hf_${string}`) => Promise<unknown[]>;
41
- interface ApiData {
42
- label: string;
43
- type: {
44
- type: any;
45
- description: string;
6
+ export declare class Client {
7
+ app_reference: string;
8
+ options: ClientOptions;
9
+ config: Config | undefined;
10
+ api_info: ApiInfo<JsApiData> | undefined;
11
+ api_map: Record<string, number>;
12
+ session_hash: string;
13
+ jwt: string | false;
14
+ last_status: Record<string, Status["stage"]>;
15
+ stream_status: {
16
+ open: boolean;
46
17
  };
47
- component: string;
48
- example_input?: any;
18
+ pending_stream_messages: Record<string, any[][]>;
19
+ pending_diff_streams: Record<string, any[][]>;
20
+ event_callbacks: Record<string, (data?: unknown) => Promise<void>>;
21
+ unclosed_events: Set<string>;
22
+ heartbeat_event: EventSource | null;
23
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
24
+ stream_factory(url: URL): EventSource | null;
25
+ view_api: () => Promise<ApiInfo<JsApiData>>;
26
+ upload_files: (root_url: string, files: (Blob | File)[], upload_id?: string) => Promise<UploadResponse>;
27
+ upload: (file_data: FileData[], root_url: string, upload_id?: string, max_file_size?: number) => Promise<(FileData | null)[] | null>;
28
+ handle_blob: (endpoint: string, data: unknown[], endpoint_info: EndpointInfo<ApiData | JsApiData>) => Promise<unknown[]>;
29
+ post_data: (url: string, body: unknown, additional_headers?: any) => Promise<unknown[]>;
30
+ submit: (endpoint: string | number, data: unknown[], event_data?: unknown, trigger_id?: number | null) => SubmitReturn;
31
+ predict: (endpoint: string | number, data?: unknown[], event_data?: unknown) => Promise<unknown>;
32
+ open_stream: () => void;
33
+ private resolve_config;
34
+ constructor(app_reference: string, options?: ClientOptions);
35
+ private init;
36
+ static connect(app_reference: string, options?: ClientOptions): Promise<Client>;
37
+ close(): void;
38
+ static duplicate(app_reference: string, options?: DuplicateOptions): Promise<Client>;
39
+ private _resolve_config;
40
+ private config_success;
41
+ handle_space_success(status: SpaceStatus): Promise<Config | void>;
42
+ component_server(component_id: number, fn_name: string, data: unknown[] | {
43
+ binary: boolean;
44
+ data: Record<string, any>;
45
+ }): Promise<unknown>;
46
+ private prepare_return_obj;
49
47
  }
50
- interface JsApiData {
51
- label: string;
52
- type: string;
53
- component: string;
54
- example_input: any;
55
- }
56
- interface EndpointInfo<T extends ApiData | JsApiData> {
57
- parameters: T[];
58
- returns: T[];
59
- }
60
- interface ApiInfo<T extends ApiData | JsApiData> {
61
- named_endpoints: {
62
- [key: string]: EndpointInfo<T>;
63
- };
64
- unnamed_endpoints: {
65
- [key: string]: EndpointInfo<T>;
66
- };
67
- }
68
- export declare function walk_and_store_blobs(param: any, type?: any, path?: any[], root?: boolean, api_info?: any): Promise<{
69
- path: string[];
70
- type: string;
71
- blob: Blob | false;
72
- }[]>;
73
- export {};
48
+ /**
49
+ * @deprecated This method will be removed in v1.0. Use `Client.connect()` instead.
50
+ * Creates a client instance for interacting with Gradio apps.
51
+ *
52
+ * @param {string} app_reference - The reference or URL to a Gradio space or app.
53
+ * @param {ClientOptions} options - Configuration options for the client.
54
+ * @returns {Promise<Client>} A promise that resolves to a `Client` instance.
55
+ */
56
+ export declare function client(app_reference: string, options?: ClientOptions): Promise<Client>;
57
+ /**
58
+ * @deprecated This method will be removed in v1.0. Use `Client.duplicate()` instead.
59
+ * Creates a duplicate of a space and returns a client instance for the duplicated space.
60
+ *
61
+ * @param {string} app_reference - The reference or URL to a Gradio space or app to duplicate.
62
+ * @param {DuplicateOptions} options - Configuration options for the client.
63
+ * @returns {Promise<Client>} A promise that resolves to a `Client` instance.
64
+ */
65
+ export declare function duplicate_space(app_reference: string, options: DuplicateOptions): Promise<Client>;
66
+ export type ClientInstance = Client;
74
67
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAQN,cAAc,EAId,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EAIb,YAAY,EACZ,cAAc,EAGd,mBAAmB,EACnB,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,KAAK,KAAK,GAAG,CAAC,CAAC,SAAS,SAAS,EAChC,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,KACtB,YAAY,CAAC;AAClB,KAAK,OAAO,GAAG,CACd,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,CAAC,EAAE,OAAO,EAAE,EAChB,UAAU,CAAC,EAAE,OAAO,KAChB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CACP,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,CAAC,EAAE,OAAO,EAAE,EAChB,UAAU,CAAC,EAAE,OAAO,EACpB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,KACtB,YAAY,CAAC;IAClB,gBAAgB,EAAE,CACjB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,EAAE,KACX,GAAG,CAAC;IACT,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,KAAK,YAAY,GAAG;IACnB,EAAE,EAAE,KAAK,CAAC;IACV,GAAG,EAAE,KAAK,CAAC;IACX,MAAM,EAAE,MAA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a,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC"}
@@ -0,0 +1,23 @@
1
+ export declare const HOST_URL = "host";
2
+ export declare const API_URL = "api/predict/";
3
+ export declare const SSE_URL_V0 = "queue/join";
4
+ export declare const SSE_DATA_URL_V0 = "queue/data";
5
+ export declare const SSE_URL = "queue/data";
6
+ export declare const SSE_DATA_URL = "queue/join";
7
+ export declare const UPLOAD_URL = "upload";
8
+ export declare const LOGIN_URL = "login";
9
+ export declare const CONFIG_URL = "config";
10
+ export declare const API_INFO_URL = "info";
11
+ export declare const RUNTIME_URL = "runtime";
12
+ export declare const SLEEPTIME_URL = "sleeptime";
13
+ export declare const RAW_API_INFO_URL = "info?serialize=False";
14
+ export declare const SPACE_FETCHER_URL = "https://gradio-space-api-fetcher-v2.hf.space/api";
15
+ export declare const RESET_URL = "reset";
16
+ export declare const SPACE_URL = "https://hf.space/{}";
17
+ export declare const QUEUE_FULL_MSG = "This application is currently busy. Please try again. ";
18
+ export declare const BROKEN_CONNECTION_MSG = "Connection errored out. ";
19
+ export declare const CONFIG_ERROR_MSG = "Could not resolve app config. ";
20
+ export declare const SPACE_STATUS_ERROR_MSG = "Could not get space status. ";
21
+ export declare const API_INFO_ERROR_MSG = "Could not get API info. ";
22
+ export declare const SPACE_METADATA_ERROR_MSG = "Space metadata could not be loaded. ";
23
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,QAAQ,SAAS,CAAC;AAC/B,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,YAAY,eAAe,CAAC;AACzC,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,YAAY,SAAS,CAAC;AACnC,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,iBAAiB,qDACqB,CAAC;AACpD,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,SAAS,wBAAwB,CAAC;AAG/C,eAAO,MAAM,cAAc,2DAC8B,CAAC;AAC1D,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAChE,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AACjE,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AACrE,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,wBAAwB,yCAAyC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Status } from "../types";
2
+ import type { ApiData, ApiInfo, Config, JsApiData } from "../types";
3
+ export declare const RE_SPACE_NAME: RegExp;
4
+ export declare const RE_SPACE_DOMAIN: RegExp;
5
+ export declare function process_endpoint(app_reference: string, hf_token?: `hf_${string}`): Promise<{
6
+ space_id: string | false;
7
+ host: string;
8
+ ws_protocol: "ws" | "wss";
9
+ http_protocol: "http:" | "https:";
10
+ }>;
11
+ export declare function transform_api_info(api_info: ApiInfo<ApiData>, config: Config, api_map: Record<string, number>): ApiInfo<JsApiData>;
12
+ export declare function get_type(type: {
13
+ type: any;
14
+ description: string;
15
+ }, component: string, serializer: string, signature_type: "return" | "parameter"): string | undefined;
16
+ export declare function get_description(type: {
17
+ type: any;
18
+ description: string;
19
+ }, serializer: string): string;
20
+ export declare function handle_message(data: any, last_status: Status["stage"]): {
21
+ type: "hash" | "data" | "update" | "complete" | "generating" | "log" | "none" | "heartbeat" | "unexpected_error";
22
+ data?: any;
23
+ status?: Status;
24
+ };
25
+ //# sourceMappingURL=api_info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api_info.d.ts","sourceRoot":"","sources":["../../src/helpers/api_info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGpE,eAAO,MAAM,aAAa,QAAqB,CAAC;AAChD,eAAO,MAAM,eAAe,QAAwB,CAAC;AAErD,wBAAsB,gBAAgB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,MAAM,MAAM,EAAE,GACvB,OAAO,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,IAAI,GAAG,KAAK,CAAC;IAC1B,aAAa,EAAE,OAAO,GAAG,QAAQ,CAAC;CAClC,CAAC,CA4CD;AAED,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,OAAO,CAAC,SAAS,CAAC,CAiDpB;AAED,wBAAgB,QAAQ,CACvB,IAAI,EAAE;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACxC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,QAAQ,GAAG,WAAW,GACpC,MAAM,GAAG,SAAS,CAiCpB;AAED,wBAAgB,eAAe,CAC9B,IAAI,EAAE;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACxC,UAAU,EAAE,MAAM,GAChB,MAAM,CASR;AAED,wBAAgB,cAAc,CAC7B,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,GAC1B;IACF,IAAI,EACD,MAAM,GACN,MAAM,GACN,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,KAAK,GACL,MAAM,GACN,WAAW,GACX,kBAAkB,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAgHA"}
@@ -0,0 +1,8 @@
1
+ import type { ApiData, BlobRef, Config, EndpointInfo, JsApiData, DataType } from "../types";
2
+ export declare function update_object(object: {
3
+ [x: string]: any;
4
+ }, newValue: any, stack: (string | number)[]): void;
5
+ export declare function walk_and_store_blobs(data: DataType, type?: string | undefined, path?: string[], root?: boolean, endpoint_info?: EndpointInfo<ApiData | JsApiData> | undefined): Promise<BlobRef[]>;
6
+ export declare function skip_queue(id: number, config: Config): boolean;
7
+ export declare function post_message<Res = any>(message: any, origin: string): Promise<Res>;
8
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/helpers/data.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,OAAO,EACP,OAAO,EACP,MAAM,EACN,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,MAAM,UAAU,CAAC;AAElB,wBAAgB,aAAa,CAC5B,MAAM,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC5B,QAAQ,EAAE,GAAG,EACb,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GACxB,IAAI,CAgBN;AAED,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,QAAQ,EACd,IAAI,GAAE,MAAM,GAAG,SAAqB,EACpC,IAAI,GAAE,MAAM,EAAO,EACnB,IAAI,UAAQ,EACZ,aAAa,GAAE,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,SAAqB,GACtE,OAAO,CAAC,OAAO,EAAE,CAAC,CAuEpB;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAK9D;AAID,wBAAgB,YAAY,CAAC,GAAG,GAAG,GAAG,EACrC,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,GAAG,CAAC,CASd"}
@@ -1,4 +1,5 @@
1
- import type { Config } from "./types.js";
1
+ import type { Config } from "../types";
2
+ import { Client } from "..";
2
3
  /**
3
4
  * This function is used to resolve the URL for making requests when the app has a root path.
4
5
  * The root path could be a path suffix like "/app" which is appended to the end of the base URL. Or
@@ -10,25 +11,12 @@ import type { Config } from "./types.js";
10
11
  * @returns {string} the resolved URL
11
12
  */
12
13
  export declare function resolve_root(base_url: string, root_path: string, prioritize_base: boolean): string;
14
+ export declare function get_jwt(space: string, token: `hf_${string}`): Promise<string | false>;
15
+ export declare function map_names_to_ids(fns: Config["dependencies"]): Record<string, number>;
16
+ export declare function resolve_config(this: Client, endpoint: string): Promise<Config | undefined>;
13
17
  export declare function determine_protocol(endpoint: string): {
14
18
  ws_protocol: "ws" | "wss";
15
19
  http_protocol: "http:" | "https:";
16
20
  host: string;
17
21
  };
18
- export declare const RE_SPACE_NAME: RegExp;
19
- export declare const RE_SPACE_DOMAIN: RegExp;
20
- export declare function process_endpoint(app_reference: string, token?: `hf_${string}`): Promise<{
21
- space_id: string | false;
22
- host: string;
23
- ws_protocol: "ws" | "wss";
24
- http_protocol: "http:" | "https:";
25
- }>;
26
- export declare function map_names_to_ids(fns: Config["dependencies"]): Record<string, number>;
27
- export declare function discussions_enabled(space_id: string): Promise<boolean>;
28
- export declare function get_space_hardware(space_id: string, token: `hf_${string}`): Promise<(typeof hardware_types)[number]>;
29
- export declare function set_space_hardware(space_id: string, new_hardware: (typeof hardware_types)[number], token: `hf_${string}`): Promise<(typeof hardware_types)[number]>;
30
- export declare function set_space_timeout(space_id: string, timeout: number, token: `hf_${string}`): Promise<number>;
31
- export declare const hardware_types: readonly ["cpu-basic", "cpu-upgrade", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a100-large"];
32
- export declare function apply_diff(obj: any, diff: [string, (number | string)[], any][]): any;
33
- export declare function post_message<Res = any>(message: any, origin: string): Promise<Res>;
34
- //# sourceMappingURL=utils.d.ts.map
22
+ //# sourceMappingURL=init_helpers.d.ts.map
@@ -0,0 +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;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B;;;;;;;;;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,GACnB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAczB;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,CAiC7B;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,CAgCA"}
@@ -0,0 +1,7 @@
1
+ import type { SpaceStatusCallback } from "../types";
2
+ export declare function check_space_status(id: string, type: "subdomain" | "space_name", status_callback: SpaceStatusCallback): Promise<void>;
3
+ export declare function discussions_enabled(space_id: string): Promise<boolean>;
4
+ export declare function get_space_hardware(space_id: string, hf_token?: `hf_${string}` | undefined): Promise<(typeof hardware_types)[number]>;
5
+ export declare function set_space_timeout(space_id: string, timeout: number, hf_token?: `hf_${string}`): Promise<any>;
6
+ export declare const hardware_types: readonly ["cpu-basic", "cpu-upgrade", "cpu-xl", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a10g-largex2", "a10g-largex4", "a100-large", "zero-a10g", "h100", "h100x8"];
7
+ //# sourceMappingURL=spaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaces.d.ts","sourceRoot":"","sources":["../../src/helpers/spaces.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,WAAW,GAAG,YAAY,EAChC,eAAe,EAAE,mBAAmB,GAClC,OAAO,CAAC,IAAI,CAAC,CAqFf;AAID,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAe5E;AAED,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,MAAM,EAAE,GAAG,SAAS,GACnC,OAAO,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAqB1C;AAED,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,MAAM,EAAE,GACvB,OAAO,CAAC,GAAG,CAAC,CAiCd;AAED,eAAO,MAAM,cAAc,mLAcjB,CAAC"}