ZTWHHH commited on
Commit
c95f9fe
·
verified ·
1 Parent(s): 52ad5e3

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. evalkit_tf437/lib/python3.10/site-packages/PIL/_imagingmath.cpython-310-x86_64-linux-gnu.so +3 -0
  3. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/accordion/package.json +34 -0
  4. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/accordion/shared/Accordion.svelte +35 -0
  5. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/CHANGELOG.md +770 -0
  6. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/client.ts +525 -0
  7. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/globals.d.ts +11 -0
  8. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/api_info.ts +458 -0
  9. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/data.ts +221 -0
  10. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/init_helpers.ts +226 -0
  11. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/spaces.ts +252 -0
  12. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/index.ts +23 -0
  13. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/types.ts +392 -0
  14. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/upload.ts +109 -0
  15. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/post_data.ts +38 -0
  16. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/predict.ts +51 -0
  17. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/stream.ts +228 -0
  18. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/submit.ts +862 -0
  19. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/upload_files.ts +52 -0
  20. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/view_api.ts +71 -0
  21. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/vite-env.d.ts +1 -0
  22. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/tsconfig.json +27 -0
  23. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/Index.svelte +159 -0
  24. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/package.json +52 -0
  25. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/Arrow.svelte +10 -0
  26. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/CellMenu.svelte +111 -0
  27. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/Example.svelte +29 -0
  28. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/Table.svelte +1235 -0
  29. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/VirtualTable.svelte +346 -0
  30. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/utils.ts +7 -0
  31. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/datetime/Example.svelte +5 -0
  32. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/datetime/Index.svelte +215 -0
  33. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dropdown/shared/Dropdown.svelte +327 -0
  34. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dropdown/shared/Multiselect.svelte +421 -0
  35. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dropdown/shared/utils.ts +56 -0
  36. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/group/Index.svelte +43 -0
  37. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/html/package.json +45 -0
  38. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/markdown/Index.svelte +87 -0
  39. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/markdown/shared/MarkdownCode.svelte +211 -0
  40. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/markdown/shared/prism-dark.css +68 -0
  41. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/nativeplot/Example.svelte +11 -0
  42. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/nativeplot/Index.svelte +552 -0
  43. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/nativeplot/package.json +44 -0
  44. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/number/Index.svelte +131 -0
  45. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/simpledropdown/Example.svelte +19 -0
  46. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/simpledropdown/Index.svelte +107 -0
  47. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/simpletextbox/Index.svelte +130 -0
  48. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/uploadbutton/Index.svelte +67 -0
  49. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/uploadbutton/package.json +36 -0
  50. evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/utils/src/color.ts +5 -0
.gitattributes CHANGED
@@ -278,3 +278,4 @@ evalkit_tf437/lib/python3.10/site-packages/yarl/_quoting_c.cpython-310-x86_64-li
278
  evalkit_tf437/lib/python3.10/site-packages/sklearn/linear_model/_cd_fast.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
279
  evalkit_tf437/lib/python3.10/site-packages/sklearn/neighbors/_ball_tree.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
280
  evalkit_tf437/lib/python3.10/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/Index.DMrntMgy.js.br filter=lfs diff=lfs merge=lfs -text
 
 
278
  evalkit_tf437/lib/python3.10/site-packages/sklearn/linear_model/_cd_fast.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
279
  evalkit_tf437/lib/python3.10/site-packages/sklearn/neighbors/_ball_tree.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
280
  evalkit_tf437/lib/python3.10/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/Index.DMrntMgy.js.br filter=lfs diff=lfs merge=lfs -text
