@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,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export let api_name: string | null = null;
|
|
3
|
+
export let fn_index: number | null = null;
|
|
4
|
+
export let named: boolean;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#if named}
|
|
8
|
+
<h3>
|
|
9
|
+
api_name:
|
|
10
|
+
<span class="post">{"/" + api_name}</span>
|
|
11
|
+
</h3>
|
|
12
|
+
{:else}
|
|
13
|
+
<h3>
|
|
14
|
+
fn_index:
|
|
15
|
+
<span class="post">{fn_index}</span>
|
|
16
|
+
</h3>
|
|
17
|
+
{/if}
|
|
18
|
+
|
|
19
|
+
<style>
|
|
20
|
+
h3 {
|
|
21
|
+
color: var(--body-text-color);
|
|
22
|
+
font-weight: var(--section-header-text-weight);
|
|
23
|
+
font-size: var(--text-lg);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.post {
|
|
27
|
+
margin-right: var(--size-2);
|
|
28
|
+
border: 1px solid var(--border-color-accent);
|
|
29
|
+
border-radius: var(--radius-sm);
|
|
30
|
+
background: var(--color-accent-soft);
|
|
31
|
+
padding-right: var(--size-1);
|
|
32
|
+
padding-bottom: var(--size-1);
|
|
33
|
+
padding-left: var(--size-1);
|
|
34
|
+
color: var(--color-accent);
|
|
35
|
+
font-weight: var(--weight-semibold);
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentMeta, Dependency } from "../types";
|
|
3
|
+
import { BaseButton } from "@gradio/button";
|
|
4
|
+
import { Block } from "@gradio/atoms";
|
|
5
|
+
|
|
6
|
+
export let dependency: Dependency;
|
|
7
|
+
export let dependency_failures: boolean[][];
|
|
8
|
+
export let dependency_index: number;
|
|
9
|
+
export let instance_map: {
|
|
10
|
+
[id: number]: ComponentMeta;
|
|
11
|
+
};
|
|
12
|
+
export let run: (id: number) => Promise<void>;
|
|
13
|
+
export let dependency_inputs: string[][];
|
|
14
|
+
|
|
15
|
+
function format_label(label: unknown): string {
|
|
16
|
+
return label ? "'" + label + "'" : "the";
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<h4>
|
|
21
|
+
<div class="toggle-icon">
|
|
22
|
+
<div class="toggle-dot" />
|
|
23
|
+
</div>
|
|
24
|
+
Input Payload
|
|
25
|
+
</h4>
|
|
26
|
+
<Block>
|
|
27
|
+
<div class="payload-details">
|
|
28
|
+
{
|
|
29
|
+
<div class="first-level">"data": [</div>
|
|
30
|
+
{#each dependency.inputs as component_id, component_index}
|
|
31
|
+
<div class="second-level">
|
|
32
|
+
<input
|
|
33
|
+
class=""
|
|
34
|
+
type="text"
|
|
35
|
+
bind:value={dependency_inputs[dependency_index][component_index]}
|
|
36
|
+
/>
|
|
37
|
+
{#if dependency_failures[dependency_index][component_index]}
|
|
38
|
+
<span class="error">ERROR</span>
|
|
39
|
+
{/if}
|
|
40
|
+
|
|
41
|
+
<span class="type">
|
|
42
|
+
: {instance_map[component_id].documentation?.type?.input_payload ||
|
|
43
|
+
instance_map[component_id].documentation?.type?.payload},
|
|
44
|
+
</span>
|
|
45
|
+
<span class="desc">
|
|
46
|
+
// represents {instance_map[component_id].documentation?.description
|
|
47
|
+
?.input_payload ||
|
|
48
|
+
instance_map[component_id].documentation?.description?.payload} of
|
|
49
|
+
{format_label(instance_map[component_id].props.label)}
|
|
50
|
+
<span class="name">
|
|
51
|
+
{instance_map[component_id].props.name}
|
|
52
|
+
</span>
|
|
53
|
+
component
|
|
54
|
+
</span>
|
|
55
|
+
</div>
|
|
56
|
+
{/each}
|
|
57
|
+
<div class="first-level">]</div>
|
|
58
|
+
}
|
|
59
|
+
</div>
|
|
60
|
+
</Block>
|
|
61
|
+
|
|
62
|
+
<span class="space" />
|
|
63
|
+
<BaseButton variant="primary" on:click={run.bind(null, dependency_index)}>
|
|
64
|
+
Try It Out
|
|
65
|
+
</BaseButton>
|
|
66
|
+
|
|
67
|
+
<style>
|
|
68
|
+
.payload-details {
|
|
69
|
+
font-family: var(--font-mono);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.space {
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-basis: 1;
|
|
75
|
+
margin-top: var(--size-4);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
h4 {
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
margin-top: var(--size-6);
|
|
82
|
+
margin-bottom: var(--size-3);
|
|
83
|
+
color: var(--body-text-color);
|
|
84
|
+
font-weight: var(--weight-bold);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.toggle-icon {
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
margin-right: var(--size-2);
|
|
91
|
+
border-radius: var(--radius-full);
|
|
92
|
+
background: var(--color-grey-300);
|
|
93
|
+
width: 12px;
|
|
94
|
+
height: 4px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.toggle-dot {
|
|
98
|
+
border-radius: var(--radius-full);
|
|
99
|
+
background: var(--color-grey-700);
|
|
100
|
+
width: 6px;
|
|
101
|
+
height: 6px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
:global(.dark) .toggle-icon {
|
|
105
|
+
background: var(--color-grey-500);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
:global(.dark) .toggle-dot {
|
|
109
|
+
background: var(--color-grey-400);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
input[type="text"] {
|
|
113
|
+
--ring-color: transparent;
|
|
114
|
+
margin: var(--size-1) 0;
|
|
115
|
+
outline: none !important;
|
|
116
|
+
box-shadow: var(--input-shadow);
|
|
117
|
+
border: var(--input-border-width) solid var(--input-border-color);
|
|
118
|
+
border-radius: var(--radius-lg);
|
|
119
|
+
background: var(--input-background-fill);
|
|
120
|
+
padding: var(--size-1-5);
|
|
121
|
+
color: var(--body-text-color);
|
|
122
|
+
font-weight: var(--input-text-weight);
|
|
123
|
+
font-size: var(--input-text-size);
|
|
124
|
+
line-height: var(--line-sm);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
input:focus {
|
|
128
|
+
box-shadow: var(--input-shadow-focus);
|
|
129
|
+
border-color: var(--input-border-color-focus);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.error {
|
|
133
|
+
color: var(--error-text-color);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.type {
|
|
137
|
+
color: var(--block-label-text-color);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.desc {
|
|
141
|
+
color: var(--body-text-color-subdued);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.name {
|
|
145
|
+
text-transform: capitalize;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.first-level {
|
|
149
|
+
margin-left: 1rem;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.second-level {
|
|
153
|
+
margin-left: 2rem;
|
|
154
|
+
}
|
|
155
|
+
</style>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import CopyButton from "./CopyButton.svelte";
|
|
3
|
+
import { Block } from "@gradio/atoms";
|
|
4
|
+
|
|
5
|
+
export let current_language: "python" | "javascript" | "bash";
|
|
6
|
+
|
|
7
|
+
let py_install = "pip install gradio_client";
|
|
8
|
+
let js_install = "npm i -D @gradio/client";
|
|
9
|
+
let bash_install = "curl --version";
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<Block border_mode="contrast">
|
|
13
|
+
<code>
|
|
14
|
+
{#if current_language === "python"}
|
|
15
|
+
<div class="copy">
|
|
16
|
+
<CopyButton code={py_install} />
|
|
17
|
+
</div>
|
|
18
|
+
<div>
|
|
19
|
+
<pre>$ {py_install}</pre>
|
|
20
|
+
</div>
|
|
21
|
+
{:else if current_language === "javascript"}
|
|
22
|
+
<div class="copy">
|
|
23
|
+
<CopyButton code={js_install} />
|
|
24
|
+
</div>
|
|
25
|
+
<div>
|
|
26
|
+
<pre>$ {js_install}</pre>
|
|
27
|
+
</div>
|
|
28
|
+
{:else if current_language === "bash"}
|
|
29
|
+
<div class="copy">
|
|
30
|
+
<CopyButton code={bash_install} />
|
|
31
|
+
</div>
|
|
32
|
+
<div>
|
|
33
|
+
<pre>$ {bash_install}</pre>
|
|
34
|
+
</div>
|
|
35
|
+
{/if}
|
|
36
|
+
</code>
|
|
37
|
+
</Block>
|
|
38
|
+
|
|
39
|
+
<style>
|
|
40
|
+
code pre {
|
|
41
|
+
overflow-x: auto;
|
|
42
|
+
color: var(--body-text-color);
|
|
43
|
+
font-family: var(--font-mono);
|
|
44
|
+
tab-size: 2;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
code {
|
|
48
|
+
position: relative;
|
|
49
|
+
display: block;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.copy {
|
|
53
|
+
position: absolute;
|
|
54
|
+
top: 0;
|
|
55
|
+
right: 0;
|
|
56
|
+
margin-top: -5px;
|
|
57
|
+
margin-right: -5px;
|
|
58
|
+
}
|
|
59
|
+
</style>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createEventDispatcher } from "svelte";
|
|
3
|
+
import Clear from "./img/clear.svelte";
|
|
4
|
+
|
|
5
|
+
const dispatch = createEventDispatcher();
|
|
6
|
+
|
|
7
|
+
export let root: string;
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<div class="wrap prose">
|
|
11
|
+
<h1>API Docs</h1>
|
|
12
|
+
<p class="attention">
|
|
13
|
+
No API Routes found for
|
|
14
|
+
<code>
|
|
15
|
+
{root}
|
|
16
|
+
</code>
|
|
17
|
+
</p>
|
|
18
|
+
<p>
|
|
19
|
+
To expose an API endpoint of your app in this page, set the <code>
|
|
20
|
+
api_name
|
|
21
|
+
</code>
|
|
22
|
+
parameter of the event listener.
|
|
23
|
+
<br />
|
|
24
|
+
For more information, visit the
|
|
25
|
+
<a href="https://gradio.app/sharing_your_app/#api-page" target="_blank">
|
|
26
|
+
API Page guide
|
|
27
|
+
</a>
|
|
28
|
+
. To hide the API documentation button and this page, set
|
|
29
|
+
<code>show_api=False</code>
|
|
30
|
+
in the
|
|
31
|
+
<code>Blocks.launch()</code>
|
|
32
|
+
method.
|
|
33
|
+
</p>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<button on:click={() => dispatch("close")}>
|
|
37
|
+
<Clear />
|
|
38
|
+
</button>
|
|
39
|
+
|
|
40
|
+
<style>
|
|
41
|
+
.wrap {
|
|
42
|
+
padding: var(--size-6);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.attention {
|
|
46
|
+
font-weight: var(--weight-bold);
|
|
47
|
+
font-size: var(--text-lg);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.attention code {
|
|
51
|
+
border: none;
|
|
52
|
+
background: none;
|
|
53
|
+
color: var(--color-accent);
|
|
54
|
+
font-weight: var(--weight-bold);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
button {
|
|
58
|
+
position: absolute;
|
|
59
|
+
top: var(--size-5);
|
|
60
|
+
right: var(--size-6);
|
|
61
|
+
width: var(--size-4);
|
|
62
|
+
color: var(--body-text-color);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
button:hover {
|
|
66
|
+
color: var(--color-accent);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@media (--screen-md) {
|
|
70
|
+
button {
|
|
71
|
+
top: var(--size-6);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
</style>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Loader } from "@gradio/statustracker";
|
|
3
|
+
import { represent_value } from "./utils";
|
|
4
|
+
|
|
5
|
+
export let is_running: boolean;
|
|
6
|
+
export let endpoint_returns: any;
|
|
7
|
+
export let js_returns: any;
|
|
8
|
+
export let current_language: "python" | "javascript" | "bash";
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<h4>
|
|
12
|
+
<div class="toggle-icon">
|
|
13
|
+
<div class="toggle-dot" />
|
|
14
|
+
</div>
|
|
15
|
+
Accepts {endpoint_returns.length} parameter{#if endpoint_returns.length != 1}s{/if}:
|
|
16
|
+
</h4>
|
|
17
|
+
|
|
18
|
+
<div class:hide={is_running}>
|
|
19
|
+
{#each endpoint_returns as { label, python_type, component, parameter_name, parameter_has_default, parameter_default }, i}
|
|
20
|
+
<hr class="hr" />
|
|
21
|
+
<div style="margin:10px;">
|
|
22
|
+
<p style="white-space: nowrap; overflow-x: auto;">
|
|
23
|
+
<span class="code" style="margin-right: 10px;"
|
|
24
|
+
>{current_language !== "bash" && parameter_name
|
|
25
|
+
? parameter_name
|
|
26
|
+
: "[" + i + "]"}</span
|
|
27
|
+
>
|
|
28
|
+
<span class="code highlight" style="margin-right: 10px;"
|
|
29
|
+
>{#if current_language === "python"}{python_type.type}{#if parameter_has_default && parameter_default === null} |
|
|
30
|
+
None{/if}{:else}{js_returns[i].type || "any"}{/if}</span
|
|
31
|
+
>
|
|
32
|
+
{#if !parameter_has_default || current_language == "bash"}<span
|
|
33
|
+
style="font-weight:bold">Required</span
|
|
34
|
+
>{:else}<span> Default: </span><span
|
|
35
|
+
class="code"
|
|
36
|
+
style="font-size: var(--text-sm);"
|
|
37
|
+
>{represent_value(parameter_default, python_type.type, "py")}</span
|
|
38
|
+
>{/if}
|
|
39
|
+
</p>
|
|
40
|
+
<p class="desc">
|
|
41
|
+
The input value that is provided in the "{label}" <!--
|
|
42
|
+
-->{component}
|
|
43
|
+
component<!--
|
|
44
|
+
-->.
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
47
|
+
{/each}
|
|
48
|
+
</div>
|
|
49
|
+
{#if is_running}
|
|
50
|
+
<div class="load-wrap">
|
|
51
|
+
<Loader margin={false} />
|
|
52
|
+
</div>
|
|
53
|
+
{/if}
|
|
54
|
+
|
|
55
|
+
<style>
|
|
56
|
+
.hr {
|
|
57
|
+
border: 0;
|
|
58
|
+
height: 1px;
|
|
59
|
+
background: var(--color-accent-soft);
|
|
60
|
+
margin-bottom: 12px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.code {
|
|
64
|
+
font-family: var(--font-mono);
|
|
65
|
+
display: inline;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.highlight {
|
|
69
|
+
background: var(--color-accent-soft);
|
|
70
|
+
color: var(--color-accent);
|
|
71
|
+
padding: var(--size-1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.desc {
|
|
75
|
+
color: var(--body-text-color-subdued);
|
|
76
|
+
font-size: var(--text-lg);
|
|
77
|
+
margin-top: var(--size-1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
h4 {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
margin-top: var(--size-6);
|
|
84
|
+
margin-bottom: var(--size-3);
|
|
85
|
+
color: var(--body-text-color);
|
|
86
|
+
font-weight: var(--weight-bold);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.toggle-icon {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
margin-right: var(--size-2);
|
|
93
|
+
border-radius: var(--radius-full);
|
|
94
|
+
background: var(--color-grey-300);
|
|
95
|
+
width: 12px;
|
|
96
|
+
height: 4px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.toggle-dot {
|
|
100
|
+
border-radius: var(--radius-full);
|
|
101
|
+
background: var(--color-grey-700);
|
|
102
|
+
width: 6px;
|
|
103
|
+
height: 6px;
|
|
104
|
+
margin-right: auto;
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Dependency, Payload } from "../types";
|
|
3
|
+
import CopyButton from "./CopyButton.svelte";
|
|
4
|
+
import { Block } from "@gradio/atoms";
|
|
5
|
+
import { represent_value } from "./utils";
|
|
6
|
+
import { onMount, tick } from "svelte";
|
|
7
|
+
|
|
8
|
+
export let dependencies: Dependency[];
|
|
9
|
+
export let short_root: string;
|
|
10
|
+
export let root: string;
|
|
11
|
+
export let current_language: "python" | "javascript" | "bash";
|
|
12
|
+
export let username: string | null;
|
|
13
|
+
|
|
14
|
+
let python_code: HTMLElement;
|
|
15
|
+
let python_code_text: string;
|
|
16
|
+
let js_code: HTMLElement;
|
|
17
|
+
let bash_code: HTMLElement;
|
|
18
|
+
|
|
19
|
+
export let api_calls: Payload[] = [];
|
|
20
|
+
|
|
21
|
+
async function get_info(): Promise<{
|
|
22
|
+
named_endpoints: any;
|
|
23
|
+
unnamed_endpoints: any;
|
|
24
|
+
}> {
|
|
25
|
+
let response = await fetch(root + "info/?all_endpoints=true");
|
|
26
|
+
let data = await response.json();
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let endpoints_info: any;
|
|
31
|
+
let py_zipped: { call: string; api_name: string }[] = [];
|
|
32
|
+
let js_zipped: { call: string; api_name: string }[] = [];
|
|
33
|
+
let bash_zipped: { call: string; api_name: string }[] = [];
|
|
34
|
+
|
|
35
|
+
function format_api_call(call: Payload, lang: "py" | "js" | "bash"): string {
|
|
36
|
+
const api_name = `/${dependencies[call.fn_index].api_name}`;
|
|
37
|
+
// If an input is undefined (distinct from null) then it corresponds to a State component.
|
|
38
|
+
let call_data_excluding_state = call.data.filter(
|
|
39
|
+
(d) => typeof d !== "undefined"
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const params = call_data_excluding_state
|
|
43
|
+
.map((param, index) => {
|
|
44
|
+
if (endpoints_info[api_name]) {
|
|
45
|
+
const param_info = endpoints_info[api_name].parameters[index];
|
|
46
|
+
if (!param_info) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const param_name = param_info.parameter_name;
|
|
50
|
+
const python_type = param_info.python_type.type;
|
|
51
|
+
if (lang === "py") {
|
|
52
|
+
return ` ${param_name}=${represent_value(
|
|
53
|
+
param as string,
|
|
54
|
+
python_type,
|
|
55
|
+
"py"
|
|
56
|
+
)}`;
|
|
57
|
+
} else if (lang === "js") {
|
|
58
|
+
return ` ${param_name}: ${represent_value(
|
|
59
|
+
param as string,
|
|
60
|
+
python_type,
|
|
61
|
+
"js"
|
|
62
|
+
)}`;
|
|
63
|
+
} else if (lang === "bash") {
|
|
64
|
+
return ` ${represent_value(
|
|
65
|
+
param as string,
|
|
66
|
+
python_type,
|
|
67
|
+
"bash"
|
|
68
|
+
)}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return ` ${represent_value(param as string, undefined, lang)}`;
|
|
72
|
+
})
|
|
73
|
+
.filter((d) => typeof d !== "undefined")
|
|
74
|
+
.join(",\n");
|
|
75
|
+
if (params) {
|
|
76
|
+
if (lang === "py") {
|
|
77
|
+
return `${params},\n`;
|
|
78
|
+
} else if (lang === "js") {
|
|
79
|
+
return `{\n${params},\n}`;
|
|
80
|
+
} else if (lang === "bash") {
|
|
81
|
+
return `\n${params}\n`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (lang === "py") {
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
return "\n";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onMount(async () => {
|
|
91
|
+
const data = await get_info();
|
|
92
|
+
endpoints_info = data["named_endpoints"];
|
|
93
|
+
let py_api_calls: string[] = api_calls.map((call) =>
|
|
94
|
+
format_api_call(call, "py")
|
|
95
|
+
);
|
|
96
|
+
let js_api_calls: string[] = api_calls.map((call) =>
|
|
97
|
+
format_api_call(call, "js")
|
|
98
|
+
);
|
|
99
|
+
let bash_api_calls: string[] = api_calls.map((call) =>
|
|
100
|
+
format_api_call(call, "bash")
|
|
101
|
+
);
|
|
102
|
+
let api_names: string[] = api_calls.map(
|
|
103
|
+
(call) => dependencies[call.fn_index].api_name || ""
|
|
104
|
+
);
|
|
105
|
+
py_zipped = py_api_calls.map((call, index) => ({
|
|
106
|
+
call,
|
|
107
|
+
api_name: api_names[index]
|
|
108
|
+
}));
|
|
109
|
+
js_zipped = js_api_calls.map((call, index) => ({
|
|
110
|
+
call,
|
|
111
|
+
api_name: api_names[index]
|
|
112
|
+
}));
|
|
113
|
+
bash_zipped = bash_api_calls.map((call, index) => ({
|
|
114
|
+
call,
|
|
115
|
+
api_name: api_names[index]
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
await tick();
|
|
119
|
+
|
|
120
|
+
python_code_text = python_code.innerText;
|
|
121
|
+
});
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
<div class="container">
|
|
125
|
+
<!-- <EndpointDetail {named} api_name={dependency.api_name} /> -->
|
|
126
|
+
<Block border_mode={"focus"}>
|
|
127
|
+
{#if current_language === "python"}
|
|
128
|
+
<code>
|
|
129
|
+
<div class="copy">
|
|
130
|
+
<CopyButton code={python_code_text} />
|
|
131
|
+
</div>
|
|
132
|
+
<div bind:this={python_code}>
|
|
133
|
+
<pre><span class="highlight">from</span> gradio_client <span
|
|
134
|
+
class="highlight">import</span
|
|
135
|
+
> Client, file
|
|
136
|
+
|
|
137
|
+
client = Client(<span class="token string">"{short_root}"</span
|
|
138
|
+
>{#if username !== null}, auth=("{username}", **password**){/if})
|
|
139
|
+
{#each py_zipped as { call, api_name }}<!--
|
|
140
|
+
-->
|
|
141
|
+
client.<span class="highlight"
|
|
142
|
+
>predict(
|
|
143
|
+
{call} api_name=<span class="api-name">"/{api_name}"</span>
|
|
144
|
+
)
|
|
145
|
+
</span>{/each}</pre>
|
|
146
|
+
</div>
|
|
147
|
+
</code>
|
|
148
|
+
{:else if current_language === "javascript"}
|
|
149
|
+
<code>
|
|
150
|
+
<div class="copy">
|
|
151
|
+
<CopyButton code={js_code?.innerText} />
|
|
152
|
+
</div>
|
|
153
|
+
<div bind:this={js_code}>
|
|
154
|
+
<pre>import { Client } from "@gradio/client";
|
|
155
|
+
|
|
156
|
+
const app = await Client.connect(<span class="token string">"{short_root}"</span
|
|
157
|
+
>{#if username !== null}, {auth: ["{username}", **password**]}{/if});
|
|
158
|
+
{#each js_zipped as { call, api_name }}<!--
|
|
159
|
+
-->
|
|
160
|
+
await client.predict(<span
|
|
161
|
+
class="api-name">
|
|
162
|
+
"/{api_name}"</span
|
|
163
|
+
>{#if call},
|
|
164
|
+
{/if}{call});
|
|
165
|
+
{/each}</pre>
|
|
166
|
+
</div>
|
|
167
|
+
</code>
|
|
168
|
+
{:else if current_language === "bash"}
|
|
169
|
+
<code>
|
|
170
|
+
<div class="copy">
|
|
171
|
+
<CopyButton code={bash_code?.innerText} />
|
|
172
|
+
</div>
|
|
173
|
+
<div bind:this={bash_code}>
|
|
174
|
+
{#each bash_zipped as { call, api_name }}
|
|
175
|
+
<pre>curl -X POST {short_root}call/{api_name} -s -H "Content-Type: application/json" -d '{"{"}
|
|
176
|
+
"data": [{call}]{"}"}' \
|
|
177
|
+
| awk -F'"' '{"{"} print $4{"}"}' \
|
|
178
|
+
| read EVENT_ID; curl -N {short_root}call/{api_name}/$EVENT_ID</pre>
|
|
179
|
+
<br />
|
|
180
|
+
{/each}
|
|
181
|
+
</div>
|
|
182
|
+
</code>
|
|
183
|
+
{/if}
|
|
184
|
+
</Block>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<style>
|
|
188
|
+
code pre {
|
|
189
|
+
overflow-x: auto;
|
|
190
|
+
color: var(--body-text-color);
|
|
191
|
+
font-family: var(--font-mono);
|
|
192
|
+
tab-size: 2;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.token.string {
|
|
196
|
+
display: contents;
|
|
197
|
+
color: var(--color-accent-base);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
code {
|
|
201
|
+
position: relative;
|
|
202
|
+
display: block;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.copy {
|
|
206
|
+
position: absolute;
|
|
207
|
+
top: 0;
|
|
208
|
+
right: 0;
|
|
209
|
+
margin-top: -5px;
|
|
210
|
+
margin-right: -5px;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.container {
|
|
214
|
+
display: flex;
|
|
215
|
+
flex-direction: column;
|
|
216
|
+
gap: var(--spacing-xxl);
|
|
217
|
+
margin-top: var(--size-3);
|
|
218
|
+
margin-bottom: var(--size-3);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.api-name {
|
|
222
|
+
color: var(--color-accent);
|
|
223
|
+
}
|
|
224
|
+
</style>
|