@gradio/client 1.6.0-beta.2 → 1.6.0-beta.4
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 +12 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/helpers/api_info.d.ts.map +1 -1
- package/dist/index.js +52 -4
- package/dist/upload.d.ts +3 -1
- package/dist/upload.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +55 -0
- package/src/helpers/api_info.ts +0 -3
- package/src/helpers/init_helpers.ts +1 -1
- package/src/test/init_helpers.test.ts +0 -10
- package/src/upload.ts +5 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @gradio/client
|
2
2
|
|
3
|
+
## 1.6.0-beta.4
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#9483](https://github.com/gradio-app/gradio/pull/9483) [`8dc7c12`](https://github.com/gradio-app/gradio/commit/8dc7c12389311b60efcde1b9d3e3668a34d2dc00) - Send Streaming data over Websocket if possible. Also support base64 output format for images. Thanks @freddyaboulton!
|
8
|
+
|
9
|
+
## 1.6.0-beta.3
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
- [#9412](https://github.com/gradio-app/gradio/pull/9412) [`c2c2fd9`](https://github.com/gradio-app/gradio/commit/c2c2fd989348f826566773c07c0e0bda200199ff) - fix SSR apps on spaces. Thanks @pngwn!
|
14
|
+
|
3
15
|
## 1.6.0-beta.2
|
4
16
|
|
5
17
|
### Features
|
package/dist/client.d.ts
CHANGED
@@ -22,6 +22,7 @@ export declare class Client {
|
|
22
22
|
abort_controller: AbortController | null;
|
23
23
|
stream_instance: EventSource | null;
|
24
24
|
current_payload: any;
|
25
|
+
ws_map: Record<string, WebSocket | "failed">;
|
25
26
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
26
27
|
stream(url: URL): EventSource;
|
27
28
|
view_api: () => Promise<ApiInfo<JsApiData>>;
|
@@ -50,6 +51,9 @@ export declare class Client {
|
|
50
51
|
}): Promise<unknown>;
|
51
52
|
set_cookies(raw_cookies: string): void;
|
52
53
|
private prepare_return_obj;
|
54
|
+
private connect_ws;
|
55
|
+
send_ws_message(url: string, data: any): Promise<void>;
|
56
|
+
close_ws(url: string): Promise<void>;
|
53
57
|
}
|
54
58
|
/**
|
55
59
|
* @deprecated This method will be removed in v1.0. Use `Client.connect()` instead.
|
package/dist/client.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,OAAO,EACP,OAAO,EACP,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,EACX,MAAM,EACN,cAAc,EAEd,cAAc,EACd,WAAW,EACX,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAU,QAAQ,EAAE,MAAM,UAAU,CAAC;AAuB5C,qBAAa,MAAM;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC;IAEvB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,SAAM;IAChB,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACrC,YAAY,EAAE,MAAM,CAA2C;IAC/D,GAAG,EAAE,MAAM,GAAG,KAAK,CAAS;IAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAM;IAElD,OAAO,CAAC,OAAO,CAAuB;IAGtC,aAAa;;MAAmB;IAChC,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAM;IACtD,oBAAoB,EAAE,MAAM,CAAC,M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AE,MAAM,CAAA;CAAE,EACxC,UAAU,EAAE,MAAM,GAChB,MAAM,CASR;AAGD,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,WAAW,GACX,kBAAkB,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAuIA;AAGD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,kBAAkB,yEAEf,aAAa,SAAS,GAAG,OAAO,CAAC,KAC9C,OAAO,EA4CT,CAAC"}
|
package/dist/index.js
CHANGED
@@ -96,7 +96,6 @@ async function resolve_config(endpoint) {
|
|
96
96
|
return { ...config, path };
|
97
97
|
} else if (endpoint) {
|
98
98
|
const config_url = join_urls(endpoint, CONFIG_URL);
|
99
|
-
console.log("config_url", config_url);
|
100
99
|
const response = await this.fetch(config_url, {
|
101
100
|
headers,
|
102
101
|
credentials: "include"
|
@@ -209,7 +208,6 @@ const parse_and_set_cookies = (cookie_header) => {
|
|
209
208
|
const RE_SPACE_NAME = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/;
|
210
209
|
const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}$/;
|
211
210
|
async function process_endpoint(app_reference, hf_token) {
|
212
|
-
console.log("app_reference", app_reference);
|
213
211
|
const headers = {};
|
214
212
|
if (hf_token) {
|
215
213
|
headers.Authorization = `Bearer ${hf_token}`;
|
@@ -239,7 +237,6 @@ async function process_endpoint(app_reference, hf_token) {
|
|
239
237
|
host
|
240
238
|
};
|
241
239
|
}
|
242
|
-
console.log("app_reference", _app_reference);
|
243
240
|
return {
|
244
241
|
space_id: false,
|
245
242
|
...determine_protocol(_app_reference)
|
@@ -660,7 +657,8 @@ class FileData {
|
|
660
657
|
blob,
|
661
658
|
is_stream,
|
662
659
|
mime_type,
|
663
|
-
alt_text
|
660
|
+
alt_text,
|
661
|
+
b64
|
664
662
|
}) {
|
665
663
|
__publicField(this, "path");
|
666
664
|
__publicField(this, "url");
|
@@ -670,6 +668,7 @@ class FileData {
|
|
670
668
|
__publicField(this, "is_stream");
|
671
669
|
__publicField(this, "mime_type");
|
672
670
|
__publicField(this, "alt_text");
|
671
|
+
__publicField(this, "b64");
|
673
672
|
__publicField(this, "meta", { _type: "gradio.FileData" });
|
674
673
|
this.path = path;
|
675
674
|
this.url = url;
|
@@ -679,6 +678,7 @@ class FileData {
|
|
679
678
|
this.is_stream = is_stream;
|
680
679
|
this.mime_type = mime_type;
|
681
680
|
this.alt_text = alt_text;
|
681
|
+
this.b64 = b64;
|
682
682
|
}
|
683
683
|
}
|
684
684
|
class Command {
|
@@ -2277,6 +2277,7 @@ class Client {
|
|
2277
2277
|
__publicField(this, "abort_controller", null);
|
2278
2278
|
__publicField(this, "stream_instance", null);
|
2279
2279
|
__publicField(this, "current_payload");
|
2280
|
+
__publicField(this, "ws_map", {});
|
2280
2281
|
__publicField(this, "view_api");
|
2281
2282
|
__publicField(this, "upload_files");
|
2282
2283
|
__publicField(this, "upload");
|
@@ -2548,6 +2549,53 @@ class Client {
|
|
2548
2549
|
component_server: this.component_server
|
2549
2550
|
};
|
2550
2551
|
}
|
2552
|
+
async connect_ws(url) {
|
2553
|
+
return new Promise((resolve, reject) => {
|
2554
|
+
let ws;
|
2555
|
+
try {
|
2556
|
+
ws = new WebSocket(url);
|
2557
|
+
} catch (e) {
|
2558
|
+
this.ws_map[url] = "failed";
|
2559
|
+
return;
|
2560
|
+
}
|
2561
|
+
ws.onopen = () => {
|
2562
|
+
resolve();
|
2563
|
+
};
|
2564
|
+
ws.onerror = (error) => {
|
2565
|
+
console.error("WebSocket error:", error);
|
2566
|
+
this.close_ws(url);
|
2567
|
+
this.ws_map[url] = "failed";
|
2568
|
+
resolve();
|
2569
|
+
};
|
2570
|
+
ws.onclose = () => {
|
2571
|
+
delete this.ws_map[url];
|
2572
|
+
this.ws_map[url] = "failed";
|
2573
|
+
};
|
2574
|
+
ws.onmessage = (event) => {
|
2575
|
+
};
|
2576
|
+
this.ws_map[url] = ws;
|
2577
|
+
});
|
2578
|
+
}
|
2579
|
+
async send_ws_message(url, data) {
|
2580
|
+
if (!(url in this.ws_map)) {
|
2581
|
+
await this.connect_ws(url);
|
2582
|
+
}
|
2583
|
+
const ws = this.ws_map[url];
|
2584
|
+
if (ws instanceof WebSocket) {
|
2585
|
+
ws.send(JSON.stringify(data));
|
2586
|
+
} else {
|
2587
|
+
this.post_data(url, data);
|
2588
|
+
}
|
2589
|
+
}
|
2590
|
+
async close_ws(url) {
|
2591
|
+
if (url in this.ws_map) {
|
2592
|
+
const ws = this.ws_map[url];
|
2593
|
+
if (ws instanceof WebSocket) {
|
2594
|
+
ws.close();
|
2595
|
+
delete this.ws_map[url];
|
2596
|
+
}
|
2597
|
+
}
|
2598
|
+
}
|
2551
2599
|
}
|
2552
2600
|
async function client(app_reference, options = {
|
2553
2601
|
events: ["data"]
|
package/dist/upload.d.ts
CHANGED
@@ -10,10 +10,11 @@ export declare class FileData {
|
|
10
10
|
is_stream?: boolean;
|
11
11
|
mime_type?: string;
|
12
12
|
alt_text?: string;
|
13
|
+
b64?: string;
|
13
14
|
readonly meta: {
|
14
15
|
_type: string;
|
15
16
|
};
|
16
|
-
constructor({ path, url, orig_name, size, blob, is_stream, mime_type, alt_text }: {
|
17
|
+
constructor({ path, url, orig_name, size, blob, is_stream, mime_type, alt_text, b64 }: {
|
17
18
|
path: string;
|
18
19
|
url?: string;
|
19
20
|
orig_name?: string;
|
@@ -22,6 +23,7 @@ export declare class FileData {
|
|
22
23
|
is_stream?: boolean;
|
23
24
|
mime_type?: string;
|
24
25
|
alt_text?: string;
|
26
|
+
b64?: string;
|
25
27
|
});
|
26
28
|
}
|
27
29
|
//# sourceMappingURL=upload.d.ts.map
|
package/dist/upload.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,wBAAsB,MAAM,CAC3B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,QAAQ,EAAE,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAsCrC;AAED,wBAAsB,aAAa,CAClC,KAAK,EAAE,IAAI,EAAE,EACb,SAAS,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAYrB;AAED,qBAAa,QAAQ;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,IAAI;;MAAgC;gBAEjC,EACX,IAAI,EACJ,GAAG,EACH,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,QAAQ,EACR,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,SAAS,CAAC,EAAE,OA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CAAC;QACZ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC;KACb;CAWD"}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
@@ -63,6 +63,7 @@ export class Client {
|
|
63
63
|
abort_controller: AbortController | null = null;
|
64
64
|
stream_instance: EventSource | null = null;
|
65
65
|
current_payload: any;
|
66
|
+
ws_map: Record<string, WebSocket | "failed"> = {};
|
66
67
|
|
67
68
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
68
69
|
const headers = new Headers(init?.headers || {});
|
@@ -433,6 +434,60 @@ export class Client {
|
|
433
434
|
component_server: this.component_server
|
434
435
|
};
|
435
436
|
}
|
437
|
+
|
438
|
+
private async connect_ws(url: string): Promise<void> {
|
439
|
+
return new Promise((resolve, reject) => {
|
440
|
+
let ws;
|
441
|
+
try {
|
442
|
+
ws = new WebSocket(url);
|
443
|
+
} catch (e) {
|
444
|
+
this.ws_map[url] = "failed";
|
445
|
+
return;
|
446
|
+
}
|
447
|
+
|
448
|
+
ws.onopen = () => {
|
449
|
+
resolve();
|
450
|
+
};
|
451
|
+
|
452
|
+
ws.onerror = (error) => {
|
453
|
+
console.error("WebSocket error:", error);
|
454
|
+
this.close_ws(url);
|
455
|
+
this.ws_map[url] = "failed";
|
456
|
+
resolve();
|
457
|
+
};
|
458
|
+
|
459
|
+
ws.onclose = () => {
|
460
|
+
delete this.ws_map[url];
|
461
|
+
this.ws_map[url] = "failed";
|
462
|
+
};
|
463
|
+
|
464
|
+
ws.onmessage = (event) => {};
|
465
|
+
this.ws_map[url] = ws;
|
466
|
+
});
|
467
|
+
}
|
468
|
+
|
469
|
+
async send_ws_message(url: string, data: any): Promise<void> {
|
470
|
+
// connect if not connected
|
471
|
+
if (!(url in this.ws_map)) {
|
472
|
+
await this.connect_ws(url);
|
473
|
+
}
|
474
|
+
const ws = this.ws_map[url];
|
475
|
+
if (ws instanceof WebSocket) {
|
476
|
+
ws.send(JSON.stringify(data));
|
477
|
+
} else {
|
478
|
+
this.post_data(url, data);
|
479
|
+
}
|
480
|
+
}
|
481
|
+
|
482
|
+
async close_ws(url: string): Promise<void> {
|
483
|
+
if (url in this.ws_map) {
|
484
|
+
const ws = this.ws_map[url];
|
485
|
+
if (ws instanceof WebSocket) {
|
486
|
+
ws.close();
|
487
|
+
delete this.ws_map[url];
|
488
|
+
}
|
489
|
+
}
|
490
|
+
}
|
436
491
|
}
|
437
492
|
|
438
493
|
/**
|
package/src/helpers/api_info.ts
CHANGED
@@ -26,7 +26,6 @@ export async function process_endpoint(
|
|
26
26
|
ws_protocol: "ws" | "wss";
|
27
27
|
http_protocol: "http:" | "https:";
|
28
28
|
}> {
|
29
|
-
console.log("app_reference", app_reference);
|
30
29
|
const headers: { Authorization?: string } = {};
|
31
30
|
if (hf_token) {
|
32
31
|
headers.Authorization = `Bearer ${hf_token}`;
|
@@ -66,8 +65,6 @@ export async function process_endpoint(
|
|
66
65
|
};
|
67
66
|
}
|
68
67
|
|
69
|
-
console.log("app_reference", _app_reference);
|
70
|
-
|
71
68
|
return {
|
72
69
|
space_id: false,
|
73
70
|
...determine_protocol(_app_reference)
|
@@ -87,7 +87,7 @@ export async function resolve_config(
|
|
87
87
|
return { ...config, path } as Config;
|
88
88
|
} else if (endpoint) {
|
89
89
|
const config_url = join_urls(endpoint, CONFIG_URL);
|
90
|
-
|
90
|
+
|
91
91
|
const response = await this.fetch(config_url, {
|
92
92
|
headers,
|
93
93
|
credentials: "include"
|
@@ -84,16 +84,6 @@ describe("determine_protocol", () => {
|
|
84
84
|
host: "lite.local"
|
85
85
|
});
|
86
86
|
});
|
87
|
-
|
88
|
-
it('should return the default protocols and host when the endpoint does not start with "http" or "file"', () => {
|
89
|
-
const endpoint = "huggingface.co";
|
90
|
-
const result = determine_protocol(endpoint);
|
91
|
-
expect(result).toEqual({
|
92
|
-
ws_protocol: "wss",
|
93
|
-
http_protocol: "https:",
|
94
|
-
host: "huggingface.co"
|
95
|
-
});
|
96
|
-
});
|
97
87
|
});
|
98
88
|
|
99
89
|
describe("parse_and_set_cookies", () => {
|
package/src/upload.ts
CHANGED
@@ -72,6 +72,7 @@ export class FileData {
|
|
72
72
|
is_stream?: boolean;
|
73
73
|
mime_type?: string;
|
74
74
|
alt_text?: string;
|
75
|
+
b64?: string;
|
75
76
|
readonly meta = { _type: "gradio.FileData" };
|
76
77
|
|
77
78
|
constructor({
|
@@ -82,7 +83,8 @@ export class FileData {
|
|
82
83
|
blob,
|
83
84
|
is_stream,
|
84
85
|
mime_type,
|
85
|
-
alt_text
|
86
|
+
alt_text,
|
87
|
+
b64
|
86
88
|
}: {
|
87
89
|
path: string;
|
88
90
|
url?: string;
|
@@ -92,6 +94,7 @@ export class FileData {
|
|
92
94
|
is_stream?: boolean;
|
93
95
|
mime_type?: string;
|
94
96
|
alt_text?: string;
|
97
|
+
b64?: string;
|
95
98
|
}) {
|
96
99
|
this.path = path;
|
97
100
|
this.url = url;
|
@@ -101,5 +104,6 @@ export class FileData {
|
|
101
104
|
this.is_stream = is_stream;
|
102
105
|
this.mime_type = mime_type;
|
103
106
|
this.alt_text = alt_text;
|
107
|
+
this.b64 = b64;
|
104
108
|
}
|
105
109
|
}
|