@gradio/core 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +201 -0
- package/blocks.ts +1 -0
- package/index.ts +4 -0
- package/login.ts +1 -0
- package/package.json +83 -0
- package/public/favicon.png +0 -0
- package/public/static/img/Bunny.obj +7474 -0
- package/public/static/img/Duck.glb +0 -0
- package/public/static/img/api-logo.svg +4 -0
- package/public/static/img/camera.svg +1 -0
- package/public/static/img/clear.svg +67 -0
- package/public/static/img/edit.svg +39 -0
- package/public/static/img/javascript.svg +16 -0
- package/public/static/img/logo.svg +19 -0
- package/public/static/img/logo_error.svg +134 -0
- package/public/static/img/python.svg +20 -0
- package/public/static/img/undo-solid.svg +1 -0
- package/src/Blocks.svelte +792 -0
- package/src/Embed.svelte +197 -0
- package/src/Login.stories.svelte +33 -0
- package/src/Login.svelte +111 -0
- package/src/MountComponents.svelte +30 -0
- package/src/Render.svelte +103 -0
- package/src/RenderComponent.svelte +67 -0
- package/src/api_docs/ApiBanner.svelte +118 -0
- package/src/api_docs/ApiDocs.svelte +418 -0
- package/src/api_docs/ApiRecorder.svelte +75 -0
- package/src/api_docs/CodeSnippet.svelte +198 -0
- package/src/api_docs/CopyButton.svelte +17 -0
- package/src/api_docs/EndpointDetail.svelte +37 -0
- package/src/api_docs/InputPayload.svelte +155 -0
- package/src/api_docs/InstallSnippet.svelte +59 -0
- package/src/api_docs/NoApi.svelte +74 -0
- package/src/api_docs/ParametersSnippet.svelte +106 -0
- package/src/api_docs/RecordingSnippet.svelte +224 -0
- package/src/api_docs/ResponseSnippet.svelte +97 -0
- package/src/api_docs/TryButton.svelte +19 -0
- package/src/api_docs/img/api-logo.svg +4 -0
- package/src/api_docs/img/bash.svg +8 -0
- package/src/api_docs/img/clear.svelte +19 -0
- package/src/api_docs/img/javascript.svg +16 -0
- package/src/api_docs/img/python.svg +20 -0
- package/src/api_docs/index.ts +2 -0
- package/src/api_docs/utils.ts +143 -0
- package/src/css.ts +116 -0
- package/src/gradio_helper.ts +7 -0
- package/src/i18n.test.ts +27 -0
- package/src/i18n.ts +36 -0
- package/src/images/lightning.svg +2 -0
- package/src/images/logo.svg +19 -0
- package/src/images/play.svg +2 -0
- package/src/images/spaces.svg +7 -0
- package/src/init.test.ts +521 -0
- package/src/init.ts +590 -0
- package/src/lang/BCP47_codes.js +58 -0
- package/src/lang/README.md +11 -0
- package/src/lang/ar.json +16 -0
- package/src/lang/ca.json +19 -0
- package/src/lang/ckb.json +108 -0
- package/src/lang/de.json +16 -0
- package/src/lang/en.json +118 -0
- package/src/lang/es.json +17 -0
- package/src/lang/eu.json +16 -0
- package/src/lang/fa.json +16 -0
- package/src/lang/fr.json +30 -0
- package/src/lang/he.json +16 -0
- package/src/lang/hi.json +16 -0
- package/src/lang/ja.json +16 -0
- package/src/lang/ko.json +16 -0
- package/src/lang/lt.json +16 -0
- package/src/lang/nl.json +16 -0
- package/src/lang/pl.json +16 -0
- package/src/lang/pt-BR.json +19 -0
- package/src/lang/ru.json +118 -0
- package/src/lang/ta.json +16 -0
- package/src/lang/tr.json +16 -0
- package/src/lang/uk.json +16 -0
- package/src/lang/ur.json +16 -0
- package/src/lang/uz.json +15 -0
- package/src/lang/zh-CN.json +115 -0
- package/src/lang/zh-TW.json +16 -0
- package/src/s-blocks.ts +1 -0
- package/src/s-login.ts +1 -0
- package/src/stores.ts +165 -0
- package/src/types.ts +106 -0
- package/src/vite-env-override.d.ts +20 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Loader } from "@gradio/statustracker";
|
|
3
|
+
|
|
4
|
+
export let is_running: boolean;
|
|
5
|
+
export let endpoint_returns: any;
|
|
6
|
+
export let js_returns: any;
|
|
7
|
+
export let current_language: "python" | "javascript" | "bash";
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<h4>
|
|
11
|
+
<div class="toggle-icon">
|
|
12
|
+
<div class="toggle-dot toggle-right" />
|
|
13
|
+
</div>
|
|
14
|
+
Returns {#if endpoint_returns.length > 1}
|
|
15
|
+
{current_language == "python" ? "tuple" : "list"} of {endpoint_returns.length}
|
|
16
|
+
elements{:else}
|
|
17
|
+
1 element{/if}
|
|
18
|
+
</h4>
|
|
19
|
+
|
|
20
|
+
<div class:hide={is_running}>
|
|
21
|
+
{#each endpoint_returns as { label, type, python_type, component, serializer }, i}
|
|
22
|
+
<hr class="hr" />
|
|
23
|
+
<div style="margin:10px;">
|
|
24
|
+
<p>
|
|
25
|
+
{#if endpoint_returns.length > 1}
|
|
26
|
+
<span class="code">[{i}]</span>
|
|
27
|
+
{/if}
|
|
28
|
+
<span class="code highlight"
|
|
29
|
+
>{#if current_language === "python"}{python_type.type}{:else}{js_returns[
|
|
30
|
+
i
|
|
31
|
+
].type}{/if}</span
|
|
32
|
+
>
|
|
33
|
+
</p>
|
|
34
|
+
<p class="desc">
|
|
35
|
+
The output value that appears in the "{label}" <!--
|
|
36
|
+
-->{component}
|
|
37
|
+
component<!--
|
|
38
|
+
-->.
|
|
39
|
+
</p>
|
|
40
|
+
</div>
|
|
41
|
+
{/each}
|
|
42
|
+
</div>
|
|
43
|
+
{#if is_running}
|
|
44
|
+
<div class="load-wrap">
|
|
45
|
+
<Loader margin={false} />
|
|
46
|
+
</div>
|
|
47
|
+
{/if}
|
|
48
|
+
|
|
49
|
+
<style>
|
|
50
|
+
.hr {
|
|
51
|
+
border: 0;
|
|
52
|
+
height: 1px;
|
|
53
|
+
background: var(--color-accent-soft);
|
|
54
|
+
}
|
|
55
|
+
.code {
|
|
56
|
+
font-family: var(--font-mono);
|
|
57
|
+
margin-right: 10px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.highlight {
|
|
61
|
+
background: var(--color-accent-soft);
|
|
62
|
+
color: var(--color-accent);
|
|
63
|
+
padding: var(--size-1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.desc {
|
|
67
|
+
color: var(--body-text-color-subdued);
|
|
68
|
+
font-size: var(--text-lg);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
h4 {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
margin-top: var(--size-6);
|
|
75
|
+
margin-bottom: var(--size-3);
|
|
76
|
+
color: var(--body-text-color);
|
|
77
|
+
font-weight: var(--weight-bold);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.toggle-icon {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
margin-right: var(--size-2);
|
|
84
|
+
border-radius: var(--radius-full);
|
|
85
|
+
background: var(--color-grey-300);
|
|
86
|
+
width: 12px;
|
|
87
|
+
height: 4px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.toggle-dot {
|
|
91
|
+
border-radius: var(--radius-full);
|
|
92
|
+
background: var(--color-grey-700);
|
|
93
|
+
width: 6px;
|
|
94
|
+
height: 6px;
|
|
95
|
+
margin-left: auto;
|
|
96
|
+
}
|
|
97
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { BaseButton } from "@gradio/button";
|
|
3
|
+
|
|
4
|
+
export let dependency_index: number;
|
|
5
|
+
export let run: (id: number) => Promise<void>;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<span class="space" />
|
|
9
|
+
<BaseButton variant="primary" on:click={run.bind(null, dependency_index)}>
|
|
10
|
+
Try It Out
|
|
11
|
+
</BaseButton>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
.space {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-basis: 1;
|
|
17
|
+
margin-top: var(--size-4);
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M26.9425 2.94265C27.4632 2.42195 27.4632 1.57773 26.9425 1.05703C26.4218 0.536329 25.5776 0.536329 25.0569 1.05703L22.5713 3.54256C21.1213 2.59333 19.5367 2.43378 18.1753 2.64006C16.5495 2.88638 15.1127 3.66838 14.3905 4.39053L12.3905 6.39053C12.1405 6.64058 12 6.97972 12 7.33334C12 7.68697 12.1405 8.0261 12.3905 8.27615L19.7239 15.6095C20.2446 16.1302 21.0888 16.1302 21.6095 15.6095L23.6095 13.6095C24.3316 12.8873 25.1136 11.4505 25.36 9.82475C25.5663 8.46312 25.4066 6.87827 24.4571 5.42807L26.9425 2.94265Z" fill="#3c4555"/>
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.276 12.9426C12.7967 12.4219 12.7967 11.5777 12.276 11.057C11.7553 10.5363 10.9111 10.5363 10.3904 11.057L8.66651 12.7809L8.27615 12.3905C8.0261 12.1405 7.68697 12 7.33334 12C6.97972 12 6.64058 12.1405 6.39053 12.3905L4.39053 14.3905C3.66838 15.1127 2.88638 16.5495 2.64006 18.1753C2.43377 19.5367 2.59333 21.1214 3.54262 22.5714L1.05703 25.057C0.536329 25.5777 0.536329 26.4219 1.05703 26.9426C1.57773 27.4633 2.42195 27.4633 2.94265 26.9426L5.42817 24.4571C6.87835 25.4066 8.46315 25.5663 9.82475 25.36C11.4505 25.1136 12.8873 24.3316 13.6095 23.6095L15.6095 21.6095C16.1302 21.0888 16.1302 20.2446 15.6095 19.7239L15.2188 19.3332L16.9426 17.6093C17.4633 17.0886 17.4633 16.2444 16.9426 15.7237C16.4219 15.203 15.5777 15.203 15.057 15.7237L13.3332 17.4475L10.5521 14.6665L12.276 12.9426Z" fill="#FF7C00"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 150 150" style="enable-background:new 0 0 150 150; background-color: #72a824;" xml:space="preserve"><script xmlns=""/>
|
|
2
|
+
<style type="text/css">
|
|
3
|
+
.st0{fill:#FFFFFF;}
|
|
4
|
+
</style>
|
|
5
|
+
<g>
|
|
6
|
+
<path class="st0" d="M118.9,40.3L81.7,18.2c-2.2-1.3-4.7-2-7.2-2s-5,0.7-7.2,2L30.1,40.3c-4.4,2.6-7.2,7.5-7.2,12.8v44.2 c0,5.3,2.7,10.1,7.2,12.8l37.2,22.1c2.2,1.3,4.7,2,7.2,2c2.5,0,5-0.7,7.2-2l37.2-22.1c4.4-2.6,7.2-7.5,7.2-12.8V53 C126.1,47.8,123.4,42.9,118.9,40.3z M90.1,109.3l0.1,3.2c0,0.4-0.2,0.8-0.5,1l-1.9,1.1c-0.3,0.2-0.5,0-0.6-0.4l0-3.1 c-1.6,0.7-3.2,0.8-4.3,0.4c-0.2-0.1-0.3-0.4-0.2-0.7l0.7-2.9c0.1-0.2,0.2-0.5,0.3-0.6c0.1-0.1,0.1-0.1,0.2-0.1 c0.1-0.1,0.2-0.1,0.3,0c1.1,0.4,2.6,0.2,3.9-0.5c1.8-0.9,2.9-2.7,2.9-4.5c0-1.6-0.9-2.3-3-2.3c-2.7,0-5.2-0.5-5.3-4.5 c0-3.3,1.7-6.7,4.4-8.8l0-3.2c0-0.4,0.2-0.8,0.5-1l1.8-1.2c0.3-0.2,0.5,0,0.6,0.4l0,3.2c1.3-0.5,2.5-0.7,3.6-0.4 c0.2,0.1,0.3,0.4,0.2,0.7l-0.7,2.8c-0.1,0.2-0.2,0.4-0.3,0.6c-0.1,0.1-0.1,0.1-0.2,0.1c-0.1,0-0.2,0.1-0.3,0 c-0.5-0.1-1.6-0.4-3.4,0.6c-1.9,1-2.6,2.6-2.5,3.8c0,1.5,0.8,1.9,3.3,1.9c3.4,0.1,4.9,1.6,5,5C94.7,103.4,92.9,107,90.1,109.3z M109.6,103.9c0,0.3,0,0.6-0.3,0.7l-9.4,5.7c-0.2,0.1-0.4,0-0.4-0.3v-2.4c0-0.3,0.2-0.5,0.4-0.6l9.3-5.5c0.2-0.1,0.4,0,0.4,0.3 V103.9z M116.1,49.6L80.9,71.3c-4.4,2.6-7.6,5.4-7.6,10.7v43.4c0,3.2,1.3,5.2,3.2,5.8c-0.6,0.1-1.3,0.2-2,0.2 c-2.1,0-4.1-0.6-5.9-1.6l-37.2-22.1c-3.6-2.2-5.9-6.2-5.9-10.5V53c0-4.3,2.3-8.4,5.9-10.5l37.2-22.1c1.8-1.1,3.8-1.6,5.9-1.6 s4.1,0.6,5.9,1.6l37.2,22.1c3.1,1.8,5.1,5,5.7,8.5C122.1,48.4,119.3,47.7,116.1,49.6z"/>
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<svg
|
|
2
|
+
width="100%"
|
|
3
|
+
height="100%"
|
|
4
|
+
viewBox="0 0 5 5"
|
|
5
|
+
version="1.1"
|
|
6
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
7
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
8
|
+
xml:space="preserve"
|
|
9
|
+
style="fill:currentColor;fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"
|
|
10
|
+
>
|
|
11
|
+
<g>
|
|
12
|
+
<path
|
|
13
|
+
d="M3.789,0.09C3.903,-0.024 4.088,-0.024 4.202,0.09L4.817,0.705C4.931,0.819 4.931,1.004 4.817,1.118L1.118,4.817C1.004,4.931 0.819,4.931 0.705,4.817L0.09,4.202C-0.024,4.088 -0.024,3.903 0.09,3.789L3.789,0.09Z"
|
|
14
|
+
/>
|
|
15
|
+
<path
|
|
16
|
+
d="M4.825,3.797C4.934,3.907 4.934,4.084 4.825,4.193L4.193,4.825C4.084,4.934 3.907,4.934 3.797,4.825L0.082,1.11C-0.027,1.001 -0.027,0.823 0.082,0.714L0.714,0.082C0.823,-0.027 1.001,-0.027 1.11,0.082L4.825,3.797Z"
|
|
17
|
+
/>
|
|
18
|
+
</g>
|
|
19
|
+
</svg>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<svg
|
|
2
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
3
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
4
|
+
aria-hidden="true"
|
|
5
|
+
focusable="false"
|
|
6
|
+
role="img"
|
|
7
|
+
width="1em"
|
|
8
|
+
height="1em"
|
|
9
|
+
preserveAspectRatio="xMidYMid meet"
|
|
10
|
+
viewBox="0 0 32 32"
|
|
11
|
+
>
|
|
12
|
+
<rect width="32" height="32" fill="#f7df1e"></rect>
|
|
13
|
+
<path
|
|
14
|
+
d="M21.5,25a3.27,3.27,0,0,0,3,1.83c1.25,0,2-.63,2-1.49,0-1-.81-1.39-2.19-2L23.56,23C21.39,22.1,20,20.94,20,18.49c0-2.25,1.72-4,4.41-4a4.44,4.44,0,0,1,4.27,2.41l-2.34,1.5a2,2,0,0,0-1.93-1.29,1.31,1.31,0,0,0-1.44,1.29c0,.9.56,1.27,1.85,1.83l.75.32c2.55,1.1,4,2.21,4,4.72,0,2.71-2.12,4.19-5,4.19a5.78,5.78,0,0,1-5.48-3.07Zm-10.63.26c.48.84.91,1.55,1.94,1.55s1.61-.39,1.61-1.89V14.69h3V25c0,3.11-1.83,4.53-4.49,4.53a4.66,4.66,0,0,1-4.51-2.75Z"
|
|
15
|
+
></path>
|
|
16
|
+
</svg>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<svg
|
|
2
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
3
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
4
|
+
aria-hidden="true"
|
|
5
|
+
focusable="false"
|
|
6
|
+
role="img"
|
|
7
|
+
width="1em"
|
|
8
|
+
height="1em"
|
|
9
|
+
preserveAspectRatio="xMidYMid meet"
|
|
10
|
+
viewBox="0 0 32 32"
|
|
11
|
+
>
|
|
12
|
+
<path
|
|
13
|
+
d="M15.84.5a16.4,16.4,0,0,0-3.57.32C9.1,1.39,8.53,2.53,8.53,4.64V7.48H16v1H5.77a4.73,4.73,0,0,0-4.7,3.74,14.82,14.82,0,0,0,0,7.54c.57,2.28,1.86,3.82,4,3.82h2.6V20.14a4.73,4.73,0,0,1,4.63-4.63h7.38a3.72,3.72,0,0,0,3.73-3.73V4.64A4.16,4.16,0,0,0,19.65.82,20.49,20.49,0,0,0,15.84.5ZM11.78,2.77a1.39,1.39,0,0,1,1.38,1.46,1.37,1.37,0,0,1-1.38,1.38A1.42,1.42,0,0,1,10.4,4.23,1.44,1.44,0,0,1,11.78,2.77Z"
|
|
14
|
+
fill="#5a9fd4"
|
|
15
|
+
></path>
|
|
16
|
+
<path
|
|
17
|
+
d="M16.16,31.5a16.4,16.4,0,0,0,3.57-.32c3.17-.57,3.74-1.71,3.74-3.82V24.52H16v-1H26.23a4.73,4.73,0,0,0,4.7-3.74,14.82,14.82,0,0,0,0-7.54c-.57-2.28-1.86-3.82-4-3.82h-2.6v3.41a4.73,4.73,0,0,1-4.63,4.63H12.35a3.72,3.72,0,0,0-3.73,3.73v7.14a4.16,4.16,0,0,0,3.73,3.82A20.49,20.49,0,0,0,16.16,31.5Zm4.06-2.27a1.39,1.39,0,0,1-1.38-1.46,1.37,1.37,0,0,1,1.38-1.38,1.42,1.42,0,0,1,1.38,1.38A1.44,1.44,0,0,1,20.22,29.23Z"
|
|
18
|
+
fill="#ffd43b"
|
|
19
|
+
></path>
|
|
20
|
+
</svg>
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// eslint-disable-next-line complexity
|
|
2
|
+
export function represent_value(
|
|
3
|
+
value: string,
|
|
4
|
+
type: string | undefined,
|
|
5
|
+
lang: "js" | "py" | "bash" | null = null
|
|
6
|
+
): string | null | number | boolean | Record<string, unknown> {
|
|
7
|
+
if (type === undefined) {
|
|
8
|
+
return lang === "py" ? "None" : null;
|
|
9
|
+
}
|
|
10
|
+
if (value === null && lang === "py") {
|
|
11
|
+
return "None";
|
|
12
|
+
}
|
|
13
|
+
if (type === "string" || type === "str") {
|
|
14
|
+
return lang === null ? value : '"' + value + '"';
|
|
15
|
+
} else if (type === "number") {
|
|
16
|
+
return lang === null ? parseFloat(value) : value;
|
|
17
|
+
} else if (type === "boolean" || type == "bool") {
|
|
18
|
+
if (lang === "py") {
|
|
19
|
+
value = String(value);
|
|
20
|
+
return value === "true" ? "True" : "False";
|
|
21
|
+
} else if (lang === "js" || lang === "bash") {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return value === "true";
|
|
25
|
+
} else if (type === "List[str]") {
|
|
26
|
+
value = JSON.stringify(value);
|
|
27
|
+
return value;
|
|
28
|
+
} else if (type.startsWith("Literal['")) {
|
|
29
|
+
// a literal of strings
|
|
30
|
+
return '"' + value + '"';
|
|
31
|
+
}
|
|
32
|
+
// assume object type
|
|
33
|
+
if (lang === null) {
|
|
34
|
+
return value === "" ? null : JSON.parse(value);
|
|
35
|
+
} else if (typeof value === "string") {
|
|
36
|
+
if (value === "") {
|
|
37
|
+
return lang === "py" ? "None" : "null";
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
if (lang === "bash") {
|
|
42
|
+
value = simplify_file_data(value);
|
|
43
|
+
}
|
|
44
|
+
if (lang === "py") {
|
|
45
|
+
value = replace_file_data_with_file_function(value);
|
|
46
|
+
}
|
|
47
|
+
return stringify_except_file_function(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function is_potentially_nested_file_data(obj: any): boolean {
|
|
51
|
+
if (typeof obj === "object" && obj !== null) {
|
|
52
|
+
if (obj.hasOwnProperty("url") && obj.hasOwnProperty("meta")) {
|
|
53
|
+
if (
|
|
54
|
+
typeof obj.meta === "object" &&
|
|
55
|
+
obj.meta !== null &&
|
|
56
|
+
obj.meta._type === "gradio.FileData"
|
|
57
|
+
) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (typeof obj === "object" && obj !== null) {
|
|
63
|
+
for (let key in obj) {
|
|
64
|
+
if (typeof obj[key] === "object") {
|
|
65
|
+
let result = is_potentially_nested_file_data(obj[key]);
|
|
66
|
+
if (result) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function simplify_file_data(obj: any): any {
|
|
76
|
+
if (typeof obj === "object" && obj !== null && !Array.isArray(obj)) {
|
|
77
|
+
if (
|
|
78
|
+
"url" in obj &&
|
|
79
|
+
obj.url &&
|
|
80
|
+
"meta" in obj &&
|
|
81
|
+
obj.meta?._type === "gradio.FileData"
|
|
82
|
+
) {
|
|
83
|
+
return { path: obj.url };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(obj)) {
|
|
87
|
+
obj.forEach((item, index) => {
|
|
88
|
+
if (typeof item === "object" && item !== null) {
|
|
89
|
+
obj[index] = simplify_file_data(item); // Recurse and update array elements
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
93
|
+
Object.keys(obj).forEach((key) => {
|
|
94
|
+
obj[key] = simplify_file_data(obj[key]); // Recurse and update object properties
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function replace_file_data_with_file_function(obj: any): any {
|
|
101
|
+
if (typeof obj === "object" && obj !== null && !Array.isArray(obj)) {
|
|
102
|
+
if (
|
|
103
|
+
"url" in obj &&
|
|
104
|
+
obj.url &&
|
|
105
|
+
"meta" in obj &&
|
|
106
|
+
obj.meta?._type === "gradio.FileData"
|
|
107
|
+
) {
|
|
108
|
+
return `handle_file('${obj.url}')`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(obj)) {
|
|
112
|
+
obj.forEach((item, index) => {
|
|
113
|
+
if (typeof item === "object" && item !== null) {
|
|
114
|
+
obj[index] = replace_file_data_with_file_function(item); // Recurse and update array elements
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
118
|
+
Object.keys(obj).forEach((key) => {
|
|
119
|
+
obj[key] = replace_file_data_with_file_function(obj[key]); // Recurse and update object properties
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return obj;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function stringify_except_file_function(obj: any): string {
|
|
126
|
+
let jsonString = JSON.stringify(obj, (key, value) => {
|
|
127
|
+
if (value === null) {
|
|
128
|
+
return "UNQUOTEDNone";
|
|
129
|
+
}
|
|
130
|
+
if (
|
|
131
|
+
typeof value === "string" &&
|
|
132
|
+
value.startsWith("handle_file(") &&
|
|
133
|
+
value.endsWith(")")
|
|
134
|
+
) {
|
|
135
|
+
return `UNQUOTED${value}`; // Flag the special strings
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
});
|
|
139
|
+
const regex = /"UNQUOTEDhandle_file\(([^)]*)\)"/g;
|
|
140
|
+
jsonString = jsonString.replace(regex, (match, p1) => `handle_file(${p1})`);
|
|
141
|
+
const regexNone = /"UNQUOTEDNone"/g;
|
|
142
|
+
return jsonString.replace(regexNone, "None");
|
|
143
|
+
}
|
package/src/css.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
let supports_adopted_stylesheets = false;
|
|
2
|
+
|
|
3
|
+
if (
|
|
4
|
+
"attachShadow" in Element.prototype &&
|
|
5
|
+
"adoptedStyleSheets" in Document.prototype
|
|
6
|
+
) {
|
|
7
|
+
// Both Shadow DOM and adoptedStyleSheets are supported
|
|
8
|
+
const shadow_root_test = document
|
|
9
|
+
.createElement("div")
|
|
10
|
+
.attachShadow({ mode: "open" });
|
|
11
|
+
supports_adopted_stylesheets = "adoptedStyleSheets" in shadow_root_test;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function mount_css(url: string, target: HTMLElement): Promise<void> {
|
|
15
|
+
const base = new URL(import.meta.url).origin;
|
|
16
|
+
const _url = new URL(url, base).href;
|
|
17
|
+
const existing_link = document.querySelector(`link[href='${_url}']`);
|
|
18
|
+
|
|
19
|
+
if (existing_link) return Promise.resolve();
|
|
20
|
+
|
|
21
|
+
const link = document.createElement("link");
|
|
22
|
+
link.rel = "stylesheet";
|
|
23
|
+
link.href = _url;
|
|
24
|
+
|
|
25
|
+
return new Promise((res, rej) => {
|
|
26
|
+
link.addEventListener("load", () => res());
|
|
27
|
+
link.addEventListener("error", () => {
|
|
28
|
+
console.error(`Unable to preload CSS for ${_url}`);
|
|
29
|
+
res();
|
|
30
|
+
});
|
|
31
|
+
target.appendChild(link);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function prefix_css(
|
|
36
|
+
string: string,
|
|
37
|
+
version: string,
|
|
38
|
+
style_element = document.createElement("style")
|
|
39
|
+
): HTMLStyleElement | null {
|
|
40
|
+
if (!supports_adopted_stylesheets) return null;
|
|
41
|
+
style_element.remove();
|
|
42
|
+
|
|
43
|
+
const stylesheet = new CSSStyleSheet();
|
|
44
|
+
stylesheet.replaceSync(string);
|
|
45
|
+
|
|
46
|
+
let importString = "";
|
|
47
|
+
string = string.replace(/@import\s+url\((.*?)\);\s*/g, (match, url) => {
|
|
48
|
+
importString += `@import url(${url});\n`;
|
|
49
|
+
return ""; // remove and store any @import statements from the CSS
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const rules = stylesheet.cssRules;
|
|
53
|
+
|
|
54
|
+
let css_string = "";
|
|
55
|
+
let gradio_css_infix = `gradio-app .gradio-container.gradio-container-${version} .contain `;
|
|
56
|
+
|
|
57
|
+
for (let i = 0; i < rules.length; i++) {
|
|
58
|
+
const rule = rules[i];
|
|
59
|
+
|
|
60
|
+
let is_dark_rule = rule.cssText.includes(".dark");
|
|
61
|
+
if (rule instanceof CSSStyleRule) {
|
|
62
|
+
const selector = rule.selectorText;
|
|
63
|
+
if (selector) {
|
|
64
|
+
const new_selector = selector
|
|
65
|
+
.replace(".dark", "")
|
|
66
|
+
.split(",")
|
|
67
|
+
.map(
|
|
68
|
+
(s) =>
|
|
69
|
+
`${is_dark_rule ? ".dark" : ""} ${gradio_css_infix} ${s.trim()} `
|
|
70
|
+
)
|
|
71
|
+
.join(",");
|
|
72
|
+
|
|
73
|
+
css_string += rule.cssText;
|
|
74
|
+
css_string += rule.cssText.replace(selector, new_selector);
|
|
75
|
+
}
|
|
76
|
+
} else if (rule instanceof CSSMediaRule) {
|
|
77
|
+
let mediaCssString = `@media ${rule.media.mediaText} {`;
|
|
78
|
+
for (let j = 0; j < rule.cssRules.length; j++) {
|
|
79
|
+
const innerRule = rule.cssRules[j];
|
|
80
|
+
if (innerRule instanceof CSSStyleRule) {
|
|
81
|
+
let is_dark_rule = innerRule.cssText.includes(".dark ");
|
|
82
|
+
const selector = innerRule.selectorText;
|
|
83
|
+
const new_selector = selector
|
|
84
|
+
.replace(".dark", "")
|
|
85
|
+
.split(",")
|
|
86
|
+
.map(
|
|
87
|
+
(s) =>
|
|
88
|
+
`${
|
|
89
|
+
is_dark_rule ? ".dark" : ""
|
|
90
|
+
} ${gradio_css_infix} ${s.trim()} `
|
|
91
|
+
)
|
|
92
|
+
.join(",");
|
|
93
|
+
mediaCssString += innerRule.cssText.replace(selector, new_selector);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
mediaCssString += "}";
|
|
97
|
+
css_string += mediaCssString;
|
|
98
|
+
} else if (rule instanceof CSSKeyframesRule) {
|
|
99
|
+
css_string += `@keyframes ${rule.name} {`;
|
|
100
|
+
for (let j = 0; j < rule.cssRules.length; j++) {
|
|
101
|
+
const innerRule = rule.cssRules[j];
|
|
102
|
+
if (innerRule instanceof CSSKeyframeRule) {
|
|
103
|
+
css_string += `${innerRule.keyText} { ${innerRule.style.cssText} }`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
css_string += "}";
|
|
107
|
+
} else if (rule instanceof CSSFontFaceRule) {
|
|
108
|
+
css_string += `@font-face { ${rule.style.cssText} }`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
css_string = importString + css_string;
|
|
112
|
+
style_element.textContent = css_string;
|
|
113
|
+
|
|
114
|
+
document.head.appendChild(style_element);
|
|
115
|
+
return style_element;
|
|
116
|
+
}
|
package/src/i18n.test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, test, assert } from "vitest";
|
|
2
|
+
import { process_langs } from "./i18n";
|
|
3
|
+
import languagesByAnyCode from "wikidata-lang/indexes/by_any_code";
|
|
4
|
+
import BCP47 from "./lang/BCP47_codes";
|
|
5
|
+
|
|
6
|
+
describe("i18n", () => {
|
|
7
|
+
test("languages are loaded correctly", () => {
|
|
8
|
+
const langs = process_langs();
|
|
9
|
+
assert.ok(langs.en);
|
|
10
|
+
assert.ok(langs.en.common);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("language codes follow the correct format", () => {
|
|
14
|
+
const langs = Object.entries(process_langs());
|
|
15
|
+
|
|
16
|
+
langs.forEach(([code, translation]) => {
|
|
17
|
+
const BCP47_REGEX = /^.{2}-.{2}$/;
|
|
18
|
+
|
|
19
|
+
if (BCP47_REGEX.test(code)) {
|
|
20
|
+
assert.ok(BCP47.includes(code));
|
|
21
|
+
} else {
|
|
22
|
+
assert.exists(languagesByAnyCode[code]);
|
|
23
|
+
}
|
|
24
|
+
assert.ok(translation.common);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
package/src/i18n.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { addMessages, init, getLocaleFromNavigator } from "svelte-i18n";
|
|
2
|
+
|
|
3
|
+
const langs = import.meta.glob("./lang/*.json", {
|
|
4
|
+
eager: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
type LangsRecord = Record<
|
|
8
|
+
string,
|
|
9
|
+
{
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export function process_langs(): LangsRecord {
|
|
15
|
+
let _langs: LangsRecord = {};
|
|
16
|
+
|
|
17
|
+
for (const lang in langs) {
|
|
18
|
+
const code = (lang.split("/").pop() as string).split(".").shift() as string;
|
|
19
|
+
_langs[code] = (langs[lang] as Record<string, any>).default;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return _langs;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const processed_langs = process_langs();
|
|
26
|
+
|
|
27
|
+
for (const lang in processed_langs) {
|
|
28
|
+
addMessages(lang, processed_langs[lang]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function setupi18n(): Promise<void> {
|
|
32
|
+
await init({
|
|
33
|
+
fallbackLocale: "en",
|
|
34
|
+
initialLocale: getLocaleFromNavigator()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<!-- Lightning https://iconscout.com/icons/lightning by IconLauk https://iconscout.com/contributors/icon-lauk on IconScout https://iconscout.com" -->
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 32 32" viewBox="0 0 32 32" id="lightning"><path fill="#ff7c00" d="M26.9,10.5C26.7,10.2,26.4,10,26,10h-9V2c0-0.4-0.3-0.8-0.7-1c-0.4-0.1-0.9,0-1.1,0.4l-10,14c-0.2,0.3-0.3,0.7-0.1,1 C5.3,16.8,5.6,17,6,17h8.8L13,29.9c-0.1,0.5,0.2,0.9,0.6,1.1c0.1,0,0.2,0.1,0.3,0.1c0.3,0,0.7-0.2,0.8-0.5l12-19 C27,11.2,27,10.8,26.9,10.5z"/></svg>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="576" height="576" viewBox="0 0 576 576" fill="none">
|
|
2
|
+
<path d="M287.5 229L86 344.5L287.5 460L489 344.5L287.5 229Z" stroke="url(#paint0_linear_102_7)" stroke-width="59" stroke-linejoin="round"/>
|
|
3
|
+
<path d="M287.5 116L86 231.5L287.5 347L489 231.5L287.5 116Z" stroke="url(#paint1_linear_102_7)" stroke-width="59" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M86 344L288 229" stroke="url(#paint2_linear_102_7)" stroke-width="59" stroke-linejoin="bevel"/>
|
|
5
|
+
<defs>
|
|
6
|
+
<linearGradient id="paint0_linear_102_7" x1="60" y1="341" x2="429.5" y2="344" gradientUnits="userSpaceOnUse">
|
|
7
|
+
<stop stop-color="#F9D100"/>
|
|
8
|
+
<stop offset="1" stop-color="#F97700"/>
|
|
9
|
+
</linearGradient>
|
|
10
|
+
<linearGradient id="paint1_linear_102_7" x1="513.5" y1="231" x2="143.5" y2="231" gradientUnits="userSpaceOnUse">
|
|
11
|
+
<stop stop-color="#F9D100"/>
|
|
12
|
+
<stop offset="1" stop-color="#F97700"/>
|
|
13
|
+
</linearGradient>
|
|
14
|
+
<linearGradient id="paint2_linear_102_7" x1="60" y1="344" x2="428.987" y2="341.811" gradientUnits="userSpaceOnUse">
|
|
15
|
+
<stop stop-color="#F9D100"/>
|
|
16
|
+
<stop offset="1" stop-color="#F97700"/>
|
|
17
|
+
</linearGradient>
|
|
18
|
+
</defs>
|
|
19
|
+
</svg>
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<!-- Play https://iconscout.com/icons/play by Alexandru Stoica https://iconscout.com/contributors/alexandru-stoica on IconScout https://iconscout.com" -->
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="6" height="7" viewBox="0 0 6 7" id="play"><g fill="#999b9e" transform="translate(-347 -3766)"><g transform="translate(56 160)"><path d="M296.495 3608.573l-3.994-2.43c-.669-.408-1.501.107-1.501.926v4.862c0 .82.832 1.333 1.5.927l3.995-2.43c.673-.41.673-1.445 0-1.855"/></g></g></svg>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" fill="none">
|
|
2
|
+
<path fill="#FF3270" d="M1.93 6.03v2.04h2.04V6.03H1.93Z"/>
|
|
3
|
+
<path fill="#861FFF" d="M6.03 6.03v2.04h2.04V6.03H6.03Z"/>
|
|
4
|
+
<path fill="#097EFF" d="M1.93 1.93v2.04h2.04V1.93H1.93Z"/>
|
|
5
|
+
<path fill="#000" fill-rule="evenodd" d="M.5 1.4c0-.5.4-.9.9-.9h3.1a.9.9 0 0 1 .87.67A2.44 2.44 0 0 1 9.5 2.95c0 .65-.25 1.24-.67 1.68.39.1.67.46.67.88v3.08c0 .5-.4.91-.9.91H1.4a.9.9 0 0 1-.9-.9V1.4Zm1.43.53v2.04h2.04V1.93H1.93Zm0 6.14V6.03h2.04v2.04H1.93Zm4.1 0V6.03h2.04v2.04H6.03Zm0-5.12a1.02 1.02 0 1 1 2.04 0 1.02 1.02 0 0 1-2.04 0Z" clip-rule="evenodd"/>
|
|
6
|
+
<path fill="#FFD702" d="M7.05 1.93a1.02 1.02 0 1 0 0 2.04 1.02 1.02 0 0 0 0-2.04Z"/>
|
|
7
|
+
</svg>
|