281
+ evalkit_tf437/lib/python3.10/site-packages/PIL/_imagingmath.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
evalkit_tf437/lib/python3.10/site-packages/PIL/_imagingmath.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b924e5a01637def5d586a728eaa6d935f185c4f146499cfe7dfec308f1334ec
3
+ size 149184
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/accordion/package.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/accordion",
3
+ "version": "0.4.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "main_changeset": true,
9
+ "dependencies": {
10
+ "@gradio/atoms": "workspace:^",
11
+ "@gradio/column": "workspace:^",
12
+ "@gradio/statustracker": "workspace:^",
13
+ "@gradio/utils": "workspace:^"
14
+ },
15
+ "peerDependencies": {
16
+ "svelte": "^4.0.0"
17
+ },
18
+ "devDependencies": {
19
+ "@gradio/preview": "workspace:^"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "gradio": "./Index.svelte",
24
+ "svelte": "./dist/Index.svelte",
25
+ "types": "./dist/Index.svelte.d.ts"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/gradio-app/gradio.git",
32
+ "directory": "js/accordion"
33
+ }
34
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/accordion/shared/Accordion.svelte ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let open = true;
3
+ export let label = "";
4
+ </script>
5
+
6
+ <button on:click={() => (open = !open)} class="label-wrap" class:open>
7
+ <span>{label}</span>
8
+ <span style:transform={open ? "rotate(0)" : "rotate(90deg)"} class="icon">
9
+
10
+ </span>
11
+ </button>
12
+ <div style:display={open ? "block" : "none"}>
13
+ <slot />
14
+ </div>
15
+
16
+ <style>
17
+ span {
18
+ font-weight: var(--section-header-text-weight);
19
+ font-size: var(--section-header-text-size);
20
+ }
21
+ .label-wrap {
22
+ display: flex;
23
+ justify-content: space-between;
24
+ cursor: pointer;
25
+ width: var(--size-full);
26
+ color: var(--accordion-text-color);
27
+ }
28
+ .label-wrap.open {
29
+ margin-bottom: var(--size-2);
30
+ }
31
+
32
+ .icon {
33
+ transition: 150ms;
34
+ }
35
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/CHANGELOG.md ADDED
@@ -0,0 +1,770 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # @gradio/client
2
+
3
+ ## 1.6.0
4
+
5
+ ### Features
6
+
7
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - Disable liking user message in chatbot by default but make it configurable
8
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - Open audio/image input stream only when queue is ready
9
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - Send Streaming data over Websocket if possible. Also support base64 output format for images.
10
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - Streaming inputs for 5.0
11
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - fix SSR apps on spaces
12
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - Ssr part 2
13
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - prefix api routes
14
+
15
+ ### Fixes
16
+
17
+
18
+ - [#8843](https://github.com/gradio-app/gradio/pull/8843) [`6f95286`](https://github.com/gradio-app/gradio/commit/6f95286337459efbccb95c9cfac63355669df9ee) - Trigger state change event on iterators
19
+
20
+ ## 1.6.0-beta.4
21
+
22
+ ### Features
23
+
24
+ - [#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!
25
+
26
+ ## 1.6.0-beta.3
27
+
28
+ ### Features
29
+
30
+ - [#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!
31
+
32
+ ## 1.6.0-beta.2
33
+
34
+ ### Features
35
+
36
+ - [#9323](https://github.com/gradio-app/gradio/pull/9323) [`06babda`](https://github.com/gradio-app/gradio/commit/06babda0395fd3fbd323c1c3cb33704ecfd6deb0) - Disable liking user message in chatbot by default but make it configurable. Thanks @freddyaboulton!
37
+ - [#9339](https://github.com/gradio-app/gradio/pull/9339) [`4c8c6f2`](https://github.com/gradio-app/gradio/commit/4c8c6f2fe603081941c5fdc43f48a0632b9f31ad) - Ssr part 2. Thanks @pngwn!
38
+
39
+ ### Fixes
40
+
41
+ - [#9299](https://github.com/gradio-app/gradio/pull/9299) [`aa35b07`](https://github.com/gradio-app/gradio/commit/aa35b0788e613fdd45446d267513e6f94fa208ea) - Trigger state change event on iterators. Thanks @freddyaboulton!
42
+
43
+ ## 1.6.0-beta.1
44
+
45
+ ### Features
46
+
47
+ - [#9200](https://github.com/gradio-app/gradio/pull/9200) [`2e179d3`](https://github.com/gradio-app/gradio/commit/2e179d35be6ed60a5a6bfc7303178d63e41781ad) - prefix api routes. Thanks @pngwn!
48
+
49
+ ## 1.6.0-beta.0
50
+
51
+ ### Features
52
+
53
+ - [#9149](https://github.com/gradio-app/gradio/pull/9149) [`3d7a9b8`](https://github.com/gradio-app/gradio/commit/3d7a9b81f6fef06187eca832471dc1692eb493a0) - Open audio/image input stream only when queue is ready. Thanks @freddyaboulton!
54
+ - [#8941](https://github.com/gradio-app/gradio/pull/8941) [`97a7bf6`](https://github.com/gradio-app/gradio/commit/97a7bf66a79179d1b91a3199d68e5c11216ca500) - Streaming inputs for 5.0. Thanks @freddyaboulton!
55
+
56
+ ## 1.5.2
57
+
58
+ ### Fixes
59
+
60
+ - [#9163](https://github.com/gradio-app/gradio/pull/9163) [`2b6cbf2`](https://github.com/gradio-app/gradio/commit/2b6cbf25908e42cf027324e54ef2cc0baad11a91) - fix exports and generate types. Thanks @pngwn!
61
+
62
+ ## 1.5.1
63
+
64
+ ### Features
65
+
66
+ - [#9118](https://github.com/gradio-app/gradio/pull/9118) [`e1c404d`](https://github.com/gradio-app/gradio/commit/e1c404da1143fb52b659d03e028bdba1badf443d) - setup npm-previews of all packages. Thanks @pngwn!
67
+
68
+ ## 1.5.0
69
+
70
+ ### Features
71
+
72
+ - [#8965](https://github.com/gradio-app/gradio/pull/8965) [`d30432e`](https://github.com/gradio-app/gradio/commit/d30432e9c6d4cc1e5cfd989a1a3ae4aba7e21290) - harden CI. Thanks @pngwn!
73
+
74
+ ### Fixes
75
+
76
+ - [#8847](https://github.com/gradio-app/gradio/pull/8847) [`4d8a473`](https://github.com/gradio-app/gradio/commit/4d8a473632e388a312aee5c705b3c1f79853441b) - fix: wrong named param check for js client. Thanks @freddyaboulton!
77
+
78
+ ## 1.4.0
79
+
80
+ ### Features
81
+
82
+ - [#8816](https://github.com/gradio-app/gradio/pull/8816) [`9ee6839`](https://github.com/gradio-app/gradio/commit/9ee6839f94d23d685a800ed3a275206e0b0e48f6) - Change optionality of the `data` param in `submit` + `predict`. Thanks @hannahblair!
83
+
84
+ ### Fixes
85
+
86
+ - [#8820](https://github.com/gradio-app/gradio/pull/8820) [`5050b36`](https://github.com/gradio-app/gradio/commit/5050b36221e75a18d8a5d4f74a725e70768a4c4a) - fix: wrong named param check for js client. Thanks @JacobLinCool!
87
+
88
+ ## 1.3.0
89
+
90
+ ### Fixes
91
+
92
+ - [#8699](https://github.com/gradio-app/gradio/pull/8699) [`012da05`](https://github.com/gradio-app/gradio/commit/012da05287846d94beb0ecdc28d7fbc48c4248ff) - Ensure JS client `status_callback` functionality works and improve status messages. Thanks @hannahblair!
93
+ - [#8505](https://github.com/gradio-app/gradio/pull/8505) [`2943d6d`](https://github.com/gradio-app/gradio/commit/2943d6d68847314885dc6c5c0247083116017ca0) - Add Timer component. Thanks @aliabid94!
94
+ - [#8715](https://github.com/gradio-app/gradio/pull/8715) [`a6b3c6c`](https://github.com/gradio-app/gradio/commit/a6b3c6ce4e1d06253860c72740024a9138e3a93a) - Ensure `@gradio/client`'s `submit` iterator releases as expected. Thanks @pngwn!
95
+ - [#8716](https://github.com/gradio-app/gradio/pull/8716) [`e834d30`](https://github.com/gradio-app/gradio/commit/e834d302e44f7a54565129bf2c11acf4e882a59b) - ensure `@gradio/client` always returns the correct data. Thanks @pngwn!
96
+ - [#8714](https://github.com/gradio-app/gradio/pull/8714) [`1b5b5b0`](https://github.com/gradio-app/gradio/commit/1b5b5b0b43e69ee84f3baad2aae59ffc9c4d995a) - Bind `fetch` and `stream` in JS client. Thanks @hannahblair!
97
+ - [#8720](https://github.com/gradio-app/gradio/pull/8720) [`936c713`](https://github.com/gradio-app/gradio/commit/936c7137a99ef59efdf75bae5dd27eea2ac1f577) - Documents auth in the guides, in the view API page, and also types the Blocks.config object. Thanks @abidlabs!
98
+
99
+ ## 1.2.1
100
+
101
+ ### Features
102
+
103
+ - [#8649](https://github.com/gradio-app/gradio/pull/8649) [`4b6c8b1`](https://github.com/gradio-app/gradio/commit/4b6c8b1c004cee67345a7f103ba2dc8e90b82e6c) - ensure `File` objects are handled in JS client `handle_file`. Thanks @hannahblair!
104
+
105
+ ## 1.2.0
106
+
107
+ ### Features
108
+
109
+ - [#8489](https://github.com/gradio-app/gradio/pull/8489) [`c2a0d05`](https://github.com/gradio-app/gradio/commit/c2a0d056d679d90631d9ccd944dadd67e7e03b7f) - Control Display of Error, Info, Warning. Thanks @freddyaboulton!
110
+ - [#8571](https://github.com/gradio-app/gradio/pull/8571) [`a77877f`](https://github.com/gradio-app/gradio/commit/a77877f62df7c610fcfac7b3b00e186a087c8ec6) - First time loading performance optimization. Thanks @baojianting!
111
+ - [#8600](https://github.com/gradio-app/gradio/pull/8600) [`7289c4b`](https://github.com/gradio-app/gradio/commit/7289c4b036d8a78c48f8c9e66ba998e6730e80d2) - Add credentials: include and Cookie header to prevent 401 error. Thanks @yinkiu602!
112
+ - [#8522](https://github.com/gradio-app/gradio/pull/8522) [`bdaa678`](https://github.com/gradio-app/gradio/commit/bdaa678d0c0a22250b41104f32e9121f98dc7437) - add handle_file docs. Thanks @pngwn!
113
+
114
+ ### Fixes
115
+
116
+ - [#8521](https://github.com/gradio-app/gradio/pull/8521) [`900cf25`](https://github.com/gradio-app/gradio/commit/900cf25256a5b0563860097d69aac28b6afbfd8b) - Ensure frontend functions work when they don't return a value. Thanks @pngwn!
117
+ - [#8548](https://github.com/gradio-app/gradio/pull/8548) [`7fc0f51`](https://github.com/gradio-app/gradio/commit/7fc0f5149bb8d31f3d01b4151b478070499751ee) - Fix reload mode by implementing `close` on the client. Thanks @freddyaboulton!
118
+
119
+ ## 1.1.1
120
+
121
+ ### Features
122
+
123
+ - [#8499](https://github.com/gradio-app/gradio/pull/8499) [`c5f6e77`](https://github.com/gradio-app/gradio/commit/c5f6e7722a197d4706419ade14276ddecf3196f8) - Cache break themes on change. Thanks @aliabid94!
124
+
125
+ ## 1.1.0
126
+
127
+ ### Features
128
+
129
+ - [#8483](https://github.com/gradio-app/gradio/pull/8483) [`e2271e2`](https://github.com/gradio-app/gradio/commit/e2271e207d98074bf39b02ae3c5443b2f097627d) - documentation for @gradio/client. Thanks @pngwn!
130
+ - [#8485](https://github.com/gradio-app/gradio/pull/8485) [`f8ebace`](https://github.com/gradio-app/gradio/commit/f8ebaceccef60a112603d290d10072ef4e938a6a) - Ensure all status are reported internally when calling `predict`. Thanks @pngwn!
131
+
132
+ ## 1.0.0
133
+
134
+ ### Highlights
135
+
136
+ #### Clients 1.0 Launch! ([#8468](https://github.com/gradio-app/gradio/pull/8468) [`7cc0a0c`](https://github.com/gradio-app/gradio/commit/7cc0a0c1abea585c3f50ffb1ff78d2b08ddbdd92))
137
+
138
+ We're excited to unveil the first major release of the Gradio clients.
139
+ We've made it even easier to turn any Gradio application into a production endpoint thanks to the clients' **ergonomic**, **transparent**, and **portable** design.
140
+
141
+ #### Ergonomic API 💆
142
+
143
+ **Stream From a Gradio app in 5 lines**
144
+
145
+ Use the `submit` method to get a job you can iterate over:
146
+
147
+ ```python
148
+ from gradio_client import Client
149
+
150
+ client = Client("gradio/llm_stream")
151
+
152
+ for result in client.submit("What's the best UI framework in Python?"):
153
+ print(result)
154
+ ```
155
+
156
+ ```ts
157
+ import { Client } from "@gradio/client";
158
+
159
+ const client = await Client.connect("gradio/llm_stream")
160
+ const job = client.submit("/predict", {"text": "What's the best UI framework in Python?"})
161
+
162
+ for await (const msg of job) console.log(msg.data)
163
+ ```
164
+
165
+ **Use the same keyword arguments as the app**
166
+
167
+
168
+ ```python
169
+ from gradio_client import Client
170
+
171
+ client = Client("http://127.0.0.1:7860/")
172
+ result = client.predict(
173
+ message="Hello!!",
174
+ system_prompt="You are helpful AI.",
175
+ tokens=10,
176
+ api_name="/chat"
177
+ )
178
+ print(result)
179
+ ```
180
+
181
+ ```ts
182
+ import { Client } from "@gradio/client";
183
+
184
+ const client = await Client.connect("http://127.0.0.1:7860/");
185
+ const result = await client.predict("/chat", {
186
+ message: "Hello!!",
187
+ system_prompt: "Hello!!",
188
+ tokens: 10,
189
+ });
190
+
191
+ console.log(result.data);
192
+ ```
193
+
194
+ **Better Error Messages**
195
+
196
+ If something goes wrong in the upstream app, the client will raise the same exception as the app provided that `show_error=True` in the original app's `launch()` function, or it's a `gr.Error` exception.
197
+
198
+ #### Transparent Design 🪟
199
+
200
+ Anything you can do in the UI, you can do with the client:
201
+ * 🔒 Authentication
202
+ * 🛑 Job Cancelling
203
+ * ℹ️ Access Queue Position and API
204
+ * 📕 View the API information
205
+
206
+ Here's an example showing how to display the queue position of a pending job:
207
+
208
+ ```python
209
+ from gradio_client import Client
210
+
211
+ client = Client("gradio/diffusion_model")
212
+
213
+ job = client.submit("A cute cat")
214
+ while not job.done():
215
+ status = job.status()
216
+ print(f"Current in position {status.rank} out of {status.queue_size}")
217
+ ```
218
+
219
+ #### Portable Design ⛺️
220
+
221
+ The client can run from pretty much any python and javascript environment (node, deno, the browser, Service Workers).
222
+
223
+ Here's an example using the client from a Flask server using gevent:
224
+
225
+ ```python
226
+ from gevent import monkey
227
+ monkey.patch_all()
228
+
229
+ from gradio_client import Client
230
+ from flask import Flask, send_file
231
+ import time
232
+
233
+ app = Flask(__name__)
234
+
235
+ imageclient = Client("gradio/diffusion_model")
236
+
237
+ @app.route("/gen")
238
+ def gen():
239
+ result = imageclient.predict(
240
+ "A cute cat",
241
+ api_name="/predict"
242
+ )
243
+ return send_file(result)
244
+
245
+ if __name__ == "__main__":
246
+ app.run(host="0.0.0.0", port=5000)
247
+ ```
248
+
249
+ #### 1.0 Migration Guide and Breaking Changes
250
+
251
+ **Python**
252
+ - The `serialize` argument of the `Client` class was removed. Has no effect.
253
+ - The `upload_files` argument of the `Client` was removed.
254
+ - All filepaths must be wrapped in the `handle_file` method. Example:
255
+ ```python
256
+ from gradio_client import Client, handle_file
257
+
258
+ client = Client("gradio/image_captioner")
259
+ client.predict(handle_file("cute_cat.jpg"))
260
+ ```
261
+ - The `output_dir` argument was removed. It is not specified in the `download_files` argument.
262
+
263
+
264
+ **Javascript**
265
+ The client has been redesigned entirely. It was refactored from a function into a class. An instance can now be constructed by awaiting the `connect` method.
266
+
267
+ ```js
268
+ const app = await Client.connect("gradio/whisper")
269
+ ```
270
+ The app variable has the same methods as the python class (`submit`, `predict`, `view_api`, `duplicate`).
271
+
272
+
273
+
274
+ #### Additional Changes
275
+
276
+ - [#8243](https://github.com/gradio-app/gradio/pull/8243) - Set orig_name in python client file uploads.
277
+ - [#8264](https://github.com/gradio-app/gradio/pull/8264) - Make exceptions in the Client more specific.
278
+ - [#8247](https://github.com/gradio-app/gradio/pull/8247) - Fix api recorder.
279
+ - [#8276](https://github.com/gradio-app/gradio/pull/8276) - Fix bug where client could not connect to apps that had self signed certificates.
280
+ - [#8245](https://github.com/gradio-app/gradio/pull/8245) - Cancel server progress from the python client.
281
+ - [#8200](https://github.com/gradio-app/gradio/pull/8200) - Support custom components in gr.load
282
+ - [#8182](https://github.com/gradio-app/gradio/pull/8182) - Convert sse calls in client from async to sync.
283
+ - [#7732](https://github.com/gradio-app/gradio/pull/7732) - Adds support for kwargs and default arguments in the python client, and improves how parameter information is displayed in the "view API" page.
284
+ - [#7888](https://github.com/gradio-app/gradio/pull/7888) - Cache view_api info in server and python client.
285
+ - [#7575](https://github.com/gradio-app/gradio/pull/7575) - Files should now be supplied as `file(...)` in the Client, and some fixes to `gr.load()` as well.
286
+ - [#8401](https://github.com/gradio-app/gradio/pull/8401) - Add CDN installation to JS docs.
287
+ - [#8299](https://github.com/gradio-app/gradio/pull/8299) - Allow JS Client to work with authenticated spaces 🍪.
288
+ - [#8408](https://github.com/gradio-app/gradio/pull/8408) - Connect heartbeat if state created in render. Also fix config cleanup bug #8407.
289
+ - [#8258](https://github.com/gradio-app/gradio/pull/8258) - Improve URL handling in JS Client.
290
+ - [#8322](https://github.com/gradio-app/gradio/pull/8322) - ensure the client correctly handles all binary data.
291
+ - [#8296](https://github.com/gradio-app/gradio/pull/8296) - always create a jwt when connecting to a space if a hf_token is present.
292
+ - [#8285](https://github.com/gradio-app/gradio/pull/8285) - use the correct query param to pass the jwt to the heartbeat event.
293
+ - [#8272](https://github.com/gradio-app/gradio/pull/8272) - ensure client works for private spaces.
294
+ - [#8197](https://github.com/gradio-app/gradio/pull/8197) - Add support for passing keyword args to `data` in JS client.
295
+ - [#8252](https://github.com/gradio-app/gradio/pull/8252) - Client node fix.
296
+ - [#8209](https://github.com/gradio-app/gradio/pull/8209) - Rename `eventSource_Factory` and `fetch_implementation`.
297
+ - [#8109](https://github.com/gradio-app/gradio/pull/8109) - Implement JS Client tests.
298
+ - [#8211](https://github.com/gradio-app/gradio/pull/8211) - remove redundant event source logic.
299
+ - [#8179](https://github.com/gradio-app/gradio/pull/8179) - rework upload to be a class method + pass client into each component.
300
+ - [#8181](https://github.com/gradio-app/gradio/pull/8181) - Ensure connectivity to private HF spaces with SSE protocol.
301
+ - [#8169](https://github.com/gradio-app/gradio/pull/8169) - Only connect to heartbeat if needed.
302
+ - [#8118](https://github.com/gradio-app/gradio/pull/8118) - Add eventsource polyfill for Node.js and browser environments.
303
+ - [#7646](https://github.com/gradio-app/gradio/pull/7646) - Refactor JS Client.
304
+ - [#7974](https://github.com/gradio-app/gradio/pull/7974) - Fix heartbeat in the js client to be Lite compatible.
305
+ - [#7926](https://github.com/gradio-app/gradio/pull/7926) - Fixes streaming event race condition.
306
+
307
+ Thanks @freddyaboulton!
308
+
309
+ ### Features
310
+
311
+ - [#8370](https://github.com/gradio-app/gradio/pull/8370) [`48eeea4`](https://github.com/gradio-app/gradio/commit/48eeea4eaab7e24168688e3c3fbafb30e4e78d51) - Refactor Cancelling Logic To Use /cancel. Thanks @freddyaboulton!
312
+
313
+ ### Fixes
314
+
315
+ - [#8477](https://github.com/gradio-app/gradio/pull/8477) [`d5a9604`](https://github.com/gradio-app/gradio/commit/d5a960493017a4890685af61d78ce7d3b3b12e6b) - Fix js client bundle. Thanks @pngwn!
316
+ - [#8451](https://github.com/gradio-app/gradio/pull/8451) [`9d2d605`](https://github.com/gradio-app/gradio/commit/9d2d6051caed5c8749a26a6fa7480a5ae6e6c4f3) - Change client submit API to be an AsyncIterable and support more platforms. Thanks @pngwn!
317
+ - [#8462](https://github.com/gradio-app/gradio/pull/8462) [`6447dfa`](https://github.com/gradio-app/gradio/commit/6447dface4d46db1c69460e8325a1928d0476a46) - Improve file handling in JS Client. Thanks @hannahblair!
318
+ - [#8439](https://github.com/gradio-app/gradio/pull/8439) [`63d36fb`](https://github.com/gradio-app/gradio/commit/63d36fbbf4bf6dc909be9a0ffc7b6bf6621d83e8) - Handle gradio apps using `state` in the JS Client. Thanks @hannahblair!
319
+
320
+ ## 0.20.1
321
+
322
+ ### Features
323
+
324
+ - [#8415](https://github.com/gradio-app/gradio/pull/8415) [`227de35`](https://github.com/gradio-app/gradio/commit/227de352982b3dcdf9384eaa28b7e9cf09afb6e8) - Fix spaces load error. Thanks @aliabid94!
325
+
326
+ ## 0.20.0
327
+
328
+ ### Features
329
+
330
+ - [#8401](https://github.com/gradio-app/gradio/pull/8401) [`d078621`](https://github.com/gradio-app/gradio/commit/d078621928136c09ca902d2f37594ed887c67d2e) - Add CDN installation to JS docs. Thanks @hannahblair!
331
+ - [#8243](https://github.com/gradio-app/gradio/pull/8243) [`55f664f`](https://github.com/gradio-app/gradio/commit/55f664f2979a49acc29a73cde16c6ebdfcc91db2) - Add event listener support to render blocks. Thanks @aliabid94!
332
+ - [#8398](https://github.com/gradio-app/gradio/pull/8398) [`945ac83`](https://github.com/gradio-app/gradio/commit/945ac837e779b120790814ea6f6f81bd2712f5f8) - Improve rendering. Thanks @aliabid94!
333
+ - [#8299](https://github.com/gradio-app/gradio/pull/8299) [`ab65360`](https://github.com/gradio-app/gradio/commit/ab653608045ff9462db7ad9fe63e1c60bf20e773) - Allow JS Client to work with authenticated spaces 🍪. Thanks @hannahblair!
334
+
335
+ ### Fixes
336
+
337
+ - [#8408](https://github.com/gradio-app/gradio/pull/8408) [`e86dd01`](https://github.com/gradio-app/gradio/commit/e86dd01b6e8f7bab3d3c25b84f2ad33129138af4) - Connect heartbeat if state created in render. Also fix config cleanup bug #8407. Thanks @freddyaboulton!
338
+ - [#8258](https://github.com/gradio-app/gradio/pull/8258) [`1f8e5c4`](https://github.com/gradio-app/gradio/commit/1f8e5c44e054b943052d8f24d044696ddfd01a54) - Improve URL handling in JS Client. Thanks @hannahblair!
339
+
340
+ ## 0.19.4
341
+
342
+ ### Fixes
343
+
344
+ - [#8322](https://github.com/gradio-app/gradio/pull/8322) [`47012a0`](https://github.com/gradio-app/gradio/commit/47012a0c4e3e8a80fcae620aaf08b16ceb343cde) - ensure the client correctly handles all binary data. Thanks @Saghen!
345
+
346
+ ## 0.19.3
347
+
348
+ ### Features
349
+
350
+ - [#8229](https://github.com/gradio-app/gradio/pull/8229) [`7c81897`](https://github.com/gradio-app/gradio/commit/7c81897076ddcd0bb05e0e4ffec35bb9a986d330) - chore(deps): update dependency esbuild to ^0.21.0. Thanks @renovate!
351
+
352
+ ### Fixes
353
+
354
+ - [#8296](https://github.com/gradio-app/gradio/pull/8296) [`929d216`](https://github.com/gradio-app/gradio/commit/929d216d49aa05614bc83f0761cf7b1cd803d8fe) - always create a jwt when connecting to a space if a hf_token is present. Thanks @pngwn!
355
+
356
+ ## 0.19.2
357
+
358
+ ### Fixes
359
+
360
+ - [#8285](https://github.com/gradio-app/gradio/pull/8285) [`7d9d8ea`](https://github.com/gradio-app/gradio/commit/7d9d8eab50d36cbecbb84c6a0f3cc1bca7215604) - use the correct query param to pass the jwt to the heartbeat event. Thanks @pngwn!
361
+
362
+ ## 0.19.1
363
+
364
+ ### Fixes
365
+
366
+ - [#8272](https://github.com/gradio-app/gradio/pull/8272) [`fbf4edd`](https://github.com/gradio-app/gradio/commit/fbf4edde7c896cdf4c903463e44c31ed96111b3c) - ensure client works for private spaces. Thanks @pngwn!
367
+
368
+ ## 0.19.0
369
+
370
+ ### Features
371
+
372
+ - [#8110](https://github.com/gradio-app/gradio/pull/8110) [`5436031`](https://github.com/gradio-app/gradio/commit/5436031f92c1596282eb64e1e74d555f279e9697) - Render decorator 2. Thanks @aliabid94!
373
+ - [#8197](https://github.com/gradio-app/gradio/pull/8197) [`e09b4e8`](https://github.com/gradio-app/gradio/commit/e09b4e8216b970bc1b142a0f08e7d190b954eb35) - Add support for passing keyword args to `data` in JS client. Thanks @hannahblair!
374
+
375
+ ### Fixes
376
+
377
+ - [#8252](https://github.com/gradio-app/gradio/pull/8252) [`22df61a`](https://github.com/gradio-app/gradio/commit/22df61a26adf8023f6dd49c051979990e8d3879a) - Client node fix. Thanks @pngwn!
378
+
379
+ ## 0.18.0
380
+
381
+ ### Features
382
+
383
+ - [#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!
384
+ - [#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!
385
+ - [#8109](https://github.com/gradio-app/gradio/pull/8109) [`bed2f82`](https://github.com/gradio-app/gradio/commit/bed2f82e2297b50f7b59423a3de05af0b9910724) - Implement JS Client tests. Thanks @hannahblair!
386
+ - [#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!
387
+
388
+ ### Fixes
389
+
390
+ - [#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!
391
+ - [#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!
392
+ - [#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!
393
+ - [#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!
394
+
395
+ ## 0.17.0
396
+
397
+ ### Highlights
398
+
399
+ #### Setting File Upload Limits ([#7909](https://github.com/gradio-app/gradio/pull/7909) [`2afca65`](https://github.com/gradio-app/gradio/commit/2afca6541912b37dc84f447c7ad4af21607d7c72))
400
+
401
+ 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).
402
+
403
+ The following code snippet sets a max file size of 5 megabytes.
404
+
405
+ ```python
406
+ import gradio as gr
407
+
408
+ demo = gr.Interface(lambda x: x, "image", "image")
409
+
410
+ demo.launch(max_file_size="5mb")
411
+ # or
412
+ demo.launch(max_file_size=5 * gr.FileSize.MB)
413
+ ```
414
+
415
+ ![max_file_size_upload](https://github.com/gradio-app/gradio/assets/41651716/7547330c-a082-4901-a291-3f150a197e45)
416
+
417
+
418
+ #### Error states can now be cleared
419
+
420
+ 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.
421
+
422
+ ![error_modal_calculator](https://github.com/gradio-app/gradio/assets/41651716/16cb071c-accd-45a6-9c18-0dea27d4bd98)
423
+
424
+ Thanks @freddyaboulton!
425
+
426
+ ### Features
427
+
428
+ - [#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!
429
+ - [#7646](https://github.com/gradio-app/gradio/pull/7646) [`450b8cc`](https://github.com/gradio-app/gradio/commit/450b8cc898f130f15caa3742f65c17b9f7a8f398) - Refactor JS Client. Thanks @hannahblair!
430
+ - [#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!
431
+
432
+ ### Fixes
433
+
434
+ - [#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!
435
+
436
+ ## 0.16.0
437
+
438
+ ### Features
439
+
440
+ - [#7845](https://github.com/gradio-app/gradio/pull/7845) [`dbb7373`](https://github.com/gradio-app/gradio/commit/dbb7373dde69d4ed2741942b5a1898f8620cec24) - ensure `ImageEditor` events work as expected. Thanks @pngwn!
441
+
442
+ ### Fixes
443
+
444
+ - [#7974](https://github.com/gradio-app/gradio/pull/7974) [`79e0aa8`](https://github.com/gradio-app/gradio/commit/79e0aa81c94e755faa6e85d76ac5d5a666313e6a) - Fix heartbeat in the js client to be Lite compatible. Thanks @whitphx!
445
+
446
+ ## 0.15.1
447
+
448
+ ### Fixes
449
+
450
+ - [#7926](https://github.com/gradio-app/gradio/pull/7926) [`9666854`](https://github.com/gradio-app/gradio/commit/966685479078f59430b3bced7e6068eb8157c003) - Fixes streaming event race condition. Thanks @aliabid94!
451
+
452
+ ## 0.15.0
453
+
454
+ ### Highlights
455
+
456
+ #### 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))
457
+
458
+ Gradio now automatically deletes `gr.State` variables stored in the server's RAM when users close their browser tab.
459
+ The deletion will happen 60 minutes after the server detected a disconnect from the user's browser.
460
+ If the user connects again in that timeframe, their state will not be deleted.
461
+
462
+ 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).
463
+ You can think of the `unload` event as the opposite of the `load` event.
464
+
465
+
466
+ ```python
467
+ with gr.Blocks() as demo:
468
+ gr.Markdown(
469
+ """# State Cleanup Demo
470
+ 🖼️ Images are saved in a user-specific directory and deleted when the users closes the page via demo.unload.
471
+ """)
472
+ with gr.Row():
473
+ with gr.Column(scale=1):
474
+ with gr.Row():
475
+ img = gr.Image(label="Generated Image", height=300, width=300)
476
+ with gr.Row():
477
+ gen = gr.Button(value="Generate")
478
+ with gr.Row():
479
+ history = gr.Gallery(label="Previous Generations", height=500, columns=10)
480
+ state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
481
+
482
+ demo.load(generate_random_img, [state], [img, state, history])
483
+ gen.click(generate_random_img, [state], [img, state, history])
484
+ demo.unload(delete_directory)
485
+
486
+
487
+ demo.launch(auth=lambda user,pwd: True,
488
+ auth_message="Enter any username and password to continue")
489
+ ```
490
+
491
+ Thanks @freddyaboulton!
492
+
493
+ ## 0.14.0
494
+
495
+ ### Features
496
+
497
+ - [#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!
498
+
499
+ ### Fixes
500
+
501
+ - [#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!
502
+
503
+ ## 0.13.0
504
+
505
+ ### Fixes
506
+
507
+ - [#7575](https://github.com/gradio-app/gradio/pull/7575) [`d0688b3`](https://github.com/gradio-app/gradio/commit/d0688b3c25feabb4fc7dfa0ab86086b3af7eb337) - Files should now be supplied as `file(...)` in the Client, and some fixes to `gr.load()` as well. Thanks @abidlabs!
508
+
509
+ ## 0.12.2
510
+
511
+ ### Features
512
+
513
+ - [#7528](https://github.com/gradio-app/gradio/pull/7528) [`eda33b3`](https://github.com/gradio-app/gradio/commit/eda33b3763897a542acf298e523fa493dc655aee) - Refactors `get_fetchable_url_or_file()` to remove it from the frontend. Thanks [@abidlabs](https://github.com/abidlabs)!
514
+ - [#7340](https://github.com/gradio-app/gradio/pull/7340) [`4b0d589`](https://github.com/gradio-app/gradio/commit/4b0d58933057432758a54169a360eb352903d6b4) - chore(deps): update all non-major dependencies. Thanks [@renovate](https://github.com/apps/renovate)!
515
+
516
+ ## 0.12.1
517
+
518
+ ### Fixes
519
+
520
+ - [#7411](https://github.com/gradio-app/gradio/pull/7411) [`32b317f`](https://github.com/gradio-app/gradio/commit/32b317f24e3d43f26684bb9f3964f31efd0ea556) - Set `root` correctly for Gradio apps that are deployed behind reverse proxies. Thanks [@abidlabs](https://github.com/abidlabs)!
521
+
522
+ ## 0.12.0
523
+
524
+ ### Features
525
+
526
+ - [#7183](https://github.com/gradio-app/gradio/pull/7183) [`49d9c48`](https://github.com/gradio-app/gradio/commit/49d9c48537aa706bf72628e3640389470138bdc6) - [WIP] Refactor file normalization to be in the backend and remove it from the frontend of each component. Thanks [@abidlabs](https://github.com/abidlabs)!
527
+
528
+ ## 0.11.0
529
+
530
+ ### Features
531
+
532
+ - [#7102](https://github.com/gradio-app/gradio/pull/7102) [`68a54a7`](https://github.com/gradio-app/gradio/commit/68a54a7a310d8d7072fdae930bf1cfdf12c45a7f) - Improve chatbot streaming performance with diffs. Thanks [@aliabid94](https://github.com/aliabid94)!/n Note that this PR changes the API format for generator functions, which would be a breaking change for any clients reading the EventStream directly
533
+
534
+ ## 0.10.1
535
+
536
+ ### Fixes
537
+
538
+ - [#7055](https://github.com/gradio-app/gradio/pull/7055) [`3c3cf86`](https://github.com/gradio-app/gradio/commit/3c3cf8618a8cad1ef66a7f96664923d2c9f5e0e2) - Fix UI freeze on rapid generators. Thanks [@aliabid94](https://github.com/aliabid94)!
539
+
540
+ ## 0.10.0
541
+
542
+ ### Features
543
+
544
+ - [#6931](https://github.com/gradio-app/gradio/pull/6931) [`6c863af`](https://github.com/gradio-app/gradio/commit/6c863af92fa9ceb5c638857eb22cc5ddb718d549) - Fix functional tests. Thanks [@aliabid94](https://github.com/aliabid94)!
545
+ - [#6820](https://github.com/gradio-app/gradio/pull/6820) [`649cd4d`](https://github.com/gradio-app/gradio/commit/649cd4d68041d11fcbe31f8efa455345ac49fc74) - Use `EventSource_factory` in `open_stream()` for Wasm. Thanks [@whitphx](https://github.com/whitphx)!
546
+
547
+ ## 0.9.4
548
+
549
+ ### Fixes
550
+
551
+ - [#6863](https://github.com/gradio-app/gradio/pull/6863) [`d406855`](https://github.com/gradio-app/gradio/commit/d4068557953746662235d595ec435c42ceb24414) - Fix JS Client when app is running behind a proxy. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
552
+
553
+ ## 0.9.3
554
+
555
+ ### Features
556
+
557
+ - [#6814](https://github.com/gradio-app/gradio/pull/6814) [`828fb9e`](https://github.com/gradio-app/gradio/commit/828fb9e6ce15b6ea08318675a2361117596a1b5d) - Refactor queue so that there are separate queues for each concurrency id. Thanks [@aliabid94](https://github.com/aliabid94)!
558
+
559
+ ## 0.9.2
560
+
561
+ ### Features
562
+
563
+ - [#6798](https://github.com/gradio-app/gradio/pull/6798) [`245d58e`](https://github.com/gradio-app/gradio/commit/245d58eff788e8d44a59d37a2d9b26d0f08a62b4) - Improve how server/js client handle unexpected errors. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
564
+
565
+ ## 0.9.1
566
+
567
+ ### Fixes
568
+
569
+ - [#6693](https://github.com/gradio-app/gradio/pull/6693) [`34f9431`](https://github.com/gradio-app/gradio/commit/34f943101bf7dd6b8a8974a6131c1ed7c4a0dac0) - Python client properly handles hearbeat and log messages. Also handles responses longer than 65k. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
570
+
571
+ ## 0.9.0
572
+
573
+ ### Features
574
+
575
+ - [#6398](https://github.com/gradio-app/gradio/pull/6398) [`67ddd40`](https://github.com/gradio-app/gradio/commit/67ddd40b4b70d3a37cb1637c33620f8d197dbee0) - Lite v4. Thanks [@whitphx](https://github.com/whitphx)!
576
+
577
+ ### Fixes
578
+
579
+ - [#6556](https://github.com/gradio-app/gradio/pull/6556) [`d76bcaa`](https://github.com/gradio-app/gradio/commit/d76bcaaaf0734aaf49a680f94ea9d4d22a602e70) - Fix api event drops. Thanks [@aliabid94](https://github.com/aliabid94)!
580
+
581
+ ## 0.8.2
582
+
583
+ ### Features
584
+
585
+ - [#6511](https://github.com/gradio-app/gradio/pull/6511) [`71f1a1f99`](https://github.com/gradio-app/gradio/commit/71f1a1f9931489d465c2c1302a5c8d768a3cd23a) - Mark `FileData.orig_name` optional on the frontend aligning the type definition on the Python side. Thanks [@whitphx](https://github.com/whitphx)!
586
+
587
+ ## 0.8.1
588
+
589
+ ### Fixes
590
+
591
+ - [#6383](https://github.com/gradio-app/gradio/pull/6383) [`324867f63`](https://github.com/gradio-app/gradio/commit/324867f63c920113d89a565892aa596cf8b1e486) - Fix event target. Thanks [@aliabid94](https://github.com/aliabid94)!
592
+
593
+ ## 0.8.0
594
+
595
+ ### Features
596
+
597
+ - [#6307](https://github.com/gradio-app/gradio/pull/6307) [`f1409f95e`](https://github.com/gradio-app/gradio/commit/f1409f95ed39c5565bed6a601e41f94e30196a57) - Provide status updates on file uploads. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
598
+
599
+ ## 0.7.2
600
+
601
+ ### Fixes
602
+
603
+ - [#6327](https://github.com/gradio-app/gradio/pull/6327) [`bca6c2c80`](https://github.com/gradio-app/gradio/commit/bca6c2c80f7e5062427019de45c282238388af95) - Restore query parameters in request. Thanks [@aliabid94](https://github.com/aliabid94)!
604
+
605
+ ## 0.7.1
606
+
607
+ ### Features
608
+
609
+ - [#6137](https://github.com/gradio-app/gradio/pull/6137) [`2ba14b284`](https://github.com/gradio-app/gradio/commit/2ba14b284f908aa13859f4337167a157075a68eb) - JS Param. Thanks [@dawoodkhan82](https://github.com/dawoodkhan82)!
610
+
611
+ ## 0.7.0
612
+
613
+ ### Features
614
+
615
+ - [#5498](https://github.com/gradio-app/gradio/pull/5498) [`287fe6782`](https://github.com/gradio-app/gradio/commit/287fe6782825479513e79a5cf0ba0fbfe51443d7) - fix circular dependency with client + upload. Thanks [@pngwn](https://github.com/pngwn)!
616
+ - [#5498](https://github.com/gradio-app/gradio/pull/5498) [`287fe6782`](https://github.com/gradio-app/gradio/commit/287fe6782825479513e79a5cf0ba0fbfe51443d7) - Image v4. Thanks [@pngwn](https://github.com/pngwn)!
617
+ - [#5498](https://github.com/gradio-app/gradio/pull/5498) [`287fe6782`](https://github.com/gradio-app/gradio/commit/287fe6782825479513e79a5cf0ba0fbfe51443d7) - Swap websockets for SSE. Thanks [@pngwn](https://github.com/pngwn)!
618
+
619
+ ## 0.7.0-beta.1
620
+
621
+ ### Features
622
+
623
+ - [#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)!
624
+ - [#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)!
625
+ - [#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)!
626
+
627
+ ## 0.7.0-beta.0
628
+
629
+ ### Features
630
+
631
+ - [#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)!
632
+
633
+ ### Fixes
634
+
635
+ - [#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)!
636
+
637
+ ## 0.6.0
638
+
639
+ ### Features
640
+
641
+ - [#5972](https://github.com/gradio-app/gradio/pull/5972) [`11a300791`](https://github.com/gradio-app/gradio/commit/11a3007916071f0791844b0a37f0fb4cec69cea3) - Lite: Support opening the entrypoint HTML page directly in browser via the `file:` protocol. Thanks [@whitphx](https://github.com/whitphx)!
642
+
643
+ ## 0.5.2
644
+
645
+ ### Fixes
646
+
647
+ - [#5840](https://github.com/gradio-app/gradio/pull/5840) [`4e62b8493`](https://github.com/gradio-app/gradio/commit/4e62b8493dfce50bafafe49f1a5deb929d822103) - Ensure websocket polyfill doesn't load if there is already a `global.Webocket` property set. Thanks [@Jay2theWhy](https://github.com/Jay2theWhy)!
648
+
649
+ ## 0.5.1
650
+
651
+ ### Fixes
652
+
653
+ - [#5816](https://github.com/gradio-app/gradio/pull/5816) [`796145e2c`](https://github.com/gradio-app/gradio/commit/796145e2c48c4087bec17f8ec0be4ceee47170cb) - Fix calls to the component server so that `gr.FileExplorer` works on Spaces. Thanks [@abidlabs](https://github.com/abidlabs)!
654
+
655
+ ## 0.5.0
656
+
657
+ ### Highlights
658
+
659
+ #### new `FileExplorer` component ([#5672](https://github.com/gradio-app/gradio/pull/5672) [`e4a307ed6`](https://github.com/gradio-app/gradio/commit/e4a307ed6cde3bbdf4ff2f17655739addeec941e))
660
+
661
+ Thanks to a new capability that allows components to communicate directly with the server _without_ passing data via the value, we have created a new `FileExplorer` component.
662
+
663
+ This component allows you to populate the explorer by passing a glob, but only provides the selected file(s) in your prediction function.
664
+
665
+ Users can then navigate the virtual filesystem and select files which will be accessible in your predict function. This component will allow developers to build more complex spaces, with more flexible input options.
666
+
667
+ ![output](https://github.com/pngwn/MDsveX/assets/12937446/ef108f0b-0e84-4292-9984-9dc66b3e144d)
668
+
669
+ For more information check the [`FileExplorer` documentation](https://gradio.app/docs/fileexplorer).
670
+
671
+ Thanks [@aliabid94](https://github.com/aliabid94)!
672
+
673
+ ### Features
674
+
675
+ - [#5787](https://github.com/gradio-app/gradio/pull/5787) [`caeee8bf7`](https://github.com/gradio-app/gradio/commit/caeee8bf7821fd5fe2f936ed82483bed00f613ec) - ensure the client does not depend on `window` when running in a node environment. Thanks [@gibiee](https://github.com/gibiee)!
676
+
677
+ ### Fixes
678
+
679
+ - [#5776](https://github.com/gradio-app/gradio/pull/5776) [`c0fef4454`](https://github.com/gradio-app/gradio/commit/c0fef44541bfa61568bdcfcdfc7d7d79869ab1df) - Revert replica proxy logic and instead implement using the `root` variable. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
680
+
681
+ ## 0.4.2
682
+
683
+ ### Features
684
+
685
+ - [#5124](https://github.com/gradio-app/gradio/pull/5124) [`6e56a0d9b`](https://github.com/gradio-app/gradio/commit/6e56a0d9b0c863e76c69e1183d9d40196922b4cd) - Lite: Websocket queueing. Thanks [@whitphx](https://github.com/whitphx)!
686
+
687
+ ## 0.4.1
688
+
689
+ ### Fixes
690
+
691
+ - [#5705](https://github.com/gradio-app/gradio/pull/5705) [`78e7cf516`](https://github.com/gradio-app/gradio/commit/78e7cf5163e8d205e8999428fce4c02dbdece25f) - ensure internal data has updated before dispatching `success` or `then` events. Thanks [@pngwn](https://github.com/pngwn)!
692
+
693
+ ## 0.4.0
694
+
695
+ ### Features
696
+
697
+ - [#5682](https://github.com/gradio-app/gradio/pull/5682) [`c57f1b75e`](https://github.com/gradio-app/gradio/commit/c57f1b75e272c76b0af4d6bd0c7f44743ff34f26) - Fix functional tests. Thanks [@abidlabs](https://github.com/abidlabs)!
698
+ - [#5681](https://github.com/gradio-app/gradio/pull/5681) [`40de3d217`](https://github.com/gradio-app/gradio/commit/40de3d2178b61ebe424b6f6228f94c0c6f679bea) - add query parameters to the `gr.Request` object through the `query_params` attribute. Thanks [@DarhkVoyd](https://github.com/DarhkVoyd)!
699
+ - [#5653](https://github.com/gradio-app/gradio/pull/5653) [`ea0e00b20`](https://github.com/gradio-app/gradio/commit/ea0e00b207b4b90a10e9d054c4202d4e705a29ba) - Prevent Clients from accessing API endpoints that set `api_name=False`. Thanks [@abidlabs](https://github.com/abidlabs)!
700
+
701
+ ## 0.3.1
702
+
703
+ ### Fixes
704
+
705
+ - [#5412](https://github.com/gradio-app/gradio/pull/5412) [`26fef8c7`](https://github.com/gradio-app/gradio/commit/26fef8c7f85a006c7e25cdbed1792df19c512d02) - Skip view_api request in js client when auth enabled. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
706
+
707
+ ## 0.3.0
708
+
709
+ ### Features
710
+
711
+ - [#5267](https://github.com/gradio-app/gradio/pull/5267) [`119c8343`](https://github.com/gradio-app/gradio/commit/119c834331bfae60d4742c8f20e9cdecdd67e8c2) - Faster reload mode. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
712
+
713
+ ## 0.2.1
714
+
715
+ ### Features
716
+
717
+ - [#5173](https://github.com/gradio-app/gradio/pull/5173) [`730f0c1d`](https://github.com/gradio-app/gradio/commit/730f0c1d54792eb11359e40c9f2326e8a6e39203) - Ensure gradio client works as expected for functions that return nothing. Thanks [@raymondtri](https://github.com/raymondtri)!
718
+
719
+ ## 0.2.0
720
+
721
+ ### Features
722
+
723
+ - [#5133](https://github.com/gradio-app/gradio/pull/5133) [`61129052`](https://github.com/gradio-app/gradio/commit/61129052ed1391a75c825c891d57fa0ad6c09fc8) - Update dependency esbuild to ^0.19.0. Thanks [@renovate](https://github.com/apps/renovate)!
724
+ - [#5035](https://github.com/gradio-app/gradio/pull/5035) [`8b4eb8ca`](https://github.com/gradio-app/gradio/commit/8b4eb8cac9ea07bde31b44e2006ca2b7b5f4de36) - JS Client: Fixes cannot read properties of null (reading 'is_file'). Thanks [@raymondtri](https://github.com/raymondtri)!
725
+
726
+ ### Fixes
727
+
728
+ - [#5075](https://github.com/gradio-app/gradio/pull/5075) [`67265a58`](https://github.com/gradio-app/gradio/commit/67265a58027ef1f9e4c0eb849a532f72eaebde48) - Allow supporting >1000 files in `gr.File()` and `gr.UploadButton()`. Thanks [@abidlabs](https://github.com/abidlabs)!
729
+
730
+ ## 0.1.4
731
+
732
+ ### Patch Changes
733
+
734
+ - [#4717](https://github.com/gradio-app/gradio/pull/4717) [`ab5d1ea0`](https://github.com/gradio-app/gradio/commit/ab5d1ea0de87ed888779b66fd2a705583bd29e02) Thanks [@whitphx](https://github.com/whitphx)! - Fix the package description
735
+
736
+ ## 0.1.3
737
+
738
+ ### Patch Changes
739
+
740
+ - [#4357](https://github.com/gradio-app/gradio/pull/4357) [`0dbd8f7f`](https://github.com/gradio-app/gradio/commit/0dbd8f7fee4b4877f783fa7bc493f98bbfc3d01d) Thanks [@pngwn](https://github.com/pngwn)! - Various internal refactors and cleanups.
741
+
742
+ ## 0.1.2
743
+
744
+ ### Patch Changes
745
+
746
+ - [#4273](https://github.com/gradio-app/gradio/pull/4273) [`1d0f0a9d`](https://github.com/gradio-app/gradio/commit/1d0f0a9db096552e67eb2197c932342587e9e61e) Thanks [@pngwn](https://github.com/pngwn)! - Ensure websocket error messages are correctly handled.
747
+
748
+ - [#4315](https://github.com/gradio-app/gradio/pull/4315) [`b525b122`](https://github.com/gradio-app/gradio/commit/b525b122dd8569bbaf7e06db5b90d622d2e9073d) Thanks [@whitphx](https://github.com/whitphx)! - Refacor types.
749
+
750
+ - [#4271](https://github.com/gradio-app/gradio/pull/4271) [`1151c525`](https://github.com/gradio-app/gradio/commit/1151c5253554cb87ebd4a44a8a470ac215ff782b) Thanks [@pngwn](https://github.com/pngwn)! - Ensure the full root path is always respected when making requests to a gradio app server.
751
+
752
+ ## 0.1.1
753
+
754
+ ### Patch Changes
755
+
756
+ - [#4201](https://github.com/gradio-app/gradio/pull/4201) [`da5b4ee1`](https://github.com/gradio-app/gradio/commit/da5b4ee11721175858ded96e5710225369097f74) Thanks [@pngwn](https://github.com/pngwn)! - Ensure semiver is bundled so CDN links work correctly.
757
+
758
+ - [#4202](https://github.com/gradio-app/gradio/pull/4202) [`a26e9afd`](https://github.com/gradio-app/gradio/commit/a26e9afde319382993e6ddc77cc4e56337a31248) Thanks [@pngwn](https://github.com/pngwn)! - Ensure all URLs returned by the client are complete URLs with the correct host instead of an absolute path relative to a server.
759
+
760
+ ## 0.1.0
761
+
762
+ ### Minor Changes
763
+
764
+ - [#4185](https://github.com/gradio-app/gradio/pull/4185) [`67239ca9`](https://github.com/gradio-app/gradio/commit/67239ca9b2fe3796853fbf7bf865c9e4b383200d) Thanks [@pngwn](https://github.com/pngwn)! - Update client for initial release
765
+
766
+ ### Patch Changes
767
+
768
+ - [#3692](https://github.com/gradio-app/gradio/pull/3692) [`48e8b113`](https://github.com/gradio-app/gradio/commit/48e8b113f4b55e461d9da4f153bf72aeb4adf0f1) Thanks [@pngwn](https://github.com/pngwn)! - Ensure client works in node, create ESM bundle and generate typescript declaration files.
769
+
770
+ - [#3605](https://github.com/gradio-app/gradio/pull/3605) [`ae4277a9`](https://github.com/gradio-app/gradio/commit/ae4277a9a83d49bdadfe523b0739ba988128e73b) Thanks [@pngwn](https://github.com/pngwn)! - Update readme.
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/client.ts ADDED
@@ -0,0 +1,525 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {
2
+ ApiData,
3
+ ApiInfo,
4
+ ClientOptions,
5
+ Config,
6
+ DuplicateOptions,
7
+ EndpointInfo,
8
+ JsApiData,
9
+ PredictReturn,
10
+ SpaceStatus,
11
+ Status,
12
+ UploadResponse,
13
+ client_return,
14
+ SubmitIterable,
15
+ GradioEvent
16
+ } from "./types";
17
+ import { view_api } from "./utils/view_api";
18
+ import { upload_files } from "./utils/upload_files";
19
+ import { upload, FileData } from "./upload";
20
+ import { handle_blob } from "./utils/handle_blob";
21
+ import { post_data } from "./utils/post_data";
22
+ import { predict } from "./utils/predict";
23
+ import { duplicate } from "./utils/duplicate";
24
+ import { submit } from "./utils/submit";
25
+ import { RE_SPACE_NAME, process_endpoint } from "./helpers/api_info";
26
+ import {
27
+ map_names_to_ids,
28
+ resolve_cookies,
29
+ resolve_config,
30
+ get_jwt,
31
+ parse_and_set_cookies
32
+ } from "./helpers/init_helpers";
33
+ import { check_and_wake_space, check_space_status } from "./helpers/spaces";
34
+ import { open_stream, readable_stream, close_stream } from "./utils/stream";
35
+ import {
36
+ API_INFO_ERROR_MSG,
37
+ CONFIG_ERROR_MSG,
38
+ HEARTBEAT_URL,
39
+ COMPONENT_SERVER_URL
40
+ } from "./constants";
41
+
42
+ export class Client {
43
+ app_reference: string;
44
+ options: ClientOptions;
45
+
46
+ config: Config | undefined;
47
+ api_prefix = "";
48
+ api_info: ApiInfo<JsApiData> | undefined;
49
+ api_map: Record<string, number> = {};
50
+ session_hash: string = Math.random().toString(36).substring(2);
51
+ jwt: string | false = false;
52
+ last_status: Record<string, Status["stage"]> = {};
53
+
54
+ private cookies: string | null = null;
55
+
56
+ // streaming
57
+ stream_status = { open: false };
58
+ pending_stream_messages: Record<string, any[][]> = {};
59
+ pending_diff_streams: Record<string, any[][]> = {};
60
+ event_callbacks: Record<string, (data?: unknown) => Promise<void>> = {};
61
+ unclosed_events: Set<string> = new Set();
62
+ heartbeat_event: EventSource | null = null;
63
+ abort_controller: AbortController | null = null;
64
+ stream_instance: EventSource | null = null;
65
+ current_payload: any;
66
+ ws_map: Record<string, WebSocket | "failed"> = {};
67
+
68
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
69
+ const headers = new Headers(init?.headers || {});
70
+ if (this && this.cookies) {
71
+ headers.append("Cookie", this.cookies);
72
+ }
73
+
74
+ return fetch(input, { ...init, headers });
75
+ }
76
+
77
+ stream(url: URL): EventSource {
78
+ const headers = new Headers();
79
+ if (this && this.cookies) {
80
+ headers.append("Cookie", this.cookies);
81
+ }
82
+
83
+ this.abort_controller = new AbortController();
84
+
85
+ this.stream_instance = readable_stream(url.toString(), {
86
+ credentials: "include",
87
+ headers: headers,
88
+ signal: this.abort_controller.signal
89
+ });
90
+
91
+ return this.stream_instance;
92
+ }
93
+
94
+ view_api: () => Promise<ApiInfo<JsApiData>>;
95
+ upload_files: (
96
+ root_url: string,
97
+ files: (Blob | File)[],
98
+ upload_id?: string
99
+ ) => Promise<UploadResponse>;
100
+ upload: (
101
+ file_data: FileData[],
102
+ root_url: string,
103
+ upload_id?: string,
104
+ max_file_size?: number
105
+ ) => Promise<(FileData | null)[] | null>;
106
+ handle_blob: (
107
+ endpoint: string,
108
+ data: unknown[],
109
+ endpoint_info: EndpointInfo<ApiData | JsApiData>
110
+ ) => Promise<unknown[]>;
111
+ post_data: (
112
+ url: string,
113
+ body: unknown,
114
+ additional_headers?: any
115
+ ) => Promise<unknown[]>;
116
+ submit: (
117
+ endpoint: string | number,
118
+ data: unknown[] | Record<string, unknown> | undefined,
119
+ event_data?: unknown,
120
+ trigger_id?: number | null,
121
+ all_events?: boolean
122
+ ) => SubmitIterable<GradioEvent>;
123
+ predict: (
124
+ endpoint: string | number,
125
+ data: unknown[] | Record<string, unknown> | undefined,
126
+ event_data?: unknown
127
+ ) => Promise<PredictReturn>;
128
+ open_stream: () => Promise<void>;
129
+ private resolve_config: (endpoint: string) => Promise<Config | undefined>;
130
+ private resolve_cookies: () => Promise<void>;
131
+ constructor(
132
+ app_reference: string,
133
+ options: ClientOptions = { events: ["data"] }
134
+ ) {
135
+ this.app_reference = app_reference;
136
+ if (!options.events) {
137
+ options.events = ["data"];
138
+ }
139
+
140
+ this.options = options;
141
+ this.current_payload = {};
142
+ this.view_api = view_api.bind(this);
143
+ this.upload_files = upload_files.bind(this);
144
+ this.handle_blob = handle_blob.bind(this);
145
+ this.post_data = post_data.bind(this);
146
+ this.submit = submit.bind(this);
147
+ this.predict = predict.bind(this);
148
+ this.open_stream = open_stream.bind(this);
149
+ this.resolve_config = resolve_config.bind(this);
150
+ this.resolve_cookies = resolve_cookies.bind(this);
151
+ this.upload = upload.bind(this);
152
+ this.fetch = this.fetch.bind(this);
153
+ this.handle_space_success = this.handle_space_success.bind(this);
154
+ this.stream = this.stream.bind(this);
155
+ }
156
+
157
+ private async init(): Promise<void> {
158
+ if (
159
+ (typeof window === "undefined" || !("WebSocket" in window)) &&
160
+ !global.WebSocket
161
+ ) {
162
+ const ws = await import("ws");
163
+ global.WebSocket = ws.WebSocket as unknown as typeof WebSocket;
164
+ }
165
+
166
+ if (this.options.auth) {
167
+ await this.resolve_cookies();
168
+ }
169
+
170
+ await this._resolve_config().then(({ config }) =>
171
+ this._resolve_hearbeat(config)
172
+ );
173
+
174
+ this.api_info = await this.view_api();
175
+ this.api_map = map_names_to_ids(this.config?.dependencies || []);
176
+ }
177
+
178
+ async _resolve_hearbeat(_config: Config): Promise<void> {
179
+ if (_config) {
180
+ this.config = _config;
181
+ this.api_prefix = _config.api_prefix || "";
182
+
183
+ if (this.config && this.config.connect_heartbeat) {
184
+ if (this.config.space_id && this.options.hf_token) {
185
+ this.jwt = await get_jwt(
186
+ this.config.space_id,
187
+ this.options.hf_token,
188
+ this.cookies
189
+ );
190
+ }
191
+ }
192
+ }
193
+
194
+ if (_config.space_id && this.options.hf_token) {
195
+ this.jwt = await get_jwt(_config.space_id, this.options.hf_token);
196
+ }
197
+
198
+ if (this.config && this.config.connect_heartbeat) {
199
+ // connect to the heartbeat endpoint via GET request
200
+ const heartbeat_url = new URL(
201
+ `${this.config.root}${this.api_prefix}/${HEARTBEAT_URL}/${this.session_hash}`
202
+ );
203
+
204
+ // if the jwt is available, add it to the query params
205
+ if (this.jwt) {
206
+ heartbeat_url.searchParams.set("__sign", this.jwt);
207
+ }
208
+
209
+ // Just connect to the endpoint without parsing the response. Ref: https://github.com/gradio-app/gradio/pull/7974#discussion_r1557717540
210
+ if (!this.heartbeat_event) {
211
+ this.heartbeat_event = this.stream(heartbeat_url);
212
+ }
213
+ }
214
+ }
215
+
216
+ static async connect(
217
+ app_reference: string,
218
+ options: ClientOptions = {
219
+ events: ["data"]
220
+ }
221
+ ): Promise<Client> {
222
+ const client = new this(app_reference, options); // this refers to the class itself, not the instance
223
+ await client.init();
224
+ return client;
225
+ }
226
+
227
+ close(): void {
228
+ close_stream(this.stream_status, this.abort_controller);
229
+ }
230
+
231
+ set_current_payload(payload: any): void {
232
+ this.current_payload = payload;
233
+ }
234
+
235
+ static async duplicate(
236
+ app_reference: string,
237
+ options: DuplicateOptions = {
238
+ events: ["data"]
239
+ }
240
+ ): Promise<Client> {
241
+ return duplicate(app_reference, options);
242
+ }
243
+
244
+ private async _resolve_config(): Promise<any> {
245
+ const { http_protocol, host, space_id } = await process_endpoint(
246
+ this.app_reference,
247
+ this.options.hf_token
248
+ );
249
+
250
+ const { status_callback } = this.options;
251
+
252
+ if (space_id && status_callback) {
253
+ await check_and_wake_space(space_id, status_callback);
254
+ }
255
+
256
+ let config: Config | undefined;
257
+
258
+ try {
259
+ config = await this.resolve_config(`${http_protocol}//${host}`);
260
+
261
+ if (!config) {
262
+ throw new Error(CONFIG_ERROR_MSG);
263
+ }
264
+
265
+ return this.config_success(config);
266
+ } catch (e: any) {
267
+ if (space_id && status_callback) {
268
+ check_space_status(
269
+ space_id,
270
+ RE_SPACE_NAME.test(space_id) ? "space_name" : "subdomain",
271
+ this.handle_space_success
272
+ );
273
+ } else {
274
+ if (status_callback)
275
+ status_callback({
276
+ status: "error",
277
+ message: "Could not load this space.",
278
+ load_status: "error",
279
+ detail: "NOT_FOUND"
280
+ });
281
+ throw Error(e);
282
+ }
283
+ }
284
+ }
285
+
286
+ private async config_success(
287
+ _config: Config
288
+ ): Promise<Config | client_return> {
289
+ this.config = _config;
290
+ this.api_prefix = _config.api_prefix || "";
291
+
292
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
293
+ if (window.location.protocol === "https:") {
294
+ this.config.root = this.config.root.replace("http://", "https://");
295
+ }
296
+ }
297
+
298
+ if (this.config.auth_required) {
299
+ return this.prepare_return_obj();
300
+ }
301
+
302
+ try {
303
+ this.api_info = await this.view_api();
304
+ } catch (e) {
305
+ console.error(API_INFO_ERROR_MSG + (e as Error).message);
306
+ }
307
+
308
+ return this.prepare_return_obj();
309
+ }
310
+
311
+ async handle_space_success(status: SpaceStatus): Promise<Config | void> {
312
+ if (!this) {
313
+ throw new Error(CONFIG_ERROR_MSG);
314
+ }
315
+ const { status_callback } = this.options;
316
+ if (status_callback) status_callback(status);
317
+ if (status.status === "running") {
318
+ try {
319
+ this.config = await this._resolve_config();
320
+ this.api_prefix = this?.config?.api_prefix || "";
321
+
322
+ if (!this.config) {
323
+ throw new Error(CONFIG_ERROR_MSG);
324
+ }
325
+
326
+ const _config = await this.config_success(this.config);
327
+
328
+ return _config as Config;
329
+ } catch (e) {
330
+ if (status_callback) {
331
+ status_callback({
332
+ status: "error",
333
+ message: "Could not load this space.",
334
+ load_status: "error",
335
+ detail: "NOT_FOUND"
336
+ });
337
+ }
338
+ throw e;
339
+ }
340
+ }
341
+ }
342
+
343
+ public async component_server(
344
+ component_id: number,
345
+ fn_name: string,
346
+ data: unknown[] | { binary: boolean; data: Record<string, any> }
347
+ ): Promise<unknown> {
348
+ if (!this.config) {
349
+ throw new Error(CONFIG_ERROR_MSG);
350
+ }
351
+
352
+ const headers: {
353
+ Authorization?: string;
354
+ "Content-Type"?: "application/json";
355
+ } = {};
356
+
357
+ const { hf_token } = this.options;
358
+ const { session_hash } = this;
359
+
360
+ if (hf_token) {
361
+ headers.Authorization = `Bearer ${this.options.hf_token}`;
362
+ }
363
+
364
+ let root_url: string;
365
+ let component = this.config.components.find(
366
+ (comp) => comp.id === component_id
367
+ );
368
+ if (component?.props?.root_url) {
369
+ root_url = component.props.root_url;
370
+ } else {
371
+ root_url = this.config.root;
372
+ }
373
+
374
+ let body: FormData | string;
375
+
376
+ if ("binary" in data) {
377
+ body = new FormData();
378
+ for (const key in data.data) {
379
+ if (key === "binary") continue;
380
+ body.append(key, data.data[key]);
381
+ }
382
+ body.set("component_id", component_id.toString());
383
+ body.set("fn_name", fn_name);
384
+ body.set("session_hash", session_hash);
385
+ } else {
386
+ body = JSON.stringify({
387
+ data: data,
388
+ component_id,
389
+ fn_name,
390
+ session_hash
391
+ });
392
+
393
+ headers["Content-Type"] = "application/json";
394
+ }
395
+
396
+ if (hf_token) {
397
+ headers.Authorization = `Bearer ${hf_token}`;
398
+ }
399
+
400
+ try {
401
+ const response = await this.fetch(
402
+ `${root_url}${this.api_prefix}/${COMPONENT_SERVER_URL}/`,
403
+ {
404
+ method: "POST",
405
+ body: body,
406
+ headers,
407
+ credentials: "include"
408
+ }
409
+ );
410
+
411
+ if (!response.ok) {
412
+ throw new Error(
413
+ "Could not connect to component server: " + response.statusText
414
+ );
415
+ }
416
+
417
+ const output = await response.json();
418
+ return output;
419
+ } catch (e) {
420
+ console.warn(e);
421
+ }
422
+ }
423
+
424
+ public set_cookies(raw_cookies: string): void {
425
+ this.cookies = parse_and_set_cookies(raw_cookies).join("; ");
426
+ }
427
+
428
+ private prepare_return_obj(): client_return {
429
+ return {
430
+ config: this.config,
431
+ predict: this.predict,
432
+ submit: this.submit,
433
+ view_api: this.view_api,
434
+ component_server: this.component_server
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
+ }
491
+ }
492
+
493
+ /**
494
+ * @deprecated This method will be removed in v1.0. Use `Client.connect()` instead.
495
+ * Creates a client instance for interacting with Gradio apps.
496
+ *
497
+ * @param {string} app_reference - The reference or URL to a Gradio space or app.
498
+ * @param {ClientOptions} options - Configuration options for the client.
499
+ * @returns {Promise<Client>} A promise that resolves to a `Client` instance.
500
+ */
501
+ export async function client(
502
+ app_reference: string,
503
+ options: ClientOptions = {
504
+ events: ["data"]
505
+ }
506
+ ): Promise<Client> {
507
+ return await Client.connect(app_reference, options);
508
+ }
509
+
510
+ /**
511
+ * @deprecated This method will be removed in v1.0. Use `Client.duplicate()` instead.
512
+ * Creates a duplicate of a space and returns a client instance for the duplicated space.
513
+ *
514
+ * @param {string} app_reference - The reference or URL to a Gradio space or app to duplicate.
515
+ * @param {DuplicateOptions} options - Configuration options for the client.
516
+ * @returns {Promise<Client>} A promise that resolves to a `Client` instance.
517
+ */
518
+ export async function duplicate_space(
519
+ app_reference: string,
520
+ options: DuplicateOptions
521
+ ): Promise<Client> {
522
+ return await Client.duplicate(app_reference, options);
523
+ }
524
+
525
+ export type ClientInstance = Client;
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/globals.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ApiData, ApiInfo, Config } from "./types";
2
+
3
+ declare global {
4
+ interface Window {
5
+ __gradio_mode__: "app" | "website";
6
+ gradio_config: Config;
7
+ gradio_api_info: ApiInfo<ApiData> | { api: ApiInfo<ApiData> };
8
+ __is_colab__: boolean;
9
+ __gradio_space__: string | null;
10
+ }
11
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/api_info.ts ADDED
@@ -0,0 +1,458 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ HOST_URL,
3
+ INVALID_URL_MSG,
4
+ QUEUE_FULL_MSG,
5
+ SPACE_METADATA_ERROR_MSG
6
+ } from "../constants";
7
+ import type {
8
+ ApiData,
9
+ ApiInfo,
10
+ Config,
11
+ JsApiData,
12
+ EndpointInfo,
13
+ Status
14
+ } from "../types";
15
+ import { determine_protocol } from "./init_helpers";
16
+
17
+ export const RE_SPACE_NAME = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/;
18
+ export const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}$/;
19
+
20
+ export async function process_endpoint(
21
+ app_reference: string,
22
+ hf_token?: `hf_${string}`
23
+ ): Promise<{
24
+ space_id: string | false;
25
+ host: string;
26
+ ws_protocol: "ws" | "wss";
27
+ http_protocol: "http:" | "https:";
28
+ }> {
29
+ const headers: { Authorization?: string } = {};
30
+ if (hf_token) {
31
+ headers.Authorization = `Bearer ${hf_token}`;
32
+ }
33
+
34
+ const _app_reference = app_reference.trim().replace(/\/$/, "");
35
+
36
+ if (RE_SPACE_NAME.test(_app_reference)) {
37
+ // app_reference is a HF space name
38
+ try {
39
+ const res = await fetch(
40
+ `https://huggingface.co/api/spaces/${_app_reference}/${HOST_URL}`,
41
+ { headers }
42
+ );
43
+
44
+ const _host = (await res.json()).host;
45
+
46
+ return {
47
+ space_id: app_reference,
48
+ ...determine_protocol(_host)
49
+ };
50
+ } catch (e) {
51
+ throw new Error(SPACE_METADATA_ERROR_MSG);
52
+ }
53
+ }
54
+
55
+ if (RE_SPACE_DOMAIN.test(_app_reference)) {
56
+ // app_reference is a direct HF space domain
57
+ const { ws_protocol, http_protocol, host } =
58
+ determine_protocol(_app_reference);
59
+
60
+ return {
61
+ space_id: host.replace(".hf.space", ""),
62
+ ws_protocol,
63
+ http_protocol,
64
+ host
65
+ };
66
+ }
67
+
68
+ return {
69
+ space_id: false,
70
+ ...determine_protocol(_app_reference)
71
+ };
72
+ }
73
+
74
+ export const join_urls = (...urls: string[]): string => {
75
+ try {
76
+ return urls.reduce((base_url: string, part: string) => {
77
+ base_url = base_url.replace(/\/+$/, "");
78
+ part = part.replace(/^\/+/, "");
79
+ return new URL(part, base_url + "/").toString();
80
+ });
81
+ } catch (e) {
82
+ throw new Error(INVALID_URL_MSG);
83
+ }
84
+ };
85
+
86
+ export function transform_api_info(
87
+ api_info: ApiInfo<ApiData>,
88
+ config: Config,
89
+ api_map: Record<string, number>
90
+ ): ApiInfo<JsApiData> {
91
+ const transformed_info: ApiInfo<JsApiData> = {
92
+ named_endpoints: {},
93
+ unnamed_endpoints: {}
94
+ };
95
+
96
+ Object.keys(api_info).forEach((category) => {
97
+ if (category === "named_endpoints" || category === "unnamed_endpoints") {
98
+ transformed_info[category] = {};
99
+
100
+ Object.entries(api_info[category]).forEach(
101
+ ([endpoint, { parameters, returns }]) => {
102
+ const dependencyIndex =
103
+ config.dependencies.find(
104
+ (dep) =>
105
+ dep.api_name === endpoint ||
106
+ dep.api_name === endpoint.replace("/", "")
107
+ )?.id ||
108
+ api_map[endpoint.replace("/", "")] ||
109
+ -1;
110
+
111
+ const dependencyTypes =
112
+ dependencyIndex !== -1
113
+ ? config.dependencies.find((dep) => dep.id == dependencyIndex)
114
+ ?.types
115
+ : { generator: false, cancel: false };
116
+
117
+ if (
118
+ dependencyIndex !== -1 &&
119
+ config.dependencies.find((dep) => dep.id == dependencyIndex)?.inputs
120
+ ?.length !== parameters.length
121
+ ) {
122
+ const components = config.dependencies
123
+ .find((dep) => dep.id == dependencyIndex)!
124
+ .inputs.map(
125
+ (input) => config.components.find((c) => c.id === input)?.type
126
+ );
127
+
128
+ try {
129
+ components.forEach((comp, idx) => {
130
+ if (comp === "state") {
131
+ const new_param = {
132
+ component: "state",
133
+ example: null,
134
+ parameter_default: null,
135
+ parameter_has_default: true,
136
+ parameter_name: null,
137
+ hidden: true
138
+ };
139
+
140
+ // @ts-ignore
141
+ parameters.splice(idx, 0, new_param);
142
+ }
143
+ });
144
+ } catch (e) {
145
+ console.error(e);
146
+ }
147
+ }
148
+
149
+ const transform_type = (
150
+ data: ApiData,
151
+ component: string,
152
+ serializer: string,
153
+ signature_type: "return" | "parameter"
154
+ ): JsApiData => ({
155
+ ...data,
156
+ description: get_description(data?.type, serializer),
157
+ type:
158
+ get_type(data?.type, component, serializer, signature_type) || ""
159
+ });
160
+
161
+ transformed_info[category][endpoint] = {
162
+ parameters: parameters.map((p: ApiData) =>
163
+ transform_type(p, p?.component, p?.serializer, "parameter")
164
+ ),
165
+ returns: returns.map((r: ApiData) =>
166
+ transform_type(r, r?.component, r?.serializer, "return")
167
+ ),
168
+ type: dependencyTypes
169
+ };
170
+ }
171
+ );
172
+ }
173
+ });
174
+
175
+ return transformed_info;
176
+ }
177
+
178
+ export function get_type(
179
+ type: { type: any; description: string },
180
+ component: string,
181
+ serializer: string,
182
+ signature_type: "return" | "parameter"
183
+ ): string | undefined {
184
+ switch (type?.type) {
185
+ case "string":
186
+ return "string";
187
+ case "boolean":
188
+ return "boolean";
189
+ case "number":
190
+ return "number";
191
+ }
192
+
193
+ if (
194
+ serializer === "JSONSerializable" ||
195
+ serializer === "StringSerializable"
196
+ ) {
197
+ return "any";
198
+ } else if (serializer === "ListStringSerializable") {
199
+ return "string[]";
200
+ } else if (component === "Image") {
201
+ return signature_type === "parameter" ? "Blob | File | Buffer" : "string";
202
+ } else if (serializer === "FileSerializable") {
203
+ if (type?.type === "array") {
204
+ return signature_type === "parameter"
205
+ ? "(Blob | File | Buffer)[]"
206
+ : `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]`;
207
+ }
208
+ return signature_type === "parameter"
209
+ ? "Blob | File | Buffer"
210
+ : `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}`;
211
+ } else if (serializer === "GallerySerializable") {
212
+ return signature_type === "parameter"
213
+ ? "[(Blob | File | Buffer), (string | null)][]"
214
+ : `[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]`;
215
+ }
216
+ }
217
+
218
+ export function get_description(
219
+ type: { type: any; description: string },
220
+ serializer: string
221
+ ): string {
222
+ if (serializer === "GallerySerializable") {
223
+ return "array of [file, label] tuples";
224
+ } else if (serializer === "ListStringSerializable") {
225
+ return "array of strings";
226
+ } else if (serializer === "FileSerializable") {
227
+ return "array of files or single file";
228
+ }
229
+ return type?.description;
230
+ }
231
+
232
+ /* eslint-disable complexity */
233
+ export function handle_message(
234
+ data: any,
235
+ last_status: Status["stage"]
236
+ ): {
237
+ type:
238
+ | "hash"
239
+ | "data"
240
+ | "update"
241
+ | "complete"
242
+ | "generating"
243
+ | "log"
244
+ | "none"
245
+ | "heartbeat"
246
+ | "streaming"
247
+ | "unexpected_error";
248
+ data?: any;
249
+ status?: Status;
250
+ original_msg?: string;
251
+ } {
252
+ const queue = true;
253
+ switch (data.msg) {
254
+ case "send_data":
255
+ return { type: "data" };
256
+ case "send_hash":
257
+ return { type: "hash" };
258
+ case "queue_full":
259
+ return {
260
+ type: "update",
261
+ status: {
262
+ queue,
263
+ message: QUEUE_FULL_MSG,
264
+ stage: "error",
265
+ code: data.code,
266
+ success: data.success
267
+ }
268
+ };
269
+ case "heartbeat":
270
+ return {
271
+ type: "heartbeat"
272
+ };
273
+ case "unexpected_error":
274
+ return {
275
+ type: "unexpected_error",
276
+ status: {
277
+ queue,
278
+ message: data.message,
279
+ stage: "error",
280
+ success: false
281
+ }
282
+ };
283
+ case "estimation":
284
+ return {
285
+ type: "update",
286
+ status: {
287
+ queue,
288
+ stage: last_status || "pending",
289
+ code: data.code,
290
+ size: data.queue_size,
291
+ position: data.rank,
292
+ eta: data.rank_eta,
293
+ success: data.success
294
+ }
295
+ };
296
+ case "progress":
297
+ return {
298
+ type: "update",
299
+ status: {
300
+ queue,
301
+ stage: "pending",
302
+ code: data.code,
303
+ progress_data: data.progress_data,
304
+ success: data.success
305
+ }
306
+ };
307
+ case "log":
308
+ return { type: "log", data: data };
309
+ case "process_generating":
310
+ return {
311
+ type: "generating",
312
+ status: {
313
+ queue,
314
+ message: !data.success ? data.output.error : null,
315
+ stage: data.success ? "generating" : "error",
316
+ code: data.code,
317
+ progress_data: data.progress_data,
318
+ eta: data.average_duration,
319
+ changed_state_ids: data.success
320
+ ? data.output.changed_state_ids
321
+ : undefined
322
+ },
323
+ data: data.success ? data.output : null
324
+ };
325
+ case "process_streaming":
326
+ return {
327
+ type: "streaming",
328
+ status: {
329
+ queue,
330
+ message: data.output.error,
331
+ stage: "streaming",
332
+ time_limit: data.time_limit,
333
+ code: data.code,
334
+ progress_data: data.progress_data,
335
+ eta: data.eta
336
+ },
337
+ data: data.output
338
+ };
339
+ case "process_completed":
340
+ if ("error" in data.output) {
341
+ return {
342
+ type: "update",
343
+ status: {
344
+ queue,
345
+ message: data.output.error as string,
346
+ visible: data.output.visible as boolean,
347
+ duration: data.output.duration as number,
348
+ stage: "error",
349
+ code: data.code,
350
+ success: data.success
351
+ }
352
+ };
353
+ }
354
+ return {
355
+ type: "complete",
356
+ status: {
357
+ queue,
358
+ message: !data.success ? data.output.error : undefined,
359
+ stage: data.success ? "complete" : "error",
360
+ code: data.code,
361
+ progress_data: data.progress_data,
362
+ changed_state_ids: data.success
363
+ ? data.output.changed_state_ids
364
+ : undefined
365
+ },
366
+ data: data.success ? data.output : null
367
+ };
368
+
369
+ case "process_starts":
370
+ return {
371
+ type: "update",
372
+ status: {
373
+ queue,
374
+ stage: "pending",
375
+ code: data.code,
376
+ size: data.rank,
377
+ position: 0,
378
+ success: data.success,
379
+ eta: data.eta
380
+ },
381
+ original_msg: "process_starts"
382
+ };
383
+ }
384
+
385
+ return { type: "none", status: { stage: "error", queue } };
386
+ }
387
+ /* eslint-enable complexity */
388
+
389
+ /**
390
+ * Maps the provided `data` to the parameters defined by the `/info` endpoint response.
391
+ * This allows us to support both positional and keyword arguments passed to the client
392
+ * and ensures that all parameters are either directly provided or have default values assigned.
393
+ *
394
+ * @param {unknown[] | Record<string, unknown>} data - The input data for the function,
395
+ * which can be either an array of values for positional arguments or an object
396
+ * with key-value pairs for keyword arguments.
397
+ * @param {JsApiData[]} parameters - Array of parameter descriptions retrieved from the
398
+ * `/info` endpoint.
399
+ *
400
+ * @returns {unknown[]} - Returns an array of resolved data where each element corresponds
401
+ * to the expected parameter from the API. The `parameter_default` value is used where
402
+ * a value is not provided for a parameter, and optional parameters without defaults are
403
+ * set to `undefined`.
404
+ *
405
+ * @throws {Error} - Throws an error:
406
+ * - If more arguments are provided than are defined in the parameters.
407
+ * * - If no parameter value is provided for a required parameter and no default value is defined.
408
+ * - If an argument is provided that does not match any defined parameter.
409
+ */
410
+
411
+ export const map_data_to_params = (
412
+ data: unknown[] | Record<string, unknown> = [],
413
+ endpoint_info: EndpointInfo<JsApiData | ApiData>
414
+ ): unknown[] => {
415
+ // Workaround for the case where the endpoint_info is undefined
416
+ // See https://github.com/gradio-app/gradio/pull/8820#issuecomment-2237381761
417
+ const parameters = endpoint_info ? endpoint_info.parameters : [];
418
+
419
+ if (Array.isArray(data)) {
420
+ if (data.length > parameters.length) {
421
+ console.warn("Too many arguments provided for the endpoint.");
422
+ }
423
+ return data;
424
+ }
425
+
426
+ const resolved_data: unknown[] = [];
427
+ const provided_keys = Object.keys(data);
428
+
429
+ parameters.forEach((param, index) => {
430
+ if (data.hasOwnProperty(param.parameter_name)) {
431
+ resolved_data[index] = data[param.parameter_name];
432
+ } else if (param.parameter_has_default) {
433
+ resolved_data[index] = param.parameter_default;
434
+ } else {
435
+ throw new Error(
436
+ `No value provided for required parameter: ${param.parameter_name}`
437
+ );
438
+ }
439
+ });
440
+
441
+ provided_keys.forEach((key) => {
442
+ if (!parameters.some((param) => param.parameter_name === key)) {
443
+ throw new Error(
444
+ `Parameter \`${key}\` is not a valid keyword argument. Please refer to the API for usage.`
445
+ );
446
+ }
447
+ });
448
+
449
+ resolved_data.forEach((value, idx) => {
450
+ if (value === undefined && !parameters[idx].parameter_has_default) {
451
+ throw new Error(
452
+ `No value provided for required parameter: ${parameters[idx].parameter_name}`
453
+ );
454
+ }
455
+ });
456
+
457
+ return resolved_data;
458
+ };
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/data.ts ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ type ApiData,
3
+ type BlobRef,
4
+ type Config,
5
+ type EndpointInfo,
6
+ type JsApiData,
7
+ type DataType,
8
+ Command,
9
+ type Dependency,
10
+ type ComponentMeta
11
+ } from "../types";
12
+ import { FileData } from "../upload";
13
+
14
+ const is_node =
15
+ typeof process !== "undefined" && process.versions && process.versions.node;
16
+
17
+ export function update_object(
18
+ object: { [x: string]: any },
19
+ newValue: any,
20
+ stack: (string | number)[]
21
+ ): void {
22
+ while (stack.length > 1) {
23
+ const key = stack.shift();
24
+ if (typeof key === "string" || typeof key === "number") {
25
+ object = object[key];
26
+ } else {
27
+ throw new Error("Invalid key type");
28
+ }
29
+ }
30
+
31
+ const key = stack.shift();
32
+ if (typeof key === "string" || typeof key === "number") {
33
+ object[key] = newValue;
34
+ } else {
35
+ throw new Error("Invalid key type");
36
+ }
37
+ }
38
+
39
+ export async function walk_and_store_blobs(
40
+ data: DataType,
41
+ type: string | undefined = undefined,
42
+ path: string[] = [],
43
+ root = false,
44
+ endpoint_info: EndpointInfo<ApiData | JsApiData> | undefined = undefined
45
+ ): Promise<BlobRef[]> {
46
+ if (Array.isArray(data)) {
47
+ let blob_refs: BlobRef[] = [];
48
+
49
+ await Promise.all(
50
+ data.map(async (_, index) => {
51
+ let new_path = path.slice();
52
+ new_path.push(String(index));
53
+
54
+ const array_refs = await walk_and_store_blobs(
55
+ data[index],
56
+ root
57
+ ? endpoint_info?.parameters[index]?.component || undefined
58
+ : type,
59
+ new_path,
60
+ false,
61
+ endpoint_info
62
+ );
63
+
64
+ blob_refs = blob_refs.concat(array_refs);
65
+ })
66
+ );
67
+
68
+ return blob_refs;
69
+ } else if (
70
+ (globalThis.Buffer && data instanceof globalThis.Buffer) ||
71
+ data instanceof Blob
72
+ ) {
73
+ return [
74
+ {
75
+ path: path,
76
+ blob: new Blob([data]),
77
+ type
78
+ }
79
+ ];
80
+ } else if (typeof data === "object" && data !== null) {
81
+ let blob_refs: BlobRef[] = [];
82
+ for (const key of Object.keys(data) as (keyof typeof data)[]) {
83
+ const new_path = [...path, key];
84
+ const value = data[key];
85
+
86
+ blob_refs = blob_refs.concat(
87
+ await walk_and_store_blobs(
88
+ value,
89
+ undefined,
90
+ new_path,
91
+ false,
92
+ endpoint_info
93
+ )
94
+ );
95
+ }
96
+
97
+ return blob_refs;
98
+ }
99
+
100
+ return [];
101
+ }
102
+
103
+ export function skip_queue(id: number, config: Config): boolean {
104
+ let fn_queue = config?.dependencies?.find((dep) => dep.id == id)?.queue;
105
+ if (fn_queue != null) {
106
+ return !fn_queue;
107
+ }
108
+ return !config.enable_queue;
109
+ }
110
+
111
+ // todo: add jsdoc for this function
112
+
113
+ export function post_message<Res = any>(
114
+ message: any,
115
+ origin: string
116
+ ): Promise<Res> {
117
+ return new Promise((res, _rej) => {
118
+ const channel = new MessageChannel();
119
+ channel.port1.onmessage = (({ data }) => {
120
+ channel.port1.close();
121
+ res(data);
122
+ }) as (ev: MessageEvent<Res>) => void;
123
+ window.parent.postMessage(message, origin, [channel.port2]);
124
+ });
125
+ }
126
+
127
+ export function handle_file(
128
+ file_or_url: File | string | Blob | Buffer
129
+ ): FileData | Blob | Command {
130
+ if (typeof file_or_url === "string") {
131
+ if (
132
+ file_or_url.startsWith("http://") ||
133
+ file_or_url.startsWith("https://")
134
+ ) {
135
+ return {
136
+ path: file_or_url,
137
+ url: file_or_url,
138
+ orig_name: file_or_url.split("/").pop() ?? "unknown",
139
+ meta: { _type: "gradio.FileData" }
140
+ };
141
+ }
142
+
143
+ if (is_node) {
144
+ // Handle local file paths
145
+ return new Command("upload_file", {
146
+ path: file_or_url,
147
+ name: file_or_url,
148
+ orig_path: file_or_url
149
+ });
150
+ }
151
+ } else if (typeof File !== "undefined" && file_or_url instanceof File) {
152
+ return new Blob([file_or_url]);
153
+ } else if (file_or_url instanceof Buffer) {
154
+ return new Blob([file_or_url]);
155
+ } else if (file_or_url instanceof Blob) {
156
+ return file_or_url;
157
+ }
158
+ throw new Error(
159
+ "Invalid input: must be a URL, File, Blob, or Buffer object."
160
+ );
161
+ }
162
+
163
+ /**
164
+ * Handles the payload by filtering out state inputs and returning an array of resolved payload values.
165
+ * We send null values for state inputs to the server, but we don't want to include them in the resolved payload.
166
+ *
167
+ * @param resolved_payload - The resolved payload values received from the client or the server
168
+ * @param dependency - The dependency object.
169
+ * @param components - The array of component metadata.
170
+ * @param with_null_state - Optional. Specifies whether to include null values for state inputs. Default is false.
171
+ * @returns An array of resolved payload values, filtered based on the dependency and component metadata.
172
+ */
173
+ export function handle_payload(
174
+ resolved_payload: unknown[],
175
+ dependency: Dependency,
176
+ components: ComponentMeta[],
177
+ type: "input" | "output",
178
+ with_null_state = false
179
+ ): unknown[] {
180
+ if (type === "input" && !with_null_state) {
181
+ throw new Error("Invalid code path. Cannot skip state inputs for input.");
182
+ }
183
+ // data comes from the server with null state values so we skip
184
+ if (type === "output" && with_null_state) {
185
+ return resolved_payload;
186
+ }
187
+
188
+ let updated_payload: unknown[] = [];
189
+ let payload_index = 0;
190
+ const deps = type === "input" ? dependency.inputs : dependency.outputs;
191
+ for (let i = 0; i < deps.length; i++) {
192
+ const input_id = deps[i];
193
+ const component = components.find((c) => c.id === input_id);
194
+
195
+ if (component?.type === "state") {
196
+ // input + with_null_state needs us to fill state with null values
197
+ if (with_null_state) {
198
+ if (resolved_payload.length === deps.length) {
199
+ const value = resolved_payload[payload_index];
200
+ updated_payload.push(value);
201
+ payload_index++;
202
+ } else {
203
+ updated_payload.push(null);
204
+ }
205
+ } else {
206
+ // this is output & !with_null_state, we skip state inputs
207
+ // the server payload always comes with null state values so we move along the payload index
208
+ payload_index++;
209
+ continue;
210
+ }
211
+ // input & !with_null_state isn't a case we care about, server needs null
212
+ continue;
213
+ } else {
214
+ const value = resolved_payload[payload_index];
215
+ updated_payload.push(value);
216
+ payload_index++;
217
+ }
218
+ }
219
+
220
+ return updated_payload;
221
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/init_helpers.ts ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Config } from "../types";
2
+ import {
3
+ CONFIG_ERROR_MSG,
4
+ CONFIG_URL,
5
+ INVALID_CREDENTIALS_MSG,
6
+ LOGIN_URL,
7
+ MISSING_CREDENTIALS_MSG,
8
+ SPACE_METADATA_ERROR_MSG,
9
+ UNAUTHORIZED_MSG
10
+ } from "../constants";
11
+ import { Client } from "..";
12
+ import { join_urls, process_endpoint } from "./api_info";
13
+
14
+ /**
15
+ * This function is used to resolve the URL for making requests when the app has a root path.
16
+ * The root path could be a path suffix like "/app" which is appended to the end of the base URL. Or
17
+ * it could be a full URL like "https://abidlabs-test-client-replica--gqf2x.hf.space" which is used when hosting
18
+ * Gradio apps on Hugging Face Spaces.
19
+ * @param {string} base_url The base URL at which the Gradio server is hosted
20
+ * @param {string} root_path The root path, which could be a path suffix (e.g. mounted in FastAPI app) or a full URL (e.g. hosted on Hugging Face Spaces)
21
+ * @param {boolean} prioritize_base Whether to prioritize the base URL over the root path. This is used when both the base path and root paths are full URLs. For example, for fetching files the root path should be prioritized, but for making requests, the base URL should be prioritized.
22
+ * @returns {string} the resolved URL
23
+ */
24
+ export function resolve_root(
25
+ base_url: string,
26
+ root_path: string,
27
+ prioritize_base: boolean
28
+ ): string {
29
+ if (root_path.startsWith("http://") || root_path.startsWith("https://")) {
30
+ return prioritize_base ? base_url : root_path;
31
+ }
32
+ return base_url + root_path;
33
+ }
34
+
35
+ export async function get_jwt(
36
+ space: string,
37
+ token: `hf_${string}`,
38
+ cookies?: string | null
39
+ ): Promise<string | false> {
40
+ try {
41
+ const r = await fetch(`https://huggingface.co/api/spaces/${space}/jwt`, {
42
+ headers: {
43
+ Authorization: `Bearer ${token}`,
44
+ ...(cookies ? { Cookie: cookies } : {})
45
+ }
46
+ });
47
+
48
+ const jwt = (await r.json()).token;
49
+
50
+ return jwt || false;
51
+ } catch (e) {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ export function map_names_to_ids(
57
+ fns: Config["dependencies"]
58
+ ): Record<string, number> {
59
+ let apis: Record<string, number> = {};
60
+
61
+ fns.forEach(({ api_name, id }) => {
62
+ if (api_name) apis[api_name] = id;
63
+ });
64
+ return apis;
65
+ }
66
+
67
+ export async function resolve_config(
68
+ this: Client,
69
+ endpoint: string
70
+ ): Promise<Config | undefined> {
71
+ const headers: Record<string, string> = this.options.hf_token
72
+ ? { Authorization: `Bearer ${this.options.hf_token}` }
73
+ : {};
74
+
75
+ headers["Content-Type"] = "application/json";
76
+
77
+ if (
78
+ typeof window !== "undefined" &&
79
+ window.gradio_config &&
80
+ location.origin !== "http://localhost:9876" &&
81
+ !window.gradio_config.dev_mode
82
+ ) {
83
+ const path = window.gradio_config.root;
84
+ const config = window.gradio_config;
85
+ let config_root = resolve_root(endpoint, config.root, false);
86
+ config.root = config_root;
87
+ return { ...config, path } as Config;
88
+ } else if (endpoint) {
89
+ const config_url = join_urls(endpoint, CONFIG_URL);
90
+
91
+ const response = await this.fetch(config_url, {
92
+ headers,
93
+ credentials: "include"
94
+ });
95
+
96
+ if (response?.status === 401 && !this.options.auth) {
97
+ throw new Error(MISSING_CREDENTIALS_MSG);
98
+ } else if (response?.status === 401 && this.options.auth) {
99
+ throw new Error(INVALID_CREDENTIALS_MSG);
100
+ }
101
+ if (response?.status === 200) {
102
+ let config = await response.json();
103
+ config.path = config.path ?? "";
104
+ config.root = endpoint;
105
+ config.dependencies?.forEach((dep: any, i: number) => {
106
+ if (dep.id === undefined) {
107
+ dep.id = i;
108
+ }
109
+ });
110
+ return config;
111
+ } else if (response?.status === 401) {
112
+ throw new Error(UNAUTHORIZED_MSG);
113
+ }
114
+ throw new Error(CONFIG_ERROR_MSG);
115
+ }
116
+
117
+ throw new Error(CONFIG_ERROR_MSG);
118
+ }
119
+
120
+ export async function resolve_cookies(this: Client): Promise<void> {
121
+ const { http_protocol, host } = await process_endpoint(
122
+ this.app_reference,
123
+ this.options.hf_token
124
+ );
125
+
126
+ try {
127
+ if (this.options.auth) {
128
+ const cookie_header = await get_cookie_header(
129
+ http_protocol,
130
+ host,
131
+ this.options.auth,
132
+ this.fetch,
133
+ this.options.hf_token
134
+ );
135
+
136
+ if (cookie_header) this.set_cookies(cookie_header);
137
+ }
138
+ } catch (e: unknown) {
139
+ throw Error((e as Error).message);
140
+ }
141
+ }
142
+
143
+ // separating this from client-bound resolve_cookies so that it can be used in duplicate
144
+ export async function get_cookie_header(
145
+ http_protocol: string,
146
+ host: string,
147
+ auth: [string, string],
148
+ _fetch: typeof fetch,
149
+ hf_token?: `hf_${string}`
150
+ ): Promise<string | null> {
151
+ const formData = new FormData();
152
+ formData.append("username", auth?.[0]);
153
+ formData.append("password", auth?.[1]);
154
+
155
+ let headers: { Authorization?: string } = {};
156
+
157
+ if (hf_token) {
158
+ headers.Authorization = `Bearer ${hf_token}`;
159
+ }
160
+
161
+ const res = await _fetch(`${http_protocol}//${host}/${LOGIN_URL}`, {
162
+ headers,
163
+ method: "POST",
164
+ body: formData,
165
+ credentials: "include"
166
+ });
167
+
168
+ if (res.status === 200) {
169
+ return res.headers.get("set-cookie");
170
+ } else if (res.status === 401) {
171
+ throw new Error(INVALID_CREDENTIALS_MSG);
172
+ } else {
173
+ throw new Error(SPACE_METADATA_ERROR_MSG);
174
+ }
175
+ }
176
+
177
+ export function determine_protocol(endpoint: string): {
178
+ ws_protocol: "ws" | "wss";
179
+ http_protocol: "http:" | "https:";
180
+ host: string;
181
+ } {
182
+ if (endpoint.startsWith("http")) {
183
+ const { protocol, host, pathname } = new URL(endpoint);
184
+
185
+ if (host.endsWith("hf.space")) {
186
+ return {
187
+ ws_protocol: "wss",
188
+ host: host,
189
+ http_protocol: protocol as "http:" | "https:"
190
+ };
191
+ }
192
+ return {
193
+ ws_protocol: protocol === "https:" ? "wss" : "ws",
194
+ http_protocol: protocol as "http:" | "https:",
195
+ host: host + (pathname !== "/" ? pathname : "")
196
+ };
197
+ } else if (endpoint.startsWith("file:")) {
198
+ // This case is only expected to be used for the Wasm mode (Gradio-lite),
199
+ // where users can create a local HTML file using it and open the page in a browser directly via the `file:` protocol.
200
+ return {
201
+ ws_protocol: "ws",
202
+ http_protocol: "http:",
203
+ host: "lite.local" // Special fake hostname only used for this case. This matches the hostname allowed in `is_self_host()` in `js/wasm/network/host.ts`.
204
+ };
205
+ }
206
+
207
+ // default to secure if no protocol is provided
208
+
209
+ return {
210
+ ws_protocol: "wss",
211
+ http_protocol: "https:",
212
+ host: new URL(endpoint).host
213
+ };
214
+ }
215
+
216
+ export const parse_and_set_cookies = (cookie_header: string): string[] => {
217
+ let cookies: string[] = [];
218
+ const parts = cookie_header.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/);
219
+ parts.forEach((cookie) => {
220
+ const [cookie_name, cookie_value] = cookie.split(";")[0].split("=");
221
+ if (cookie_name && cookie_value) {
222
+ cookies.push(`${cookie_name.trim()}=${cookie_value.trim()}`);
223
+ }
224
+ });
225
+ return cookies;
226
+ };
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/helpers/spaces.ts ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ RUNTIME_URL,
3
+ SLEEPTIME_URL,
4
+ SPACE_STATUS_ERROR_MSG
5
+ } from "../constants";
6
+ import { RE_SPACE_NAME } from "./api_info";
7
+ import type { SpaceStatusCallback } from "../types";
8
+
9
+ export async function check_space_status(
10
+ id: string,
11
+ type: "subdomain" | "space_name",
12
+ status_callback: SpaceStatusCallback
13
+ ): Promise<void> {
14
+ let endpoint =
15
+ type === "subdomain"
16
+ ? `https://huggingface.co/api/spaces/by-subdomain/${id}`
17
+ : `https://huggingface.co/api/spaces/${id}`;
18
+ let response;
19
+ let _status;
20
+ try {
21
+ response = await fetch(endpoint);
22
+ _status = response.status;
23
+ if (_status !== 200) {
24
+ throw new Error();
25
+ }
26
+ response = await response.json();
27
+ } catch (e) {
28
+ status_callback({
29
+ status: "error",
30
+ load_status: "error",
31
+ message: SPACE_STATUS_ERROR_MSG,
32
+ detail: "NOT_FOUND"
33
+ });
34
+ return;
35
+ }
36
+
37
+ if (!response || _status !== 200) return;
38
+ const {
39
+ runtime: { stage },
40
+ id: space_name
41
+ } = response;
42
+
43
+ switch (stage) {
44
+ case "STOPPED":
45
+ case "SLEEPING":
46
+ status_callback({
47
+ status: "sleeping",
48
+ load_status: "pending",
49
+ message: "Space is asleep. Waking it up...",
50
+ detail: stage
51
+ });
52
+
53
+ setTimeout(() => {
54
+ check_space_status(id, type, status_callback);
55
+ }, 1000); // poll for status
56
+ break;
57
+ case "PAUSED":
58
+ status_callback({
59
+ status: "paused",
60
+ load_status: "error",
61
+ message:
62
+ "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
63
+ detail: stage,
64
+ discussions_enabled: await discussions_enabled(space_name)
65
+ });
66
+ break;
67
+ case "RUNNING":
68
+ case "RUNNING_BUILDING":
69
+ status_callback({
70
+ status: "running",
71
+ load_status: "complete",
72
+ message: "Space is running.",
73
+ detail: stage
74
+ });
75
+ break;
76
+ case "BUILDING":
77
+ status_callback({
78
+ status: "building",
79
+ load_status: "pending",
80
+ message: "Space is building...",
81
+ detail: stage
82
+ });
83
+
84
+ setTimeout(() => {
85
+ check_space_status(id, type, status_callback);
86
+ }, 1000);
87
+ break;
88
+ case "APP_STARTING":
89
+ status_callback({
90
+ status: "starting",
91
+ load_status: "pending",
92
+ message: "Space is starting...",
93
+ detail: stage
94
+ });
95
+
96
+ setTimeout(() => {
97
+ check_space_status(id, type, status_callback);
98
+ }, 1000);
99
+ break;
100
+ default:
101
+ status_callback({
102
+ status: "space_error",
103
+ load_status: "error",
104
+ message: "This space is experiencing an issue.",
105
+ detail: stage,
106
+ discussions_enabled: await discussions_enabled(space_name)
107
+ });
108
+ break;
109
+ }
110
+ }
111
+
112
+ export const check_and_wake_space = async (
113
+ space_id: string,
114
+ status_callback: SpaceStatusCallback
115
+ ): Promise<void> => {
116
+ let retries = 0;
117
+ const max_retries = 12;
118
+ const check_interval = 5000;
119
+
120
+ return new Promise((resolve) => {
121
+ check_space_status(
122
+ space_id,
123
+ RE_SPACE_NAME.test(space_id) ? "space_name" : "subdomain",
124
+ (status) => {
125
+ status_callback(status);
126
+
127
+ if (status.status === "running") {
128
+ resolve();
129
+ } else if (
130
+ status.status === "error" ||
131
+ status.status === "paused" ||
132
+ status.status === "space_error"
133
+ ) {
134
+ resolve();
135
+ } else if (
136
+ status.status === "sleeping" ||
137
+ status.status === "building"
138
+ ) {
139
+ if (retries < max_retries) {
140
+ retries++;
141
+ setTimeout(() => {
142
+ check_and_wake_space(space_id, status_callback).then(resolve);
143
+ }, check_interval);
144
+ } else {
145
+ resolve();
146
+ }
147
+ }
148
+ }
149
+ );
150
+ });
151
+ };
152
+
153
+ const RE_DISABLED_DISCUSSION =
154
+ /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
155
+ export async function discussions_enabled(space_id: string): Promise<boolean> {
156
+ try {
157
+ const r = await fetch(
158
+ `https://huggingface.co/api/spaces/${space_id}/discussions`,
159
+ {
160
+ method: "HEAD"
161
+ }
162
+ );
163
+
164
+ const error = r.headers.get("x-error-message");
165
+
166
+ if (!r.ok || (error && RE_DISABLED_DISCUSSION.test(error))) return false;
167
+ return true;
168
+ } catch (e) {
169
+ return false;
170
+ }
171
+ }
172
+
173
+ export async function get_space_hardware(
174
+ space_id: string,
175
+ hf_token?: `hf_${string}` | undefined
176
+ ): Promise<(typeof hardware_types)[number]> {
177
+ const headers: { Authorization?: string } = {};
178
+ if (hf_token) {
179
+ headers.Authorization = `Bearer ${hf_token}`;
180
+ }
181
+
182
+ try {
183
+ const res = await fetch(
184
+ `https://huggingface.co/api/spaces/${space_id}/${RUNTIME_URL}`,
185
+ { headers }
186
+ );
187
+
188
+ if (res.status !== 200)
189
+ throw new Error("Space hardware could not be obtained.");
190
+
191
+ const { hardware } = await res.json();
192
+
193
+ return hardware.current;
194
+ } catch (e: any) {
195
+ throw new Error(e.message);
196
+ }
197
+ }
198
+
199
+ export async function set_space_timeout(
200
+ space_id: string,
201
+ timeout: number,
202
+ hf_token?: `hf_${string}`
203
+ ): Promise<any> {
204
+ const headers: { Authorization?: string } = {};
205
+ if (hf_token) {
206
+ headers.Authorization = `Bearer ${hf_token}`;
207
+ }
208
+
209
+ const body: {
210
+ seconds?: number;
211
+ } = {
212
+ seconds: timeout
213
+ };
214
+
215
+ try {
216
+ const res = await fetch(
217
+ `https://huggingface.co/api/spaces/${space_id}/${SLEEPTIME_URL}`,
218
+ {
219
+ method: "POST",
220
+ headers: { "Content-Type": "application/json", ...headers },
221
+ body: JSON.stringify(body)
222
+ }
223
+ );
224
+
225
+ if (res.status !== 200) {
226
+ throw new Error(
227
+ "Could not set sleep timeout on duplicated Space. Please visit *ADD HF LINK TO SETTINGS* to set a timeout manually to reduce billing charges."
228
+ );
229
+ }
230
+
231
+ const response = await res.json();
232
+ return response;
233
+ } catch (e: any) {
234
+ throw new Error(e.message);
235
+ }
236
+ }
237
+
238
+ export const hardware_types = [
239
+ "cpu-basic",
240
+ "cpu-upgrade",
241
+ "cpu-xl",
242
+ "t4-small",
243
+ "t4-medium",
244
+ "a10g-small",
245
+ "a10g-large",
246
+ "a10g-largex2",
247
+ "a10g-largex4",
248
+ "a100-large",
249
+ "zero-a10g",
250
+ "h100",
251
+ "h100x8"
252
+ ] as const;
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/index.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export { Client } from "./client";
2
+
3
+ export { predict } from "./utils/predict";
4
+ export { submit } from "./utils/submit";
5
+ export { upload_files } from "./utils/upload_files";
6
+ export { FileData, upload, prepare_files } from "./upload";
7
+ export { handle_file } from "./helpers/data";
8
+
9
+ export type {
10
+ SpaceStatus,
11
+ StatusMessage,
12
+ Status,
13
+ client_return,
14
+ UploadResponse,
15
+ RenderMessage,
16
+ LogMessage,
17
+ Payload,
18
+ Config
19
+ } from "./types";
20
+
21
+ // todo: remove in @gradio/client v1.0
22
+ export { client } from "./client";
23
+ export { duplicate_space as duplicate } from "./client";
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/types.ts ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // API Data Types
2
+
3
+ import { hardware_types } from "./helpers/spaces";
4
+ import type { SvelteComponent } from "svelte";
5
+ import type { ComponentType } from "svelte";
6
+
7
+ export interface ApiData {
8
+ label: string;
9
+ parameter_name: string;
10
+ parameter_default?: any;
11
+ parameter_has_default?: boolean;
12
+ type: {
13
+ type: any;
14
+ description: string;
15
+ };
16
+ component: string;
17
+ example_input?: any;
18
+ python_type: { type: string; description: string };
19
+ serializer: string;
20
+ }
21
+
22
+ export interface JsApiData {
23
+ label: string;
24
+ parameter_name: string;
25
+ parameter_default?: any;
26
+ parameter_has_default?: boolean;
27
+ type: string;
28
+ description: string;
29
+ component: string;
30
+ example_input?: any;
31
+ serializer: string;
32
+ python_type: { type: string; description: string };
33
+ }
34
+
35
+ export interface EndpointInfo<T extends ApiData | JsApiData> {
36
+ parameters: T[];
37
+ returns: T[];
38
+ type?: DependencyTypes;
39
+ }
40
+
41
+ export interface ApiInfo<T extends ApiData | JsApiData> {
42
+ named_endpoints: Record<string, EndpointInfo<T>>;
43
+ unnamed_endpoints: Record<string, EndpointInfo<T>>;
44
+ }
45
+
46
+ export interface BlobRef {
47
+ path: string[];
48
+ type: string | undefined;
49
+ blob: Blob | File | false;
50
+ }
51
+
52
+ export type DataType = string | Buffer | Record<string, any> | any[];
53
+
54
+ // custom class used for uploading local files
55
+ export class Command {
56
+ type: string;
57
+ command: string;
58
+ meta: {
59
+ path: string;
60
+ name: string;
61
+ orig_path: string;
62
+ };
63
+ fileData?: FileData;
64
+
65
+ constructor(
66
+ command: string,
67
+ meta: { path: string; name: string; orig_path: string }
68
+ ) {
69
+ this.type = "command";
70
+ this.command = command;
71
+ this.meta = meta;
72
+ }
73
+ }
74
+
75
+ // Function Signature Types
76
+
77
+ export type SubmitFunction = (
78
+ endpoint: string | number,
79
+ data?: unknown[] | Record<string, unknown>,
80
+ event_data?: unknown,
81
+ trigger_id?: number | null
82
+ ) => SubmitIterable<GradioEvent>;
83
+
84
+ export type PredictFunction = (
85
+ endpoint: string | number,
86
+ data?: unknown[] | Record<string, unknown>,
87
+ event_data?: unknown
88
+ ) => Promise<PredictReturn>;
89
+
90
+ export type client_return = {
91
+ config: Config | undefined;
92
+ predict: PredictFunction;
93
+ submit: SubmitFunction;
94
+ component_server: (
95
+ component_id: number,
96
+ fn_name: string,
97
+ data: unknown[]
98
+ ) => any;
99
+ view_api: (_fetch: typeof fetch) => Promise<ApiInfo<JsApiData>>;
100
+ };
101
+
102
+ export interface SubmitIterable<T> extends AsyncIterable<T> {
103
+ [Symbol.asyncIterator](): AsyncIterator<T>;
104
+ cancel: () => Promise<void>;
105
+ event_id: () => string;
106
+ }
107
+
108
+ export type PredictReturn = {
109
+ type: EventType;
110
+ time: Date;
111
+ data: unknown;
112
+ endpoint: string;
113
+ fn_index: number;
114
+ };
115
+
116
+ // Space Status Types
117
+
118
+ export type SpaceStatus = SpaceStatusNormal | SpaceStatusError;
119
+
120
+ export interface SpaceStatusNormal {
121
+ status:
122
+ | "sleeping"
123
+ | "running"
124
+ | "building"
125
+ | "error"
126
+ | "stopped"
127
+ | "starting";
128
+ detail:
129
+ | "SLEEPING"
130
+ | "RUNNING"
131
+ | "RUNNING_BUILDING"
132
+ | "BUILDING"
133
+ | "APP_STARTING"
134
+ | "NOT_FOUND";
135
+ load_status: "pending" | "error" | "complete" | "generating";
136
+ message: string;
137
+ }
138
+
139
+ export interface SpaceStatusError {
140
+ status: "space_error" | "paused";
141
+ detail:
142
+ | "NO_APP_FILE"
143
+ | "CONFIG_ERROR"
144
+ | "BUILD_ERROR"
145
+ | "RUNTIME_ERROR"
146
+ | "PAUSED";
147
+ load_status: "error";
148
+ message: string;
149
+ discussions_enabled: boolean;
150
+ }
151
+
152
+ export type SpaceStatusCallback = (a: SpaceStatus) => void;
153
+
154
+ // Configuration and Response Types
155
+ // --------------------------------
156
+ export interface Config {
157
+ auth_required?: true;
158
+ analytics_enabled: boolean;
159
+ connect_heartbeat: boolean;
160
+ auth_message: string;
161
+ components: ComponentMeta[];
162
+ css: string | null;
163
+ js: string | null;
164
+ head: string | null;
165
+ dependencies: Dependency[];
166
+ dev_mode: boolean;
167
+ enable_queue: boolean;
168
+ show_error: boolean;
169
+ layout: any;
170
+ mode: "blocks" | "interface";
171
+ root: string;
172
+ root_url?: string;
173
+ theme: string;
174
+ title: string;
175
+ version: string;
176
+ space_id: string | null;
177
+ is_space: boolean;
178
+ is_colab: boolean;
179
+ show_api: boolean;
180
+ stylesheets: string[];
181
+ path: string;
182
+ protocol: "sse_v3" | "sse_v2.1" | "sse_v2" | "sse_v1" | "sse" | "ws";
183
+ max_file_size?: number;
184
+ theme_hash?: number;
185
+ username: string | null;
186
+ api_prefix?: string;
187
+ fill_height?: boolean;
188
+ fill_width?: boolean;
189
+ }
190
+
191
+ // todo: DRY up types
192
+ export interface ComponentMeta {
193
+ type: string;
194
+ id: number;
195
+ has_modes: boolean;
196
+ props: SharedProps;
197
+ instance: SvelteComponent;
198
+ component: ComponentType<SvelteComponent>;
199
+ documentation?: Documentation;
200
+ children?: ComponentMeta[];
201
+ parent?: ComponentMeta;
202
+ value?: any;
203
+ component_class_id: string;
204
+ key: string | number | null;
205
+ rendered_in?: number;
206
+ }
207
+
208
+ interface SharedProps {
209
+ elem_id?: string;
210
+ elem_classes?: string[];
211
+ components?: string[];
212
+ server_fns?: string[];
213
+ interactive: boolean;
214
+ [key: string]: unknown;
215
+ root_url?: string;
216
+ }
217
+
218
+ export interface Documentation {
219
+ type?: TypeDescription;
220
+ description?: TypeDescription;
221
+ example_data?: string;
222
+ }
223
+
224
+ interface TypeDescription {
225
+ input_payload?: string;
226
+ response_object?: string;
227
+ payload?: string;
228
+ }
229
+
230
+ export interface Dependency {
231
+ id: number;
232
+ targets: [number, string][];
233
+ inputs: number[];
234
+ outputs: number[];
235
+ backend_fn: boolean;
236
+ js: string | null;
237
+ scroll_to_output: boolean;
238
+ trigger: "click" | "load" | string;
239
+ max_batch_size: number;
240
+ show_progress: "full" | "minimal" | "hidden";
241
+ frontend_fn: ((...args: unknown[]) => Promise<unknown[]>) | null;
242
+ status?: string;
243
+ queue: boolean | null;
244
+ every: number | null;
245
+ batch: boolean;
246
+ api_name: string | null;
247
+ cancels: number[];
248
+ types: DependencyTypes;
249
+ collects_event_data: boolean;
250
+ pending_request?: boolean;
251
+ trigger_after?: number;
252
+ trigger_only_on_success?: boolean;
253
+ trigger_mode: "once" | "multiple" | "always_last";
254
+ final_event: Payload | null;
255
+ show_api: boolean;
256
+ zerogpu?: boolean;
257
+ rendered_in: number | null;
258
+ connection: "stream" | "sse";
259
+ time_limit: number;
260
+ stream_every: number;
261
+ like_user_message: boolean;
262
+ event_specific_args: string[];
263
+ }
264
+
265
+ export interface DependencyTypes {
266
+ generator: boolean;
267
+ cancel: boolean;
268
+ }
269
+
270
+ export interface Payload {
271
+ fn_index: number;
272
+ data: unknown[];
273
+ time?: Date;
274
+ event_data?: unknown;
275
+ trigger_id?: number | null;
276
+ }
277
+
278
+ export interface PostResponse {
279
+ error?: string;
280
+ [x: string]: any;
281
+ }
282
+
283
+ export interface UploadResponse {
284
+ error?: string;
285
+ files?: string[];
286
+ }
287
+
288
+ // Client and File Handling Types
289
+
290
+ export interface DuplicateOptions extends ClientOptions {
291
+ private?: boolean;
292
+ hardware?: (typeof hardware_types)[number];
293
+ timeout?: number;
294
+ }
295
+
296
+ export interface ClientOptions {
297
+ hf_token?: `hf_${string}`;
298
+ status_callback?: SpaceStatusCallback | null;
299
+ auth?: [string, string] | null;
300
+ with_null_state?: boolean;
301
+ events?: EventType[];
302
+ }
303
+
304
+ export interface FileData {
305
+ name: string;
306
+ orig_name?: string;
307
+ size?: number;
308
+ data: string;
309
+ blob?: File;
310
+ is_file?: boolean;
311
+ mime_type?: string;
312
+ alt_text?: string;
313
+ }
314
+
315
+ // Event and Listener Types
316
+
317
+ export type EventType = "data" | "status" | "log" | "render";
318
+
319
+ export interface EventMap {
320
+ data: PayloadMessage;
321
+ status: StatusMessage;
322
+ log: LogMessage;
323
+ render: RenderMessage;
324
+ }
325
+
326
+ export type GradioEvent = {
327
+ [P in EventType]: EventMap[P];
328
+ }[EventType];
329
+
330
+ export interface Log {
331
+ log: string;
332
+ level: "warning" | "info";
333
+ }
334
+ export interface Render {
335
+ data: {
336
+ components: any[];
337
+ layout: any;
338
+ dependencies: Dependency[];
339
+ render_id: number;
340
+ };
341
+ }
342
+
343
+ export interface Status {
344
+ queue: boolean;
345
+ code?: string;
346
+ success?: boolean;
347
+ stage: "pending" | "error" | "complete" | "generating" | "streaming";
348
+ duration?: number;
349
+ visible?: boolean;
350
+ broken?: boolean;
351
+ size?: number;
352
+ position?: number;
353
+ eta?: number;
354
+ message?: string;
355
+ progress_data?: {
356
+ progress: number | null;
357
+ index: number | null;
358
+ length: number | null;
359
+ unit: string | null;
360
+ desc: string | null;
361
+ }[];
362
+ time?: Date;
363
+ changed_state_ids?: number[];
364
+ time_limit?: number;
365
+ }
366
+
367
+ export interface StatusMessage extends Status {
368
+ type: "status";
369
+ endpoint: string;
370
+ fn_index: number;
371
+ original_msg?: string;
372
+ }
373
+
374
+ export interface PayloadMessage extends Payload {
375
+ type: "data";
376
+ endpoint: string;
377
+ fn_index: number;
378
+ }
379
+
380
+ export interface LogMessage extends Log {
381
+ type: "log";
382
+ endpoint: string;
383
+ fn_index: number;
384
+ duration: number | null;
385
+ visible: boolean;
386
+ }
387
+
388
+ export interface RenderMessage extends Render {
389
+ type: "render";
390
+ endpoint: string;
391
+ fn_index: number;
392
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/upload.ts ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Client } from "./client";
2
+
3
+ export async function upload(
4
+ this: Client,
5
+ file_data: FileData[],
6
+ root_url: string,
7
+ upload_id?: string,
8
+ max_file_size?: number
9
+ ): Promise<(FileData | null)[] | null> {
10
+ let files = (Array.isArray(file_data) ? file_data : [file_data]).map(
11
+ (file_data) => file_data.blob!
12
+ );
13
+
14
+ const oversized_files = files.filter(
15
+ (f) => f.size > (max_file_size ?? Infinity)
16
+ );
17
+ if (oversized_files.length) {
18
+ throw new Error(
19
+ `File size exceeds the maximum allowed size of ${max_file_size} bytes: ${oversized_files
20
+ .map((f) => f.name)
21
+ .join(", ")}`
22
+ );
23
+ }
24
+
25
+ return await Promise.all(
26
+ await this.upload_files(root_url, files, upload_id).then(
27
+ async (response: { files?: string[]; error?: string }) => {
28
+ if (response.error) {
29
+ throw new Error(response.error);
30
+ } else {
31
+ if (response.files) {
32
+ return response.files.map((f, i) => {
33
+ const file = new FileData({
34
+ ...file_data[i],
35
+ path: f,
36
+ url: `${root_url}${this.api_prefix}/file=${f}`
37
+ });
38
+ return file;
39
+ });
40
+ }
41
+
42
+ return [];
43
+ }
44
+ }
45
+ )
46
+ );
47
+ }
48
+
49
+ export async function prepare_files(
50
+ files: File[],
51
+ is_stream?: boolean
52
+ ): Promise<FileData[]> {
53
+ return files.map(
54
+ (f) =>
55
+ new FileData({
56
+ path: f.name,
57
+ orig_name: f.name,
58
+ blob: f,
59
+ size: f.size,
60
+ mime_type: f.type,
61
+ is_stream
62
+ })
63
+ );
64
+ }
65
+
66
+ export class FileData {
67
+ path: string;
68
+ url?: string;
69
+ orig_name?: string;
70
+ size?: number;
71
+ blob?: File;
72
+ is_stream?: boolean;
73
+ mime_type?: string;
74
+ alt_text?: string;
75
+ b64?: string;
76
+ readonly meta = { _type: "gradio.FileData" };
77
+
78
+ constructor({
79
+ path,
80
+ url,
81
+ orig_name,
82
+ size,
83
+ blob,
84
+ is_stream,
85
+ mime_type,
86
+ alt_text,
87
+ b64
88
+ }: {
89
+ path: string;
90
+ url?: string;
91
+ orig_name?: string;
92
+ size?: number;
93
+ blob?: File;
94
+ is_stream?: boolean;
95
+ mime_type?: string;
96
+ alt_text?: string;
97
+ b64?: string;
98
+ }) {
99
+ this.path = path;
100
+ this.url = url;
101
+ this.orig_name = orig_name;
102
+ this.size = size;
103
+ this.blob = url ? undefined : blob;
104
+ this.is_stream = is_stream;
105
+ this.mime_type = mime_type;
106
+ this.alt_text = alt_text;
107
+ this.b64 = b64;
108
+ }
109
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/post_data.ts ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { BROKEN_CONNECTION_MSG } from "../constants";
2
+ import type { PostResponse } from "../types";
3
+ import { Client } from "..";
4
+
5
+ export async function post_data(
6
+ this: Client,
7
+ url: string,
8
+ body: unknown,
9
+ additional_headers?: any
10
+ ): Promise<[PostResponse, number]> {
11
+ const headers: {
12
+ Authorization?: string;
13
+ "Content-Type": "application/json";
14
+ } = { "Content-Type": "application/json" };
15
+ if (this.options.hf_token) {
16
+ headers.Authorization = `Bearer ${this.options.hf_token}`;
17
+ }
18
+ try {
19
+ var response = await this.fetch(url, {
20
+ method: "POST",
21
+ body: JSON.stringify(body),
22
+ headers: { ...headers, ...additional_headers },
23
+ credentials: "include"
24
+ });
25
+ } catch (e) {
26
+ return [{ error: BROKEN_CONNECTION_MSG }, 500];
27
+ }
28
+ let output: PostResponse;
29
+ let status: number;
30
+ try {
31
+ output = await response.json();
32
+ status = response.status;
33
+ } catch (e) {
34
+ output = { error: `Could not parse server response: ${e}` };
35
+ status = 500;
36
+ }
37
+ return [output, status];
38
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/predict.ts ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Client } from "../client";
2
+ import type { Dependency, PredictReturn } from "../types";
3
+
4
+ export async function predict(
5
+ this: Client,
6
+ endpoint: string | number,
7
+ data: unknown[] | Record<string, unknown> = {}
8
+ ): Promise<PredictReturn> {
9
+ let data_returned = false;
10
+ let status_complete = false;
11
+ let dependency: Dependency;
12
+
13
+ if (!this.config) {
14
+ throw new Error("Could not resolve app config");
15
+ }
16
+
17
+ if (typeof endpoint === "number") {
18
+ dependency = this.config.dependencies.find((dep) => dep.id == endpoint)!;
19
+ } else {
20
+ const trimmed_endpoint = endpoint.replace(/^\//, "");
21
+ dependency = this.config.dependencies.find(
22
+ (dep) => dep.id == this.api_map[trimmed_endpoint]
23
+ )!;
24
+ }
25
+
26
+ return new Promise(async (resolve, reject) => {
27
+ const app = this.submit(endpoint, data, null, null, true);
28
+ let result: unknown;
29
+
30
+ for await (const message of app) {
31
+ if (message.type === "data") {
32
+ if (status_complete) {
33
+ resolve(result as PredictReturn);
34
+ }
35
+ data_returned = true;
36
+ result = message;
37
+ }
38
+
39
+ if (message.type === "status") {
40
+ if (message.stage === "error") reject(message);
41
+ if (message.stage === "complete") {
42
+ status_complete = true;
43
+ // if complete message comes after data, resolve here
44
+ if (data_returned) {
45
+ resolve(result as PredictReturn);
46
+ }
47
+ }
48
+ }
49
+ }
50
+ });
51
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/stream.ts ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { BROKEN_CONNECTION_MSG, SSE_URL } from "../constants";
2
+ import type { Client } from "../client";
3
+ import { stream } from "fetch-event-stream";
4
+
5
+ export async function open_stream(this: Client): Promise<void> {
6
+ let {
7
+ event_callbacks,
8
+ unclosed_events,
9
+ pending_stream_messages,
10
+ stream_status,
11
+ config,
12
+ jwt
13
+ } = this;
14
+
15
+ const that = this;
16
+
17
+ if (!config) {
18
+ throw new Error("Could not resolve app config");
19
+ }
20
+
21
+ stream_status.open = true;
22
+
23
+ let stream: EventSource | null = null;
24
+ let params = new URLSearchParams({
25
+ session_hash: this.session_hash
26
+ }).toString();
27
+
28
+ let url = new URL(`${config.root}${this.api_prefix}/${SSE_URL}?${params}`);
29
+
30
+ if (jwt) {
31
+ url.searchParams.set("__sign", jwt);
32
+ }
33
+
34
+ stream = this.stream(url);
35
+
36
+ if (!stream) {
37
+ console.warn("Cannot connect to SSE endpoint: " + url.toString());
38
+ return;
39
+ }
40
+
41
+ stream.onmessage = async function (event: MessageEvent) {
42
+ let _data = JSON.parse(event.data);
43
+ if (_data.msg === "close_stream") {
44
+ close_stream(stream_status, that.abort_controller);
45
+ return;
46
+ }
47
+ const event_id = _data.event_id;
48
+ if (!event_id) {
49
+ await Promise.all(
50
+ Object.keys(event_callbacks).map((event_id) =>
51
+ event_callbacks[event_id](_data)
52
+ )
53
+ );
54
+ } else if (event_callbacks[event_id] && config) {
55
+ if (
56
+ _data.msg === "process_completed" &&
57
+ ["sse", "sse_v1", "sse_v2", "sse_v2.1", "sse_v3"].includes(
58
+ config.protocol
59
+ )
60
+ ) {
61
+ unclosed_events.delete(event_id);
62
+ }
63
+ let fn: (data: any) => void = event_callbacks[event_id];
64
+
65
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
66
+ // fn(_data); // need to do this to put the event on the end of the event loop, so the browser can refresh between callbacks and not freeze in case of quick generations. See
67
+ setTimeout(fn, 0, _data); // need to do this to put the event on the end of the event loop, so the browser can refresh between callbacks and not freeze in case of quick generations. See https://github.com/gradio-app/gradio/pull/7055
68
+ } else {
69
+ fn(_data);
70
+ }
71
+ } else {
72
+ if (!pending_stream_messages[event_id]) {
73
+ pending_stream_messages[event_id] = [];
74
+ }
75
+ pending_stream_messages[event_id].push(_data);
76
+ }
77
+ };
78
+ stream.onerror = async function () {
79
+ await Promise.all(
80
+ Object.keys(event_callbacks).map((event_id) =>
81
+ event_callbacks[event_id]({
82
+ msg: "unexpected_error",
83
+ message: BROKEN_CONNECTION_MSG
84
+ })
85
+ )
86
+ );
87
+ };
88
+ }
89
+
90
+ export function close_stream(
91
+ stream_status: { open: boolean },
92
+ abort_controller: AbortController | null
93
+ ): void {
94
+ if (stream_status) {
95
+ stream_status.open = false;
96
+ abort_controller?.abort();
97
+ }
98
+ }
99
+
100
+ export function apply_diff_stream(
101
+ pending_diff_streams: Record<string, any[][]>,
102
+ event_id: string,
103
+ data: any
104
+ ): void {
105
+ let is_first_generation = !pending_diff_streams[event_id];
106
+ if (is_first_generation) {
107
+ pending_diff_streams[event_id] = [];
108
+ data.data.forEach((value: any, i: number) => {
109
+ pending_diff_streams[event_id][i] = value;
110
+ });
111
+ } else {
112
+ data.data.forEach((value: any, i: number) => {
113
+ let new_data = apply_diff(pending_diff_streams[event_id][i], value);
114
+ pending_diff_streams[event_id][i] = new_data;
115
+ data.data[i] = new_data;
116
+ });
117
+ }
118
+ }
119
+
120
+ export function apply_diff(
121
+ obj: any,
122
+ diff: [string, (number | string)[], any][]
123
+ ): any {
124
+ diff.forEach(([action, path, value]) => {
125
+ obj = apply_edit(obj, path, action, value);
126
+ });
127
+
128
+ return obj;
129
+ }
130
+
131
+ function apply_edit(
132
+ target: any,
133
+ path: (number | string)[],
134
+ action: string,
135
+ value: any
136
+ ): any {
137
+ if (path.length === 0) {
138
+ if (action === "replace") {
139
+ return value;
140
+ } else if (action === "append") {
141
+ return target + value;
142
+ }
143
+ throw new Error(`Unsupported action: ${action}`);
144
+ }
145
+
146
+ let current = target;
147
+ for (let i = 0; i < path.length - 1; i++) {
148
+ current = current[path[i]];
149
+ }
150
+
151
+ const last_path = path[path.length - 1];
152
+ switch (action) {
153
+ case "replace":
154
+ current[last_path] = value;
155
+ break;
156
+ case "append":
157
+ current[last_path] += value;
158
+ break;
159
+ case "add":
160
+ if (Array.isArray(current)) {
161
+ current.splice(Number(last_path), 0, value);
162
+ } else {
163
+ current[last_path] = value;
164
+ }
165
+ break;
166
+ case "delete":
167
+ if (Array.isArray(current)) {
168
+ current.splice(Number(last_path), 1);
169
+ } else {
170
+ delete current[last_path];
171
+ }
172
+ break;
173
+ default:
174
+ throw new Error(`Unknown action: ${action}`);
175
+ }
176
+ return target;
177
+ }
178
+
179
+ export function readable_stream(
180
+ input: RequestInfo | URL,
181
+ init: RequestInit = {}
182
+ ): EventSource {
183
+ const instance: EventSource & { readyState: number } = {
184
+ close: () => {
185
+ console.warn("Method not implemented.");
186
+ },
187
+ onerror: null,
188
+ onmessage: null,
189
+ onopen: null,
190
+ readyState: 0,
191
+ url: input.toString(),
192
+ withCredentials: false,
193
+ CONNECTING: 0,
194
+ OPEN: 1,
195
+ CLOSED: 2,
196
+ addEventListener: () => {
197
+ throw new Error("Method not implemented.");
198
+ },
199
+ dispatchEvent: () => {
200
+ throw new Error("Method not implemented.");
201
+ },
202
+ removeEventListener: () => {
203
+ throw new Error("Method not implemented.");
204
+ }
205
+ };
206
+
207
+ stream(input, init)
208
+ .then(async (res) => {
209
+ instance.readyState = instance.OPEN;
210
+ try {
211
+ for await (const chunk of res) {
212
+ //@ts-ignore
213
+ instance.onmessage && instance.onmessage(chunk);
214
+ }
215
+ instance.readyState = instance.CLOSED;
216
+ } catch (e) {
217
+ instance.onerror && instance.onerror(e as Event);
218
+ instance.readyState = instance.CLOSED;
219
+ }
220
+ })
221
+ .catch((e) => {
222
+ console.error(e);
223
+ instance.onerror && instance.onerror(e as Event);
224
+ instance.readyState = instance.CLOSED;
225
+ });
226
+
227
+ return instance as EventSource;
228
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/submit.ts ADDED
@@ -0,0 +1,862 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* eslint-disable complexity */
2
+ import type {
3
+ Status,
4
+ Payload,
5
+ GradioEvent,
6
+ JsApiData,
7
+ EndpointInfo,
8
+ ApiInfo,
9
+ Config,
10
+ Dependency,
11
+ SubmitIterable
12
+ } from "../types";
13
+
14
+ import { skip_queue, post_message, handle_payload } from "../helpers/data";
15
+ import { resolve_root } from "../helpers/init_helpers";
16
+ import {
17
+ handle_message,
18
+ map_data_to_params,
19
+ process_endpoint
20
+ } from "../helpers/api_info";
21
+ import semiver from "semiver";
22
+ import {
23
+ BROKEN_CONNECTION_MSG,
24
+ QUEUE_FULL_MSG,
25
+ SSE_URL,
26
+ SSE_DATA_URL,
27
+ RESET_URL,
28
+ CANCEL_URL
29
+ } from "../constants";
30
+ import { apply_diff_stream, close_stream } from "./stream";
31
+ import { Client } from "../client";
32
+
33
+ export function submit(
34
+ this: Client,
35
+ endpoint: string | number,
36
+ data: unknown[] | Record<string, unknown> = {},
37
+ event_data?: unknown,
38
+ trigger_id?: number | null,
39
+ all_events?: boolean
40
+ ): SubmitIterable<GradioEvent> {
41
+ try {
42
+ const { hf_token } = this.options;
43
+ const {
44
+ fetch,
45
+ app_reference,
46
+ config,
47
+ session_hash,
48
+ api_info,
49
+ api_map,
50
+ stream_status,
51
+ pending_stream_messages,
52
+ pending_diff_streams,
53
+ event_callbacks,
54
+ unclosed_events,
55
+ post_data,
56
+ options,
57
+ api_prefix
58
+ } = this;
59
+
60
+ const that = this;
61
+
62
+ if (!api_info) throw new Error("No API found");
63
+ if (!config) throw new Error("Could not resolve app config");
64
+
65
+ let { fn_index, endpoint_info, dependency } = get_endpoint_info(
66
+ api_info,
67
+ endpoint,
68
+ api_map,
69
+ config
70
+ );
71
+
72
+ let resolved_data = map_data_to_params(data, endpoint_info);
73
+
74
+ let websocket: WebSocket;
75
+ let stream: EventSource | null;
76
+ let protocol = config.protocol ?? "ws";
77
+ let event_id_final = "";
78
+ let event_id_cb: () => string = () => event_id_final;
79
+
80
+ const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
81
+ let payload: Payload;
82
+ let event_id: string | null = null;
83
+ let complete: Status | undefined | false = false;
84
+ let last_status: Record<string, Status["stage"]> = {};
85
+ let url_params =
86
+ typeof window !== "undefined" && typeof document !== "undefined"
87
+ ? new URLSearchParams(window.location.search).toString()
88
+ : "";
89
+
90
+ const events_to_publish =
91
+ options?.events?.reduce(
92
+ (acc, event) => {
93
+ acc[event] = true;
94
+ return acc;
95
+ },
96
+ {} as Record<string, boolean>
97
+ ) || {};
98
+
99
+ // event subscription methods
100
+ function fire_event(event: GradioEvent): void {
101
+ if (all_events || events_to_publish[event.type]) {
102
+ push_event(event);
103
+ }
104
+ }
105
+
106
+ async function cancel(): Promise<void> {
107
+ const _status: Status = {
108
+ stage: "complete",
109
+ queue: false,
110
+ time: new Date()
111
+ };
112
+ complete = _status;
113
+ fire_event({
114
+ ..._status,
115
+ type: "status",
116
+ endpoint: _endpoint,
117
+ fn_index: fn_index
118
+ });
119
+
120
+ let reset_request = {};
121
+ let cancel_request = {};
122
+ if (protocol === "ws") {
123
+ if (websocket && websocket.readyState === 0) {
124
+ websocket.addEventListener("open", () => {
125
+ websocket.close();
126
+ });
127
+ } else {
128
+ websocket.close();
129
+ }
130
+ reset_request = { fn_index, session_hash };
131
+ } else {
132
+ close_stream(stream_status, that.abort_controller);
133
+ close();
134
+ reset_request = { event_id };
135
+ cancel_request = { event_id, session_hash, fn_index };
136
+ }
137
+
138
+ try {
139
+ if (!config) {
140
+ throw new Error("Could not resolve app config");
141
+ }
142
+
143
+ if ("event_id" in cancel_request) {
144
+ await fetch(`${config.root}${api_prefix}/${CANCEL_URL}`, {
145
+ headers: { "Content-Type": "application/json" },
146
+ method: "POST",
147
+ body: JSON.stringify(cancel_request)
148
+ });
149
+ }
150
+
151
+ await fetch(`${config.root}${api_prefix}/${RESET_URL}`, {
152
+ headers: { "Content-Type": "application/json" },
153
+ method: "POST",
154
+ body: JSON.stringify(reset_request)
155
+ });
156
+ } catch (e) {
157
+ console.warn(
158
+ "The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable."
159
+ );
160
+ }
161
+ }
162
+
163
+ const resolve_heartbeat = async (config: Config): Promise<void> => {
164
+ await this._resolve_hearbeat(config);
165
+ };
166
+
167
+ async function handle_render_config(render_config: any): Promise<void> {
168
+ if (!config) return;
169
+ let render_id: number = render_config.render_id;
170
+ config.components = [
171
+ ...config.components.filter((c) => c.props.rendered_in !== render_id),
172
+ ...render_config.components
173
+ ];
174
+ config.dependencies = [
175
+ ...config.dependencies.filter((d) => d.rendered_in !== render_id),
176
+ ...render_config.dependencies
177
+ ];
178
+ const any_state = config.components.some((c) => c.type === "state");
179
+ const any_unload = config.dependencies.some((d) =>
180
+ d.targets.some((t) => t[1] === "unload")
181
+ );
182
+ config.connect_heartbeat = any_state || any_unload;
183
+ await resolve_heartbeat(config);
184
+ fire_event({
185
+ type: "render",
186
+ data: render_config,
187
+ endpoint: _endpoint,
188
+ fn_index
189
+ });
190
+ }
191
+
192
+ this.handle_blob(config.root, resolved_data, endpoint_info).then(
193
+ async (_payload) => {
194
+ let input_data = handle_payload(
195
+ _payload,
196
+ dependency,
197
+ config.components,
198
+ "input",
199
+ true
200
+ );
201
+ payload = {
202
+ data: input_data || [],
203
+ event_data,
204
+ fn_index,
205
+ trigger_id
206
+ };
207
+ if (skip_queue(fn_index, config)) {
208
+ fire_event({
209
+ type: "status",
210
+ endpoint: _endpoint,
211
+ stage: "pending",
212
+ queue: false,
213
+ fn_index,
214
+ time: new Date()
215
+ });
216
+
217
+ post_data(
218
+ `${config.root}${api_prefix}/run${
219
+ _endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
220
+ }${url_params ? "?" + url_params : ""}`,
221
+ {
222
+ ...payload,
223
+ session_hash
224
+ }
225
+ )
226
+ .then(([output, status_code]: any) => {
227
+ const data = output.data;
228
+ if (status_code == 200) {
229
+ fire_event({
230
+ type: "data",
231
+ endpoint: _endpoint,
232
+ fn_index,
233
+ data: handle_payload(
234
+ data,
235
+ dependency,
236
+ config.components,
237
+ "output",
238
+ options.with_null_state
239
+ ),
240
+ time: new Date(),
241
+ event_data,
242
+ trigger_id
243
+ });
244
+ if (output.render_config) {
245
+ handle_render_config(output.render_config);
246
+ }
247
+
248
+ fire_event({
249
+ type: "status",
250
+ endpoint: _endpoint,
251
+ fn_index,
252
+ stage: "complete",
253
+ eta: output.average_duration,
254
+ queue: false,
255
+ time: new Date()
256
+ });
257
+ } else {
258
+ fire_event({
259
+ type: "status",
260
+ stage: "error",
261
+ endpoint: _endpoint,
262
+ fn_index,
263
+ message: output.error,
264
+ queue: false,
265
+ time: new Date()
266
+ });
267
+ }
268
+ })
269
+ .catch((e) => {
270
+ fire_event({
271
+ type: "status",
272
+ stage: "error",
273
+ message: e.message,
274
+ endpoint: _endpoint,
275
+ fn_index,
276
+ queue: false,
277
+ time: new Date()
278
+ });
279
+ });
280
+ } else if (protocol == "ws") {
281
+ const { ws_protocol, host } = await process_endpoint(
282
+ app_reference,
283
+ hf_token
284
+ );
285
+
286
+ fire_event({
287
+ type: "status",
288
+ stage: "pending",
289
+ queue: true,
290
+ endpoint: _endpoint,
291
+ fn_index,
292
+ time: new Date()
293
+ });
294
+
295
+ let url = new URL(
296
+ `${ws_protocol}://${resolve_root(
297
+ host,
298
+ config.path as string,
299
+ true
300
+ )}/queue/join${url_params ? "?" + url_params : ""}`
301
+ );
302
+
303
+ if (this.jwt) {
304
+ url.searchParams.set("__sign", this.jwt);
305
+ }
306
+
307
+ websocket = new WebSocket(url);
308
+
309
+ websocket.onclose = (evt) => {
310
+ if (!evt.wasClean) {
311
+ fire_event({
312
+ type: "status",
313
+ stage: "error",
314
+ broken: true,
315
+ message: BROKEN_CONNECTION_MSG,
316
+ queue: true,
317
+ endpoint: _endpoint,
318
+ fn_index,
319
+ time: new Date()
320
+ });
321
+ }
322
+ };
323
+
324
+ websocket.onmessage = function (event) {
325
+ const _data = JSON.parse(event.data);
326
+ const { type, status, data } = handle_message(
327
+ _data,
328
+ last_status[fn_index]
329
+ );
330
+
331
+ if (type === "update" && status && !complete) {
332
+ // call 'status' listeners
333
+ fire_event({
334
+ type: "status",
335
+ endpoint: _endpoint,
336
+ fn_index,
337
+ time: new Date(),
338
+ ...status
339
+ });
340
+ if (status.stage === "error") {
341
+ websocket.close();
342
+ }
343
+ } else if (type === "hash") {
344
+ websocket.send(JSON.stringify({ fn_index, session_hash }));
345
+ return;
346
+ } else if (type === "data") {
347
+ websocket.send(JSON.stringify({ ...payload, session_hash }));
348
+ } else if (type === "complete") {
349
+ complete = status;
350
+ } else if (type === "log") {
351
+ fire_event({
352
+ type: "log",
353
+ log: data.log,
354
+ level: data.level,
355
+ endpoint: _endpoint,
356
+ duration: data.duration,
357
+ visible: data.visible,
358
+ fn_index
359
+ });
360
+ } else if (type === "generating") {
361
+ fire_event({
362
+ type: "status",
363
+ time: new Date(),
364
+ ...status,
365
+ stage: status?.stage!,
366
+ queue: true,
367
+ endpoint: _endpoint,
368
+ fn_index
369
+ });
370
+ }
371
+ if (data) {
372
+ fire_event({
373
+ type: "data",
374
+ time: new Date(),
375
+ data: handle_payload(
376
+ data.data,
377
+ dependency,
378
+ config.components,
379
+ "output",
380
+ options.with_null_state
381
+ ),
382
+ endpoint: _endpoint,
383
+ fn_index,
384
+ event_data,
385
+ trigger_id
386
+ });
387
+
388
+ if (complete) {
389
+ fire_event({
390
+ type: "status",
391
+ time: new Date(),
392
+ ...complete,
393
+ stage: status?.stage!,
394
+ queue: true,
395
+ endpoint: _endpoint,
396
+ fn_index
397
+ });
398
+ websocket.close();
399
+ }
400
+ }
401
+ };
402
+
403
+ // different ws contract for gradio versions older than 3.6.0
404
+ //@ts-ignore
405
+ if (semiver(config.version || "2.0.0", "3.6") < 0) {
406
+ addEventListener("open", () =>
407
+ websocket.send(JSON.stringify({ hash: session_hash }))
408
+ );
409
+ }
410
+ } else if (protocol == "sse") {
411
+ fire_event({
412
+ type: "status",
413
+ stage: "pending",
414
+ queue: true,
415
+ endpoint: _endpoint,
416
+ fn_index,
417
+ time: new Date()
418
+ });
419
+ var params = new URLSearchParams({
420
+ fn_index: fn_index.toString(),
421
+ session_hash: session_hash
422
+ }).toString();
423
+ let url = new URL(
424
+ `${config.root}${api_prefix}/${SSE_URL}?${
425
+ url_params ? url_params + "&" : ""
426
+ }${params}`
427
+ );
428
+
429
+ if (this.jwt) {
430
+ url.searchParams.set("__sign", this.jwt);
431
+ }
432
+
433
+ stream = this.stream(url);
434
+
435
+ if (!stream) {
436
+ return Promise.reject(
437
+ new Error("Cannot connect to SSE endpoint: " + url.toString())
438
+ );
439
+ }
440
+
441
+ stream.onmessage = async function (event: MessageEvent) {
442
+ const _data = JSON.parse(event.data);
443
+ const { type, status, data } = handle_message(
444
+ _data,
445
+ last_status[fn_index]
446
+ );
447
+
448
+ if (type === "update" && status && !complete) {
449
+ // call 'status' listeners
450
+ fire_event({
451
+ type: "status",
452
+ endpoint: _endpoint,
453
+ fn_index,
454
+ time: new Date(),
455
+ ...status
456
+ });
457
+ if (status.stage === "error") {
458
+ stream?.close();
459
+ close();
460
+ }
461
+ } else if (type === "data") {
462
+ let [_, status] = await post_data(
463
+ `${config.root}${api_prefix}/queue/data`,
464
+ {
465
+ ...payload,
466
+ session_hash,
467
+ event_id
468
+ }
469
+ );
470
+ if (status !== 200) {
471
+ fire_event({
472
+ type: "status",
473
+ stage: "error",
474
+ message: BROKEN_CONNECTION_MSG,
475
+ queue: true,
476
+ endpoint: _endpoint,
477
+ fn_index,
478
+ time: new Date()
479
+ });
480
+ stream?.close();
481
+ close();
482
+ }
483
+ } else if (type === "complete") {
484
+ complete = status;
485
+ } else if (type === "log") {
486
+ fire_event({
487
+ type: "log",
488
+ log: data.log,
489
+ level: data.level,
490
+ endpoint: _endpoint,
491
+ duration: data.duration,
492
+ visible: data.visible,
493
+ fn_index
494
+ });
495
+ } else if (type === "generating" || type === "streaming") {
496
+ fire_event({
497
+ type: "status",
498
+ time: new Date(),
499
+ ...status,
500
+ stage: status?.stage!,
501
+ queue: true,
502
+ endpoint: _endpoint,
503
+ fn_index
504
+ });
505
+ }
506
+ if (data) {
507
+ fire_event({
508
+ type: "data",
509
+ time: new Date(),
510
+ data: handle_payload(
511
+ data.data,
512
+ dependency,
513
+ config.components,
514
+ "output",
515
+ options.with_null_state
516
+ ),
517
+ endpoint: _endpoint,
518
+ fn_index,
519
+ event_data,
520
+ trigger_id
521
+ });
522
+
523
+ if (complete) {
524
+ fire_event({
525
+ type: "status",
526
+ time: new Date(),
527
+ ...complete,
528
+ stage: status?.stage!,
529
+ queue: true,
530
+ endpoint: _endpoint,
531
+ fn_index
532
+ });
533
+ stream?.close();
534
+ close();
535
+ }
536
+ }
537
+ };
538
+ } else if (
539
+ protocol == "sse_v1" ||
540
+ protocol == "sse_v2" ||
541
+ protocol == "sse_v2.1" ||
542
+ protocol == "sse_v3"
543
+ ) {
544
+ // latest API format. v2 introduces sending diffs for intermediate outputs in generative functions, which makes payloads lighter.
545
+ // v3 only closes the stream when the backend sends the close stream message.
546
+ fire_event({
547
+ type: "status",
548
+ stage: "pending",
549
+ queue: true,
550
+ endpoint: _endpoint,
551
+ fn_index,
552
+ time: new Date()
553
+ });
554
+ let hostname = "";
555
+ if (
556
+ typeof window !== "undefined" &&
557
+ typeof document !== "undefined"
558
+ ) {
559
+ hostname = window?.location?.hostname;
560
+ }
561
+
562
+ let hfhubdev = "dev.spaces.huggingface.tech";
563
+ const origin = hostname.includes(".dev.")
564
+ ? `https://moon-${hostname.split(".")[1]}.${hfhubdev}`
565
+ : `https://huggingface.co`;
566
+
567
+ const is_iframe =
568
+ typeof window !== "undefined" &&
569
+ typeof document !== "undefined" &&
570
+ window.parent != window;
571
+ const is_zerogpu_space = dependency.zerogpu && config.space_id;
572
+ const zerogpu_auth_promise =
573
+ is_iframe && is_zerogpu_space
574
+ ? post_message<Headers>("zerogpu-headers", origin)
575
+ : Promise.resolve(null);
576
+ const post_data_promise = zerogpu_auth_promise.then((headers) => {
577
+ return post_data(
578
+ `${config.root}${api_prefix}/${SSE_DATA_URL}?${url_params}`,
579
+ {
580
+ ...payload,
581
+ session_hash
582
+ },
583
+ headers
584
+ );
585
+ });
586
+ post_data_promise.then(async ([response, status]: any) => {
587
+ if (status === 503) {
588
+ fire_event({
589
+ type: "status",
590
+ stage: "error",
591
+ message: QUEUE_FULL_MSG,
592
+ queue: true,
593
+ endpoint: _endpoint,
594
+ fn_index,
595
+ time: new Date()
596
+ });
597
+ } else if (status !== 200) {
598
+ fire_event({
599
+ type: "status",
600
+ stage: "error",
601
+ message: BROKEN_CONNECTION_MSG,
602
+ queue: true,
603
+ endpoint: _endpoint,
604
+ fn_index,
605
+ time: new Date()
606
+ });
607
+ } else {
608
+ event_id = response.event_id as string;
609
+ event_id_final = event_id;
610
+ let callback = async function (_data: object): Promise<void> {
611
+ try {
612
+ const { type, status, data, original_msg } = handle_message(
613
+ _data,
614
+ last_status[fn_index]
615
+ );
616
+
617
+ if (type == "heartbeat") {
618
+ return;
619
+ }
620
+
621
+ if (type === "update" && status && !complete) {
622
+ // call 'status' listeners
623
+ fire_event({
624
+ type: "status",
625
+ endpoint: _endpoint,
626
+ fn_index,
627
+ time: new Date(),
628
+ original_msg: original_msg,
629
+ ...status
630
+ });
631
+ } else if (type === "complete") {
632
+ complete = status;
633
+ } else if (type == "unexpected_error") {
634
+ console.error("Unexpected error", status?.message);
635
+ fire_event({
636
+ type: "status",
637
+ stage: "error",
638
+ message:
639
+ status?.message || "An Unexpected Error Occurred!",
640
+ queue: true,
641
+ endpoint: _endpoint,
642
+ fn_index,
643
+ time: new Date()
644
+ });
645
+ } else if (type === "log") {
646
+ fire_event({
647
+ type: "log",
648
+ log: data.log,
649
+ level: data.level,
650
+ endpoint: _endpoint,
651
+ duration: data.duration,
652
+ visible: data.visible,
653
+ fn_index
654
+ });
655
+ return;
656
+ } else if (type === "generating" || type === "streaming") {
657
+ fire_event({
658
+ type: "status",
659
+ time: new Date(),
660
+ ...status,
661
+ stage: status?.stage!,
662
+ queue: true,
663
+ endpoint: _endpoint,
664
+ fn_index
665
+ });
666
+ if (
667
+ data &&
668
+ dependency.connection !== "stream" &&
669
+ ["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)
670
+ ) {
671
+ apply_diff_stream(pending_diff_streams, event_id!, data);
672
+ }
673
+ }
674
+ if (data) {
675
+ fire_event({
676
+ type: "data",
677
+ time: new Date(),
678
+ data: handle_payload(
679
+ data.data,
680
+ dependency,
681
+ config.components,
682
+ "output",
683
+ options.with_null_state
684
+ ),
685
+ endpoint: _endpoint,
686
+ fn_index
687
+ });
688
+ if (data.render_config) {
689
+ await handle_render_config(data.render_config);
690
+ }
691
+
692
+ if (complete) {
693
+ fire_event({
694
+ type: "status",
695
+ time: new Date(),
696
+ ...complete,
697
+ stage: status?.stage!,
698
+ queue: true,
699
+ endpoint: _endpoint,
700
+ fn_index
701
+ });
702
+
703
+ close();
704
+ }
705
+ }
706
+
707
+ if (
708
+ status?.stage === "complete" ||
709
+ status?.stage === "error"
710
+ ) {
711
+ if (event_callbacks[event_id!]) {
712
+ delete event_callbacks[event_id!];
713
+ }
714
+ if (event_id! in pending_diff_streams) {
715
+ delete pending_diff_streams[event_id!];
716
+ }
717
+ }
718
+ } catch (e) {
719
+ console.error("Unexpected client exception", e);
720
+ fire_event({
721
+ type: "status",
722
+ stage: "error",
723
+ message: "An Unexpected Error Occurred!",
724
+ queue: true,
725
+ endpoint: _endpoint,
726
+ fn_index,
727
+ time: new Date()
728
+ });
729
+ if (["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)) {
730
+ close_stream(stream_status, that.abort_controller);
731
+ stream_status.open = false;
732
+ close();
733
+ }
734
+ }
735
+ };
736
+
737
+ if (event_id in pending_stream_messages) {
738
+ pending_stream_messages[event_id].forEach((msg) =>
739
+ callback(msg)
740
+ );
741
+ delete pending_stream_messages[event_id];
742
+ }
743
+ // @ts-ignore
744
+ event_callbacks[event_id] = callback;
745
+ unclosed_events.add(event_id);
746
+ if (!stream_status.open) {
747
+ await this.open_stream();
748
+ }
749
+ }
750
+ });
751
+ }
752
+ }
753
+ );
754
+
755
+ let done = false;
756
+ const values: (IteratorResult<GradioEvent> | PromiseLike<never>)[] = [];
757
+ const resolvers: ((
758
+ value: IteratorResult<GradioEvent> | PromiseLike<never>
759
+ ) => void)[] = [];
760
+
761
+ function close(): void {
762
+ done = true;
763
+ while (resolvers.length > 0)
764
+ (resolvers.shift() as (typeof resolvers)[0])({
765
+ value: undefined,
766
+ done: true
767
+ });
768
+ }
769
+
770
+ function push(
771
+ data: { value: GradioEvent; done: boolean } | PromiseLike<never>
772
+ ): void {
773
+ if (done) return;
774
+ if (resolvers.length > 0) {
775
+ (resolvers.shift() as (typeof resolvers)[0])(data);
776
+ } else {
777
+ values.push(data);
778
+ }
779
+ }
780
+
781
+ function push_error(error: unknown): void {
782
+ push(thenable_reject(error));
783
+ close();
784
+ }
785
+
786
+ function push_event(event: GradioEvent): void {
787
+ push({ value: event, done: false });
788
+ }
789
+
790
+ function next(): Promise<IteratorResult<GradioEvent, unknown>> {
791
+ if (values.length > 0)
792
+ return Promise.resolve(values.shift() as (typeof values)[0]);
793
+ if (done) return Promise.resolve({ value: undefined, done: true });
794
+ return new Promise((resolve) => resolvers.push(resolve));
795
+ }
796
+
797
+ const iterator = {
798
+ [Symbol.asyncIterator]: () => iterator,
799
+ next,
800
+ throw: async (value: unknown) => {
801
+ push_error(value);
802
+ return next();
803
+ },
804
+ return: async () => {
805
+ close();
806
+ return next();
807
+ },
808
+ cancel,
809
+ event_id: event_id_cb
810
+ };
811
+
812
+ return iterator;
813
+ } catch (error) {
814
+ console.error("Submit function encountered an error:", error);
815
+ throw error;
816
+ }
817
+ }
818
+
819
+ function thenable_reject<T>(error: T): PromiseLike<never> {
820
+ return {
821
+ then: (
822
+ resolve: (value: never) => PromiseLike<never>,
823
+ reject: (error: T) => PromiseLike<never>
824
+ ) => reject(error)
825
+ };
826
+ }
827
+
828
+ function get_endpoint_info(
829
+ api_info: ApiInfo<JsApiData>,
830
+ endpoint: string | number,
831
+ api_map: Record<string, number>,
832
+ config: Config
833
+ ): {
834
+ fn_index: number;
835
+ endpoint_info: EndpointInfo<JsApiData>;
836
+ dependency: Dependency;
837
+ } {
838
+ let fn_index: number;
839
+ let endpoint_info: EndpointInfo<JsApiData>;
840
+ let dependency: Dependency;
841
+
842
+ if (typeof endpoint === "number") {
843
+ fn_index = endpoint;
844
+ endpoint_info = api_info.unnamed_endpoints[fn_index];
845
+ dependency = config.dependencies.find((dep) => dep.id == endpoint)!;
846
+ } else {
847
+ const trimmed_endpoint = endpoint.replace(/^\//, "");
848
+
849
+ fn_index = api_map[trimmed_endpoint];
850
+ endpoint_info = api_info.named_endpoints[endpoint.trim()];
851
+ dependency = config.dependencies.find(
852
+ (dep) => dep.id == api_map[trimmed_endpoint]
853
+ )!;
854
+ }
855
+
856
+ if (typeof fn_index !== "number") {
857
+ throw new Error(
858
+ "There is no endpoint matching that name of fn_index matching that number."
859
+ );
860
+ }
861
+ return { fn_index, endpoint_info, dependency };
862
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/upload_files.ts ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Client } from "..";
2
+ import { BROKEN_CONNECTION_MSG, UPLOAD_URL } from "../constants";
3
+ import type { UploadResponse } from "../types";
4
+
5
+ export async function upload_files(
6
+ this: Client,
7
+ root_url: string,
8
+ files: (Blob | File)[],
9
+ upload_id?: string
10
+ ): Promise<UploadResponse> {
11
+ const headers: {
12
+ Authorization?: string;
13
+ } = {};
14
+ if (this?.options?.hf_token) {
15
+ headers.Authorization = `Bearer ${this.options.hf_token}`;
16
+ }
17
+
18
+ const chunkSize = 1000;
19
+ const uploadResponses = [];
20
+ let response: Response;
21
+
22
+ for (let i = 0; i < files.length; i += chunkSize) {
23
+ const chunk = files.slice(i, i + chunkSize);
24
+ const formData = new FormData();
25
+ chunk.forEach((file) => {
26
+ formData.append("files", file);
27
+ });
28
+ try {
29
+ const upload_url = upload_id
30
+ ? `${root_url}${this.api_prefix}/${UPLOAD_URL}?upload_id=${upload_id}`
31
+ : `${root_url}${this.api_prefix}/${UPLOAD_URL}`;
32
+
33
+ response = await this.fetch(upload_url, {
34
+ method: "POST",
35
+ body: formData,
36
+ headers,
37
+ credentials: "include"
38
+ });
39
+ } catch (e) {
40
+ throw new Error(BROKEN_CONNECTION_MSG + (e as Error).message);
41
+ }
42
+ if (!response.ok) {
43
+ const error_text = await response.text();
44
+ return { error: `HTTP ${response.status}: ${error_text}` };
45
+ }
46
+ const output: UploadResponse["files"] = await response.json();
47
+ if (output) {
48
+ uploadResponses.push(...output);
49
+ }
50
+ }
51
+ return { files: uploadResponses };
52
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/utils/view_api.ts ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { ApiInfo, ApiData } from "../types";
2
+ import semiver from "semiver";
3
+ import { API_INFO_URL, BROKEN_CONNECTION_MSG } from "../constants";
4
+ import { Client } from "../client";
5
+ import { SPACE_FETCHER_URL } from "../constants";
6
+ import { join_urls, transform_api_info } from "../helpers/api_info";
7
+
8
+ export async function view_api(this: Client): Promise<any> {
9
+ if (this.api_info) return this.api_info;
10
+
11
+ const { hf_token } = this.options;
12
+ const { config } = this;
13
+
14
+ const headers: {
15
+ Authorization?: string;
16
+ "Content-Type": "application/json";
17
+ } = { "Content-Type": "application/json" };
18
+
19
+ if (hf_token) {
20
+ headers.Authorization = `Bearer ${hf_token}`;
21
+ }
22
+
23
+ if (!config) {
24
+ return;
25
+ }
26
+
27
+ try {
28
+ let response: Response;
29
+ let api_info: ApiInfo<ApiData> | { api: ApiInfo<ApiData> };
30
+ if (typeof window !== "undefined" && window.gradio_api_info) {
31
+ api_info = window.gradio_api_info;
32
+ } else {
33
+ if (semiver(config?.version || "2.0.0", "3.30") < 0) {
34
+ response = await this.fetch(SPACE_FETCHER_URL, {
35
+ method: "POST",
36
+ body: JSON.stringify({
37
+ serialize: false,
38
+ config: JSON.stringify(config)
39
+ }),
40
+ headers,
41
+ credentials: "include"
42
+ });
43
+ } else {
44
+ const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
45
+ response = await this.fetch(url, {
46
+ headers,
47
+ credentials: "include"
48
+ });
49
+ }
50
+
51
+ if (!response.ok) {
52
+ throw new Error(BROKEN_CONNECTION_MSG);
53
+ }
54
+ api_info = await response.json();
55
+ }
56
+ if ("api" in api_info) {
57
+ api_info = api_info.api;
58
+ }
59
+
60
+ if (
61
+ api_info.named_endpoints["/predict"] &&
62
+ !api_info.unnamed_endpoints["0"]
63
+ ) {
64
+ api_info.unnamed_endpoints[0] = api_info.named_endpoints["/predict"];
65
+ }
66
+
67
+ return transform_api_info(api_info, config, this.api_map);
68
+ } catch (e) {
69
+ "Could not get API info. " + (e as Error).message;
70
+ }
71
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/src/vite-env.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ /// <reference types="vite/client" />
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/client/tsconfig.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "include": ["src/**/*"],
3
+ "exclude": ["src/**/*.test.ts", "src/**/*.node-test.ts"],
4
+ "compilerOptions": {
5
+ "allowJs": true,
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true,
8
+ "outDir": "dist",
9
+ "declarationMap": true,
10
+ "module": "ESNext",
11
+ "target": "ES2020",
12
+ "useDefineForClassFields": true,
13
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
14
+ "skipLibCheck": true,
15
+
16
+ /* Bundler */
17
+ "moduleResolution": "bundler",
18
+ "skipDefaultLibCheck": true,
19
+ "allowImportingTsExtensions": true,
20
+ "esModuleInterop": true,
21
+ "resolveJsonModule": true,
22
+ "isolatedModules": true,
23
+
24
+ /* Linting */
25
+ "strict": true
26
+ }
27
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/Index.svelte ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseDataFrame } from "./shared/Table.svelte";
3
+ export { default as BaseExample } from "./Example.svelte";
4
+ </script>
5
+
6
+ <script lang="ts">
7
+ import { afterUpdate, tick } from "svelte";
8
+ import type { Gradio, SelectData } from "@gradio/utils";
9
+ import { Block } from "@gradio/atoms";
10
+ import Table from "./shared/Table.svelte";
11
+ import { StatusTracker } from "@gradio/statustracker";
12
+ import type { LoadingStatus } from "@gradio/statustracker";
13
+ import type { Headers, Data, Metadata, Datatype } from "./shared/utils";
14
+ export let headers: Headers = [];
15
+ export let elem_id = "";
16
+ export let elem_classes: string[] = [];
17
+ export let visible = true;
18
+ export let value: { data: Data; headers: Headers; metadata: Metadata } = {
19
+ data: [["", "", ""]],
20
+ headers: ["1", "2", "3"],
21
+ metadata: null
22
+ };
23
+ let old_value = "";
24
+ export let value_is_output = false;
25
+ export let col_count: [number, "fixed" | "dynamic"];
26
+ export let row_count: [number, "fixed" | "dynamic"];
27
+ export let label: string | null = null;
28
+ export let show_label = true;
29
+ export let wrap: boolean;
30
+ export let datatype: Datatype | Datatype[];
31
+ export let scale: number | null = null;
32
+ export let min_width: number | undefined = undefined;
33
+ export let root: string;
34
+
35
+ export let line_breaks = true;
36
+ export let column_widths: string[] = [];
37
+ export let gradio: Gradio<{
38
+ change: never;
39
+ select: SelectData;
40
+ input: never;
41
+ clear_status: LoadingStatus;
42
+ }>;
43
+ export let latex_delimiters: {
44
+ left: string;
45
+ right: string;
46
+ display: boolean;
47
+ }[];
48
+ export let max_height: number | undefined = undefined;
49
+
50
+ export let loading_status: LoadingStatus;
51
+ export let interactive: boolean;
52
+
53
+ let _headers: Headers;
54
+ let display_value: string[][] | null;
55
+ let styling: string[][] | null;
56
+ let values: (string | number)[][];
57
+ async function handle_change(data?: {
58
+ data: Data;
59
+ headers: Headers;
60
+ metadata: Metadata;
61
+ }): Promise<void> {
62
+ let _data = data || value;
63
+
64
+ _headers = [...(_data.headers || headers)];
65
+ values = _data.data ? [..._data.data] : [];
66
+ display_value = _data?.metadata?.display_value
67
+ ? [..._data?.metadata?.display_value]
68
+ : null;
69
+ styling =
70
+ !interactive && _data?.metadata?.styling
71
+ ? [..._data?.metadata?.styling]
72
+ : null;
73
+ await tick();
74
+
75
+ gradio.dispatch("change");
76
+ if (!value_is_output) {
77
+ gradio.dispatch("input");
78
+ }
79
+ }
80
+
81
+ handle_change();
82
+
83
+ afterUpdate(() => {
84
+ value_is_output = false;
85
+ });
86
+
87
+ $: {
88
+ if (old_value && JSON.stringify(value) !== old_value) {
89
+ old_value = JSON.stringify(value);
90
+ handle_change();
91
+ }
92
+ }
93
+
94
+ if (
95
+ (Array.isArray(value) && value?.[0]?.length === 0) ||
96
+ value.data?.[0]?.length === 0
97
+ ) {
98
+ value = {
99
+ data: [Array(col_count?.[0] || 3).fill("")],
100
+ headers: Array(col_count?.[0] || 3)
101
+ .fill("")
102
+ .map((_, i) => `${i + 1}`),
103
+ metadata: null
104
+ };
105
+ }
106
+
107
+ async function handle_value_change(data: {
108
+ data: Data;
109
+ headers: Headers;
110
+ metadata: Metadata;
111
+ }): Promise<void> {
112
+ if (JSON.stringify(data) !== old_value) {
113
+ value = { ...data };
114
+ old_value = JSON.stringify(value);
115
+ handle_change(data);
116
+ }
117
+ }
118
+ </script>
119
+
120
+ <Block
121
+ {visible}
122
+ padding={false}
123
+ {elem_id}
124
+ {elem_classes}
125
+ container={false}
126
+ {scale}
127
+ {min_width}
128
+ allow_overflow={false}
129
+ >
130
+ <StatusTracker
131
+ autoscroll={gradio.autoscroll}
132
+ i18n={gradio.i18n}
133
+ {...loading_status}
134
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
135
+ />
136
+ <Table
137
+ {root}
138
+ {label}
139
+ {show_label}
140
+ {row_count}
141
+ {col_count}
142
+ {values}
143
+ {display_value}
144
+ {styling}
145
+ headers={_headers}
146
+ on:change={(e) => handle_value_change(e.detail)}
147
+ on:select={(e) => gradio.dispatch("select", e.detail)}
148
+ {wrap}
149
+ {datatype}
150
+ {latex_delimiters}
151
+ editable={interactive}
152
+ {max_height}
153
+ i18n={gradio.i18n}
154
+ {line_breaks}
155
+ {column_widths}
156
+ upload={(...args) => gradio.client.upload(...args)}
157
+ stream_handler={(...args) => gradio.client.stream(...args)}
158
+ />
159
+ </Block>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/package.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/dataframe",
3
+ "version": "0.11.2",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "./Index.svelte",
11
+ "dependencies": {
12
+ "@gradio/atoms": "workspace:^",
13
+ "@gradio/button": "workspace:^",
14
+ "@gradio/client": "workspace:^",
15
+ "@gradio/markdown": "workspace:^",
16
+ "@gradio/statustracker": "workspace:^",
17
+ "@gradio/upload": "workspace:^",
18
+ "@gradio/utils": "workspace:^",
19
+ "@types/d3-dsv": "^3.0.0",
20
+ "@types/dompurify": "^3.0.2",
21
+ "@types/katex": "^0.16.0",
22
+ "d3-dsv": "^3.0.1",
23
+ "dequal": "^2.0.2",
24
+ "dompurify": "^3.0.3",
25
+ "katex": "^0.16.7",
26
+ "marked": "^12.0.0"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "gradio": "./Index.svelte",
31
+ "svelte": "./dist/Index.svelte",
32
+ "types": "./dist/Index.svelte.d.ts"
33
+ },
34
+ "./example": {
35
+ "gradio": "./Example.svelte",
36
+ "svelte": "./dist/Example.svelte",
37
+ "types": "./dist/Example.svelte.d.ts"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "peerDependencies": {
42
+ "svelte": "^4.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@gradio/preview": "workspace:^"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/gradio-app/gradio.git",
50
+ "directory": "js/dataframe"
51
+ }
52
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/Arrow.svelte ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let transform: string;
3
+ </script>
4
+
5
+ <svg viewBox="0 0 24 24" width="16" height="16">
6
+ <path
7
+ d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"
8
+ {transform}
9
+ />
10
+ </svg>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/CellMenu.svelte ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import Arrow from "./Arrow.svelte";
4
+ import type { I18nFormatter } from "js/utils/src";
5
+
6
+ export let x: number;
7
+ export let y: number;
8
+ export let on_add_row_above: () => void;
9
+ export let on_add_row_below: () => void;
10
+ export let on_add_column_left: () => void;
11
+ export let on_add_column_right: () => void;
12
+ export let row: number;
13
+
14
+ export let i18n: I18nFormatter;
15
+ let menu_element: HTMLDivElement;
16
+
17
+ $: is_header = row === -1;
18
+
19
+ onMount(() => {
20
+ position_menu();
21
+ });
22
+
23
+ function position_menu(): void {
24
+ if (!menu_element) return;
25
+
26
+ const viewport_width = window.innerWidth;
27
+ const viewport_height = window.innerHeight;
28
+ const menu_rect = menu_element.getBoundingClientRect();
29
+
30
+ let new_x = x - 30;
31
+ let new_y = y - 20;
32
+
33
+ if (new_x + menu_rect.width > viewport_width) {
34
+ new_x = x - menu_rect.width + 10;
35
+ }
36
+
37
+ if (new_y + menu_rect.height > viewport_height) {
38
+ new_y = y - menu_rect.height + 10;
39
+ }
40
+
41
+ menu_element.style.left = `${new_x}px`;
42
+ menu_element.style.top = `${new_y}px`;
43
+ }
44
+ </script>
45
+
46
+ <div bind:this={menu_element} class="cell-menu">
47
+ {#if !is_header}
48
+ <button on:click={() => on_add_row_above()}>
49
+ <Arrow transform="rotate(-90 12 12)" />
50
+ {i18n("dataframe.add_row_above")}
51
+ </button>
52
+ <button on:click={() => on_add_row_below()}>
53
+ <Arrow transform="rotate(90 12 12)" />
54
+ {i18n("dataframe.add_row_below")}
55
+ </button>
56
+ {/if}
57
+ <button on:click={() => on_add_column_left()}>
58
+ <Arrow transform="rotate(180 12 12)" />
59
+ {i18n("dataframe.add_column_left")}
60
+ </button>
61
+ <button on:click={() => on_add_column_right()}>
62
+ <Arrow transform="rotate(0 12 12)" />
63
+ {i18n("dataframe.add_column_right")}
64
+ </button>
65
+ </div>
66
+
67
+ <style>
68
+ .cell-menu {
69
+ position: fixed;
70
+ z-index: var(--layer-2);
71
+ background: var(--background-fill-primary);
72
+ border: 1px solid var(--border-color-primary);
73
+ border-radius: var(--radius-sm);
74
+ padding: var(--size-1);
75
+ display: flex;
76
+ flex-direction: column;
77
+ gap: var(--size-1);
78
+ box-shadow: var(--shadow-drop-lg);
79
+ min-width: 150px;
80
+ }
81
+
82
+ .cell-menu button {
83
+ background: none;
84
+ border: none;
85
+ cursor: pointer;
86
+ text-align: left;
87
+ padding: var(--size-1) var(--size-2);
88
+ border-radius: var(--radius-sm);
89
+ color: var(--body-text-color);
90
+ font-size: var(--text-sm);
91
+ transition:
92
+ background-color 0.2s,
93
+ color 0.2s;
94
+ display: flex;
95
+ align-items: center;
96
+ gap: var(--size-2);
97
+ }
98
+
99
+ .cell-menu button:hover {
100
+ background-color: var(--background-fill-secondary);
101
+ }
102
+
103
+ .cell-menu button :global(svg) {
104
+ fill: currentColor;
105
+ transition: fill 0.2s;
106
+ }
107
+
108
+ .cell-menu button:hover :global(svg) {
109
+ fill: var(--color-accent);
110
+ }
111
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/Example.svelte ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: (string | number)[][];
3
+ </script>
4
+
5
+ <table class="input-dataframe-example">
6
+ {#each value.slice(0, 3) as row}
7
+ <tr>
8
+ {#each row.slice(0, 3) as cell}
9
+ <td class="p-2">{cell}</td>
10
+ {/each}
11
+ {#if row.length > 3}
12
+ <td class="p-2">...</td>
13
+ {/if}
14
+ </tr>
15
+ {/each}
16
+ {#if value.length > 3}
17
+ <tr>
18
+ {#each Array(Math.min(4, value[0].length)) as _}
19
+ <td class="p-2">...</td>
20
+ {/each}
21
+ </tr>
22
+ {/if}
23
+ </table>
24
+
25
+ <style>
26
+ table {
27
+ border-collapse: separate;
28
+ }
29
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/Table.svelte ADDED
@@ -0,0 +1,1235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, tick, onMount } from "svelte";
3
+ import { dsvFormat } from "d3-dsv";
4
+ import { dequal } from "dequal/lite";
5
+ import { copy } from "@gradio/utils";
6
+ import { Upload } from "@gradio/upload";
7
+
8
+ import EditableCell from "./EditableCell.svelte";
9
+ import type { SelectData } from "@gradio/utils";
10
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
11
+ import { type Client } from "@gradio/client";
12
+ import VirtualTable from "./VirtualTable.svelte";
13
+ import type { Headers, HeadersWithIDs, Metadata, Datatype } from "./utils";
14
+ import CellMenu from "./CellMenu.svelte";
15
+
16
+ export let datatype: Datatype | Datatype[];
17
+ export let label: string | null = null;
18
+ export let show_label = true;
19
+ export let headers: Headers = [];
20
+ export let values: (string | number)[][] = [];
21
+ export let col_count: [number, "fixed" | "dynamic"];
22
+ export let row_count: [number, "fixed" | "dynamic"];
23
+ export let latex_delimiters: {
24
+ left: string;
25
+ right: string;
26
+ display: boolean;
27
+ }[];
28
+
29
+ export let editable = true;
30
+ export let wrap = false;
31
+ export let root: string;
32
+ export let i18n: I18nFormatter;
33
+
34
+ export let max_height = 500;
35
+ export let line_breaks = true;
36
+ export let column_widths: string[] = [];
37
+ export let upload: Client["upload"];
38
+ export let stream_handler: Client["stream"];
39
+
40
+ let selected: false | [number, number] = false;
41
+ export let display_value: string[][] | null = null;
42
+ export let styling: string[][] | null = null;
43
+ let t_rect: DOMRectReadOnly;
44
+
45
+ const dispatch = createEventDispatcher<{
46
+ change: {
47
+ data: (string | number)[][];
48
+ headers: string[];
49
+ metadata: Metadata;
50
+ };
51
+ select: SelectData;
52
+ }>();
53
+
54
+ let editing: false | [number, number] = false;
55
+
56
+ const get_data_at = (row: number, col: number): string | number =>
57
+ data?.[row]?.[col]?.value;
58
+
59
+ $: {
60
+ if (selected !== false) {
61
+ const [row, col] = selected;
62
+ if (!isNaN(row) && !isNaN(col) && data[row]) {
63
+ dispatch("select", {
64
+ index: [row, col],
65
+ value: get_data_at(row, col),
66
+ row_value: data[row].map((d) => d.value)
67
+ });
68
+ }
69
+ }
70
+ }
71
+
72
+ let els: Record<
73
+ string,
74
+ { cell: null | HTMLTableCellElement; input: null | HTMLInputElement }
75
+ > = {};
76
+
77
+ let data_binding: Record<string, (typeof data)[0][0]> = {};
78
+
79
+ function make_id(): string {
80
+ return Math.random().toString(36).substring(2, 15);
81
+ }
82
+
83
+ function make_headers(_head: Headers): HeadersWithIDs {
84
+ let _h = _head || [];
85
+ if (col_count[1] === "fixed" && _h.length < col_count[0]) {
86
+ const fill = Array(col_count[0] - _h.length)
87
+ .fill("")
88
+ .map((_, i) => `${i + _h.length}`);
89
+ _h = _h.concat(fill);
90
+ }
91
+
92
+ if (!_h || _h.length === 0) {
93
+ return Array(col_count[0])
94
+ .fill(0)
95
+ .map((_, i) => {
96
+ const _id = make_id();
97
+ els[_id] = { cell: null, input: null };
98
+ return { id: _id, value: JSON.stringify(i + 1) };
99
+ });
100
+ }
101
+
102
+ return _h.map((h, i) => {
103
+ const _id = make_id();
104
+ els[_id] = { cell: null, input: null };
105
+ return { id: _id, value: h ?? "" };
106
+ });
107
+ }
108
+
109
+ function process_data(_values: (string | number)[][]): {
110
+ value: string | number;
111
+ id: string;
112
+ }[][] {
113
+ const data_row_length = _values.length;
114
+ return Array(
115
+ row_count[1] === "fixed"
116
+ ? row_count[0]
117
+ : data_row_length < row_count[0]
118
+ ? row_count[0]
119
+ : data_row_length
120
+ )
121
+ .fill(0)
122
+ .map((_, i) =>
123
+ Array(
124
+ col_count[1] === "fixed"
125
+ ? col_count[0]
126
+ : data_row_length > 0
127
+ ? _values[0].length
128
+ : headers.length
129
+ )
130
+ .fill(0)
131
+ .map((_, j) => {
132
+ const id = make_id();
133
+ els[id] = els[id] || { input: null, cell: null };
134
+ const obj = { value: _values?.[i]?.[j] ?? "", id };
135
+ data_binding[id] = obj;
136
+ return obj;
137
+ })
138
+ );
139
+ }
140
+
141
+ let _headers = make_headers(headers);
142
+ let old_headers: string[] | undefined;
143
+
144
+ $: {
145
+ if (!dequal(headers, old_headers)) {
146
+ trigger_headers();
147
+ }
148
+ }
149
+
150
+ function trigger_headers(): void {
151
+ _headers = make_headers(headers);
152
+
153
+ old_headers = headers.slice();
154
+ trigger_change();
155
+ }
156
+
157
+ $: if (!dequal(values, old_val)) {
158
+ data = process_data(values as (string | number)[][]);
159
+ old_val = values as (string | number)[][];
160
+ }
161
+
162
+ let data: { id: string; value: string | number }[][] = [[]];
163
+
164
+ let old_val: undefined | (string | number)[][] = undefined;
165
+
166
+ async function trigger_change(): Promise<void> {
167
+ dispatch("change", {
168
+ data: data.map((r) => r.map(({ value }) => value)),
169
+ headers: _headers.map((h) => h.value),
170
+ metadata: editable
171
+ ? null
172
+ : { display_value: display_value, styling: styling }
173
+ });
174
+ }
175
+
176
+ function get_sort_status(
177
+ name: string,
178
+ _sort?: number,
179
+ direction?: SortDirection
180
+ ): "none" | "ascending" | "descending" {
181
+ if (!_sort) return "none";
182
+ if (headers[_sort] === name) {
183
+ if (direction === "asc") return "ascending";
184
+ if (direction === "des") return "descending";
185
+ }
186
+
187
+ return "none";
188
+ }
189
+
190
+ function get_current_indices(id: string): [number, number] {
191
+ return data.reduce(
192
+ (acc, arr, i) => {
193
+ const j = arr.reduce(
194
+ (_acc, _data, k) => (id === _data.id ? k : _acc),
195
+ -1
196
+ );
197
+
198
+ return j === -1 ? acc : [i, j];
199
+ },
200
+ [-1, -1]
201
+ );
202
+ }
203
+
204
+ async function start_edit(i: number, j: number): Promise<void> {
205
+ if (!editable || dequal(editing, [i, j])) return;
206
+
207
+ editing = [i, j];
208
+ }
209
+
210
+ function move_cursor(
211
+ key: "ArrowRight" | "ArrowLeft" | "ArrowDown" | "ArrowUp",
212
+ current_coords: [number, number]
213
+ ): void {
214
+ const dir = {
215
+ ArrowRight: [0, 1],
216
+ ArrowLeft: [0, -1],
217
+ ArrowDown: [1, 0],
218
+ ArrowUp: [-1, 0]
219
+ }[key];
220
+
221
+ const i = current_coords[0] + dir[0];
222
+ const j = current_coords[1] + dir[1];
223
+
224
+ if (i < 0 && j <= 0) {
225
+ selected_header = j;
226
+ selected = false;
227
+ } else {
228
+ const is_data = data[i]?.[j];
229
+ selected = is_data ? [i, j] : selected;
230
+ }
231
+ }
232
+
233
+ let clear_on_focus = false;
234
+ // eslint-disable-next-line complexity
235
+ async function handle_keydown(event: KeyboardEvent): Promise<void> {
236
+ if (selected_header !== false && header_edit === false) {
237
+ switch (event.key) {
238
+ case "ArrowDown":
239
+ selected = [0, selected_header];
240
+ selected_header = false;
241
+ return;
242
+ case "ArrowLeft":
243
+ selected_header =
244
+ selected_header > 0 ? selected_header - 1 : selected_header;
245
+ return;
246
+ case "ArrowRight":
247
+ selected_header =
248
+ selected_header < _headers.length - 1
249
+ ? selected_header + 1
250
+ : selected_header;
251
+ return;
252
+ case "Escape":
253
+ event.preventDefault();
254
+ selected_header = false;
255
+ break;
256
+ case "Enter":
257
+ event.preventDefault();
258
+ break;
259
+ }
260
+ }
261
+ if (!selected) {
262
+ return;
263
+ }
264
+
265
+ const [i, j] = selected;
266
+
267
+ switch (event.key) {
268
+ case "ArrowRight":
269
+ case "ArrowLeft":
270
+ case "ArrowDown":
271
+ case "ArrowUp":
272
+ if (editing) break;
273
+ event.preventDefault();
274
+ move_cursor(event.key, [i, j]);
275
+ break;
276
+
277
+ case "Escape":
278
+ if (!editable) break;
279
+ event.preventDefault();
280
+ editing = false;
281
+ break;
282
+ case "Enter":
283
+ if (!editable) break;
284
+ event.preventDefault();
285
+
286
+ if (event.shiftKey) {
287
+ add_row(i);
288
+ await tick();
289
+
290
+ selected = [i + 1, j];
291
+ } else {
292
+ if (dequal(editing, [i, j])) {
293
+ editing = false;
294
+ await tick();
295
+ selected = [i, j];
296
+ } else {
297
+ editing = [i, j];
298
+ }
299
+ }
300
+
301
+ break;
302
+ case "Backspace":
303
+ if (!editable) break;
304
+ if (!editing) {
305
+ event.preventDefault();
306
+ data[i][j].value = "";
307
+ }
308
+ break;
309
+ case "Delete":
310
+ if (!editable) break;
311
+ if (!editing) {
312
+ event.preventDefault();
313
+ data[i][j].value = "";
314
+ }
315
+ break;
316
+ case "Tab":
317
+ let direction = event.shiftKey ? -1 : 1;
318
+
319
+ let is_data_x = data[i][j + direction];
320
+ let is_data_y =
321
+ data?.[i + direction]?.[direction > 0 ? 0 : _headers.length - 1];
322
+
323
+ if (is_data_x || is_data_y) {
324
+ event.preventDefault();
325
+ selected = is_data_x
326
+ ? [i, j + direction]
327
+ : [i + direction, direction > 0 ? 0 : _headers.length - 1];
328
+ }
329
+ editing = false;
330
+
331
+ break;
332
+ default:
333
+ if (!editable) break;
334
+ if (
335
+ (!editing || (editing && dequal(editing, [i, j]))) &&
336
+ event.key.length === 1
337
+ ) {
338
+ clear_on_focus = true;
339
+ editing = [i, j];
340
+ }
341
+ }
342
+ }
343
+
344
+ let active_cell: { row: number; col: number } | null = null;
345
+
346
+ async function handle_cell_click(i: number, j: number): Promise<void> {
347
+ if (active_cell && active_cell.row === i && active_cell.col === j) {
348
+ active_cell = null;
349
+ } else {
350
+ active_cell = { row: i, col: j };
351
+ }
352
+ if (dequal(editing, [i, j])) return;
353
+ header_edit = false;
354
+ selected_header = false;
355
+ editing = false;
356
+ selected = [i, j];
357
+ await tick();
358
+ parent.focus();
359
+ }
360
+
361
+ type SortDirection = "asc" | "des";
362
+ let sort_direction: SortDirection | undefined;
363
+ let sort_by: number | undefined;
364
+
365
+ function handle_sort(col: number): void {
366
+ if (typeof sort_by !== "number" || sort_by !== col) {
367
+ sort_direction = "asc";
368
+ sort_by = col;
369
+ } else {
370
+ if (sort_direction === "asc") {
371
+ sort_direction = "des";
372
+ } else if (sort_direction === "des") {
373
+ sort_direction = "asc";
374
+ }
375
+ }
376
+ }
377
+
378
+ let header_edit: number | false;
379
+
380
+ let select_on_focus = false;
381
+ let selected_header: number | false = false;
382
+ async function edit_header(i: number, _select = false): Promise<void> {
383
+ if (!editable || col_count[1] !== "dynamic" || header_edit === i) return;
384
+ selected = false;
385
+ selected_header = i;
386
+ header_edit = i;
387
+ select_on_focus = _select;
388
+ }
389
+
390
+ function end_header_edit(event: KeyboardEvent): void {
391
+ if (!editable) return;
392
+
393
+ switch (event.key) {
394
+ case "Escape":
395
+ case "Enter":
396
+ case "Tab":
397
+ event.preventDefault();
398
+ selected = false;
399
+ selected_header = header_edit;
400
+ header_edit = false;
401
+ parent.focus();
402
+ break;
403
+ }
404
+ }
405
+
406
+ async function add_row(index?: number): Promise<void> {
407
+ parent.focus();
408
+
409
+ if (row_count[1] !== "dynamic") return;
410
+ if (data.length === 0) {
411
+ values = [Array(headers.length).fill("")];
412
+ return;
413
+ }
414
+
415
+ const new_row = Array(data[0].length)
416
+ .fill(0)
417
+ .map((_, i) => {
418
+ const _id = make_id();
419
+ els[_id] = { cell: null, input: null };
420
+ return { id: _id, value: "" };
421
+ });
422
+
423
+ if (index !== undefined && index >= 0 && index <= data.length) {
424
+ data.splice(index, 0, new_row);
425
+ } else {
426
+ data.push(new_row);
427
+ }
428
+
429
+ data = data;
430
+ selected = [index !== undefined ? index : data.length - 1, 0];
431
+ }
432
+
433
+ $: (data || selected_header) && trigger_change();
434
+
435
+ async function add_col(index?: number): Promise<void> {
436
+ parent.focus();
437
+ if (col_count[1] !== "dynamic") return;
438
+
439
+ const insert_index = index !== undefined ? index : data[0].length;
440
+
441
+ for (let i = 0; i < data.length; i++) {
442
+ const _id = make_id();
443
+ els[_id] = { cell: null, input: null };
444
+ data[i].splice(insert_index, 0, { id: _id, value: "" });
445
+ }
446
+
447
+ headers.splice(insert_index, 0, `Header ${headers.length + 1}`);
448
+
449
+ data = data;
450
+ headers = headers;
451
+
452
+ await tick();
453
+
454
+ requestAnimationFrame(() => {
455
+ edit_header(insert_index, true);
456
+ const new_w = parent.querySelectorAll("tbody")[1].offsetWidth;
457
+ parent.querySelectorAll("table")[1].scrollTo({ left: new_w });
458
+ });
459
+ }
460
+
461
+ function handle_click_outside(event: Event): void {
462
+ if (
463
+ (active_cell_menu &&
464
+ !(event.target as HTMLElement).closest(".cell-menu")) ||
465
+ (active_header_menu &&
466
+ !(event.target as HTMLElement).closest(".cell-menu"))
467
+ ) {
468
+ active_cell_menu = null;
469
+ active_header_menu = null;
470
+ }
471
+
472
+ event.stopImmediatePropagation();
473
+ const [trigger] = event.composedPath() as HTMLElement[];
474
+ if (parent.contains(trigger)) {
475
+ return;
476
+ }
477
+
478
+ editing = false;
479
+ header_edit = false;
480
+ selected_header = false;
481
+ selected = false;
482
+ active_cell = null;
483
+ active_cell_menu = null;
484
+ active_header_menu = null;
485
+ }
486
+
487
+ function guess_delimitaor(
488
+ text: string,
489
+ possibleDelimiters: string[]
490
+ ): string[] {
491
+ return possibleDelimiters.filter(weedOut);
492
+
493
+ function weedOut(delimiter: string): boolean {
494
+ var cache = -1;
495
+ return text.split("\n").every(checkLength);
496
+
497
+ function checkLength(line: string): boolean {
498
+ if (!line) {
499
+ return true;
500
+ }
501
+
502
+ var length = line.split(delimiter).length;
503
+ if (cache < 0) {
504
+ cache = length;
505
+ }
506
+ return cache === length && length > 1;
507
+ }
508
+ }
509
+ }
510
+
511
+ function data_uri_to_blob(data_uri: string): Blob {
512
+ const byte_str = atob(data_uri.split(",")[1]);
513
+ const mime_str = data_uri.split(",")[0].split(":")[1].split(";")[0];
514
+
515
+ const ab = new ArrayBuffer(byte_str.length);
516
+ const ia = new Uint8Array(ab);
517
+
518
+ for (let i = 0; i < byte_str.length; i++) {
519
+ ia[i] = byte_str.charCodeAt(i);
520
+ }
521
+
522
+ return new Blob([ab], { type: mime_str });
523
+ }
524
+
525
+ function blob_to_string(blob: Blob): void {
526
+ const reader = new FileReader();
527
+
528
+ function handle_read(e: ProgressEvent<FileReader>): void {
529
+ if (!e?.target?.result || typeof e.target.result !== "string") return;
530
+
531
+ const [delimiter] = guess_delimitaor(e.target.result, [",", "\t"]);
532
+
533
+ const [head, ...rest] = dsvFormat(delimiter).parseRows(e.target.result);
534
+
535
+ _headers = make_headers(
536
+ col_count[1] === "fixed" ? head.slice(0, col_count[0]) : head
537
+ );
538
+
539
+ values = rest;
540
+ reader.removeEventListener("loadend", handle_read);
541
+ }
542
+
543
+ reader.addEventListener("loadend", handle_read);
544
+
545
+ reader.readAsText(blob);
546
+ }
547
+
548
+ let dragging = false;
549
+
550
+ function get_max(
551
+ _d: { value: any; id: string }[][]
552
+ ): { value: any; id: string }[] {
553
+ let max = _d[0].slice();
554
+ for (let i = 0; i < _d.length; i++) {
555
+ for (let j = 0; j < _d[i].length; j++) {
556
+ if (`${max[j].value}`.length < `${_d[i][j].value}`.length) {
557
+ max[j] = _d[i][j];
558
+ }
559
+ }
560
+ }
561
+
562
+ return max;
563
+ }
564
+
565
+ $: max = get_max(data);
566
+
567
+ $: cells[0] && set_cell_widths();
568
+ let cells: HTMLTableCellElement[] = [];
569
+ let parent: HTMLDivElement;
570
+ let table: HTMLTableElement;
571
+
572
+ function set_cell_widths(): void {
573
+ const widths = cells.map((el, i) => {
574
+ return el?.clientWidth || 0;
575
+ });
576
+ if (widths.length === 0) return;
577
+ for (let i = 0; i < widths.length; i++) {
578
+ parent.style.setProperty(
579
+ `--cell-width-${i}`,
580
+ `${widths[i] - scrollbar_width / widths.length}px`
581
+ );
582
+ }
583
+ }
584
+
585
+ let table_height: number =
586
+ values.slice(0, (max_height / values.length) * 37).length * 37 + 37;
587
+ let scrollbar_width = 0;
588
+
589
+ function sort_data(
590
+ _data: typeof data,
591
+ _display_value: string[][] | null,
592
+ _styling: string[][] | null,
593
+ col?: number,
594
+ dir?: SortDirection
595
+ ): void {
596
+ let id = null;
597
+ //Checks if the selected cell is still in the data
598
+ if (selected && selected[0] in data && selected[1] in data[selected[0]]) {
599
+ id = data[selected[0]][selected[1]].id;
600
+ }
601
+ if (typeof col !== "number" || !dir) {
602
+ return;
603
+ }
604
+ const indices = [...Array(_data.length).keys()];
605
+
606
+ if (dir === "asc") {
607
+ indices.sort((i, j) =>
608
+ _data[i][col].value < _data[j][col].value ? -1 : 1
609
+ );
610
+ } else if (dir === "des") {
611
+ indices.sort((i, j) =>
612
+ _data[i][col].value > _data[j][col].value ? -1 : 1
613
+ );
614
+ } else {
615
+ return;
616
+ }
617
+
618
+ // sort all the data and metadata based on the values in the data
619
+ const temp_data = [..._data];
620
+ const temp_display_value = _display_value ? [..._display_value] : null;
621
+ const temp_styling = _styling ? [..._styling] : null;
622
+ indices.forEach((originalIndex, sortedIndex) => {
623
+ _data[sortedIndex] = temp_data[originalIndex];
624
+ if (_display_value && temp_display_value)
625
+ _display_value[sortedIndex] = temp_display_value[originalIndex];
626
+ if (_styling && temp_styling)
627
+ _styling[sortedIndex] = temp_styling[originalIndex];
628
+ });
629
+
630
+ data = data;
631
+
632
+ if (id) {
633
+ const [i, j] = get_current_indices(id);
634
+ selected = [i, j];
635
+ }
636
+ }
637
+
638
+ $: sort_data(data, display_value, styling, sort_by, sort_direction);
639
+
640
+ $: selected_index = !!selected && selected[0];
641
+
642
+ let is_visible = false;
643
+
644
+ onMount(() => {
645
+ const observer = new IntersectionObserver((entries, observer) => {
646
+ entries.forEach((entry) => {
647
+ if (entry.isIntersecting && !is_visible) {
648
+ set_cell_widths();
649
+ data = data;
650
+ }
651
+
652
+ is_visible = entry.isIntersecting;
653
+ });
654
+ });
655
+
656
+ observer.observe(parent);
657
+
658
+ return () => {
659
+ observer.disconnect();
660
+ };
661
+ });
662
+
663
+ let highlighted_column: number | null = null;
664
+
665
+ let active_cell_menu: {
666
+ row: number;
667
+ col: number;
668
+ x: number;
669
+ y: number;
670
+ } | null = null;
671
+
672
+ function toggle_cell_menu(event: MouseEvent, row: number, col: number): void {
673
+ event.stopPropagation();
674
+ if (
675
+ active_cell_menu &&
676
+ active_cell_menu.row === row &&
677
+ active_cell_menu.col === col
678
+ ) {
679
+ active_cell_menu = null;
680
+ } else {
681
+ const cell = (event.target as HTMLElement).closest("td");
682
+ if (cell) {
683
+ const rect = cell.getBoundingClientRect();
684
+ active_cell_menu = {
685
+ row,
686
+ col,
687
+ x: rect.right,
688
+ y: rect.bottom
689
+ };
690
+ }
691
+ }
692
+ }
693
+
694
+ function add_row_at(index: number, position: "above" | "below"): void {
695
+ const row_index = position === "above" ? index : index + 1;
696
+ add_row(row_index);
697
+ active_cell_menu = null;
698
+ active_header_menu = null;
699
+ }
700
+
701
+ function add_col_at(index: number, position: "left" | "right"): void {
702
+ const col_index = position === "left" ? index : index + 1;
703
+ add_col(col_index);
704
+ active_cell_menu = null;
705
+ active_header_menu = null;
706
+ }
707
+
708
+ onMount(() => {
709
+ document.addEventListener("click", handle_click_outside);
710
+ return () => {
711
+ document.removeEventListener("click", handle_click_outside);
712
+ };
713
+ });
714
+
715
+ let active_button: {
716
+ type: "header" | "cell";
717
+ row?: number;
718
+ col: number;
719
+ } | null = null;
720
+
721
+ function toggle_header_button(col: number): void {
722
+ if (active_button?.type === "header" && active_button.col === col) {
723
+ active_button = null;
724
+ } else {
725
+ active_button = { type: "header", col };
726
+ }
727
+ }
728
+
729
+ function toggle_cell_button(row: number, col: number): void {
730
+ if (
731
+ active_button?.type === "cell" &&
732
+ active_button.row === row &&
733
+ active_button.col === col
734
+ ) {
735
+ active_button = null;
736
+ } else {
737
+ active_button = { type: "cell", row, col };
738
+ }
739
+ }
740
+
741
+ let active_header_menu: {
742
+ col: number;
743
+ x: number;
744
+ y: number;
745
+ } | null = null;
746
+
747
+ function toggle_header_menu(event: MouseEvent, col: number): void {
748
+ event.stopPropagation();
749
+ if (active_header_menu && active_header_menu.col === col) {
750
+ active_header_menu = null;
751
+ } else {
752
+ const header = (event.target as HTMLElement).closest("th");
753
+ if (header) {
754
+ const rect = header.getBoundingClientRect();
755
+ active_header_menu = {
756
+ col,
757
+ x: rect.right,
758
+ y: rect.bottom
759
+ };
760
+ }
761
+ }
762
+ }
763
+ </script>
764
+
765
+ <svelte:window
766
+ on:click={handle_click_outside}
767
+ on:touchstart={handle_click_outside}
768
+ on:resize={() => set_cell_widths()}
769
+ />
770
+
771
+ <div class:label={label && label.length !== 0} use:copy>
772
+ {#if label && label.length !== 0 && show_label}
773
+ <p>
774
+ {label}
775
+ </p>
776
+ {/if}
777
+ <div
778
+ bind:this={parent}
779
+ class="table-wrap"
780
+ class:dragging
781
+ class:no-wrap={!wrap}
782
+ style="height:{table_height}px"
783
+ on:keydown={(e) => handle_keydown(e)}
784
+ role="grid"
785
+ tabindex="0"
786
+ >
787
+ <table
788
+ bind:contentRect={t_rect}
789
+ bind:this={table}
790
+ class:fixed-layout={column_widths.length != 0}
791
+ >
792
+ {#if label && label.length !== 0}
793
+ <caption class="sr-only">{label}</caption>
794
+ {/if}
795
+ <thead>
796
+ <tr>
797
+ {#each _headers as { value, id }, i (id)}
798
+ <th
799
+ class:editing={header_edit === i}
800
+ aria-sort={get_sort_status(value, sort_by, sort_direction)}
801
+ style:width={column_widths.length ? column_widths[i] : undefined}
802
+ >
803
+ <div class="cell-wrap">
804
+ <EditableCell
805
+ {value}
806
+ {latex_delimiters}
807
+ {line_breaks}
808
+ header
809
+ edit={false}
810
+ el={null}
811
+ {root}
812
+ />
813
+
814
+ <div
815
+ class:sorted={sort_by === i}
816
+ class:des={sort_by === i && sort_direction === "des"}
817
+ class="sort-button {sort_direction} "
818
+ >
819
+ <svg
820
+ width="1em"
821
+ height="1em"
822
+ viewBox="0 0 9 7"
823
+ fill="none"
824
+ xmlns="http://www.w3.org/2000/svg"
825
+ >
826
+ <path d="M4.49999 0L8.3971 6.75H0.602875L4.49999 0Z" />
827
+ </svg>
828
+ </div>
829
+ </div>
830
+ </th>
831
+ {/each}
832
+ </tr>
833
+ </thead>
834
+ <tbody>
835
+ <tr>
836
+ {#each max as { value, id }, j (id)}
837
+ <td tabindex="-1" bind:this={cells[j]}>
838
+ <div class="cell-wrap">
839
+ <EditableCell
840
+ {value}
841
+ {latex_delimiters}
842
+ {line_breaks}
843
+ datatype={Array.isArray(datatype) ? datatype[j] : datatype}
844
+ edit={false}
845
+ el={null}
846
+ {root}
847
+ />
848
+ </div>
849
+ </td>
850
+ {/each}
851
+ </tr>
852
+ </tbody>
853
+ </table>
854
+ <Upload
855
+ {upload}
856
+ {stream_handler}
857
+ flex={false}
858
+ center={false}
859
+ boundedheight={false}
860
+ disable_click={true}
861
+ {root}
862
+ on:load={(e) => blob_to_string(data_uri_to_blob(e.detail.data))}
863
+ bind:dragging
864
+ >
865
+ <VirtualTable
866
+ bind:items={data}
867
+ {max_height}
868
+ bind:actual_height={table_height}
869
+ bind:table_scrollbar_width={scrollbar_width}
870
+ selected={selected_index}
871
+ >
872
+ {#if label && label.length !== 0}
873
+ <caption class="sr-only">{label}</caption>
874
+ {/if}
875
+ <tr slot="thead">
876
+ {#each _headers as { value, id }, i (id)}
877
+ <th
878
+ class:focus={header_edit === i || selected_header === i}
879
+ aria-sort={get_sort_status(value, sort_by, sort_direction)}
880
+ style="width: var(--cell-width-{i});"
881
+ on:click={() => {
882
+ toggle_header_button(i);
883
+ }}
884
+ >
885
+ <div class="cell-wrap">
886
+ <div class="header-content">
887
+ <EditableCell
888
+ bind:value={_headers[i].value}
889
+ bind:el={els[id].input}
890
+ {latex_delimiters}
891
+ {line_breaks}
892
+ edit={header_edit === i}
893
+ on:keydown={end_header_edit}
894
+ on:dblclick={() => edit_header(i)}
895
+ {select_on_focus}
896
+ header
897
+ {root}
898
+ />
899
+ <!-- TODO: fix -->
900
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
901
+ <!-- svelte-ignore a11y-no-static-element-interactions-->
902
+ <div
903
+ class:sorted={sort_by === i}
904
+ class:des={sort_by === i && sort_direction === "des"}
905
+ class="sort-button {sort_direction}"
906
+ on:click={(event) => {
907
+ event.stopPropagation();
908
+ handle_sort(i);
909
+ }}
910
+ >
911
+ <svg
912
+ width="1em"
913
+ height="1em"
914
+ viewBox="0 0 9 7"
915
+ fill="none"
916
+ xmlns="http://www.w3.org/2000/svg"
917
+ >
918
+ <path d="M4.49999 0L8.3971 6.75H0.602875L4.49999 0Z" />
919
+ </svg>
920
+ </div>
921
+ </div>
922
+
923
+ {#if editable}
924
+ <button
925
+ class="cell-menu-button"
926
+ class:visible={active_button?.type === "header" &&
927
+ active_button.col === i}
928
+ on:click={(event) => toggle_header_menu(event, i)}
929
+ >
930
+
931
+ </button>
932
+ {/if}
933
+ </div>
934
+ </th>
935
+ {/each}
936
+ </tr>
937
+
938
+ <tr slot="tbody" let:item let:index class:row_odd={index % 2 === 0}>
939
+ {#each item as { value, id }, j (id)}
940
+ <td
941
+ tabindex="0"
942
+ on:touchstart={() => start_edit(index, j)}
943
+ on:click={() => {
944
+ handle_cell_click(index, j);
945
+ toggle_cell_button(index, j);
946
+ }}
947
+ on:dblclick={() => start_edit(index, j)}
948
+ style:width="var(--cell-width-{j})"
949
+ style={styling?.[index]?.[j] || ""}
950
+ class:focus={dequal(selected, [index, j])}
951
+ class:menu-active={active_cell_menu &&
952
+ active_cell_menu.row === index &&
953
+ active_cell_menu.col === j}
954
+ >
955
+ <div class="cell-wrap">
956
+ <EditableCell
957
+ bind:value={data[index][j].value}
958
+ bind:el={els[id].input}
959
+ display_value={display_value?.[index]?.[j]}
960
+ {latex_delimiters}
961
+ {line_breaks}
962
+ {editable}
963
+ edit={dequal(editing, [index, j])}
964
+ datatype={Array.isArray(datatype) ? datatype[j] : datatype}
965
+ on:blur={() => ((clear_on_focus = false), parent.focus())}
966
+ {clear_on_focus}
967
+ {root}
968
+ />
969
+ {#if editable}
970
+ <button
971
+ class="cell-menu-button"
972
+ class:visible={active_button?.type === "cell" &&
973
+ active_button.row === index &&
974
+ active_button.col === j}
975
+ on:click={(event) => toggle_cell_menu(event, index, j)}
976
+ >
977
+
978
+ </button>
979
+ {/if}
980
+ </div>
981
+ </td>
982
+ {/each}
983
+ </tr>
984
+ </VirtualTable>
985
+ </Upload>
986
+ </div>
987
+ </div>
988
+
989
+ {#if active_cell_menu !== null}
990
+ <CellMenu
991
+ {i18n}
992
+ x={active_cell_menu.x}
993
+ y={active_cell_menu.y}
994
+ row={active_cell_menu?.row ?? -1}
995
+ on_add_row_above={() => add_row_at(active_cell_menu?.row ?? -1, "above")}
996
+ on_add_row_below={() => add_row_at(active_cell_menu?.row ?? -1, "below")}
997
+ on_add_column_left={() => add_col_at(active_cell_menu?.col ?? -1, "left")}
998
+ on_add_column_right={() => add_col_at(active_cell_menu?.col ?? -1, "right")}
999
+ />
1000
+ {/if}
1001
+
1002
+ {#if active_header_menu !== null}
1003
+ <CellMenu
1004
+ {i18n}
1005
+ x={active_header_menu.x}
1006
+ y={active_header_menu.y}
1007
+ row={-1}
1008
+ on_add_column_left={() => add_col_at(active_header_menu?.col ?? -1, "left")}
1009
+ on_add_column_right={() =>
1010
+ add_col_at(active_header_menu?.col ?? -1, "right")}
1011
+ />
1012
+ {/if}
1013
+
1014
+ <style>
1015
+ .button-wrap:hover svg {
1016
+ color: var(--color-accent);
1017
+ }
1018
+
1019
+ .button-wrap svg {
1020
+ margin-right: var(--size-1);
1021
+ margin-left: -5px;
1022
+ }
1023
+
1024
+ .label p {
1025
+ position: relative;
1026
+ z-index: var(--layer-4);
1027
+ margin-bottom: var(--size-2);
1028
+ color: var(--block-label-text-color);
1029
+ font-size: var(--block-label-text-size);
1030
+ }
1031
+
1032
+ .table-wrap {
1033
+ position: relative;
1034
+ transition: 150ms;
1035
+ border: 1px solid var(--border-color-primary);
1036
+ border-radius: var(--table-radius);
1037
+ overflow: hidden;
1038
+ }
1039
+
1040
+ .table-wrap:focus-within {
1041
+ outline: none;
1042
+ background-color: none;
1043
+ }
1044
+
1045
+ .dragging {
1046
+ border-color: var(--color-accent);
1047
+ }
1048
+
1049
+ .no-wrap {
1050
+ white-space: nowrap;
1051
+ }
1052
+
1053
+ table {
1054
+ position: absolute;
1055
+ opacity: 0;
1056
+ transition: 150ms;
1057
+ width: var(--size-full);
1058
+ table-layout: auto;
1059
+ color: var(--body-text-color);
1060
+ font-size: var(--input-text-size);
1061
+ line-height: var(--line-md);
1062
+ font-family: var(--font-mono);
1063
+ border-spacing: 0;
1064
+ }
1065
+
1066
+ div:not(.no-wrap) td {
1067
+ overflow-wrap: anywhere;
1068
+ }
1069
+
1070
+ div.no-wrap td {
1071
+ overflow-x: hidden;
1072
+ }
1073
+
1074
+ table.fixed-layout {
1075
+ table-layout: fixed;
1076
+ }
1077
+
1078
+ thead {
1079
+ position: sticky;
1080
+ top: 0;
1081
+ left: 0;
1082
+ z-index: var(--layer-1);
1083
+ }
1084
+
1085
+ tr {
1086
+ border-bottom: 1px solid var(--border-color-primary);
1087
+ text-align: left;
1088
+ }
1089
+
1090
+ tr > * + * {
1091
+ border-right-width: 0px;
1092
+ border-left-width: 1px;
1093
+ border-style: solid;
1094
+ border-color: var(--border-color-primary);
1095
+ }
1096
+
1097
+ th,
1098
+ td {
1099
+ --ring-color: transparent;
1100
+ position: relative;
1101
+ outline: none;
1102
+ padding: 0;
1103
+ }
1104
+
1105
+ th:first-child {
1106
+ border-top-left-radius: var(--table-radius);
1107
+ }
1108
+
1109
+ th:last-child {
1110
+ border-top-right-radius: var(--table-radius);
1111
+ }
1112
+
1113
+ th.focus,
1114
+ td.focus,
1115
+ td.menu-active {
1116
+ z-index: 1;
1117
+ }
1118
+
1119
+ tr:last-child td:first-child {
1120
+ border-bottom-left-radius: var(--table-radius);
1121
+ }
1122
+
1123
+ tr:last-child td:last-child {
1124
+ border-bottom-right-radius: var(--table-radius);
1125
+ }
1126
+
1127
+ tr th {
1128
+ background: var(--table-even-background-fill);
1129
+ }
1130
+
1131
+ th svg {
1132
+ fill: currentColor;
1133
+ font-size: 10px;
1134
+ }
1135
+
1136
+ .sort-button {
1137
+ display: flex;
1138
+ flex: none;
1139
+ justify-content: center;
1140
+ align-items: center;
1141
+ transition: 150ms;
1142
+ cursor: pointer;
1143
+ padding: var(--size-2);
1144
+ color: var(--body-text-color-subdued);
1145
+ line-height: var(--text-sm);
1146
+ }
1147
+
1148
+ .sort-button:hover {
1149
+ color: var(--body-text-color);
1150
+ }
1151
+
1152
+ .des {
1153
+ transform: scaleY(-1);
1154
+ }
1155
+
1156
+ .sort-button.sorted {
1157
+ color: var(--color-accent);
1158
+ }
1159
+
1160
+ .editing {
1161
+ background: var(--table-editing);
1162
+ }
1163
+
1164
+ .cell-wrap {
1165
+ position: relative;
1166
+ display: flex;
1167
+ align-items: center;
1168
+ justify-content: space-between;
1169
+ outline: none;
1170
+ height: var(--size-full);
1171
+ min-height: var(--size-9);
1172
+ overflow: hidden;
1173
+ }
1174
+
1175
+ .header-content {
1176
+ display: flex;
1177
+ align-items: center;
1178
+ overflow: hidden;
1179
+ flex-grow: 1;
1180
+ min-width: 0;
1181
+ }
1182
+
1183
+ .row_odd {
1184
+ background: var(--table-odd-background-fill);
1185
+ }
1186
+
1187
+ .row_odd.focus {
1188
+ background: var(--background-fill-primary);
1189
+ }
1190
+
1191
+ table {
1192
+ border-collapse: separate;
1193
+ }
1194
+
1195
+ .select-column {
1196
+ width: var(--size-3);
1197
+ text-align: center;
1198
+ padding: var(--size-1);
1199
+ border-right: none;
1200
+ }
1201
+
1202
+ .cell-menu-button {
1203
+ flex-shrink: 0;
1204
+ display: none;
1205
+ background-color: var(--block-background-fill);
1206
+ border: 1px solid var(--border-color-primary);
1207
+ border-radius: var(--block-radius);
1208
+ width: var(--size-5);
1209
+ height: var(--size-5);
1210
+ min-width: var(--size-5);
1211
+ padding: 0;
1212
+ margin-right: var(--spacing-sm);
1213
+ z-index: var(--layer-2);
1214
+ }
1215
+
1216
+ .cell-menu-button:hover {
1217
+ background-color: var(--color-bg-hover);
1218
+ }
1219
+
1220
+ .cell-menu-button.visible {
1221
+ display: flex;
1222
+ align-items: center;
1223
+ justify-content: center;
1224
+ }
1225
+
1226
+ th .cell-wrap {
1227
+ padding-right: var(--spacing-sm);
1228
+ }
1229
+
1230
+ th .header-content {
1231
+ white-space: nowrap;
1232
+ overflow: hidden;
1233
+ text-overflow: ellipsis;
1234
+ }
1235
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/VirtualTable.svelte ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount, tick } from "svelte";
3
+ import { _ } from "svelte-i18n";
4
+
5
+ export let items: any[][] = [];
6
+
7
+ export let max_height: number;
8
+ export let actual_height: number;
9
+ export let table_scrollbar_width: number;
10
+ export let start = 0;
11
+ export let end = 20;
12
+ export let selected: number | false;
13
+ let height = "100%";
14
+
15
+ let average_height = 30;
16
+ let bottom = 0;
17
+ let contents: HTMLTableSectionElement;
18
+ let head_height = 0;
19
+ let foot_height = 0;
20
+ let height_map: number[] = [];
21
+ let mounted: boolean;
22
+ let rows: HTMLCollectionOf<HTMLTableRowElement>;
23
+ let top = 0;
24
+ let viewport: HTMLTableElement;
25
+ let viewport_height = 200;
26
+ let visible: { index: number; data: any[] }[] = [];
27
+ let viewport_box: DOMRectReadOnly;
28
+
29
+ $: viewport_height = viewport_box?.height || 200;
30
+
31
+ const is_browser = typeof window !== "undefined";
32
+ const raf = is_browser
33
+ ? window.requestAnimationFrame
34
+ : (cb: (...args: any[]) => void) => cb();
35
+
36
+ $: mounted && raf(() => refresh_height_map(sortedItems));
37
+
38
+ let content_height = 0;
39
+ async function refresh_height_map(_items: typeof items): Promise<void> {
40
+ if (viewport_height === 0) {
41
+ return;
42
+ }
43
+
44
+ const { scrollTop } = viewport;
45
+ table_scrollbar_width = viewport.offsetWidth - viewport.clientWidth;
46
+
47
+ content_height = top - (scrollTop - head_height);
48
+ let i = start;
49
+
50
+ while (content_height < max_height && i < _items.length) {
51
+ let row = rows[i - start];
52
+ if (!row) {
53
+ end = i + 1;
54
+ await tick(); // render the newly visible row
55
+ row = rows[i - start];
56
+ }
57
+ let _h = row?.getBoundingClientRect().height;
58
+ if (!_h) {
59
+ _h = average_height;
60
+ }
61
+ const row_height = (height_map[i] = _h);
62
+ content_height += row_height;
63
+ i += 1;
64
+ }
65
+
66
+ end = i;
67
+ const remaining = _items.length - end;
68
+
69
+ const scrollbar_height = viewport.offsetHeight - viewport.clientHeight;
70
+ if (scrollbar_height > 0) {
71
+ content_height += scrollbar_height;
72
+ }
73
+
74
+ let filtered_height_map = height_map.filter((v) => typeof v === "number");
75
+ average_height =
76
+ filtered_height_map.reduce((a, b) => a + b, 0) /
77
+ filtered_height_map.length;
78
+
79
+ bottom = remaining * average_height;
80
+ height_map.length = _items.length;
81
+ await tick();
82
+ if (!max_height) {
83
+ actual_height = content_height + 1;
84
+ } else if (content_height < max_height) {
85
+ actual_height = content_height + 2;
86
+ } else {
87
+ actual_height = max_height;
88
+ }
89
+
90
+ await tick();
91
+ }
92
+
93
+ $: scroll_and_render(selected);
94
+
95
+ async function scroll_and_render(n: number | false): Promise<void> {
96
+ raf(async () => {
97
+ if (typeof n !== "number") return;
98
+ const direction = typeof n !== "number" ? false : is_in_view(n);
99
+ if (direction === true) {
100
+ return;
101
+ }
102
+ if (direction === "back") {
103
+ await scroll_to_index(n, { behavior: "instant" });
104
+ }
105
+
106
+ if (direction === "forwards") {
107
+ await scroll_to_index(n, { behavior: "instant" }, true);
108
+ }
109
+ });
110
+ }
111
+
112
+ function is_in_view(n: number): "back" | "forwards" | true {
113
+ const current = rows && rows[n - start];
114
+ if (!current && n < start) {
115
+ return "back";
116
+ }
117
+ if (!current && n >= end - 1) {
118
+ return "forwards";
119
+ }
120
+
121
+ const { top: viewport_top } = viewport.getBoundingClientRect();
122
+ const { top, bottom } = current.getBoundingClientRect();
123
+
124
+ if (top - viewport_top < 37) {
125
+ return "back";
126
+ }
127
+
128
+ if (bottom - viewport_top > viewport_height) {
129
+ return "forwards";
130
+ }
131
+
132
+ return true;
133
+ }
134
+
135
+ function get_computed_px_amount(elem: HTMLElement, property: string): number {
136
+ if (!elem) {
137
+ return 0;
138
+ }
139
+ const compStyle = getComputedStyle(elem);
140
+
141
+ let x = parseInt(compStyle.getPropertyValue(property));
142
+ return x;
143
+ }
144
+
145
+ async function handle_scroll(e: Event): Promise<void> {
146
+ const scroll_top = viewport.scrollTop;
147
+
148
+ rows = contents.children as HTMLCollectionOf<HTMLTableRowElement>;
149
+ const is_start_overflow = sortedItems.length < start;
150
+
151
+ const row_top_border = get_computed_px_amount(rows[1], "border-top-width");
152
+
153
+ const actual_border_collapsed_width = 0;
154
+
155
+ if (is_start_overflow) {
156
+ await scroll_to_index(sortedItems.length - 1, { behavior: "auto" });
157
+ }
158
+
159
+ let new_start = 0;
160
+ // acquire height map for currently visible rows
161
+ for (let v = 0; v < rows.length; v += 1) {
162
+ height_map[start + v] = rows[v].getBoundingClientRect().height;
163
+ }
164
+ let i = 0;
165
+ // start from top: thead, with its borders, plus the first border to afterwards neglect
166
+ let y = head_height + row_top_border / 2;
167
+ let row_heights = [];
168
+ // loop items to find new start
169
+ while (i < sortedItems.length) {
170
+ const row_height = height_map[i] || average_height;
171
+ row_heights[i] = row_height;
172
+ // we only want to jump if the full (incl. border) row is away
173
+ if (y + row_height + actual_border_collapsed_width > scroll_top) {
174
+ // this is the last index still inside the viewport
175
+ new_start = i;
176
+ top = y - (head_height + row_top_border / 2);
177
+ break;
178
+ }
179
+ y += row_height;
180
+ i += 1;
181
+ }
182
+
183
+ new_start = Math.max(0, new_start);
184
+ while (i < sortedItems.length) {
185
+ const row_height = height_map[i] || average_height;
186
+ y += row_height;
187
+ i += 1;
188
+ if (y > scroll_top + viewport_height) {
189
+ break;
190
+ }
191
+ }
192
+ start = new_start;
193
+ end = i;
194
+ const remaining = sortedItems.length - end;
195
+ if (end === 0) {
196
+ end = 10;
197
+ }
198
+ average_height = (y - head_height) / end;
199
+ let remaining_height = remaining * average_height; // 0
200
+ // compute height map for remaining items
201
+ while (i < sortedItems.length) {
202
+ i += 1;
203
+ height_map[i] = average_height;
204
+ }
205
+ bottom = remaining_height;
206
+ if (!isFinite(bottom)) {
207
+ bottom = 200000;
208
+ }
209
+ }
210
+
211
+ export async function scroll_to_index(
212
+ index: number,
213
+ opts: ScrollToOptions,
214
+ align_end = false
215
+ ): Promise<void> {
216
+ await tick();
217
+
218
+ const _itemHeight = average_height;
219
+
220
+ let distance = index * _itemHeight;
221
+ if (align_end) {
222
+ distance = distance - viewport_height + _itemHeight + head_height;
223
+ }
224
+
225
+ const scrollbar_height = viewport.offsetHeight - viewport.clientHeight;
226
+ if (scrollbar_height > 0) {
227
+ distance += scrollbar_height;
228
+ }
229
+
230
+ const _opts = {
231
+ top: distance,
232
+ behavior: "smooth" as ScrollBehavior,
233
+ ...opts
234
+ };
235
+
236
+ viewport.scrollTo(_opts);
237
+ }
238
+
239
+ $: sortedItems = items;
240
+
241
+ $: visible = is_browser
242
+ ? sortedItems.slice(start, end).map((data, i) => {
243
+ return { index: i + start, data };
244
+ })
245
+ : sortedItems
246
+ .slice(0, (max_height / sortedItems.length) * average_height + 1)
247
+ .map((data, i) => {
248
+ return { index: i + start, data };
249
+ });
250
+
251
+ $: actual_height = visible.length * average_height + 10;
252
+ onMount(() => {
253
+ rows = contents.children as HTMLCollectionOf<HTMLTableRowElement>;
254
+ mounted = true;
255
+ refresh_height_map(items);
256
+ });
257
+ </script>
258
+
259
+ <svelte-virtual-table-viewport>
260
+ <table
261
+ class="table"
262
+ bind:this={viewport}
263
+ bind:contentRect={viewport_box}
264
+ on:scroll={handle_scroll}
265
+ style="height: {height}; --bw-svt-p-top: {top}px; --bw-svt-p-bottom: {bottom}px; --bw-svt-head-height: {head_height}px; --bw-svt-foot-height: {foot_height}px; --bw-svt-avg-row-height: {average_height}px"
266
+ >
267
+ <thead class="thead" bind:offsetHeight={head_height}>
268
+ <slot name="thead" />
269
+ </thead>
270
+ <tbody bind:this={contents} class="tbody">
271
+ {#if visible.length && visible[0].data.length}
272
+ {#each visible as item (item.data[0].id)}
273
+ <slot name="tbody" item={item.data} index={item.index}>
274
+ Missing Table Row
275
+ </slot>
276
+ {/each}
277
+ {/if}
278
+ </tbody>
279
+ <tfoot class="tfoot" bind:offsetHeight={foot_height}>
280
+ <slot name="tfoot" />
281
+ </tfoot>
282
+ </table>
283
+ </svelte-virtual-table-viewport>
284
+
285
+ <style type="text/css">
286
+ table {
287
+ position: relative;
288
+ overflow-y: scroll;
289
+ overflow-x: scroll;
290
+ -webkit-overflow-scrolling: touch;
291
+ max-height: 100vh;
292
+ box-sizing: border-box;
293
+ display: block;
294
+ padding: 0;
295
+ margin: 0;
296
+ color: var(--body-text-color);
297
+ font-size: var(--input-text-size);
298
+ line-height: var(--line-md);
299
+ font-family: var(--font-mono);
300
+ border-spacing: 0;
301
+ width: 100%;
302
+ scroll-snap-type: x proximity;
303
+ border-collapse: separate;
304
+ }
305
+ table :is(thead, tfoot, tbody) {
306
+ display: table;
307
+ table-layout: fixed;
308
+ width: 100%;
309
+ box-sizing: border-box;
310
+ }
311
+
312
+ tbody {
313
+ overflow-x: scroll;
314
+ overflow-y: hidden;
315
+ }
316
+
317
+ table tbody {
318
+ padding-top: var(--bw-svt-p-top);
319
+ padding-bottom: var(--bw-svt-p-bottom);
320
+ }
321
+ tbody {
322
+ position: relative;
323
+ box-sizing: border-box;
324
+ border: 0px solid currentColor;
325
+ }
326
+
327
+ tbody > :global(tr:last-child) {
328
+ border: none;
329
+ }
330
+
331
+ table :global(td) {
332
+ scroll-snap-align: start;
333
+ }
334
+
335
+ tbody > :global(tr:nth-child(even)) {
336
+ background: var(--table-even-background-fill);
337
+ }
338
+
339
+ thead {
340
+ position: sticky;
341
+ top: 0;
342
+ left: 0;
343
+ z-index: var(--layer-1);
344
+ overflow: hidden;
345
+ }
346
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dataframe/shared/utils.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ export type Headers = string[];
2
+ export type Data = (string | number)[][];
3
+ export type Datatype = "str" | "markdown" | "html" | "number" | "bool" | "date";
4
+ export type Metadata = {
5
+ [key: string]: string[][] | null;
6
+ } | null;
7
+ export type HeadersWithIDs = { value: string; id: string }[];
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/datetime/Example.svelte ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string | null;
3
+ </script>
4
+
5
+ {value || ""}
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/datetime/Index.svelte ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseExample } from "./Example.svelte";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import type { Gradio } from "@gradio/utils";
7
+ import { Block, BlockTitle } from "@gradio/atoms";
8
+ import { Back, Calendar } from "@gradio/icons";
9
+
10
+ export let gradio: Gradio<{
11
+ change: undefined;
12
+ submit: undefined;
13
+ }>;
14
+ export let label = "Time";
15
+ export let show_label = true;
16
+ export let info: string | undefined = undefined;
17
+ export let elem_id = "";
18
+ export let elem_classes: string[] = [];
19
+ export let visible = true;
20
+ export let value = "";
21
+ let old_value = value;
22
+ export let scale: number | null = null;
23
+ export let min_width: number | undefined = undefined;
24
+ export let root: string;
25
+
26
+ export let include_time = true;
27
+ $: if (value !== old_value) {
28
+ old_value = value;
29
+ entered_value = value;
30
+ datevalue = value;
31
+ gradio.dispatch("change");
32
+ }
33
+
34
+ const format_date = (date: Date): string => {
35
+ if (date.toJSON() === null) return "";
36
+ const pad = (num: number): string => num.toString().padStart(2, "0");
37
+
38
+ const year = date.getFullYear();
39
+ const month = pad(date.getMonth() + 1); // getMonth() returns 0-11
40
+ const day = pad(date.getDate());
41
+ const hours = pad(date.getHours());
42
+ const minutes = pad(date.getMinutes());
43
+ const seconds = pad(date.getSeconds());
44
+
45
+ const date_str = `${year}-${month}-${day}`;
46
+ const time_str = `${hours}:${minutes}:${seconds}`;
47
+ if (include_time) {
48
+ return `${date_str} ${time_str}`;
49
+ }
50
+ return date_str;
51
+ };
52
+
53
+ let entered_value = value;
54
+ let datetime: HTMLInputElement;
55
+ let datevalue = value;
56
+
57
+ const date_is_valid_format = (date: string): boolean => {
58
+ if (date === "") return false;
59
+ const valid_regex = include_time
60
+ ? /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/
61
+ : /^\d{4}-\d{2}-\d{2}$/;
62
+ const is_valid_date = date.match(valid_regex) !== null;
63
+ const is_valid_now =
64
+ date.match(/^(?:\s*now\s*(?:-\s*\d+\s*[dmhs])?)?\s*$/) !== null;
65
+ return is_valid_date || is_valid_now;
66
+ };
67
+
68
+ $: valid = date_is_valid_format(entered_value);
69
+
70
+ const submit_values = (): void => {
71
+ if (entered_value === value) return;
72
+ if (!date_is_valid_format(entered_value)) return;
73
+ old_value = value = entered_value;
74
+ gradio.dispatch("change");
75
+ };
76
+ </script>
77
+
78
+ <Block
79
+ {visible}
80
+ {elem_id}
81
+ {elem_classes}
82
+ {scale}
83
+ {min_width}
84
+ allow_overflow={false}
85
+ padding={true}
86
+ >
87
+ <div class="label-content">
88
+ <BlockTitle {root} {show_label} {info}>{label}</BlockTitle>
89
+ </div>
90
+ <div class="timebox">
91
+ <input
92
+ class="time"
93
+ bind:value={entered_value}
94
+ class:invalid={!valid}
95
+ on:keydown={(evt) => {
96
+ if (evt.key === "Enter") {
97
+ submit_values();
98
+ gradio.dispatch("submit");
99
+ }
100
+ }}
101
+ on:blur={submit_values}
102
+ />
103
+ {#if include_time}
104
+ <input
105
+ type="datetime-local"
106
+ class="datetime"
107
+ step="1"
108
+ bind:this={datetime}
109
+ bind:value={datevalue}
110
+ on:input={() => {
111
+ const date = new Date(datevalue);
112
+ entered_value = format_date(date);
113
+ submit_values();
114
+ }}
115
+ />
116
+ {:else}
117
+ <input
118
+ type="date"
119
+ class="datetime"
120
+ step="1"
121
+ bind:this={datetime}
122
+ bind:value={datevalue}
123
+ on:input={() => {
124
+ const date = new Date(datevalue);
125
+ entered_value = format_date(date);
126
+ submit_values();
127
+ }}
128
+ />
129
+ {/if}
130
+
131
+ <button
132
+ class="calendar"
133
+ on:click={() => {
134
+ datetime.showPicker();
135
+ }}><Calendar></Calendar></button
136
+ >
137
+ </div>
138
+ </Block>
139
+
140
+ <style>
141
+ .label-content {
142
+ display: flex;
143
+ justify-content: space-between;
144
+ align-items: flex-start;
145
+ }
146
+ button {
147
+ cursor: pointer;
148
+ color: var(--body-text-color-subdued);
149
+ }
150
+ button:hover {
151
+ color: var(--body-text-color);
152
+ }
153
+
154
+ ::placeholder {
155
+ color: var(--input-placeholder-color);
156
+ }
157
+ .timebox {
158
+ flex-grow: 1;
159
+ flex-shrink: 1;
160
+ display: flex;
161
+ position: relative;
162
+ background: var(--input-background-fill);
163
+ }
164
+ .timebox :global(svg) {
165
+ height: 18px;
166
+ }
167
+ .time {
168
+ padding: var(--input-padding);
169
+ color: var(--body-text-color);
170
+ font-weight: var(--input-text-weight);
171
+ font-size: var(--input-text-size);
172
+ line-height: var(--line-sm);
173
+ outline: none;
174
+ flex-grow: 1;
175
+ background: none;
176
+ border: var(--input-border-width) solid var(--input-border-color);
177
+ border-right: none;
178
+ border-top-left-radius: var(--input-radius);
179
+ border-bottom-left-radius: var(--input-radius);
180
+ box-shadow: var(--input-shadow);
181
+ }
182
+ .time.invalid {
183
+ color: var(--body-text-color-subdued);
184
+ }
185
+ .calendar {
186
+ display: inline-flex;
187
+ justify-content: center;
188
+ align-items: center;
189
+ transition: var(--button-transition);
190
+ box-shadow: var(--button-primary-shadow);
191
+ text-align: center;
192
+ background: var(--button-secondary-background-fill);
193
+ color: var(--button-secondary-text-color);
194
+ font-weight: var(--button-large-text-weight);
195
+ font-size: var(--button-large-text-size);
196
+ border-top-right-radius: var(--input-radius);
197
+ border-bottom-right-radius: var(--input-radius);
198
+ padding: var(--size-2);
199
+ border: var(--input-border-width) solid var(--input-border-color);
200
+ }
201
+ .calendar:hover {
202
+ background: var(--button-secondary-background-fill-hover);
203
+ box-shadow: var(--button-primary-shadow-hover);
204
+ }
205
+ .calendar:active {
206
+ box-shadow: var(--button-primary-shadow-active);
207
+ }
208
+ .datetime {
209
+ width: 0px;
210
+ padding: 0;
211
+ border: 0;
212
+ margin: 0;
213
+ background: none;
214
+ }
215
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dropdown/shared/Dropdown.svelte ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import DropdownOptions from "./DropdownOptions.svelte";
3
+ import { createEventDispatcher, afterUpdate } from "svelte";
4
+ import { BlockTitle } from "@gradio/atoms";
5
+ import { DropdownArrow } from "@gradio/icons";
6
+ import type { SelectData, KeyUpData } from "@gradio/utils";
7
+ import { handle_filter, handle_change, handle_shared_keys } from "./utils";
8
+
9
+ type Item = string | number;
10
+
11
+ export let label: string;
12
+ export let info: string | undefined = undefined;
13
+ export let value: Item | Item[] | undefined = undefined;
14
+ let old_value: typeof value = undefined;
15
+ export let value_is_output = false;
16
+ export let choices: [string, Item][];
17
+ let old_choices: typeof choices;
18
+ export let disabled = false;
19
+ export let show_label: boolean;
20
+ export let container = true;
21
+ export let allow_custom_value = false;
22
+ export let filterable = true;
23
+ export let root: string;
24
+
25
+ let filter_input: HTMLElement;
26
+
27
+ let show_options = false;
28
+ let choices_names: string[];
29
+ let choices_values: (string | number)[];
30
+ let input_text = "";
31
+ let old_input_text = "";
32
+ let initialized = false;
33
+
34
+ // All of these are indices with respect to the choices array
35
+ let filtered_indices: number[] = [];
36
+ let active_index: number | null = null;
37
+ // selected_index is null if allow_custom_value is true and the input_text is not in choices_names
38
+ let selected_index: number | null = null;
39
+ let old_selected_index: number | null;
40
+
41
+ const dispatch = createEventDispatcher<{
42
+ change: string | undefined;
43
+ input: undefined;
44
+ select: SelectData;
45
+ blur: undefined;
46
+ focus: undefined;
47
+ key_up: KeyUpData;
48
+ }>();
49
+
50
+ // Setting the initial value of the dropdown
51
+ if (value) {
52
+ old_selected_index = choices.map((c) => c[1]).indexOf(value as string);
53
+ selected_index = old_selected_index;
54
+ if (selected_index === -1) {
55
+ old_value = value;
56
+ selected_index = null;
57
+ } else {
58
+ [input_text, old_value] = choices[selected_index];
59
+ old_input_text = input_text;
60
+ }
61
+ set_input_text();
62
+ } else if (choices.length > 0) {
63
+ old_selected_index = 0;
64
+ selected_index = 0;
65
+ [input_text, value] = choices[selected_index];
66
+ old_value = value;
67
+ old_input_text = input_text;
68
+ }
69
+
70
+ $: {
71
+ if (
72
+ selected_index !== old_selected_index &&
73
+ selected_index !== null &&
74
+ initialized
75
+ ) {
76
+ [input_text, value] = choices[selected_index];
77
+ old_selected_index = selected_index;
78
+ dispatch("select", {
79
+ index: selected_index,
80
+ value: choices_values[selected_index],
81
+ selected: true
82
+ });
83
+ }
84
+ }
85
+
86
+ $: if (JSON.stringify(old_value) !== JSON.stringify(value)) {
87
+ set_input_text();
88
+ handle_change(dispatch, value, value_is_output);
89
+ old_value = value;
90
+ }
91
+
92
+ function set_choice_names_values(): void {
93
+ choices_names = choices.map((c) => c[0]);
94
+ choices_values = choices.map((c) => c[1]);
95
+ }
96
+
97
+ $: choices, set_choice_names_values();
98
+
99
+ const is_browser = typeof window !== "undefined";
100
+
101
+ $: {
102
+ if (choices !== old_choices) {
103
+ if (!allow_custom_value) {
104
+ set_input_text();
105
+ }
106
+ old_choices = choices;
107
+ filtered_indices = handle_filter(choices, input_text);
108
+ if (!allow_custom_value && filtered_indices.length > 0) {
109
+ active_index = filtered_indices[0];
110
+ }
111
+ if (is_browser && filter_input === document.activeElement) {
112
+ show_options = true;
113
+ }
114
+ }
115
+ }
116
+
117
+ $: {
118
+ if (input_text !== old_input_text) {
119
+ filtered_indices = handle_filter(choices, input_text);
120
+ old_input_text = input_text;
121
+ if (!allow_custom_value && filtered_indices.length > 0) {
122
+ active_index = filtered_indices[0];
123
+ }
124
+ }
125
+ }
126
+
127
+ function set_input_text(): void {
128
+ set_choice_names_values();
129
+ if (value === undefined || (Array.isArray(value) && value.length === 0)) {
130
+ input_text = "";
131
+ selected_index = null;
132
+ } else if (choices_values.includes(value as string)) {
133
+ input_text = choices_names[choices_values.indexOf(value as string)];
134
+ selected_index = choices_values.indexOf(value as string);
135
+ } else if (allow_custom_value) {
136
+ input_text = value as string;
137
+ selected_index = null;
138
+ } else {
139
+ input_text = "";
140
+ selected_index = null;
141
+ }
142
+ old_selected_index = selected_index;
143
+ }
144
+
145
+ function handle_option_selected(e: any): void {
146
+ selected_index = parseInt(e.detail.target.dataset.index);
147
+ if (isNaN(selected_index)) {
148
+ // This is the case when the user clicks on the scrollbar
149
+ selected_index = null;
150
+ return;
151
+ }
152
+ show_options = false;
153
+ active_index = null;
154
+ filter_input.blur();
155
+ }
156
+
157
+ function handle_focus(e: FocusEvent): void {
158
+ filtered_indices = choices.map((_, i) => i);
159
+ show_options = true;
160
+ dispatch("focus");
161
+ }
162
+
163
+ function handle_blur(): void {
164
+ if (!allow_custom_value) {
165
+ input_text = choices_names[choices_values.indexOf(value as string)];
166
+ } else {
167
+ value = input_text;
168
+ }
169
+ show_options = false;
170
+ active_index = null;
171
+ dispatch("blur");
172
+ }
173
+
174
+ function handle_key_down(e: KeyboardEvent): void {
175
+ [show_options, active_index] = handle_shared_keys(
176
+ e,
177
+ active_index,
178
+ filtered_indices
179
+ );
180
+ if (e.key === "Enter") {
181
+ if (active_index !== null) {
182
+ selected_index = active_index;
183
+ show_options = false;
184
+ filter_input.blur();
185
+ active_index = null;
186
+ } else if (choices_names.includes(input_text)) {
187
+ selected_index = choices_names.indexOf(input_text);
188
+ show_options = false;
189
+ active_index = null;
190
+ filter_input.blur();
191
+ } else if (allow_custom_value) {
192
+ value = input_text;
193
+ selected_index = null;
194
+ show_options = false;
195
+ active_index = null;
196
+ filter_input.blur();
197
+ }
198
+ }
199
+ }
200
+
201
+ afterUpdate(() => {
202
+ value_is_output = false;
203
+ initialized = true;
204
+ });
205
+ </script>
206
+
207
+ <div class:container>
208
+ <BlockTitle {root} {show_label} {info}>{label}</BlockTitle>
209
+
210
+ <div class="wrap">
211
+ <div class="wrap-inner" class:show_options>
212
+ <div class="secondary-wrap">
213
+ <input
214
+ role="listbox"
215
+ aria-controls="dropdown-options"
216
+ aria-expanded={show_options}
217
+ aria-label={label}
218
+ class="border-none"
219
+ class:subdued={!choices_names.includes(input_text) &&
220
+ !allow_custom_value}
221
+ {disabled}
222
+ autocomplete="off"
223
+ bind:value={input_text}
224
+ bind:this={filter_input}
225
+ on:keydown={handle_key_down}
226
+ on:keyup={(e) =>
227
+ dispatch("key_up", {
228
+ key: e.key,
229
+ input_value: input_text
230
+ })}
231
+ on:blur={handle_blur}
232
+ on:focus={handle_focus}
233
+ readonly={!filterable}
234
+ />
235
+ {#if !disabled}
236
+ <div class="icon-wrap">
237
+ <DropdownArrow />
238
+ </div>
239
+ {/if}
240
+ </div>
241
+ </div>
242
+ <DropdownOptions
243
+ {show_options}
244
+ {choices}
245
+ {filtered_indices}
246
+ {disabled}
247
+ selected_indices={selected_index === null ? [] : [selected_index]}
248
+ {active_index}
249
+ on:change={handle_option_selected}
250
+ />
251
+ </div>
252
+ </div>
253
+
254
+ <style>
255
+ .icon-wrap {
256
+ position: absolute;
257
+ top: 50%;
258
+ transform: translateY(-50%);
259
+ right: var(--size-5);
260
+ color: var(--body-text-color);
261
+ width: var(--size-5);
262
+ pointer-events: none;
263
+ }
264
+ .container {
265
+ height: 100%;
266
+ }
267
+ .container .wrap {
268
+ box-shadow: var(--input-shadow);
269
+ border: var(--input-border-width) solid var(--border-color-primary);
270
+ }
271
+
272
+ .wrap {
273
+ position: relative;
274
+ border-radius: var(--input-radius);
275
+ background: var(--input-background-fill);
276
+ }
277
+
278
+ .wrap:focus-within {
279
+ box-shadow: var(--input-shadow-focus);
280
+ border-color: var(--input-border-color-focus);
281
+ background: var(--input-background-fill-focus);
282
+ }
283
+
284
+ .wrap-inner {
285
+ display: flex;
286
+ position: relative;
287
+ flex-wrap: wrap;
288
+ align-items: center;
289
+ gap: var(--checkbox-label-gap);
290
+ padding: var(--checkbox-label-padding);
291
+ height: 100%;
292
+ }
293
+ .secondary-wrap {
294
+ display: flex;
295
+ flex: 1 1 0%;
296
+ align-items: center;
297
+ border: none;
298
+ min-width: min-content;
299
+ height: 100%;
300
+ }
301
+
302
+ input {
303
+ margin: var(--spacing-sm);
304
+ outline: none;
305
+ border: none;
306
+ background: inherit;
307
+ width: var(--size-full);
308
+ color: var(--body-text-color);
309
+ font-size: var(--input-text-size);
310
+ height: 100%;
311
+ }
312
+
313
+ input:disabled {
314
+ -webkit-text-fill-color: var(--body-text-color);
315
+ -webkit-opacity: 1;
316
+ opacity: 1;
317
+ cursor: not-allowed;
318
+ }
319
+
320
+ .subdued {
321
+ color: var(--body-text-color-subdued);
322
+ }
323
+
324
+ input[readonly] {
325
+ cursor: pointer;
326
+ }
327
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dropdown/shared/Multiselect.svelte ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { afterUpdate, createEventDispatcher } from "svelte";
3
+ import { _ } from "svelte-i18n";
4
+ import { BlockTitle } from "@gradio/atoms";
5
+ import { Remove, DropdownArrow } from "@gradio/icons";
6
+ import type { KeyUpData, SelectData, I18nFormatter } from "@gradio/utils";
7
+ import DropdownOptions from "./DropdownOptions.svelte";
8
+ import { handle_filter, handle_change, handle_shared_keys } from "./utils";
9
+
10
+ type Item = string | number;
11
+
12
+ export let label: string;
13
+ export let info: string | undefined = undefined;
14
+ export let value: Item | Item[] | undefined = [];
15
+ let old_value: typeof value = [];
16
+ export let value_is_output = false;
17
+ export let max_choices: number | null = null;
18
+ export let choices: [string, Item][];
19
+ let old_choices: typeof choices;
20
+ export let disabled = false;
21
+ export let show_label: boolean;
22
+ export let container = true;
23
+ export let allow_custom_value = false;
24
+ export let filterable = true;
25
+ export let i18n: I18nFormatter;
26
+ export let root: string;
27
+
28
+ let filter_input: HTMLElement;
29
+ let input_text = "";
30
+ let old_input_text = "";
31
+ let show_options = false;
32
+ let choices_names: string[];
33
+ let choices_values: (string | number)[];
34
+
35
+ // All of these are indices with respect to the choices array
36
+ let filtered_indices: number[] = [];
37
+ let active_index: number | null = null;
38
+ // selected_index consists of indices from choices or strings if allow_custom_value is true and user types in a custom value
39
+ let selected_indices: (number | string)[] = [];
40
+ let old_selected_index: (number | string)[] = [];
41
+
42
+ const dispatch = createEventDispatcher<{
43
+ change: string | string[] | undefined;
44
+ input: undefined;
45
+ select: SelectData;
46
+ blur: undefined;
47
+ focus: undefined;
48
+ key_up: KeyUpData;
49
+ }>();
50
+
51
+ // Setting the initial value of the multiselect dropdown
52
+ if (Array.isArray(value)) {
53
+ value.forEach((element) => {
54
+ const index = choices.map((c) => c[1]).indexOf(element);
55
+ if (index !== -1) {
56
+ selected_indices.push(index);
57
+ } else {
58
+ selected_indices.push(element);
59
+ }
60
+ });
61
+ }
62
+
63
+ $: {
64
+ choices_names = choices.map((c) => c[0]);
65
+ choices_values = choices.map((c) => c[1]);
66
+ }
67
+
68
+ $: {
69
+ if (choices !== old_choices || input_text !== old_input_text) {
70
+ filtered_indices = handle_filter(choices, input_text);
71
+ old_choices = choices;
72
+ old_input_text = input_text;
73
+ if (!allow_custom_value) {
74
+ active_index = filtered_indices[0];
75
+ }
76
+ }
77
+ }
78
+
79
+ $: {
80
+ if (JSON.stringify(value) != JSON.stringify(old_value)) {
81
+ handle_change(dispatch, value, value_is_output);
82
+ old_value = Array.isArray(value) ? value.slice() : value;
83
+ }
84
+ }
85
+
86
+ $: {
87
+ if (
88
+ JSON.stringify(selected_indices) != JSON.stringify(old_selected_index)
89
+ ) {
90
+ value = selected_indices.map((index) =>
91
+ typeof index === "number" ? choices_values[index] : index
92
+ );
93
+ old_selected_index = selected_indices.slice();
94
+ }
95
+ }
96
+
97
+ function handle_blur(): void {
98
+ if (!allow_custom_value) {
99
+ input_text = "";
100
+ }
101
+
102
+ if (allow_custom_value && input_text !== "") {
103
+ add_selected_choice(input_text);
104
+ input_text = "";
105
+ }
106
+
107
+ show_options = false;
108
+ active_index = null;
109
+ dispatch("blur");
110
+ }
111
+
112
+ function remove_selected_choice(option_index: number | string): void {
113
+ selected_indices = selected_indices.filter((v) => v !== option_index);
114
+ dispatch("select", {
115
+ index: typeof option_index === "number" ? option_index : -1,
116
+ value:
117
+ typeof option_index === "number"
118
+ ? choices_values[option_index]
119
+ : option_index,
120
+ selected: false
121
+ });
122
+ }
123
+
124
+ function add_selected_choice(option_index: number | string): void {
125
+ if (max_choices === null || selected_indices.length < max_choices) {
126
+ selected_indices = [...selected_indices, option_index];
127
+ dispatch("select", {
128
+ index: typeof option_index === "number" ? option_index : -1,
129
+ value:
130
+ typeof option_index === "number"
131
+ ? choices_values[option_index]
132
+ : option_index,
133
+ selected: true
134
+ });
135
+ }
136
+ if (selected_indices.length === max_choices) {
137
+ show_options = false;
138
+ active_index = null;
139
+ filter_input.blur();
140
+ }
141
+ }
142
+
143
+ function handle_option_selected(e: any): void {
144
+ const option_index = parseInt(e.detail.target.dataset.index);
145
+ add_or_remove_index(option_index);
146
+ }
147
+
148
+ function add_or_remove_index(option_index: number): void {
149
+ if (selected_indices.includes(option_index)) {
150
+ remove_selected_choice(option_index);
151
+ } else {
152
+ add_selected_choice(option_index);
153
+ }
154
+ input_text = "";
155
+ }
156
+
157
+ function remove_all(e: any): void {
158
+ selected_indices = [];
159
+ input_text = "";
160
+ e.preventDefault();
161
+ }
162
+
163
+ function handle_focus(e: FocusEvent): void {
164
+ filtered_indices = choices.map((_, i) => i);
165
+ if (max_choices === null || selected_indices.length < max_choices) {
166
+ show_options = true;
167
+ }
168
+ dispatch("focus");
169
+ }
170
+
171
+ function handle_key_down(e: KeyboardEvent): void {
172
+ [show_options, active_index] = handle_shared_keys(
173
+ e,
174
+ active_index,
175
+ filtered_indices
176
+ );
177
+ if (e.key === "Enter") {
178
+ if (active_index !== null) {
179
+ add_or_remove_index(active_index);
180
+ } else {
181
+ if (allow_custom_value) {
182
+ add_selected_choice(input_text);
183
+ input_text = "";
184
+ }
185
+ }
186
+ }
187
+ if (e.key === "Backspace" && input_text === "") {
188
+ selected_indices = [...selected_indices.slice(0, -1)];
189
+ }
190
+ if (selected_indices.length === max_choices) {
191
+ show_options = false;
192
+ active_index = null;
193
+ }
194
+ }
195
+
196
+ function set_selected_indices(): void {
197
+ if (value === undefined) {
198
+ selected_indices = [];
199
+ } else if (Array.isArray(value)) {
200
+ selected_indices = value
201
+ .map((v) => {
202
+ const index = choices_values.indexOf(v);
203
+ if (index !== -1) {
204
+ return index;
205
+ }
206
+ if (allow_custom_value) {
207
+ return v;
208
+ }
209
+ // Instead of returning null, skip this iteration
210
+ return undefined;
211
+ })
212
+ .filter((val): val is string | number => val !== undefined);
213
+ }
214
+ }
215
+
216
+ $: value, set_selected_indices();
217
+
218
+ afterUpdate(() => {
219
+ value_is_output = false;
220
+ });
221
+ </script>
222
+
223
+ <label class:container>
224
+ <BlockTitle {root} {show_label} {info}>{label}</BlockTitle>
225
+
226
+ <div class="wrap">
227
+ <div class="wrap-inner" class:show_options>
228
+ {#each selected_indices as s}
229
+ <div class="token">
230
+ <span>
231
+ {#if typeof s === "number"}
232
+ {choices_names[s]}
233
+ {:else}
234
+ {s}
235
+ {/if}
236
+ </span>
237
+ {#if !disabled}
238
+ <div
239
+ class="token-remove"
240
+ on:click|preventDefault={() => remove_selected_choice(s)}
241
+ on:keydown|preventDefault={(event) => {
242
+ if (event.key === "Enter") {
243
+ remove_selected_choice(s);
244
+ }
245
+ }}
246
+ role="button"
247
+ tabindex="0"
248
+ title={i18n("common.remove") + " " + s}
249
+ >
250
+ <Remove />
251
+ </div>
252
+ {/if}
253
+ </div>
254
+ {/each}
255
+ <div class="secondary-wrap">
256
+ <input
257
+ class="border-none"
258
+ class:subdued={(!choices_names.includes(input_text) &&
259
+ !allow_custom_value) ||
260
+ selected_indices.length === max_choices}
261
+ {disabled}
262
+ autocomplete="off"
263
+ bind:value={input_text}
264
+ bind:this={filter_input}
265
+ on:keydown={handle_key_down}
266
+ on:keyup={(e) =>
267
+ dispatch("key_up", {
268
+ key: e.key,
269
+ input_value: input_text
270
+ })}
271
+ on:blur={handle_blur}
272
+ on:focus={handle_focus}
273
+ readonly={!filterable}
274
+ />
275
+
276
+ {#if !disabled}
277
+ {#if selected_indices.length > 0}
278
+ <div
279
+ role="button"
280
+ tabindex="0"
281
+ class="token-remove remove-all"
282
+ title={i18n("common.clear")}
283
+ on:click={remove_all}
284
+ on:keydown={(event) => {
285
+ if (event.key === "Enter") {
286
+ remove_all(event);
287
+ }
288
+ }}
289
+ >
290
+ <Remove />
291
+ </div>
292
+ {/if}
293
+ <span class="icon-wrap"> <DropdownArrow /></span>
294
+ {/if}
295
+ </div>
296
+ </div>
297
+ <DropdownOptions
298
+ {show_options}
299
+ {choices}
300
+ {filtered_indices}
301
+ {disabled}
302
+ {selected_indices}
303
+ {active_index}
304
+ on:change={handle_option_selected}
305
+ />
306
+ </div>
307
+ </label>
308
+
309
+ <style>
310
+ .icon-wrap {
311
+ color: var(--body-text-color);
312
+ margin-right: var(--size-2);
313
+ width: var(--size-5);
314
+ }
315
+ label:not(.container),
316
+ label:not(.container) .wrap,
317
+ label:not(.container) .wrap-inner,
318
+ label:not(.container) .secondary-wrap,
319
+ label:not(.container) .token,
320
+ label:not(.container) input {
321
+ height: 100%;
322
+ }
323
+ .container .wrap {
324
+ box-shadow: var(--input-shadow);
325
+ border: var(--input-border-width) solid var(--border-color-primary);
326
+ }
327
+
328
+ .wrap {
329
+ position: relative;
330
+ border-radius: var(--input-radius);
331
+ background: var(--input-background-fill);
332
+ }
333
+
334
+ .wrap:focus-within {
335
+ box-shadow: var(--input-shadow-focus);
336
+ border-color: var(--input-border-color-focus);
337
+ }
338
+
339
+ .wrap-inner {
340
+ display: flex;
341
+ position: relative;
342
+ flex-wrap: wrap;
343
+ align-items: center;
344
+ gap: var(--checkbox-label-gap);
345
+ padding: var(--checkbox-label-padding);
346
+ }
347
+
348
+ .token {
349
+ display: flex;
350
+ align-items: center;
351
+ transition: var(--button-transition);
352
+ cursor: pointer;
353
+ box-shadow: var(--checkbox-label-shadow);
354
+ border: var(--checkbox-label-border-width) solid
355
+ var(--checkbox-label-border-color);
356
+ border-radius: var(--button-small-radius);
357
+ background: var(--checkbox-label-background-fill);
358
+ padding: var(--checkbox-label-padding);
359
+ color: var(--checkbox-label-text-color);
360
+ font-weight: var(--checkbox-label-text-weight);
361
+ font-size: var(--checkbox-label-text-size);
362
+ line-height: var(--line-md);
363
+ word-break: break-word;
364
+ }
365
+
366
+ .token > * + * {
367
+ margin-left: var(--size-2);
368
+ }
369
+
370
+ .token-remove {
371
+ fill: var(--body-text-color);
372
+ display: flex;
373
+ justify-content: center;
374
+ align-items: center;
375
+ cursor: pointer;
376
+ border: var(--checkbox-border-width) solid var(--border-color-primary);
377
+ border-radius: var(--radius-full);
378
+ background: var(--background-fill-primary);
379
+ padding: var(--size-0-5);
380
+ width: 16px;
381
+ height: 16px;
382
+ flex-shrink: 0;
383
+ }
384
+
385
+ .secondary-wrap {
386
+ display: flex;
387
+ flex: 1 1 0%;
388
+ align-items: center;
389
+ border: none;
390
+ min-width: min-content;
391
+ }
392
+
393
+ input {
394
+ margin: var(--spacing-sm);
395
+ outline: none;
396
+ border: none;
397
+ background: inherit;
398
+ width: var(--size-full);
399
+ color: var(--body-text-color);
400
+ font-size: var(--input-text-size);
401
+ }
402
+
403
+ input:disabled {
404
+ -webkit-text-fill-color: var(--body-text-color);
405
+ -webkit-opacity: 1;
406
+ opacity: 1;
407
+ cursor: not-allowed;
408
+ }
409
+
410
+ .remove-all {
411
+ margin-left: var(--size-1);
412
+ width: 20px;
413
+ height: 20px;
414
+ }
415
+ .subdued {
416
+ color: var(--body-text-color-subdued);
417
+ }
418
+ input[readonly] {
419
+ cursor: pointer;
420
+ }
421
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/dropdown/shared/utils.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function positive_mod(n: number, m: number): number {
2
+ return ((n % m) + m) % m;
3
+ }
4
+
5
+ export function handle_filter(
6
+ choices: [string, string | number][],
7
+ input_text: string
8
+ ): number[] {
9
+ return choices.reduce((filtered_indices, o, index) => {
10
+ if (
11
+ input_text ? o[0].toLowerCase().includes(input_text.toLowerCase()) : true
12
+ ) {
13
+ filtered_indices.push(index);
14
+ }
15
+ return filtered_indices;
16
+ }, [] as number[]);
17
+ }
18
+
19
+ export function handle_change(
20
+ dispatch: any,
21
+ value: string | number | (string | number)[] | undefined,
22
+ value_is_output: boolean
23
+ ): void {
24
+ dispatch("change", value);
25
+ if (!value_is_output) {
26
+ dispatch("input");
27
+ }
28
+ }
29
+
30
+ export function handle_shared_keys(
31
+ e: KeyboardEvent,
32
+ active_index: number | null,
33
+ filtered_indices: number[]
34
+ ): [boolean, number | null] {
35
+ if (e.key === "Escape") {
36
+ return [false, active_index];
37
+ }
38
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
39
+ if (filtered_indices.length >= 0) {
40
+ if (active_index === null) {
41
+ active_index =
42
+ e.key === "ArrowDown"
43
+ ? filtered_indices[0]
44
+ : filtered_indices[filtered_indices.length - 1];
45
+ } else {
46
+ const index_in_filtered = filtered_indices.indexOf(active_index);
47
+ const increment = e.key === "ArrowUp" ? -1 : 1;
48
+ active_index =
49
+ filtered_indices[
50
+ positive_mod(index_in_filtered + increment, filtered_indices.length)
51
+ ];
52
+ }
53
+ }
54
+ }
55
+ return [true, active_index];
56
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/group/Index.svelte ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let elem_id = "";
3
+ export let elem_classes: string[] = [];
4
+ export let visible = true;
5
+ </script>
6
+
7
+ <div
8
+ id={elem_id}
9
+ class="gr-group {elem_classes.join(' ')}"
10
+ class:hide={!visible}
11
+ >
12
+ <div
13
+ class="styler"
14
+ style:--block-radius="0px"
15
+ style:--block-border-width="0px"
16
+ style:--layout-gap="1px"
17
+ style:--form-gap-width="1px"
18
+ style:--button-border-width="0px"
19
+ style:--button-large-radius="0px"
20
+ style:--button-small-radius="0px"
21
+ >
22
+ <slot />
23
+ </div>
24
+ </div>
25
+
26
+ <style>
27
+ div {
28
+ border: var(--block-border-width) solid var(--border-color-primary);
29
+ background: var(--block-border-color);
30
+ border-radius: var(--block-radius);
31
+ display: flex;
32
+ flex-direction: column;
33
+ gap: var(--form-gap-width);
34
+ overflow: hidden;
35
+ }
36
+ div > :global(*:not(.absolute)) {
37
+ border: none;
38
+ border-radius: 0;
39
+ }
40
+ .hide {
41
+ display: none;
42
+ }
43
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/html/package.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/html",
3
+ "version": "0.4.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "dependencies": {
11
+ "@gradio/atoms": "workspace:^",
12
+ "@gradio/statustracker": "workspace:^",
13
+ "@gradio/utils": "workspace:^",
14
+ "@gradio/icons": "workspace:^"
15
+ },
16
+ "devDependencies": {
17
+ "@gradio/preview": "workspace:^"
18
+ },
19
+ "exports": {
20
+ "./package.json": "./package.json",
21
+ ".": {
22
+ "gradio": "./Index.svelte",
23
+ "svelte": "./dist/Index.svelte",
24
+ "types": "./dist/Index.svelte.d.ts"
25
+ },
26
+ "./example": {
27
+ "gradio": "./Example.svelte",
28
+ "svelte": "./dist/Example.svelte",
29
+ "types": "./dist/Example.svelte.d.ts"
30
+ },
31
+ "./base": {
32
+ "gradio": "./Index.svelte",
33
+ "svelte": "./dist/Index.svelte",
34
+ "types": "./dist/Index.svelte.d.ts"
35
+ }
36
+ },
37
+ "peerDependencies": {
38
+ "svelte": "^4.0.0"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/gradio-app/gradio.git",
43
+ "directory": "js/html"
44
+ }
45
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/markdown/Index.svelte ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as MarkdownCode } from "./shared/MarkdownCode.svelte";
3
+ export { default as BaseMarkdown } from "./shared/Markdown.svelte";
4
+ export { default as BaseExample } from "./Example.svelte";
5
+ </script>
6
+
7
+ <script lang="ts">
8
+ import type { Gradio } from "@gradio/utils";
9
+ import Markdown from "./shared/Markdown.svelte";
10
+
11
+ import { StatusTracker } from "@gradio/statustracker";
12
+ import type { LoadingStatus } from "@gradio/statustracker";
13
+ import { Block } from "@gradio/atoms";
14
+
15
+ export let label: string;
16
+ export let elem_id = "";
17
+ export let elem_classes: string[] = [];
18
+ export let visible = true;
19
+ export let value = "";
20
+ export let loading_status: LoadingStatus;
21
+ export let rtl = false;
22
+ export let sanitize_html = true;
23
+ export let line_breaks = false;
24
+ export let gradio: Gradio<{
25
+ change: never;
26
+ clear_status: LoadingStatus;
27
+ }>;
28
+ export let latex_delimiters: {
29
+ left: string;
30
+ right: string;
31
+ display: boolean;
32
+ }[];
33
+ export let header_links = false;
34
+ export let height: number | string | undefined;
35
+ export let min_height: number | string | undefined;
36
+ export let max_height: number | string | undefined;
37
+ export let show_copy_button = false;
38
+ export let container = false;
39
+
40
+ $: label, gradio.dispatch("change");
41
+ </script>
42
+
43
+ <Block
44
+ {visible}
45
+ {elem_id}
46
+ {elem_classes}
47
+ {container}
48
+ allow_overflow={true}
49
+ overflow_behavior="auto"
50
+ {height}
51
+ {min_height}
52
+ {max_height}
53
+ >
54
+ <StatusTracker
55
+ autoscroll={gradio.autoscroll}
56
+ i18n={gradio.i18n}
57
+ {...loading_status}
58
+ variant="center"
59
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
60
+ />
61
+ <div class:pending={loading_status?.status === "pending"}>
62
+ <Markdown
63
+ {value}
64
+ {elem_classes}
65
+ {visible}
66
+ {rtl}
67
+ on:change={() => gradio.dispatch("change")}
68
+ {latex_delimiters}
69
+ {sanitize_html}
70
+ {line_breaks}
71
+ {header_links}
72
+ {show_copy_button}
73
+ root={gradio.root}
74
+ {loading_status}
75
+ />
76
+ </div>
77
+ </Block>
78
+
79
+ <style>
80
+ div {
81
+ transition: 150ms;
82
+ }
83
+
84
+ .pending {
85
+ opacity: 0.2;
86
+ }
87
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/markdown/shared/MarkdownCode.svelte ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { afterUpdate } from "svelte";
3
+ import render_math_in_element from "katex/contrib/auto-render";
4
+ import "katex/dist/katex.min.css";
5
+ import { create_marked } from "./utils";
6
+ import sanitize_server from "sanitize-html";
7
+ import Amuchina from "amuchina";
8
+ import "./prism.css";
9
+
10
+ export let chatbot = true;
11
+ export let message: string;
12
+ export let sanitize_html = true;
13
+ export let latex_delimiters: {
14
+ left: string;
15
+ right: string;
16
+ display: boolean;
17
+ }[] = [];
18
+ export let render_markdown = true;
19
+ export let line_breaks = true;
20
+ export let header_links = false;
21
+ export let root: string;
22
+
23
+ let el: HTMLSpanElement;
24
+ let html: string;
25
+
26
+ const marked = create_marked({
27
+ header_links,
28
+ line_breaks,
29
+ latex_delimiters
30
+ });
31
+
32
+ const amuchina = new Amuchina();
33
+ const is_browser = typeof window !== "undefined";
34
+
35
+ let sanitize = is_browser ? sanitize_browser : sanitize_server;
36
+
37
+ function sanitize_browser(source: string): string {
38
+ const node = new DOMParser().parseFromString(source, "text/html");
39
+ walk_nodes(node.body, "A", (node) => {
40
+ if (node instanceof HTMLElement && "target" in node) {
41
+ if (is_external_url(node.getAttribute("href"))) {
42
+ node.setAttribute("target", "_blank");
43
+ node.setAttribute("rel", "noopener noreferrer");
44
+ }
45
+ }
46
+ });
47
+
48
+ return amuchina.sanitize(node).body.innerHTML;
49
+ }
50
+
51
+ function walk_nodes(
52
+ node: Node | null | HTMLElement,
53
+ test: string | ((node: Node | HTMLElement) => boolean),
54
+ callback: (node: Node | HTMLElement) => void
55
+ ): void {
56
+ if (
57
+ node &&
58
+ ((typeof test === "string" && node.nodeName === test) ||
59
+ (typeof test === "function" && test(node)))
60
+ ) {
61
+ callback(node);
62
+ }
63
+ const children = node?.childNodes || [];
64
+ for (let i = 0; i < children.length; i++) {
65
+ // @ts-ignore
66
+ walk_nodes(children[i], test, callback);
67
+ }
68
+ }
69
+
70
+ const is_external_url = (link: string | null): boolean => {
71
+ try {
72
+ return !!link && new URL(link).origin !== new URL(root).origin;
73
+ } catch (e) {
74
+ return false;
75
+ }
76
+ };
77
+
78
+ function escapeRegExp(string: string): string {
79
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
80
+ }
81
+
82
+ function process_message(value: string): string {
83
+ let parsedValue = value;
84
+
85
+ if (render_markdown) {
86
+ const latexBlocks: string[] = [];
87
+ latex_delimiters.forEach((delimiter, index) => {
88
+ const leftDelimiter = escapeRegExp(delimiter.left);
89
+ const rightDelimiter = escapeRegExp(delimiter.right);
90
+ const regex = new RegExp(
91
+ `${leftDelimiter}([\\s\\S]+?)${rightDelimiter}`,
92
+ "g"
93
+ );
94
+ parsedValue = parsedValue.replace(regex, (match, p1) => {
95
+ latexBlocks.push(match);
96
+ return `%%%LATEX_BLOCK_${latexBlocks.length - 1}%%%`;
97
+ });
98
+ });
99
+
100
+ parsedValue = marked.parse(parsedValue) as string;
101
+
102
+ parsedValue = parsedValue.replace(
103
+ /%%%LATEX_BLOCK_(\d+)%%%/g,
104
+ (match, p1) => latexBlocks[parseInt(p1, 10)]
105
+ );
106
+ }
107
+
108
+ if (sanitize_html && sanitize) {
109
+ parsedValue = sanitize(parsedValue);
110
+ }
111
+
112
+ return parsedValue;
113
+ }
114
+
115
+ $: if (message && message.trim()) {
116
+ html = process_message(message);
117
+ } else {
118
+ html = "";
119
+ }
120
+
121
+ async function render_html(value: string): Promise<void> {
122
+ if (latex_delimiters.length > 0 && value) {
123
+ const containsDelimiter = latex_delimiters.some(
124
+ (delimiter) =>
125
+ value.includes(delimiter.left) && value.includes(delimiter.right)
126
+ );
127
+ if (containsDelimiter) {
128
+ render_math_in_element(el, {
129
+ delimiters: latex_delimiters,
130
+ throwOnError: false
131
+ });
132
+ }
133
+ }
134
+ }
135
+
136
+ afterUpdate(async () => {
137
+ if (el && document.body.contains(el)) {
138
+ await render_html(message);
139
+ } else {
140
+ console.error("Element is not in the DOM");
141
+ }
142
+ });
143
+ </script>
144
+
145
+ <span class:chatbot bind:this={el} class="md" class:prose={render_markdown}>
146
+ {@html html}
147
+ </span>
148
+
149
+ <style>
150
+ span :global(div[class*="code_wrap"]) {
151
+ position: relative;
152
+ }
153
+
154
+ /* KaTeX */
155
+ span :global(span.katex) {
156
+ font-size: var(--text-lg);
157
+ direction: ltr;
158
+ }
159
+
160
+ span :global(div[class*="code_wrap"] > button) {
161
+ z-index: 1;
162
+ cursor: pointer;
163
+ border-bottom-left-radius: var(--radius-sm);
164
+ padding: var(--spacing-md);
165
+ width: 25px;
166
+ height: 25px;
167
+ position: absolute;
168
+ right: 0;
169
+ }
170
+
171
+ span :global(.check) {
172
+ opacity: 0;
173
+ z-index: var(--layer-top);
174
+ transition: opacity 0.2s;
175
+ background: var(--code-background-fill);
176
+ color: var(--body-text-color);
177
+ position: absolute;
178
+ top: var(--size-1-5);
179
+ left: var(--size-1-5);
180
+ }
181
+
182
+ span :global(p:not(:first-child)) {
183
+ margin-top: var(--spacing-xxl);
184
+ }
185
+
186
+ span :global(.md-header-anchor) {
187
+ /* position: absolute; */
188
+ margin-left: -25px;
189
+ padding-right: 8px;
190
+ line-height: 1;
191
+ color: var(--body-text-color-subdued);
192
+ opacity: 0;
193
+ }
194
+
195
+ span :global(h1:hover .md-header-anchor),
196
+ span :global(h2:hover .md-header-anchor),
197
+ span :global(h3:hover .md-header-anchor),
198
+ span :global(h4:hover .md-header-anchor),
199
+ span :global(h5:hover .md-header-anchor),
200
+ span :global(h6:hover .md-header-anchor) {
201
+ opacity: 1;
202
+ }
203
+
204
+ span.md :global(.md-header-anchor > svg) {
205
+ color: var(--body-text-color-subdued);
206
+ }
207
+
208
+ span :global(table) {
209
+ word-break: break-word;
210
+ }
211
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/markdown/shared/prism-dark.css ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .dark .md .token.comment,
2
+ .dark .md .token.prolog,
3
+ .dark .md .token.doctype,
4
+ .dark .md .token.cdata {
5
+ color: hsl(30, 20%, 50%);
6
+ }
7
+
8
+ .dark .md .token.punctuation {
9
+ opacity: 0.7;
10
+ }
11
+
12
+ .dark .md .token.namespace {
13
+ opacity: 0.7;
14
+ }
15
+
16
+ .dark .md .token.property,
17
+ .dark .md .token.tag,
18
+ .dark .md .token.boolean,
19
+ .dark .md .token.number,
20
+ .dark .md .token.constant,
21
+ .dark .md .token.symbol {
22
+ color: hsl(350, 40%, 70%);
23
+ }
24
+
25
+ .dark .md .token.selector,
26
+ .dark .md .token.attr-name,
27
+ .dark .md .token.string,
28
+ .dark .md .token.char,
29
+ .dark .md .token.builtin,
30
+ .dark .md .token.inserted {
31
+ color: hsl(75, 70%, 60%);
32
+ }
33
+
34
+ .dark .md .token.operator,
35
+ .dark .md .token.entity,
36
+ .dark .md .token.url,
37
+ .dark .md .language-css .token.string,
38
+ .dark .md .style .token.string,
39
+ .dark .md .token.variable {
40
+ color: hsl(40, 90%, 60%);
41
+ }
42
+
43
+ .dark .md .token.atrule,
44
+ .dark .md .token.attr-value,
45
+ .dark .md .token.keyword {
46
+ color: hsl(350, 40%, 70%);
47
+ }
48
+
49
+ .dark .md .token.regex,
50
+ .dark .md .token.important {
51
+ color: #e90;
52
+ }
53
+
54
+ .dark .md .token.important,
55
+ .dark .md .token.bold {
56
+ font-weight: bold;
57
+ }
58
+ .dark .md .token.italic {
59
+ font-style: italic;
60
+ }
61
+
62
+ .dark .md .token.entity {
63
+ cursor: help;
64
+ }
65
+
66
+ .dark .md .token.deleted {
67
+ color: red;
68
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/nativeplot/Example.svelte ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let title: string | null;
3
+ export let x: string;
4
+ export let y: string;
5
+ </script>
6
+
7
+ {#if title}
8
+ {title}
9
+ {:else}
10
+ {x} x {y}
11
+ {/if}
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/nativeplot/Index.svelte ADDED
@@ -0,0 +1,552 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Gradio, SelectData } from "@gradio/utils";
3
+ import { BlockTitle } from "@gradio/atoms";
4
+ import { Block } from "@gradio/atoms";
5
+ import { StatusTracker } from "@gradio/statustracker";
6
+ import type { LoadingStatus } from "@gradio/statustracker";
7
+ import { onMount } from "svelte";
8
+
9
+ import type { TopLevelSpec as Spec } from "vega-lite";
10
+ import type { View } from "vega";
11
+ import { LineChart as LabelIcon } from "@gradio/icons";
12
+ import { Empty } from "@gradio/atoms";
13
+
14
+ interface PlotData {
15
+ columns: string[];
16
+ data: [string | number][];
17
+ datatypes: Record<string, "quantitative" | "temporal" | "nominal">;
18
+ mark: "line" | "point" | "bar";
19
+ }
20
+ export let value: PlotData | null;
21
+ export let x: string;
22
+ export let y: string;
23
+ export let color: string | null = null;
24
+ export let root: string;
25
+ $: unique_colors =
26
+ color && value && value.datatypes[color] === "nominal"
27
+ ? Array.from(new Set(_data.map((d) => d[color])))
28
+ : [];
29
+
30
+ export let title: string | null = null;
31
+ export let x_title: string | null = null;
32
+ export let y_title: string | null = null;
33
+ export let color_title: string | null = null;
34
+ export let x_bin: string | number | null = null;
35
+ export let y_aggregate:
36
+ | "sum"
37
+ | "mean"
38
+ | "median"
39
+ | "min"
40
+ | "max"
41
+ | undefined = undefined;
42
+ export let color_map: Record<string, string> | null = null;
43
+ export let x_lim: [number, number] | null = null;
44
+ export let y_lim: [number, number] | null = null;
45
+ export let x_label_angle: number | null = null;
46
+ export let y_label_angle: number | null = null;
47
+ export let x_axis_labels_visible = true;
48
+ export let caption: string | null = null;
49
+ export let sort: "x" | "y" | "-x" | "-y" | string[] | null = null;
50
+ function reformat_sort(
51
+ _sort: typeof sort
52
+ ):
53
+ | string
54
+ | "ascending"
55
+ | "descending"
56
+ | { field: string; order: "ascending" | "descending" }
57
+ | string[]
58
+ | undefined {
59
+ if (_sort === "x") {
60
+ return "ascending";
61
+ } else if (_sort === "-x") {
62
+ return "descending";
63
+ } else if (_sort === "y") {
64
+ return { field: y, order: "ascending" };
65
+ } else if (_sort === "-y") {
66
+ return { field: y, order: "descending" };
67
+ } else if (_sort === null) {
68
+ return undefined;
69
+ } else if (Array.isArray(_sort)) {
70
+ return _sort;
71
+ }
72
+ }
73
+ $: _sort = reformat_sort(sort);
74
+ export let _selectable = false;
75
+ let _data: {
76
+ [x: string]: string | number;
77
+ }[];
78
+ export let gradio: Gradio<{
79
+ select: SelectData;
80
+ double_click: undefined;
81
+ clear_status: LoadingStatus;
82
+ }>;
83
+
84
+ $: x_temporal = value && value.datatypes[x] === "temporal";
85
+ $: _x_lim = x_lim && x_temporal ? [x_lim[0] * 1000, x_lim[1] * 1000] : x_lim;
86
+ let _x_bin: number | undefined;
87
+ let mouse_down_on_chart = false;
88
+ const SUFFIX_DURATION: Record<string, number> = {
89
+ s: 1,
90
+ m: 60,
91
+ h: 60 * 60,
92
+ d: 24 * 60 * 60
93
+ };
94
+ $: _x_bin = x_bin
95
+ ? typeof x_bin === "string"
96
+ ? 1000 *
97
+ parseInt(x_bin.substring(0, x_bin.length - 1)) *
98
+ SUFFIX_DURATION[x_bin[x_bin.length - 1]]
99
+ : x_bin
100
+ : undefined;
101
+ let _y_aggregate: typeof y_aggregate;
102
+ let aggregating: boolean;
103
+ $: {
104
+ if (value) {
105
+ if (value.mark === "point") {
106
+ aggregating = _x_bin !== undefined;
107
+ _y_aggregate = y_aggregate || aggregating ? "sum" : undefined;
108
+ } else {
109
+ aggregating = _x_bin !== undefined || value.datatypes[x] === "nominal";
110
+ _y_aggregate = y_aggregate ? y_aggregate : "sum";
111
+ }
112
+ }
113
+ }
114
+ function reformat_data(data: PlotData): {
115
+ [x: string]: string | number;
116
+ }[] {
117
+ let x_index = data.columns.indexOf(x);
118
+ let y_index = data.columns.indexOf(y);
119
+ let color_index = color ? data.columns.indexOf(color) : null;
120
+ return data.data.map((row) => {
121
+ const obj = {
122
+ [x]: row[x_index],
123
+ [y]: row[y_index]
124
+ };
125
+ if (color && color_index !== null) {
126
+ obj[color] = row[color_index];
127
+ }
128
+ return obj;
129
+ });
130
+ }
131
+ $: _data = value ? reformat_data(value) : [];
132
+
133
+ const is_browser = typeof window !== "undefined";
134
+ let chart_element: HTMLDivElement;
135
+ $: computed_style = chart_element
136
+ ? window.getComputedStyle(chart_element)
137
+ : null;
138
+ let view: View;
139
+ let mounted = false;
140
+ let old_width: number;
141
+ let resizeObserver: ResizeObserver;
142
+
143
+ let vegaEmbed: typeof import("vega-embed").default;
144
+ async function load_chart(): Promise<void> {
145
+ if (view) {
146
+ view.finalize();
147
+ }
148
+ if (!value || !chart_element) return;
149
+ old_width = chart_element.offsetWidth;
150
+ const spec = create_vega_lite_spec();
151
+ if (!spec) return;
152
+ resizeObserver = new ResizeObserver((el) => {
153
+ if (!el[0].target || !(el[0].target instanceof HTMLElement)) return;
154
+ if (
155
+ old_width === 0 &&
156
+ chart_element.offsetWidth !== 0 &&
157
+ value.datatypes[x] === "nominal"
158
+ ) {
159
+ // a bug where when a nominal chart is first loaded, the width is 0, it doesn't resize
160
+ load_chart();
161
+ } else {
162
+ view.signal("width", el[0].target.offsetWidth).run();
163
+ }
164
+ });
165
+
166
+ if (!vegaEmbed) {
167
+ vegaEmbed = (await import("vega-embed")).default;
168
+ }
169
+ vegaEmbed(chart_element, spec, { actions: false }).then(function (result) {
170
+ view = result.view;
171
+
172
+ resizeObserver.observe(chart_element);
173
+ var debounceTimeout: NodeJS.Timeout;
174
+ view.addEventListener("dblclick", () => {
175
+ gradio.dispatch("double_click");
176
+ });
177
+ // prevent double-clicks from highlighting text
178
+ chart_element.addEventListener(
179
+ "mousedown",
180
+ function (e) {
181
+ if (e.detail > 1) {
182
+ e.preventDefault();
183
+ }
184
+ },
185
+ false
186
+ );
187
+ if (_selectable) {
188
+ view.addSignalListener("brush", function (_, value) {
189
+ if (Object.keys(value).length === 0) return;
190
+ clearTimeout(debounceTimeout);
191
+ let range: [number, number] = value[Object.keys(value)[0]];
192
+ if (x_temporal) {
193
+ range = [range[0] / 1000, range[1] / 1000];
194
+ }
195
+ let callback = (): void => {
196
+ gradio.dispatch("select", {
197
+ value: range,
198
+ index: range,
199
+ selected: true
200
+ });
201
+ };
202
+ if (mouse_down_on_chart) {
203
+ release_callback = callback;
204
+ } else {
205
+ debounceTimeout = setTimeout(function () {
206
+ gradio.dispatch("select", {
207
+ value: range,
208
+ index: range,
209
+ selected: true
210
+ });
211
+ }, 250);
212
+ }
213
+ });
214
+ }
215
+ });
216
+ }
217
+
218
+ let release_callback: (() => void) | null = null;
219
+ onMount(() => {
220
+ mounted = true;
221
+ chart_element.addEventListener("mousedown", () => {
222
+ mouse_down_on_chart = true;
223
+ });
224
+ chart_element.addEventListener("mouseup", () => {
225
+ mouse_down_on_chart = false;
226
+ if (release_callback) {
227
+ release_callback();
228
+ release_callback = null;
229
+ }
230
+ });
231
+
232
+ return () => {
233
+ mounted = false;
234
+ if (view) {
235
+ view.finalize();
236
+ }
237
+ if (resizeObserver) {
238
+ resizeObserver.disconnect();
239
+ }
240
+ };
241
+ });
242
+
243
+ $: title,
244
+ x_title,
245
+ y_title,
246
+ color_title,
247
+ x,
248
+ y,
249
+ color,
250
+ x_bin,
251
+ _y_aggregate,
252
+ color_map,
253
+ x_lim,
254
+ y_lim,
255
+ caption,
256
+ sort,
257
+ value,
258
+ mounted,
259
+ chart_element,
260
+ computed_style && requestAnimationFrame(load_chart);
261
+
262
+ function create_vega_lite_spec(): Spec | null {
263
+ if (!value || !computed_style) return null;
264
+ let accent_color = computed_style.getPropertyValue("--color-accent");
265
+ let body_text_color = computed_style.getPropertyValue("--body-text-color");
266
+ let borderColorPrimary = computed_style.getPropertyValue(
267
+ "--border-color-primary"
268
+ );
269
+ let font_family = computed_style.fontFamily;
270
+ let title_weight = computed_style.getPropertyValue(
271
+ "--block-title-text-weight"
272
+ ) as
273
+ | "bold"
274
+ | "normal"
275
+ | 100
276
+ | 200
277
+ | 300
278
+ | 400
279
+ | 500
280
+ | 600
281
+ | 700
282
+ | 800
283
+ | 900;
284
+ const font_to_px_val = (font: string): number => {
285
+ return font.endsWith("px") ? parseFloat(font.slice(0, -2)) : 12;
286
+ };
287
+ let text_size_md = font_to_px_val(
288
+ computed_style.getPropertyValue("--text-md")
289
+ );
290
+ let text_size_sm = font_to_px_val(
291
+ computed_style.getPropertyValue("--text-sm")
292
+ );
293
+
294
+ /* eslint-disable complexity */
295
+ return {
296
+ $schema: "https://vega.github.io/schema/vega-lite/v5.17.0.json",
297
+ background: "transparent",
298
+ config: {
299
+ autosize: { type: "fit", contains: "padding" },
300
+ axis: {
301
+ labelFont: font_family,
302
+ labelColor: body_text_color,
303
+ titleFont: font_family,
304
+ titleColor: body_text_color,
305
+ titlePadding: 8,
306
+ tickColor: borderColorPrimary,
307
+ labelFontSize: text_size_sm,
308
+ gridColor: borderColorPrimary,
309
+ titleFontWeight: "normal",
310
+ titleFontSize: text_size_sm,
311
+ labelFontWeight: "normal",
312
+ domain: false,
313
+ labelAngle: 0
314
+ },
315
+ legend: {
316
+ labelColor: body_text_color,
317
+ labelFont: font_family,
318
+ titleColor: body_text_color,
319
+ titleFont: font_family,
320
+ titleFontWeight: "normal",
321
+ titleFontSize: text_size_sm,
322
+ labelFontWeight: "normal",
323
+ offset: 2
324
+ },
325
+ title: {
326
+ color: body_text_color,
327
+ font: font_family,
328
+ fontSize: text_size_md,
329
+ fontWeight: title_weight,
330
+ anchor: "middle"
331
+ },
332
+ view: { stroke: borderColorPrimary },
333
+ mark: {
334
+ stroke: value.mark !== "bar" ? accent_color : undefined,
335
+ fill: value.mark === "bar" ? accent_color : undefined,
336
+ cursor: "crosshair"
337
+ }
338
+ },
339
+ data: { name: "data" },
340
+ datasets: {
341
+ data: _data
342
+ },
343
+ layer: ["plot", ...(value.mark === "line" ? ["hover"] : [])].map(
344
+ (mode) => {
345
+ return {
346
+ encoding: {
347
+ size:
348
+ value.mark === "line"
349
+ ? mode == "plot"
350
+ ? {
351
+ condition: {
352
+ empty: false,
353
+ param: "hoverPlot",
354
+ value: 3
355
+ },
356
+ value: 2
357
+ }
358
+ : {
359
+ condition: { empty: false, param: "hover", value: 100 },
360
+ value: 0
361
+ }
362
+ : undefined,
363
+ opacity:
364
+ mode === "plot"
365
+ ? undefined
366
+ : {
367
+ condition: { empty: false, param: "hover", value: 1 },
368
+ value: 0
369
+ },
370
+ x: {
371
+ axis: {
372
+ ...(x_label_angle !== null && { labelAngle: x_label_angle }),
373
+ labels: x_axis_labels_visible,
374
+ ticks: x_axis_labels_visible
375
+ },
376
+ field: x,
377
+ title: x_title || x,
378
+ type: value.datatypes[x],
379
+ scale: _x_lim ? { domain: _x_lim } : undefined,
380
+ bin: _x_bin ? { step: _x_bin } : undefined,
381
+ sort: _sort
382
+ },
383
+ y: {
384
+ axis: y_label_angle ? { labelAngle: y_label_angle } : {},
385
+ field: y,
386
+ title: y_title || y,
387
+ type: value.datatypes[y],
388
+ scale: y_lim ? { domain: y_lim } : undefined,
389
+ aggregate: aggregating ? _y_aggregate : undefined
390
+ },
391
+ color: color
392
+ ? {
393
+ field: color,
394
+ legend: { orient: "bottom", title: color_title },
395
+ scale:
396
+ value.datatypes[color] === "nominal"
397
+ ? {
398
+ domain: unique_colors,
399
+ range: color_map
400
+ ? unique_colors.map((c) => color_map[c])
401
+ : undefined
402
+ }
403
+ : {
404
+ range: [
405
+ 100, 200, 300, 400, 500, 600, 700, 800, 900
406
+ ].map((n) =>
407
+ computed_style.getPropertyValue("--primary-" + n)
408
+ ),
409
+ interpolate: "hsl"
410
+ },
411
+ type: value.datatypes[color]
412
+ }
413
+ : undefined,
414
+ tooltip: [
415
+ {
416
+ field: y,
417
+ type: value.datatypes[y],
418
+ aggregate: aggregating ? _y_aggregate : undefined,
419
+ title: y_title || y
420
+ },
421
+ {
422
+ field: x,
423
+ type: value.datatypes[x],
424
+ title: x_title || x,
425
+ format: x_temporal ? "%Y-%m-%d %H:%M:%S" : undefined,
426
+ bin: _x_bin ? { step: _x_bin } : undefined
427
+ },
428
+ ...(color
429
+ ? [
430
+ {
431
+ field: color,
432
+ type: value.datatypes[color]
433
+ }
434
+ ]
435
+ : [])
436
+ ]
437
+ },
438
+ strokeDash: {},
439
+ mark: { clip: true, type: mode === "hover" ? "point" : value.mark },
440
+ name: mode
441
+ };
442
+ }
443
+ ),
444
+ // @ts-ignore
445
+ params: [
446
+ ...(value.mark === "line"
447
+ ? [
448
+ {
449
+ name: "hoverPlot",
450
+ select: {
451
+ clear: "mouseout",
452
+ fields: color ? [color] : [],
453
+ nearest: true,
454
+ on: "mouseover",
455
+ type: "point" as "point"
456
+ },
457
+ views: ["hover"]
458
+ },
459
+ {
460
+ name: "hover",
461
+ select: {
462
+ clear: "mouseout",
463
+ nearest: true,
464
+ on: "mouseover",
465
+ type: "point" as "point"
466
+ },
467
+ views: ["hover"]
468
+ }
469
+ ]
470
+ : []),
471
+ ...(_selectable
472
+ ? [
473
+ {
474
+ name: "brush",
475
+ select: {
476
+ encodings: ["x"],
477
+ mark: { fill: "gray", fillOpacity: 0.3, stroke: "none" },
478
+ type: "interval" as "interval"
479
+ },
480
+ views: ["plot"]
481
+ }
482
+ ]
483
+ : [])
484
+ ],
485
+ width: chart_element.offsetWidth,
486
+ title: title || undefined
487
+ };
488
+ /* eslint-enable complexity */
489
+ }
490
+
491
+ export let label = "Textbox";
492
+ export let elem_id = "";
493
+ export let elem_classes: string[] = [];
494
+ export let visible = true;
495
+ export let show_label: boolean;
496
+ export let scale: number | null = null;
497
+ export let min_width: number | undefined = undefined;
498
+ export let loading_status: LoadingStatus | undefined = undefined;
499
+ export let height: number | undefined = undefined;
500
+ </script>
501
+
502
+ <Block
503
+ {visible}
504
+ {elem_id}
505
+ {elem_classes}
506
+ {scale}
507
+ {min_width}
508
+ allow_overflow={false}
509
+ padding={true}
510
+ {height}
511
+ >
512
+ {#if loading_status}
513
+ <StatusTracker
514
+ autoscroll={gradio.autoscroll}
515
+ i18n={gradio.i18n}
516
+ {...loading_status}
517
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
518
+ />
519
+ {/if}
520
+ <BlockTitle {root} {show_label} info={undefined}>{label}</BlockTitle>
521
+ {#if value && is_browser}
522
+ <div bind:this={chart_element}></div>
523
+
524
+ {#if caption}
525
+ <p class="caption">{caption}</p>
526
+ {/if}
527
+ {:else}
528
+ <Empty unpadded_box={true}><LabelIcon /></Empty>
529
+ {/if}
530
+ </Block>
531
+
532
+ <style>
533
+ div {
534
+ width: 100%;
535
+ }
536
+ :global(#vg-tooltip-element) {
537
+ font-family: var(--font) !important;
538
+ font-size: var(--text-xs) !important;
539
+ box-shadow: none !important;
540
+ background-color: var(--block-background-fill) !important;
541
+ border: 1px solid var(--border-color-primary) !important;
542
+ color: var(--body-text-color) !important;
543
+ }
544
+ :global(#vg-tooltip-element .key) {
545
+ color: var(--body-text-color-subdued) !important;
546
+ }
547
+ .caption {
548
+ padding: 0 4px;
549
+ margin: 0;
550
+ text-align: center;
551
+ }
552
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/nativeplot/package.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/nativeplot",
3
+ "version": "0.4.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": {
12
+ "gradio": "./Index.svelte",
13
+ "svelte": "./dist/Index.svelte",
14
+ "types": "./dist/Index.svelte.d.ts"
15
+ },
16
+ "./example": {
17
+ "gradio": "./Example.svelte",
18
+ "svelte": "./dist/Example.svelte",
19
+ "types": "./dist/Example.svelte.d.ts"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "dependencies": {
24
+ "@gradio/atoms": "workspace:^",
25
+ "@gradio/icons": "workspace:^",
26
+ "@gradio/statustracker": "workspace:^",
27
+ "@gradio/utils": "workspace:^",
28
+ "@gradio/theme": "workspace:^",
29
+ "vega": "^5.23.0",
30
+ "vega-embed": "^6.25.0",
31
+ "vega-lite": "^5.12.0"
32
+ },
33
+ "devDependencies": {
34
+ "@gradio/preview": "workspace:^"
35
+ },
36
+ "peerDependencies": {
37
+ "svelte": "^4.0.0"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/gradio-app/gradio.git",
42
+ "directory": "js/nativeplot"
43
+ }
44
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/number/Index.svelte ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Gradio } from "@gradio/utils";
3
+ import { Block, BlockTitle } from "@gradio/atoms";
4
+ import { StatusTracker } from "@gradio/statustracker";
5
+ import type { LoadingStatus } from "@gradio/statustracker";
6
+ import { afterUpdate, tick } from "svelte";
7
+
8
+ export let gradio: Gradio<{
9
+ change: never;
10
+ input: never;
11
+ submit: never;
12
+ blur: never;
13
+ focus: never;
14
+ clear_status: LoadingStatus;
15
+ }>;
16
+ export let label = gradio.i18n("number.number");
17
+ export let info: string | undefined = undefined;
18
+ export let elem_id = "";
19
+ export let elem_classes: string[] = [];
20
+ export let visible = true;
21
+ export let container = true;
22
+ export let scale: number | null = null;
23
+ export let min_width: number | undefined = undefined;
24
+ export let value = 0;
25
+ export let show_label: boolean;
26
+ export let minimum: number | undefined = undefined;
27
+ export let maximum: number | undefined = undefined;
28
+ export let loading_status: LoadingStatus;
29
+ export let value_is_output = false;
30
+ export let step: number | null = null;
31
+ export let interactive: boolean;
32
+ export let root: string;
33
+
34
+ function handle_change(): void {
35
+ if (!isNaN(value) && value !== null) {
36
+ gradio.dispatch("change");
37
+ if (!value_is_output) {
38
+ gradio.dispatch("input");
39
+ }
40
+ }
41
+ }
42
+ afterUpdate(() => {
43
+ value_is_output = false;
44
+ });
45
+
46
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
47
+ await tick();
48
+ if (e.key === "Enter") {
49
+ e.preventDefault();
50
+ gradio.dispatch("submit");
51
+ }
52
+ }
53
+
54
+ $: value, handle_change();
55
+ $: disabled = !interactive;
56
+ </script>
57
+
58
+ <Block
59
+ {visible}
60
+ {elem_id}
61
+ {elem_classes}
62
+ padding={container}
63
+ allow_overflow={false}
64
+ {scale}
65
+ {min_width}
66
+ >
67
+ <StatusTracker
68
+ autoscroll={gradio.autoscroll}
69
+ i18n={gradio.i18n}
70
+ {...loading_status}
71
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
72
+ />
73
+ <label class="block" class:container>
74
+ <BlockTitle {root} {show_label} {info}>{label}</BlockTitle>
75
+ <input
76
+ aria-label={label}
77
+ type="number"
78
+ bind:value
79
+ min={minimum}
80
+ max={maximum}
81
+ {step}
82
+ on:keypress={handle_keypress}
83
+ on:blur={() => gradio.dispatch("blur")}
84
+ on:focus={() => gradio.dispatch("focus")}
85
+ {disabled}
86
+ />
87
+ </label>
88
+ </Block>
89
+
90
+ <style>
91
+ label:not(.container),
92
+ label:not(.container) > input {
93
+ height: 100%;
94
+ border: none;
95
+ }
96
+ .container > input {
97
+ border: var(--input-border-width) solid var(--input-border-color);
98
+ border-radius: var(--input-radius);
99
+ }
100
+ input[type="number"] {
101
+ display: block;
102
+ position: relative;
103
+ outline: none !important;
104
+ box-shadow: var(--input-shadow);
105
+ background: var(--input-background-fill);
106
+ padding: var(--input-padding);
107
+ width: 100%;
108
+ color: var(--body-text-color);
109
+ font-size: var(--input-text-size);
110
+ line-height: var(--line-sm);
111
+ }
112
+ input:disabled {
113
+ -webkit-text-fill-color: var(--body-text-color);
114
+ -webkit-opacity: 1;
115
+ opacity: 1;
116
+ }
117
+
118
+ input:focus {
119
+ box-shadow: var(--input-shadow-focus);
120
+ border-color: var(--input-border-color-focus);
121
+ background: var(--input-background-fill-focus);
122
+ }
123
+
124
+ input::placeholder {
125
+ color: var(--input-placeholder-color);
126
+ }
127
+
128
+ input:out-of-range {
129
+ border: var(--input-border-width) solid var(--error-border-color);
130
+ }
131
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/simpledropdown/Example.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string | null;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ </script>
6
+
7
+ <div
8
+ class:table={type === "table"}
9
+ class:gallery={type === "gallery"}
10
+ class:selected
11
+ >
12
+ {value ? value : ""}
13
+ </div>
14
+
15
+ <style>
16
+ .gallery {
17
+ padding: var(--size-1) var(--size-2);
18
+ }
19
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/simpledropdown/Index.svelte ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Gradio } from "@gradio/utils";
3
+ import { Block, BlockTitle } from "@gradio/atoms";
4
+ import { StatusTracker } from "@gradio/statustracker";
5
+ import type { LoadingStatus } from "@gradio/statustracker";
6
+
7
+ export let label = "Dropdown";
8
+ export let elem_id = "";
9
+ export let elem_classes: string[] = [];
10
+ export let visible = true;
11
+ export let value: string | number;
12
+ export let value_is_output = false;
13
+ export let choices: [string, string | number][];
14
+ export let show_label: boolean;
15
+ export let scale: number | null = null;
16
+ export let min_width: number | undefined = undefined;
17
+ export let loading_status: LoadingStatus;
18
+ export let root: string;
19
+ export let gradio: Gradio<{
20
+ change: string;
21
+ input: never;
22
+ clear_status: LoadingStatus;
23
+ }>;
24
+ export let interactive: boolean;
25
+
26
+ const container = true;
27
+ let display_value: string;
28
+ let candidate: [string, string | number][];
29
+
30
+ function handle_change(): void {
31
+ gradio.dispatch("change");
32
+ if (!value_is_output) {
33
+ gradio.dispatch("input");
34
+ }
35
+ }
36
+
37
+ $: if (display_value) {
38
+ candidate = choices.filter((choice) => choice[0] === display_value);
39
+ value = candidate.length ? candidate[0][1] : "";
40
+ }
41
+
42
+ // When the value changes, dispatch the change event via handle_change()
43
+ // See the docs for an explanation: https://svelte.dev/docs/svelte-components#script-3-$-marks-a-statement-as-reactive
44
+ $: value, handle_change();
45
+ </script>
46
+
47
+ <Block
48
+ {visible}
49
+ {elem_id}
50
+ {elem_classes}
51
+ padding={container}
52
+ allow_overflow={false}
53
+ {scale}
54
+ {min_width}
55
+ >
56
+ {#if loading_status}
57
+ <StatusTracker
58
+ autoscroll={gradio.autoscroll}
59
+ i18n={gradio.i18n}
60
+ {...loading_status}
61
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
62
+ />
63
+ {/if}
64
+
65
+ <label class:container>
66
+ <BlockTitle {root} {show_label} info={undefined}>{label}</BlockTitle>
67
+ <select disabled={!interactive} bind:value={display_value}>
68
+ {#each choices as choice}
69
+ <option>{choice[0]}</option>
70
+ {/each}
71
+ </select>
72
+ </label>
73
+ </Block>
74
+
75
+ <style>
76
+ select {
77
+ --ring-color: transparent;
78
+ display: block;
79
+ position: relative;
80
+ outline: none !important;
81
+ box-shadow:
82
+ 0 0 0 var(--shadow-spread) var(--ring-color),
83
+ var(--shadow-inset);
84
+ border: var(--input-border-width) solid var(--border-color-primary);
85
+ border-radius: var(--radius-lg);
86
+ background-color: var(--input-background-base);
87
+ padding: var(--size-2-5);
88
+ width: 100%;
89
+ color: var(--color-text-body);
90
+ font-size: var(--scale-00);
91
+ line-height: var(--line-sm);
92
+ }
93
+
94
+ select:focus {
95
+ --ring-color: var(--color-focus-ring);
96
+ border-color: var(--input-border-color-focus);
97
+ }
98
+
99
+ select::placeholder {
100
+ color: var(--color-text-placeholder);
101
+ }
102
+
103
+ select[disabled] {
104
+ cursor: not-allowed;
105
+ box-shadow: none;
106
+ }
107
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/simpletextbox/Index.svelte ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script lang="ts">
4
+ import type { Gradio } from "@gradio/utils";
5
+ import { BlockTitle } from "@gradio/atoms";
6
+ import { Block } from "@gradio/atoms";
7
+ import { StatusTracker } from "@gradio/statustracker";
8
+ import type { LoadingStatus } from "@gradio/statustracker";
9
+ import { tick } from "svelte";
10
+
11
+ export let gradio: Gradio<{
12
+ change: never;
13
+ submit: never;
14
+ input: never;
15
+ clear_status: LoadingStatus;
16
+ }>;
17
+ export let label = "Textbox";
18
+ export let elem_id = "";
19
+ export let elem_classes: string[] = [];
20
+ export let visible = true;
21
+ export let value = "";
22
+ export let placeholder = "";
23
+ export let show_label: boolean;
24
+ export let scale: number | null = null;
25
+ export let min_width: number | undefined = undefined;
26
+ export let loading_status: LoadingStatus | undefined = undefined;
27
+ export let value_is_output = false;
28
+ export let interactive: boolean;
29
+ export let rtl = false;
30
+ export let root: string;
31
+
32
+ let el: HTMLTextAreaElement | HTMLInputElement;
33
+ const container = true;
34
+
35
+ function handle_change(): void {
36
+ gradio.dispatch("change");
37
+ if (!value_is_output) {
38
+ gradio.dispatch("input");
39
+ }
40
+ }
41
+
42
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
43
+ await tick();
44
+ if (e.key === "Enter") {
45
+ e.preventDefault();
46
+ gradio.dispatch("submit");
47
+ }
48
+ }
49
+
50
+ $: if (value === null) value = "";
51
+
52
+ // When the value changes, dispatch the change event via handle_change()
53
+ // See the docs for an explanation: https://svelte.dev/docs/svelte-components#script-3-$-marks-a-statement-as-reactive
54
+ $: value, handle_change();
55
+ </script>
56
+
57
+ <Block
58
+ {visible}
59
+ {elem_id}
60
+ {elem_classes}
61
+ {scale}
62
+ {min_width}
63
+ allow_overflow={false}
64
+ padding={true}
65
+ >
66
+ {#if loading_status}
67
+ <StatusTracker
68
+ autoscroll={gradio.autoscroll}
69
+ i18n={gradio.i18n}
70
+ {...loading_status}
71
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
72
+ />
73
+ {/if}
74
+
75
+ <label class:container>
76
+ <BlockTitle {root} {show_label} info={undefined}>{label}</BlockTitle>
77
+
78
+ <input
79
+ data-testid="textbox"
80
+ type="text"
81
+ class="scroll-hide"
82
+ bind:value
83
+ bind:this={el}
84
+ {placeholder}
85
+ disabled={!interactive}
86
+ dir={rtl ? "rtl" : "ltr"}
87
+ on:keypress={handle_keypress}
88
+ />
89
+ </label>
90
+ </Block>
91
+
92
+ <style>
93
+ label {
94
+ display: block;
95
+ width: 100%;
96
+ }
97
+
98
+ input {
99
+ display: block;
100
+ position: relative;
101
+ outline: none !important;
102
+ box-shadow: var(--input-shadow);
103
+ background: var(--input-background-fill);
104
+ padding: var(--input-padding);
105
+ width: 100%;
106
+ color: var(--body-text-color);
107
+ font-weight: var(--input-text-weight);
108
+ font-size: var(--input-text-size);
109
+ line-height: var(--line-sm);
110
+ border: none;
111
+ }
112
+ .container > input {
113
+ border: var(--input-border-width) solid var(--input-border-color);
114
+ border-radius: var(--input-radius);
115
+ }
116
+ input:disabled {
117
+ -webkit-text-fill-color: var(--body-text-color);
118
+ -webkit-opacity: 1;
119
+ opacity: 1;
120
+ }
121
+
122
+ input:focus {
123
+ box-shadow: var(--input-shadow-focus);
124
+ border-color: var(--input-border-color-focus);
125
+ }
126
+
127
+ input::placeholder {
128
+ color: var(--input-placeholder-color);
129
+ }
130
+ </style>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/uploadbutton/Index.svelte ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts" context="module">
2
+ export { default as BaseUploadButton } from "./shared/UploadButton.svelte";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import type { Gradio } from "@gradio/utils";
7
+ import type { FileData } from "@gradio/client";
8
+ import UploadButton from "./shared/UploadButton.svelte";
9
+
10
+ export let elem_id = "";
11
+ export let elem_classes: string[] = [];
12
+ export let visible = true;
13
+ export let label: string | null;
14
+ export let value: null | FileData | FileData[];
15
+ export let file_count: string;
16
+ export let file_types: string[] = [];
17
+ export let root: string;
18
+ export let size: "sm" | "lg" = "lg";
19
+ export let scale: number | null = null;
20
+ export let icon: FileData | null = null;
21
+ export let min_width: number | undefined = undefined;
22
+ export let variant: "primary" | "secondary" | "stop" = "secondary";
23
+ export let gradio: Gradio<{
24
+ change: never;
25
+ upload: never;
26
+ click: never;
27
+ error: string;
28
+ }>;
29
+ export let interactive: boolean;
30
+
31
+ $: disabled = !interactive;
32
+
33
+ async function handle_event(
34
+ detail: null | FileData | FileData[],
35
+ event: "change" | "upload" | "click"
36
+ ): Promise<void> {
37
+ value = detail;
38
+ gradio.dispatch(event);
39
+ }
40
+ </script>
41
+
42
+ <UploadButton
43
+ {elem_id}
44
+ {elem_classes}
45
+ {visible}
46
+ {file_count}
47
+ {file_types}
48
+ {size}
49
+ {scale}
50
+ {icon}
51
+ {min_width}
52
+ {root}
53
+ {value}
54
+ {disabled}
55
+ {variant}
56
+ {label}
57
+ max_file_size={gradio.max_file_size}
58
+ on:click={() => gradio.dispatch("click")}
59
+ on:change={({ detail }) => handle_event(detail, "change")}
60
+ on:upload={({ detail }) => handle_event(detail, "upload")}
61
+ on:error={({ detail }) => {
62
+ gradio.dispatch("error", detail);
63
+ }}
64
+ upload={(...args) => gradio.client.upload(...args)}
65
+ >
66
+ {label ? gradio.i18n(label) : ""}
67
+ </UploadButton>
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/uploadbutton/package.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/uploadbutton",
3
+ "version": "0.7.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": {
12
+ "gradio": "./Index.svelte",
13
+ "svelte": "./dist/Index.svelte",
14
+ "types": "./dist/Index.svelte.d.ts"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "main": "./Index.svelte",
19
+ "dependencies": {
20
+ "@gradio/button": "workspace:^",
21
+ "@gradio/client": "workspace:^",
22
+ "@gradio/upload": "workspace:^",
23
+ "@gradio/utils": "workspace:^"
24
+ },
25
+ "devDependencies": {
26
+ "@gradio/preview": "workspace:^"
27
+ },
28
+ "peerDependencies": {
29
+ "svelte": "^4.0.0"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/gradio-app/gradio.git",
34
+ "directory": "js/uploadbutton"
35
+ }
36
+ }
evalkit_tf437/lib/python3.10/site-packages/gradio/_frontend_code/utils/src/color.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import { colors, ordered_colors } from "@gradio/theme";
2
+
3
+ export const get_next_color = (index: number): keyof typeof colors => {
4
+ return ordered_colors[index % ordered_colors.length];
5
+ };