@gradio/client 0.6.0 → 0.7.0-beta.1

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @gradio/client
2
2
 
3
+ ## 0.7.0-beta.1
4
+
5
+ ### Features
6
+
7
+ - [#6143](https://github.com/gradio-app/gradio/pull/6143) [`e4f7b4b40`](https://github.com/gradio-app/gradio/commit/e4f7b4b409323b01aa01b39e15ce6139e29aa073) - fix circular dependency with client + upload. Thanks [@pngwn](https://github.com/pngwn)!
8
+ - [#6094](https://github.com/gradio-app/gradio/pull/6094) [`c476bd5a5`](https://github.com/gradio-app/gradio/commit/c476bd5a5b70836163b9c69bf4bfe068b17fbe13) - Image v4. Thanks [@pngwn](https://github.com/pngwn)!
9
+ - [#6069](https://github.com/gradio-app/gradio/pull/6069) [`bf127e124`](https://github.com/gradio-app/gradio/commit/bf127e1241a41401e144874ea468dff8474eb505) - Swap websockets for SSE. Thanks [@aliabid94](https://github.com/aliabid94)!
10
+
11
+ ## 0.7.0-beta.0
12
+
13
+ ### Features
14
+
15
+ - [#6016](https://github.com/gradio-app/gradio/pull/6016) [`83e947676`](https://github.com/gradio-app/gradio/commit/83e947676d327ca2ab6ae2a2d710c78961c771a0) - Format js in v4 branch. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
16
+
17
+ ### Fixes
18
+
19
+ - [#6046](https://github.com/gradio-app/gradio/pull/6046) [`dbb7de5e0`](https://github.com/gradio-app/gradio/commit/dbb7de5e02c53fee05889d696d764d212cb96c74) - fix tests. Thanks [@pngwn](https://github.com/pngwn)!
20
+
3
21
  ## 0.6.0
4
22
 
5
23
  ### Features
package/dist/client.d.ts CHANGED
@@ -69,7 +69,6 @@ interface ApiInfo<T extends ApiData | JsApiData> {
69
69
  }
70
70
  export declare function walk_and_store_blobs(param: any, type?: any, path?: any[], root?: boolean, api_info?: any): Promise<{
71
71
  path: string[];
72
- data: string | false;
73
72
  type: string;
74
73
  blob: Blob | false;
75
74
  }[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAQN,cAAc,EAEd,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EAIb,YAAY,EACZ,cAAc,EAGd,mBAAmB,EAEnB,MAAM,YAAY,CAAC;AAEpB,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,KAAK,aAAa,GAAG;IACpB,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,KAChB,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,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,O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,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,3 +1,4 @@
1
1
  export { client, post_data, upload_files, duplicate, api_factory } from "./client.js";
2
2
  export type { SpaceStatus } from "./types.js";
3
+ export { normalise_file, FileData, upload, get_fetchable_url_or_file, prepare_files } from "./upload.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACN,cAAc,EACd,QAAQ,EACR,MAAM,EACN,yBAAyB,EACzB,aAAa,EACb,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -170,6 +170,110 @@ const hardware_types = [
170
170
  "a10g-large",
171
171
  "a100-large"
172
172
  ];
173
+ function normalise_file(file, server_url, proxy_url) {
174
+ if (file == null) {
175
+ return null;
176
+ }
177
+ if (Array.isArray(file)) {
178
+ const normalized_file = [];
179
+ for (const x of file) {
180
+ if (x == null) {
181
+ normalized_file.push(null);
182
+ } else {
183
+ normalized_file.push(normalise_file(x, server_url, proxy_url));
184
+ }
185
+ }
186
+ return normalized_file;
187
+ }
188
+ if (file.is_stream) {
189
+ if (proxy_url == null) {
190
+ return new FileData({
191
+ ...file,
192
+ url: server_url + "/stream/" + file.path
193
+ });
194
+ }
195
+ return new FileData({
196
+ ...file,
197
+ url: "/proxy=" + proxy_url + "stream/" + file.path
198
+ });
199
+ }
200
+ return new FileData({
201
+ ...file,
202
+ url: get_fetchable_url_or_file(file.path, server_url, proxy_url)
203
+ });
204
+ }
205
+ function is_url(str) {
206
+ try {
207
+ const url = new URL(str);
208
+ return url.protocol === "http:" || url.protocol === "https:";
209
+ } catch {
210
+ return false;
211
+ }
212
+ }
213
+ function get_fetchable_url_or_file(path, server_url, proxy_url) {
214
+ if (path == null) {
215
+ return proxy_url ? `/proxy=${proxy_url}file=` : `${server_url}/file=`;
216
+ }
217
+ if (is_url(path)) {
218
+ return path;
219
+ }
220
+ return proxy_url ? `/proxy=${proxy_url}file=${path}` : `${server_url}/file=${path}`;
221
+ }
222
+ async function upload(file_data, root, upload_fn = upload_files) {
223
+ let files = (Array.isArray(file_data) ? file_data : [file_data]).map(
224
+ (file_data2) => file_data2.blob
225
+ );
226
+ return await Promise.all(
227
+ await upload_fn(root, files).then(
228
+ async (response) => {
229
+ if (response.error) {
230
+ throw new Error(response.error);
231
+ } else {
232
+ if (response.files) {
233
+ return response.files.map((f, i) => {
234
+ const file = new FileData({ ...file_data[i], path: f });
235
+ return normalise_file(file, root, null);
236
+ });
237
+ }
238
+ return [];
239
+ }
240
+ }
241
+ )
242
+ );
243
+ }
244
+ async function prepare_files(files, is_stream) {
245
+ return files.map(
246
+ (f, i) => new FileData({
247
+ path: f.name,
248
+ orig_name: f.name,
249
+ blob: f,
250
+ size: f.size,
251
+ mime_type: f.type,
252
+ is_stream
253
+ })
254
+ );
255
+ }
256
+ class FileData {
257
+ constructor({
258
+ path,
259
+ url,
260
+ orig_name,
261
+ size,
262
+ blob,
263
+ is_stream,
264
+ mime_type,
265
+ alt_text
266
+ }) {
267
+ this.path = path;
268
+ this.url = url;
269
+ this.orig_name = orig_name;
270
+ this.size = size;
271
+ this.blob = url ? void 0 : blob;
272
+ this.is_stream = is_stream;
273
+ this.mime_type = mime_type;
274
+ this.alt_text = alt_text;
275
+ }
276
+ }
173
277
  const QUEUE_FULL_MSG = "This application is too busy. Keep trying!";
174
278
  const BROKEN_CONNECTION_MSG = "Connection errored out.";
175
279
  let NodeBlob;
@@ -276,11 +380,10 @@ function api_factory(fetch_implementation, WebSocket_factory) {
276
380
  submit,
277
381
  view_api,
278
382
  component_server
279
- // duplicate
280
383
  };
281
384
  const transform_files = normalise_files ?? true;
282
385
  if ((typeof window === "undefined" || !("WebSocket" in window)) && !global.Websocket) {
283
- const ws = await import("./wrapper-6f348d45.js");
386
+ const ws = await import("./wrapper-98f94c21.js");
284
387
  NodeBlob = (await import("node:buffer")).Blob;
285
388
  global.WebSocket = ws.WebSocket;
286
389
  }
@@ -418,15 +521,16 @@ function api_factory(fetch_implementation, WebSocket_factory) {
418
521
  );
419
522
  }
420
523
  let websocket;
524
+ let eventSource;
525
+ let protocol = config.protocol ?? "sse";
421
526
  const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
422
527
  let payload;
528
+ let event_id = null;
423
529
  let complete = false;
424
530
  const listener_map = {};
425
531
  let url_params = "";
426
532
  if (typeof window !== "undefined") {
427
- url_params = new URLSearchParams(
428
- window.location.search
429
- ).toString();
533
+ url_params = new URLSearchParams(window.location.search).toString();
430
534
  }
431
535
  handle_blob2(
432
536
  `${http_protocol}//${resolve_root(host, config.path, true)}`,
@@ -497,7 +601,7 @@ function api_factory(fetch_implementation, WebSocket_factory) {
497
601
  time: /* @__PURE__ */ new Date()
498
602
  });
499
603
  });
500
- } else {
604
+ } else if (protocol == "ws") {
501
605
  fire_event({
502
606
  type: "status",
503
607
  stage: "pending",
@@ -606,6 +710,119 @@ function api_factory(fetch_implementation, WebSocket_factory) {
606
710
  () => websocket.send(JSON.stringify({ hash: session_hash }))
607
711
  );
608
712
  }
713
+ } else {
714
+ fire_event({
715
+ type: "status",
716
+ stage: "pending",
717
+ queue: true,
718
+ endpoint: _endpoint,
719
+ fn_index,
720
+ time: /* @__PURE__ */ new Date()
721
+ });
722
+ var params = new URLSearchParams({
723
+ fn_index: fn_index.toString(),
724
+ session_hash
725
+ }).toString();
726
+ let url = new URL(
727
+ `${http_protocol}//${resolve_root(
728
+ host,
729
+ config.path,
730
+ true
731
+ )}/queue/join?${params}`
732
+ );
733
+ eventSource = new EventSource(url);
734
+ eventSource.onmessage = async function(event) {
735
+ const _data = JSON.parse(event.data);
736
+ const { type, status, data: data2 } = handle_message(
737
+ _data,
738
+ last_status[fn_index]
739
+ );
740
+ if (type === "update" && status && !complete) {
741
+ fire_event({
742
+ type: "status",
743
+ endpoint: _endpoint,
744
+ fn_index,
745
+ time: /* @__PURE__ */ new Date(),
746
+ ...status
747
+ });
748
+ if (status.stage === "error") {
749
+ eventSource.close();
750
+ }
751
+ } else if (type === "data") {
752
+ event_id = _data.event_id;
753
+ let [_, status2] = await post_data2(
754
+ `${http_protocol}//${resolve_root(
755
+ host,
756
+ config.path,
757
+ true
758
+ )}/queue/data`,
759
+ {
760
+ ...payload,
761
+ session_hash,
762
+ event_id
763
+ },
764
+ hf_token
765
+ );
766
+ if (status2 !== 200) {
767
+ fire_event({
768
+ type: "status",
769
+ stage: "error",
770
+ message: BROKEN_CONNECTION_MSG,
771
+ queue: true,
772
+ endpoint: _endpoint,
773
+ fn_index,
774
+ time: /* @__PURE__ */ new Date()
775
+ });
776
+ eventSource.close();
777
+ }
778
+ } else if (type === "complete") {
779
+ complete = status;
780
+ } else if (type === "log") {
781
+ fire_event({
782
+ type: "log",
783
+ log: data2.log,
784
+ level: data2.level,
785
+ endpoint: _endpoint,
786
+ fn_index
787
+ });
788
+ } else if (type === "generating") {
789
+ fire_event({
790
+ type: "status",
791
+ time: /* @__PURE__ */ new Date(),
792
+ ...status,
793
+ stage: status == null ? void 0 : status.stage,
794
+ queue: true,
795
+ endpoint: _endpoint,
796
+ fn_index
797
+ });
798
+ }
799
+ if (data2) {
800
+ fire_event({
801
+ type: "data",
802
+ time: /* @__PURE__ */ new Date(),
803
+ data: transform_files ? transform_output(
804
+ data2.data,
805
+ api_info,
806
+ config.root,
807
+ config.root_url
808
+ ) : data2.data,
809
+ endpoint: _endpoint,
810
+ fn_index
811
+ });
812
+ if (complete) {
813
+ fire_event({
814
+ type: "status",
815
+ time: /* @__PURE__ */ new Date(),
816
+ ...complete,
817
+ stage: status == null ? void 0 : status.stage,
818
+ queue: true,
819
+ endpoint: _endpoint,
820
+ fn_index
821
+ });
822
+ eventSource.close();
823
+ }
824
+ }
825
+ };
609
826
  }
610
827
  });
