You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have previously duplicated a Space, re-running `Client.duplicate` will _not_ create a new Space. Instead, the client will attach to the previously-created Space. So it is safe to re-run the `Client.duplicate` method multiple times with the same space.
@@ -202,7 +202,7 @@ const result = await app.predict("/predict", [audio_file]);
202
202
203
203
## Using events
204
204
205
-
If the API you are working with can return results over time, or you wish to access information about the status of a job, you can use the event interface for more flexibility. This is especially useful for iterative endpoints or generator endpoints that will produce a series of values over time as discreet responses.
205
+
If the API you are working with can return results over time, or you wish to access information about the status of a job, you can use the iterable interface for more flexibility. This is especially useful for iterative endpoints or generator endpoints that will produce a series of values over time as discreet responses.
206
206
207
207
```js
208
208
import { Client } from"@gradio/client";
@@ -218,12 +218,27 @@ function log_result(payload) {
218
218
constapp=awaitClient.connect("abidlabs/en2fr");
219
219
constjob=app.submit("/predict", ["Hello"]);
220
220
221
-
job.on("data", log_result);
221
+
forawait (constmessageofjob) {
222
+
log_result(message);
223
+
}
222
224
```
223
225
224
226
## Status
225
227
226
-
The event interface also allows you to get the status of the running job by listening to the `"status"` event. This returns an object with the following attributes: `status` (a human readbale status of the current job, `"pending" | "generating" | "complete" | "error"`), `code` (the detailed gradio code for the job), `position` (the current position of this job in the queue), `queue_size` (the total queue size), `eta` (estimated time this job will complete), `success` (a boolean representing whether the job completed successfully), and `time` ( as `Date` object detailing the time that the status was generated).
228
+
The event interface also allows you to get the status of the running job by instantiating the client with the `events` options passing `status` and `data` as an array:
This ensures that status messages are also reported to the client.
240
+
241
+
`status`es are returned as an object with the following attributes: `status` (a human readbale status of the current job, `"pending" | "generating" | "complete" | "error"`), `code` (the detailed gradio code for the job), `position` (the current position of this job in the queue), `queue_size` (the total queue size), `eta` (estimated time this job will complete), `success` (a boolean representing whether the job completed successfully), and `time` ( as `Date` object detailing the time that the status was generated).
227
242
228
243
```js
229
244
import { Client } from"@gradio/client";
@@ -234,10 +249,16 @@ function log_status(status) {
234
249
);
235
250
}
236
251
237
-
constapp=awaitClient.connect("abidlabs/en2fr");
252
+
constapp=awaitClient.connect("abidlabs/en2fr", {
253
+
events: ["status", "data"]
254
+
});
238
255
constjob=app.submit("/predict", ["Hello"]);
239
256
240
-
job.on("status", log_status);
257
+
forawait (constmessageofjob) {
258
+
if (message.type==="status") {
259
+
log_status(message);
260
+
}
261
+
}
241
262
```
242
263
243
264
## Cancelling Jobs
@@ -259,15 +280,17 @@ If the first job has started processing, then it will not be canceled but the cl
259
280
260
281
## Generator Endpoints
261
282
262
-
Some Gradio API endpoints do not return a single value, rather they return a series of values. You can listen for these values in real time using the event interface:
283
+
Some Gradio API endpoints do not return a single value, rather they return a series of values. You can listen for these values in real time using the iterable interface:
0 commit comments