@gradio/client 0.13.0 → 0.15.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 +51 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/package.json +1 -1
- package/src/client.ts +20 -5
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,56 @@
|
|
1
1
|
# @gradio/client
|
2
2
|
|
3
|
+
## 0.15.0
|
4
|
+
|
5
|
+
### Highlights
|
6
|
+
|
7
|
+
#### Automatically delete state after user has disconnected from the webpage ([#7829](https://github.com/gradio-app/gradio/pull/7829) [`6a4bf7a`](https://github.com/gradio-app/gradio/commit/6a4bf7abe29059dbdc6a342e0366fdaa2e4120ee))
|
8
|
+
|
9
|
+
Gradio now automatically deletes `gr.State` variables stored in the server's RAM when users close their browser tab.
|
10
|
+
The deletion will happen 60 minutes after the server detected a disconnect from the user's browser.
|
11
|
+
If the user connects again in that timeframe, their state will not be deleted.
|
12
|
+
|
13
|
+
Additionally, Gradio now includes a `Blocks.unload()` event, allowing you to run arbitrary cleanup functions when users disconnect (this does not have a 60 minute delay).
|
14
|
+
You can think of the `unload` event as the opposite of the `load` event.
|
15
|
+
|
16
|
+
|
17
|
+
```python
|
18
|
+
with gr.Blocks() as demo:
|
19
|
+
gr.Markdown(
|
20
|
+
"""# State Cleanup Demo
|
21
|
+
🖼️ Images are saved in a user-specific directory and deleted when the users closes the page via demo.unload.
|
22
|
+
""")
|
23
|
+
with gr.Row():
|
24
|
+
with gr.Column(scale=1):
|
25
|
+
with gr.Row():
|
26
|
+
img = gr.Image(label="Generated Image", height=300, width=300)
|
27
|
+
with gr.Row():
|
28
|
+
gen = gr.Button(value="Generate")
|
29
|
+
with gr.Row():
|
30
|
+
history = gr.Gallery(label="Previous Generations", height=500, columns=10)
|
31
|
+
state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
|
32
|
+
|
33
|
+
demo.load(generate_random_img, [state], [img, state, history])
|
34
|
+
gen.click(generate_random_img, [state], [img, state, history])
|
35
|
+
demo.unload(delete_directory)
|
36
|
+
|
37
|
+
|
38
|
+
demo.launch(auth=lambda user,pwd: True,
|
39
|
+
auth_message="Enter any username and password to continue")
|
40
|
+
```
|
41
|
+
|
42
|
+
Thanks @freddyaboulton!
|
43
|
+
|
44
|
+
## 0.14.0
|
45
|
+
|
46
|
+
### Features
|
47
|
+
|
48
|
+
- [#7691](https://github.com/gradio-app/gradio/pull/7691) [`84f81fe`](https://github.com/gradio-app/gradio/commit/84f81fec9287b041203a141bbf2852720f7d199c) - Closing stream from the backend. Thanks @aliabid94!
|
49
|
+
|
50
|
+
### Fixes
|
51
|
+
|
52
|
+
- [#7564](https://github.com/gradio-app/gradio/pull/7564) [`5d1e8da`](https://github.com/gradio-app/gradio/commit/5d1e8dae5ac23f605c3b5f41dbe18751dff380a0) - batch UI updates on a per frame basis. Thanks @pngwn!
|
53
|
+
|
3
54
|
## 0.13.0
|
4
55
|
|
5
56
|
### Fixes
|
package/dist/client.d.ts
CHANGED
@@ -3,7 +3,7 @@ import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatu
|
|
3
3
|
import type { Config } from "./types.js";
|
4
4
|
type event = <K extends EventType>(eventType: K, listener: EventListener<K>) => SubmitReturn;
|
5
5
|
type predict = (endpoint: string | number, data?: unknown[], event_data?: unknown) => Promise<unknown>;
|
6
|
-
type client_return = {
|
6
|
+
export type client_return = {
|
7
7
|
predict: predict;
|
8
8
|
config: Config;
|
9
9
|
submit: (endpoint: string | number, data?: unknown[], event_data?: unknown, trigger_id?: number | null) => SubmitReturn;
|
package/dist/client.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAQN,cAAc,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,EAAE,GAAG,CAAC;CACpB;AAED,UAAU,SAAS;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,GAAG,CAAC;CACnB;AAED,UAAU,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS;IACnD,UAAU,EAAE,CAAC,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,EAAE,CAAC;CACb;AACD,UAAU,OAAO,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS;IAC9C,eAAe,EAAE;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,iBAAiB,EAAE;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;KAC/B,CAAC;CACF;AAiID,wBAAsB,oBAAoB,CACzC,KAAK,KAAA,EACL,IAAI,MAAY,EAChB,IAAI,QAAK,EACT,IAAI,UAAQ,EACZ,QAAQ,MAAY,GAClB,OAAO,CACT;IACC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC;CACnB,EAAE,CACH,CAmDA"}
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export { client, post_data, upload_files, duplicate, api_factory } from "./client.js";
|
2
|
+
export type { client_return } from "./client.js";
|
2
3
|
export type { SpaceStatus } from "./types.js";
|
3
4
|
export { FileData, upload, prepare_files } from "./upload.js";
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,MAAM,EACN,SAAS,EACT,YAAY,EACZ,SAAS,EACT,WAAW,EACX,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,MAAM,EACN,SAAS,EACT,YAAY,EACZ,SAAS,EACT,WAAW,EACX,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
@@ -466,6 +466,9 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
466
466
|
hf_token
|
467
467
|
);
|
468
468
|
const _config = await config_success(config);
|
469
|
+
const heartbeat = new EventSource(
|
470
|
+
`${config.root}/heartbeat/${session_hash}`
|
471
|
+
);
|
469
472
|
res(_config);
|
470
473
|
} catch (e) {
|
471
474
|
console.error(e);
|
@@ -820,7 +823,7 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
820
823
|
}
|
821
824
|
}
|
822
825
|
};
|
823
|
-
} else if (protocol == "sse_v1" || protocol == "sse_v2" || protocol == "sse_v2.1") {
|
826
|
+
} else if (protocol == "sse_v1" || protocol == "sse_v2" || protocol == "sse_v2.1" || protocol == "sse_v3") {
|
824
827
|
fire_event({
|
825
828
|
type: "status",
|
826
829
|
stage: "pending",
|
@@ -908,7 +911,7 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
908
911
|
endpoint: _endpoint,
|
909
912
|
fn_index
|
910
913
|
});
|
911
|
-
if (data2 &&
|
914
|
+
if (data2 && ["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)) {
|
912
915
|
apply_diff_stream(event_id, data2);
|
913
916
|
}
|
914
917
|
}
|
@@ -951,7 +954,9 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
951
954
|
fn_index,
|
952
955
|
time: /* @__PURE__ */ new Date()
|
953
956
|
});
|
954
|
-
|
957
|
+
if (["sse_v2", "sse_v2.1"].includes(protocol)) {
|
958
|
+
close_stream();
|
959
|
+
}
|
955
960
|
}
|
956
961
|
};
|
957
962
|
if (event_id in pending_stream_messages) {
|
@@ -1077,7 +1082,7 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1077
1082
|
)
|
1078
1083
|
);
|
1079
1084
|
} else if (event_callbacks[event_id]) {
|
1080
|
-
if (_data.msg === "process_completed") {
|
1085
|
+
if (_data.msg === "process_completed" && ["sse", "sse_v1", "sse_v2", "sse_v2.1"].includes(config.protocol)) {
|
1081
1086
|
unclosed_events.delete(event_id);
|
1082
1087
|
if (unclosed_events.size === 0) {
|
1083
1088
|
close_stream();
|
@@ -1091,6 +1096,9 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1091
1096
|
}
|
1092
1097
|
pending_stream_messages[event_id].push(_data);
|
1093
1098
|
}
|
1099
|
+
if (_data.msg === "close_stream") {
|
1100
|
+
close_stream();
|
1101
|
+
}
|
1094
1102
|
};
|
1095
1103
|
event_stream.onerror = async function(event) {
|
1096
1104
|
await Promise.all(
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
@@ -42,7 +42,7 @@ type predict = (
|
|
42
42
|
event_data?: unknown
|
43
43
|
) => Promise<unknown>;
|
44
44
|
|
45
|
-
type client_return = {
|
45
|
+
export type client_return = {
|
46
46
|
predict: predict;
|
47
47
|
config: Config;
|
48
48
|
submit: (
|
@@ -194,6 +194,7 @@ export function api_factory(
|
|
194
194
|
if (token) {
|
195
195
|
headers.Authorization = `Bearer ${token}`;
|
196
196
|
}
|
197
|
+
|
197
198
|
try {
|
198
199
|
var response = await fetch_implementation(url, {
|
199
200
|
method: "POST",
|
@@ -356,6 +357,10 @@ export function api_factory(
|
|
356
357
|
);
|
357
358
|
|
358
359
|
const _config = await config_success(config);
|
360
|
+
// connect to the heartbeat endpoint via GET request
|
361
|
+
const heartbeat = new EventSource(
|
362
|
+
`${config.root}/heartbeat/${session_hash}`
|
363
|
+
);
|
359
364
|
res(_config);
|
360
365
|
} catch (e) {
|
361
366
|
console.error(e);
|
@@ -758,9 +763,11 @@ export function api_factory(
|
|
758
763
|
} else if (
|
759
764
|
protocol == "sse_v1" ||
|
760
765
|
protocol == "sse_v2" ||
|
761
|
-
protocol == "sse_v2.1"
|
766
|
+
protocol == "sse_v2.1" ||
|
767
|
+
protocol == "sse_v3"
|
762
768
|
) {
|
763
769
|
// latest API format. v2 introduces sending diffs for intermediate outputs in generative functions, which makes payloads lighter.
|
770
|
+
// v3 only closes the stream when the backend sends the close stream message.
|
764
771
|
fire_event({
|
765
772
|
type: "status",
|
766
773
|
stage: "pending",
|
@@ -855,7 +862,7 @@ export function api_factory(
|
|
855
862
|
});
|
856
863
|
if (
|
857
864
|
data &&
|
858
|
-
|
865
|
+
["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)
|
859
866
|
) {
|
860
867
|
apply_diff_stream(event_id!, data);
|
861
868
|
}
|
@@ -904,7 +911,9 @@ export function api_factory(
|
|
904
911
|
fn_index,
|
905
912
|
time: new Date()
|
906
913
|
});
|
907
|
-
|
914
|
+
if (["sse_v2", "sse_v2.1"].includes(protocol)) {
|
915
|
+
close_stream();
|
916
|
+
}
|
908
917
|
}
|
909
918
|
};
|
910
919
|
if (event_id in pending_stream_messages) {
|
@@ -1048,7 +1057,10 @@ export function api_factory(
|
|
1048
1057
|
)
|
1049
1058
|
);
|
1050
1059
|
} else if (event_callbacks[event_id]) {
|
1051
|
-
if (
|
1060
|
+
if (
|
1061
|
+
_data.msg === "process_completed" &&
|
1062
|
+
["sse", "sse_v1", "sse_v2", "sse_v2.1"].includes(config.protocol)
|
1063
|
+
) {
|
1052
1064
|
unclosed_events.delete(event_id);
|
1053
1065
|
if (unclosed_events.size === 0) {
|
1054
1066
|
close_stream();
|
@@ -1062,6 +1074,9 @@ export function api_factory(
|
|
1062
1074
|
}
|
1063
1075
|
pending_stream_messages[event_id].push(_data);
|
1064
1076
|
}
|
1077
|
+
if (_data.msg === "close_stream") {
|
1078
|
+
close_stream();
|
1079
|
+
}
|
1065
1080
|
};
|
1066
1081
|
event_stream.onerror = async function (event) {
|
1067
1082
|
await Promise.all(
|