611
828
  function fire_event(event) {
@@ -640,12 +857,19 @@ function api_factory(fetch_implementation, WebSocket_factory) {
640
857
  endpoint: _endpoint,
641
858
  fn_index
642
859
  });
643
- if (websocket && websocket.readyState === 0) {
644
- websocket.addEventListener("open", () => {
860
+ let cancel_request = {};
861
+ if (protocol === "ws") {
862
+ if (websocket && websocket.readyState === 0) {
863
+ websocket.addEventListener("open", () => {
864
+ websocket.close();
865
+ });
866
+ } else {
645
867
  websocket.close();
646
- });
868
+ }
869
+ cancel_request = { fn_index, session_hash };
647
870
  } else {
648
- websocket.close();
871
+ eventSource.close();
872
+ cancel_request = { event_id };
649
873
  }
650
874
  try {
651
875
  await fetch_implementation(
@@ -657,7 +881,7 @@ function api_factory(fetch_implementation, WebSocket_factory) {
657
881
  {
658
882
  headers: { "Content-Type": "application/json" },
659
883
  method: "POST",
660
- body: JSON.stringify({ fn_index, session_hash })
884
+ body: JSON.stringify(cancel_request)
661
885
  }
662
886
  );
663
887
  } catch (e) {
@@ -769,27 +993,20 @@ function api_factory(fetch_implementation, WebSocket_factory) {
769
993
  api_info
770
994
  );
771
995
  return Promise.all(
772
- blob_refs.map(async ({ path, blob, data: data2, type }) => {
996
+ blob_refs.map(async ({ path, blob, type }) => {
773
997
  if (blob) {
774
998
  const file_url = (await upload_files2(endpoint, [blob], token)).files[0];
775
- return { path, file_url, type };
999
+ return { path, file_url, type, name: blob == null ? void 0 : blob.name };
776
1000
  }
777
- return { path, base64: data2, type };
1001
+ return { path, type };
778
1002
  })
779
1003
  ).then((r) => {
780
- r.forEach(({ path, file_url, base64, type }) => {
781
- if (base64) {
782
- update_object(data, base64, path);
783
- } else if (type === "Gallery") {
1004
+ r.forEach(({ path, file_url, type, name }) => {
1005
+ if (type === "Gallery") {
784
1006
  update_object(data, file_url, path);
785
1007
  } else if (file_url) {
786
- const o = {
787
- is_file: true,
788
- name: `${file_url}`,
789
- data: null
790
- // orig_name: "file.csv"
791
- };
792
- update_object(data, o, path);
1008
+ const file = new FileData({ path: file_url, orig_name: name });
1009
+ update_object(data, file, path);
793
1010
  }
794
1011
  });
795
1012
  return data;
@@ -809,39 +1026,12 @@ function transform_output(data, api_info, root_url, remote_url) {
809
1026
  return d.map((img) => {
810
1027
  return Array.isArray(img) ? [normalise_file(img[0], root_url, remote_url), img[1]] : [normalise_file(img, root_url, remote_url), null];
811
1028
  });
812
- } else if (typeof d === "object" && (d == null ? void 0 : d.is_file)) {
1029
+ } else if (typeof d === "object" && d.path) {
813
1030
  return normalise_file(d, root_url, remote_url);
814
1031
  }
815
1032
  return d;
816
1033
  });
817
1034
  }
818
- function normalise_file(file, root, root_url) {
819
- if (file == null)
820
- return null;
821
- if (typeof file === "string") {
822
- return {
823
- name: "file_data",
824
- data: file
825
- };
826
- } else if (Array.isArray(file)) {
827
- const normalized_file = [];
828
- for (const x of file) {
829
- if (x === null) {
830
- normalized_file.push(null);
831
- } else {
832
- normalized_file.push(normalise_file(x, root, root_url));
833
- }
834
- }
835
- return normalized_file;
836
- } else if (file.is_file) {
837
- if (!root_url) {
838
- file.data = root + "/file=" + file.name;
839
- } else {
840
- file.data = "/proxy=" + root_url + "file=" + file.name;
841
- }
842
- }
843
- return file;
844
- }
845
1035
  function get_type(type, component, serializer, signature_type) {
846
1036
  switch (type.type) {
847
1037
  case "string":
@@ -955,22 +1145,9 @@ async function walk_and_store_blobs(param, type = void 0, path = [], root = fals
955
1145
  {
956
1146
  path,
957
1147
  blob: is_image ? false : new NodeBlob([param]),
958
- data: is_image ? `${param.toString("base64")}` : false,
959
1148
  type
960
1149
  }
961
1150
  ];
962
- } else if (param instanceof Blob || typeof window !== "undefined" && param instanceof File) {
963
- if (type === "Image") {
964
- let data;
965
- if (typeof window !== "undefined") {
966
- data = await image_to_data_uri(param);
967
- } else {
968
- const buffer = await param.arrayBuffer();
969
- data = Buffer.from(buffer).toString("base64");
970
- }
971
- return [{ path, data, type, blob: false }];
972
- }
973
- return [{ path, blob: param, type, data: false }];
974
1151
  } else if (typeof param === "object") {
975
1152
  let blob_refs = [];
976
1153
  for (let key in param) {
@@ -992,13 +1169,6 @@ async function walk_and_store_blobs(param, type = void 0, path = [], root = fals
992
1169
  }
993
1170
  return [];
994
1171
  }
995
- function image_to_data_uri(blob) {
996
- return new Promise((resolve, _) => {
997
- const reader = new FileReader();
998
- reader.onloadend = () => resolve(reader.result);
999
- reader.readAsDataURL(blob);
1000
- });
1001
- }
1002
1172
  function skip_queue(id, config) {
1003
1173
  var _a, _b, _c, _d;
1004
1174
  return !(((_b = (_a = config == null ? void 0 : config.dependencies) == null ? void 0 : _a[id]) == null ? void 0 : _b.queue) === null ? config.enable_queue : (_d = (_c = config == null ? void 0 : config.dependencies) == null ? void 0 : _c[id]) == null ? void 0 : _d.queue) || false;
@@ -1204,9 +1374,14 @@ function handle_message(data, last_status) {
1204
1374
  return { type: "none", status: { stage: "error", queue } };
1205
1375
  }
1206
1376
  export {
1377
+ FileData,
1207
1378
  api_factory,
1208
1379
  client,
1209
1380
  duplicate,
1381
+ get_fetchable_url_or_file,
1382
+ normalise_file,
1210
1383
  post_data,
1384
+ prepare_files,
1385
+ upload,
1211
1386
  upload_files
1212
1387
  };
package/dist/types.d.ts CHANGED
@@ -18,6 +18,7 @@ export interface Config {
18
18
  show_api: boolean;
19
19
  stylesheets: string[];
20
20
  path: string;
21
+ protocol?: "sse" | "ws";
21
22
  }
22
23
  export interface Payload {
23
24
  data: unknown[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACtB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,EAAE,GAAG,EAAE,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,O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,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAC3E,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,IAAI;KAC7C,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE;CAC7B,CAAC;AACF,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,29 @@
1
+ import { upload_files } from "./client";
2
+ export declare function normalise_file(file: FileData | null, server_url: string, proxy_url: string | null): FileData | null;
3
+ export declare function normalise_file(file: FileData[] | null, server_url: string, proxy_url: string | null): FileData[] | null;
4
+ export declare function normalise_file(file: FileData[] | FileData | null, server_url: string, // root: string,
5
+ proxy_url: string | null): FileData[] | FileData | null;
6
+ export declare function get_fetchable_url_or_file(path: string | null, server_url: string, proxy_url: string | null): string;
7
+ export declare function upload(file_data: FileData[], root: string, upload_fn?: typeof upload_files): Promise<(FileData | null)[] | null>;
8
+ export declare function prepare_files(files: File[], is_stream?: boolean): Promise<FileData[]>;
9
+ export declare class FileData {
10
+ path: string;
11
+ url?: string;
12
+ orig_name: string;
13
+ size?: number;
14
+ blob?: File;
15
+ is_stream?: boolean;
16
+ mime_type?: string;
17
+ alt_text?: string;
18
+ constructor({ path, url, orig_name, size, blob, is_stream, mime_type, alt_text }: {
19
+ path: string;
20
+ url?: string;
21
+ orig_name: string;
22
+ size?: number;
23
+ blob?: File;
24
+ is_stream?: boolean;
25
+ mime_type?: string;
26
+ alt_text?: string;
27
+ });
28
+ }
29
+ //# sourceMappingURL=upload.d.ts.map
@@ -0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,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;gBAEN,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,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB;CAUD"}
@@ -18,10 +18,7 @@ function getAugmentedNamespace(n) {
18
18
  if (typeof f == "function") {
19
19
  var a = function a2() {
20
20
  if (this instanceof a2) {
21
- var args = [null];
22
- args.push.apply(args, arguments);
23
- var Ctor = Function.bind.apply(f, args);
24
- return new Ctor();
21
+ return Reflect.construct(f, arguments, this.constructor);
25
22
  }
26
23
  return f.apply(this, arguments);
27
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/client",
3
- "version": "0.6.0",
3
+ "version": "0.7.0-beta.1",
4
4
  "description": "Gradio API client",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/client.ts CHANGED
@@ -1,3 +1,5 @@
1
+ //@ts-nocheck
2
+
1
3
  import semiver from "semiver";
2
4
 
3
5
  import {
@@ -22,10 +24,11 @@ import type {
22
24
  UploadResponse,
23
25
  Status,
24
26
  SpaceStatus,
25
- SpaceStatusCallback,
26
- FileData
27
+ SpaceStatusCallback
27
28
  } from "./types.js";
28
29
 
30
+ import { FileData, normalise_file } from "./upload";
31
+
29
32
  import type { Config } from "./types.js";
30
33
 
31
34
  type event = <K extends EventType>(
@@ -251,7 +254,6 @@ export function api_factory(
251
254
  submit,
252
255
  view_api,
253
256
  component_server
254
- // duplicate
255
257
  };
256
258
 
257
259
  const transform_files = normalise_files ?? true;
@@ -427,16 +429,17 @@ export function api_factory(
427
429
  }
428
430
 
429
431
  let websocket: WebSocket;
432
+ let eventSource: EventSource;
433
+ let protocol = config.protocol ?? "sse";
430
434
 
431
435
  const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
432
436
  let payload: Payload;
437
+ let event_id: string | null = null;
433
438
  let complete: false | Record<string, any> = false;
434
439
  const listener_map: ListenerMap<EventType> = {};
435
- let url_params = ""
436
- if (typeof(window) !== "undefined") {
437
- url_params = new URLSearchParams(
438
- window.location.search
439
- ).toString();
440
+ let url_params = "";
441
+ if (typeof window !== "undefined") {
442
+ url_params = new URLSearchParams(window.location.search).toString();
440
443
  }
441
444
 
442
445
  handle_blob(
@@ -516,7 +519,7 @@ export function api_factory(
516
519
  time: new Date()
517
520
  });
518
521
  });
519
- } else {
522
+ } else if (protocol == "ws") {
520
523
  fire_event({
521
524
  type: "status",
522
525
  stage: "pending",
@@ -636,6 +639,126 @@ export function api_factory(
636
639
  websocket.send(JSON.stringify({ hash: session_hash }))
637
640
  );
638
641
  }
642
+ } else {
643
+ fire_event({
644
+ type: "status",
645
+ stage: "pending",
646
+ queue: true,
647
+ endpoint: _endpoint,
648
+ fn_index,
649
+ time: new Date()
650
+ });
651
+ var params = new URLSearchParams({
652
+ fn_index: fn_index.toString(),
653
+ session_hash: session_hash
654
+ }).toString();
655
+ let url = new URL(
656
+ `${http_protocol}//${resolve_root(
657
+ host,
658
+ config.path,
659
+ true
660
+ )}/queue/join?${params}`
661
+ );
662
+
663
+ eventSource = new EventSource(url);
664
+
665
+ eventSource.onmessage = async function (event) {
666
+ const _data = JSON.parse(event.data);
667
+ const { type, status, data } = handle_message(
668
+ _data,
669
+ last_status[fn_index]
670
+ );
671
+
672
+ if (type === "update" && status && !complete) {
673
+ // call 'status' listeners
674
+ fire_event({
675
+ type: "status",
676
+ endpoint: _endpoint,
677
+ fn_index,
678
+ time: new Date(),
679
+ ...status
680
+ });
681
+ if (status.stage === "error") {
682
+ eventSource.close();
683
+ }
684
+ } else if (type === "data") {
685
+ event_id = _data.event_id as string;
686
+ let [_, status] = await post_data(
687
+ `${http_protocol}//${resolve_root(
688
+ host,
689
+ config.path,
690
+ true
691
+ )}/queue/data`,
692
+ {
693
+ ...payload,
694
+ session_hash,
695
+ event_id
696
+ },
697
+ hf_token
698
+ );
699
+ if (status !== 200) {
700
+ fire_event({
701
+ type: "status",
702
+ stage: "error",
703
+ message: BROKEN_CONNECTION_MSG,
704
+ queue: true,
705
+ endpoint: _endpoint,
706
+ fn_index,
707
+ time: new Date()
708
+ });
709
+ eventSource.close();
710
+ }
711
+ } else if (type === "complete") {
712
+ complete = status;
713
+ } else if (type === "log") {
714
+ fire_event({
715
+ type: "log",
716
+ log: data.log,
717
+ level: data.level,
718
+ endpoint: _endpoint,
719
+ fn_index
720
+ });
721
+ } else if (type === "generating") {
722
+ fire_event({
723
+ type: "status",
724
+ time: new Date(),
725
+ ...status,
726
+ stage: status?.stage!,
727
+ queue: true,
728
+ endpoint: _endpoint,
729
+ fn_index
730
+ });
731
+ }
732
+ if (data) {
733
+ fire_event({
734
+ type: "data",
735
+ time: new Date(),
736
+ data: transform_files
737
+ ? transform_output(
738
+ data.data,
739
+ api_info,
740
+ config.root,
741
+ config.root_url
742
+ )
743
+ : data.data,
744
+ endpoint: _endpoint,
745
+ fn_index
746
+ });
747
+
748
+ if (complete) {
749
+ fire_event({
750
+ type: "status",
751
+ time: new Date(),
752
+ ...complete,
753
+ stage: status?.stage!,
754
+ queue: true,
755
+ endpoint: _endpoint,
756
+ fn_index
757
+ });
758
+ eventSource.close();
759
+ }
760
+ }
761
+ };
639
762
  }
640
763
  });
641
764
 
@@ -683,12 +806,19 @@ export function api_factory(
683
806
  fn_index: fn_index
684
807
  });
685
808
 
686
- if (websocket && websocket.readyState === 0) {
687
- websocket.addEventListener("open", () => {
809
+ let cancel_request = {};
810
+ if (protocol === "ws") {
811
+ if (websocket && websocket.readyState === 0) {
812
+ websocket.addEventListener("open", () => {
813
+ websocket.close();
814
+ });
815
+ } else {
688
816
  websocket.close();
689
- });
817
+ }
818
+ cancel_request = { fn_index, session_hash };
690
819
  } else {
691
- websocket.close();
820
+ eventSource.close();
821
+ cancel_request = { event_id };
692
822
  }
693
823
 
694
824
  try {
@@ -701,7 +831,7 @@ export function api_factory(
701
831
  {
702
832
  headers: { "Content-Type": "application/json" },
703
833
  method: "POST",
704
- body: JSON.stringify({ fn_index, session_hash })
834
+ body: JSON.stringify(cancel_request)
705
835
  }
706
836
  );
707
837
  } catch (e) {
@@ -845,28 +975,21 @@ export function api_factory(
845
975
  );
846
976
 
847
977
  return Promise.all(
848
- blob_refs.map(async ({ path, blob, data, type }) => {
978
+ blob_refs.map(async ({ path, blob, type }) => {
849
979
  if (blob) {
850
980
  const file_url = (await upload_files(endpoint, [blob], token))
851
981
  .files[0];
852
- return { path, file_url, type };
982
+ return { path, file_url, type, name: blob?.name };
853
983
  }
854
- return { path, base64: data, type };
984
+ return { path, type };
855
985
  })
856
986
  ).then((r) => {
857
- r.forEach(({ path, file_url, base64, type }) => {
858
- if (base64) {
859
- update_object(data, base64, path);
860
- } else if (type === "Gallery") {
987
+ r.forEach(({ path, file_url, type, name }) => {
988
+ if (type === "Gallery") {
861
989
  update_object(data, file_url, path);
862
990
  } else if (file_url) {
863
- const o = {
864
- is_file: true,
865
- name: `${file_url}`,
866
- data: null
867
- // orig_name: "file.csv"
868
- };
869
- update_object(data, o, path);
991
+ const file = new FileData({ path: file_url, orig_name: name });
992
+ update_object(data, file, path);
870
993
  }
871
994
  });
872
995
 
@@ -895,57 +1018,13 @@ function transform_output(
895
1018
  ? [normalise_file(img[0], root_url, remote_url), img[1]]
896
1019
  : [normalise_file(img, root_url, remote_url), null];
897
1020
  });
898
- } else if (typeof d === "object" && d?.is_file) {
1021
+ } else if (typeof d === "object" && d.path) {
899
1022
  return normalise_file(d, root_url, remote_url);
900
1023
  }
901
1024
  return d;
902
1025
  });
903
1026
  }
904
1027
 
905
- function normalise_file(
906
- file: FileData[],
907
- root: string,
908
- root_url: string | null
909
- ): FileData[];
910
- function normalise_file(
911
- file: FileData | string,
912
- root: string,
913
- root_url: string | null
914
- ): FileData;
915
- function normalise_file(
916
- file: null,
917
- root: string,
918
- root_url: string | null
919
- ): null;
920
- function normalise_file(file, root, root_url): FileData[] | FileData | null {
921
- if (file == null) return null;
922
- if (typeof file === "string") {
923
- return {
924
- name: "file_data",
925
- data: file
926
- };
927
- } else if (Array.isArray(file)) {
928
- const normalized_file: (FileData | null)[] = [];
929
-
930
- for (const x of file) {
931
- if (x === null) {
932
- normalized_file.push(null);
933
- } else {
934
- normalized_file.push(normalise_file(x, root, root_url));
935
- }
936
- }
937
-
938
- return normalized_file as FileData[];
939
- } else if (file.is_file) {
940
- if (!root_url) {
941
- file.data = root + "/file=" + file.name;
942
- } else {
943
- file.data = "/proxy=" + root_url + "file=" + file.name;
944
- }
945
- }
946
- return file;
947
- }
948
-
949
1028
  interface ApiData {
950
1029
  label: string;
951
1030
  type: {
@@ -1112,7 +1191,6 @@ export async function walk_and_store_blobs(
1112
1191
  ): Promise<
1113
1192
  {
1114
1193
  path: string[];
1115
- data: string | false;
1116
1194
  type: string;
1117
1195
  blob: Blob | false;
1118
1196
  }[]
@@ -1144,28 +1222,9 @@ export async function walk_and_store_blobs(
1144
1222
  {
1145
1223
  path: path,
1146
1224
  blob: is_image ? false : new NodeBlob([param]),
1147
- data: is_image ? `${param.toString("base64")}` : false,
1148
1225
  type
1149
1226
  }
1150
1227
  ];
1151
- } else if (
1152
- param instanceof Blob ||
1153
- (typeof window !== "undefined" && param instanceof File)
1154
- ) {
1155
- if (type === "Image") {
1156
- let data;
1157
-
1158
- if (typeof window !== "undefined") {
1159
- // browser
1160
- data = await image_to_data_uri(param);
1161
- } else {
1162
- const buffer = await param.arrayBuffer();
1163
- data = Buffer.from(buffer).toString("base64");
1164
- }
1165
-
1166
- return [{ path, data, type, blob: false }];
1167
- }
1168
- return [{ path: path, blob: param, type, data: false }];
1169
1228
  } else if (typeof param === "object") {
1170
1229
  let blob_refs = [];
1171
1230
  for (let key in param) {
package/src/index.ts CHANGED
@@ -6,3 +6,10 @@ export {
6
6
  api_factory
7
7
  } from "./client.js";
8
8
  export type { SpaceStatus } from "./types.js";
9
+ export {
10
+ normalise_file,
11
+ FileData,
12
+ upload,
13
+ get_fetchable_url_or_file,
14
+ prepare_files
15
+ } from "./upload.js";
package/src/types.ts CHANGED
@@ -18,6 +18,7 @@ export interface Config {
18
18
  show_api: boolean;
19
19
  stylesheets: string[];
20
20
  path: string;
21
+ protocol?: "sse" | "ws";
21
22
  }
22
23
 
23
24
  export interface Payload {
package/src/upload.ts ADDED
@@ -0,0 +1,173 @@
1
+ import { upload_files } from "./client";
2
+
3
+ export function normalise_file(
4
+ file: FileData | null,
5
+ server_url: string,
6
+ proxy_url: string | null
7
+ ): FileData | null;
8
+
9
+ export function normalise_file(
10
+ file: FileData[] | null,
11
+ server_url: string,
12
+ proxy_url: string | null
13
+ ): FileData[] | null;
14
+
15
+ export function normalise_file(
16
+ file: FileData[] | FileData | null,
17
+ server_url: string, // root: string,
18
+ proxy_url: string | null // root_url: string | null
19
+ ): FileData[] | FileData | null;
20
+
21
+ export function normalise_file(
22
+ file: FileData[] | FileData | null,
23
+ server_url: string, // root: string,
24
+ proxy_url: string | null // root_url: string | null
25
+ ): FileData[] | FileData | null {
26
+ if (file == null) {
27
+ return null;
28
+ }
29
+
30
+ if (Array.isArray(file)) {
31
+ const normalized_file: (FileData | null)[] = [];
32
+
33
+ for (const x of file) {
34
+ if (x == null) {
35
+ normalized_file.push(null);
36
+ } else {
37
+ normalized_file.push(normalise_file(x, server_url, proxy_url));
38
+ }
39
+ }
40
+
41
+ return normalized_file as FileData[];
42
+ }
43
+
44
+ if (file.is_stream) {
45
+ if (proxy_url == null) {
46
+ return new FileData({
47
+ ...file,
48
+ url: server_url + "/stream/" + file.path
49
+ });
50
+ }
51
+ return new FileData({
52
+ ...file,
53
+ url: "/proxy=" + proxy_url + "stream/" + file.path
54
+ });
55
+ }
56
+
57
+ return new FileData({
58
+ ...file,
59
+ url: get_fetchable_url_or_file(file.path, server_url, proxy_url)
60
+ });
61
+ }
62
+
63
+ function is_url(str: string): boolean {
64
+ try {
65
+ const url = new URL(str);
66
+ return url.protocol === "http:" || url.protocol === "https:";
67
+ } catch {
68
+ return false;
69
+ }
70
+ }
71
+
72
+ export function get_fetchable_url_or_file(
73
+ path: string | null,
74
+ server_url: string,
75
+ proxy_url: string | null
76
+ ): string {
77
+ if (path == null) {
78
+ return proxy_url ? `/proxy=${proxy_url}file=` : `${server_url}/file=`;
79
+ }
80
+ if (is_url(path)) {
81
+ return path;
82
+ }
83
+ return proxy_url
84
+ ? `/proxy=${proxy_url}file=${path}`
85
+ : `${server_url}/file=${path}`;
86
+ }
87
+
88
+ export async function upload(
89
+ file_data: FileData[],
90
+ root: string,
91
+ upload_fn: typeof upload_files = upload_files
92
+ ): Promise<(FileData | null)[] | null> {
93
+ let files = (Array.isArray(file_data) ? file_data : [file_data]).map(
94
+ (file_data) => file_data.blob!
95
+ );
96
+
97
+ return await Promise.all(
98
+ await upload_fn(root, files).then(
99
+ async (response: { files?: string[]; error?: string }) => {
100
+ if (response.error) {
101
+ throw new Error(response.error);
102
+ } else {
103
+ if (response.files) {
104
+ return response.files.map((f, i) => {
105
+ const file = new FileData({ ...file_data[i], path: f });
106
+
107
+ return normalise_file(file, root, null);
108
+ });
109
+ }
110
+
111
+ return [];
112
+ }
113
+ }
114
+ )
115
+ );
116
+ }
117
+
118
+ export async function prepare_files(
119
+ files: File[],
120
+ is_stream?: boolean
121
+ ): Promise<FileData[]> {
122
+ return files.map(
123
+ (f, i) =>
124
+ new FileData({
125
+ path: f.name,
126
+ orig_name: f.name,
127
+ blob: f,
128
+ size: f.size,
129
+ mime_type: f.type,
130
+ is_stream
131
+ })
132
+ );
133
+ }
134
+
135
+ export class FileData {
136
+ path: string;
137
+ url?: string;
138
+ orig_name: string;
139
+ size?: number;
140
+ blob?: File;
141
+ is_stream?: boolean;
142
+ mime_type?: string;
143
+ alt_text?: string;
144
+
145
+ constructor({
146
+ path,
147
+ url,
148
+ orig_name,
149
+ size,
150
+ blob,
151
+ is_stream,
152
+ mime_type,
153
+ alt_text
154
+ }: {
155
+ path: string;
156
+ url?: string;
157
+ orig_name: string;
158
+ size?: number;
159
+ blob?: File;
160
+ is_stream?: boolean;
161
+ mime_type?: string;
162
+ alt_text?: string;
163
+ }) {
164
+ this.path = path;
165
+ this.url = url;
166
+ this.orig_name = orig_name;
167
+ this.size = size;
168
+ this.blob = url ? undefined : blob;
169
+ this.is_stream = is_stream;
170
+ this.mime_type = mime_type;
171
+ this.alt_text = alt_text;
172
+ }
173
+ }
package/src/utils.ts CHANGED
@@ -92,7 +92,7 @@ export async function process_endpoint(
92
92
  space_id: app_reference,
93
93
  ...determine_protocol(_host)
94
94
  };
95
- } catch (e) {
95
+ } catch (e: any) {
96
96
  throw new Error("Space metadata could not be loaded." + e.message);
97
97
  }
98
98
  }
@@ -167,7 +167,7 @@ export async function get_space_hardware(
167
167
  const { hardware } = await res.json();
168
168
 
169
169
  return hardware;
170
- } catch (e) {
170
+ } catch (e: any) {
171
171
  throw new Error(e.message);
172
172
  }
173
173
  }
@@ -196,7 +196,7 @@ export async function set_space_hardware(
196
196
  const { hardware } = await res.json();
197
197
 
198
198
  return hardware;
199
- } catch (e) {
199
+ } catch (e: any) {
200
200
  throw new Error(e.message);
201
201
  }
202
202
  }
@@ -225,7 +225,7 @@ export async function set_space_timeout(
225
225
  const { hardware } = await res.json();
226
226
 
227
227
  return hardware;
228
- } catch (e) {
228
+ } catch (e: any) {
229
229
  throw new Error(e.message);
230
230
  }
231
231
  }
package/tsconfig.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "outDir": "dist",
9
9
  "declarationMap": true,
10
10
  "module": "es2020",
11
- "moduleResolution": "node16",
11
+ "moduleResolution": "bundler",
12
12
  "skipDefaultLibCheck": true
13
13
  }
14
14
  }
package/vite.config.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { defineConfig } from "vite";
2
+ import { svelte } from "@sveltejs/vite-plugin-svelte";
3
+ import { fileURLToPath } from "url";
4
+ import path from "path";
5
+ const __dirname = fileURLToPath(new URL(".", import.meta.url));
2
6
 
3
7
  export default defineConfig({
4
8
  build: {
5
- // minify: true,
6
9
  lib: {
7
10
  entry: "src/index.ts",
8
11
  formats: ["es"]
@@ -14,10 +17,22 @@ export default defineConfig({
14
17
  }
15
18
  }
16
19
  },
20
+ plugins: [
21
+ svelte()
22
+ // {
23
+ // name: "resolve-gradio-client",
24
+ // enforce: "pre",
25
+ // resolveId(id) {
26
+ // if (id === "@gradio/client") {
27
+ // return path.join(__dirname, "src", "index.ts");
28
+ // }
29
+ // }
30
+ // }
31
+ ],
17
32
 
18
33
  ssr: {
19
34
  target: "node",
20
35
  format: "esm",
21
- noExternal: ["ws", "semiver"]
36
+ noExternal: ["ws", "semiver", "@gradio/upload"]
22
37
  }
23
38
  });