@gradio/core 1.0.0-dev.0 → 1.0.0
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 +110 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/Blocks.svelte +534 -1001
- package/dist/src/Blocks.svelte.d.ts +32 -45
- package/dist/src/Embed.svelte +82 -55
- package/dist/src/Embed.svelte.d.ts +39 -30
- package/dist/src/Login.svelte +33 -29
- package/dist/src/Login.svelte.d.ts +21 -19
- package/dist/src/MountComponents.svelte +19 -25
- package/dist/src/MountComponents.svelte.d.ts +5 -28
- package/dist/src/{init.d.ts → _init.d.ts} +5 -4
- package/dist/src/{init.js → _init.js} +31 -108
- package/dist/src/api_docs/ApiBanner.svelte +12 -8
- package/dist/src/api_docs/ApiBanner.svelte.d.ts +22 -20
- package/dist/src/api_docs/ApiDocs.svelte +356 -247
- package/dist/src/api_docs/ApiDocs.svelte.d.ts +27 -24
- package/dist/src/api_docs/ApiRecorder.svelte +6 -3
- package/dist/src/api_docs/ApiRecorder.svelte.d.ts +19 -17
- package/dist/src/api_docs/CodeSnippet.svelte +122 -48
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +29 -25
- package/dist/src/api_docs/CopyButton.svelte +69 -13
- package/dist/src/api_docs/CopyButton.svelte.d.ts +18 -16
- package/dist/src/api_docs/CopyMarkdown.svelte +734 -0
- package/dist/src/api_docs/CopyMarkdown.svelte.d.ts +37 -0
- package/dist/src/api_docs/EndpointDetail.svelte +81 -23
- package/dist/src/api_docs/EndpointDetail.svelte.d.ts +23 -18
- package/dist/src/api_docs/IconArrowUpRight.svelte +34 -0
- package/dist/src/api_docs/IconArrowUpRight.svelte.d.ts +20 -0
- package/dist/src/api_docs/IconCaret.svelte +39 -0
- package/dist/src/api_docs/IconCaret.svelte.d.ts +20 -0
- package/dist/src/api_docs/IconHuggingChat.svelte +62 -0
- package/dist/src/api_docs/IconHuggingChat.svelte.d.ts +20 -0
- package/dist/src/api_docs/InputPayload.svelte +17 -11
- package/dist/src/api_docs/InputPayload.svelte.d.ts +25 -23
- package/dist/src/api_docs/InstallSnippet.svelte +9 -6
- package/dist/src/api_docs/InstallSnippet.svelte.d.ts +18 -16
- package/dist/src/api_docs/MCPSnippet.svelte +139 -126
- package/dist/src/api_docs/MCPSnippet.svelte.d.ts +60 -58
- package/dist/src/api_docs/NoApi.svelte +7 -4
- package/dist/src/api_docs/NoApi.svelte.d.ts +20 -18
- package/dist/src/api_docs/ParametersSnippet.svelte +8 -6
- package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +21 -19
- package/dist/src/api_docs/PercentileChart.svelte +125 -0
- package/dist/src/api_docs/PercentileChart.svelte.d.ts +22 -0
- package/dist/src/api_docs/RecordingSnippet.svelte +124 -110
- package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +24 -22
- package/dist/src/api_docs/ResponseSnippet.svelte +7 -5
- package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +21 -19
- package/dist/src/api_docs/Settings.svelte +73 -62
- package/dist/src/api_docs/Settings.svelte.d.ts +25 -23
- package/dist/src/api_docs/SettingsBanner.svelte +11 -8
- package/dist/src/api_docs/SettingsBanner.svelte.d.ts +20 -18
- package/dist/src/api_docs/TryButton.svelte +5 -3
- package/dist/src/api_docs/TryButton.svelte.d.ts +19 -17
- package/dist/src/api_docs/img/IconCheck.svelte +33 -0
- package/dist/src/api_docs/img/IconCheck.svelte.d.ts +26 -0
- package/dist/src/api_docs/img/IconCopy.svelte +40 -0
- package/dist/src/api_docs/img/IconCopy.svelte.d.ts +26 -0
- package/dist/src/api_docs/img/clear.svelte.d.ts +22 -21
- package/dist/src/dependency.d.ts +145 -0
- package/dist/src/dependency.js +668 -0
- package/dist/src/init.svelte.d.ts +78 -0
- package/dist/src/init.svelte.js +469 -0
- package/dist/src/init_utils.d.ts +32 -0
- package/dist/src/init_utils.js +73 -0
- package/dist/src/lang/en.json +10 -1
- package/dist/src/lang/get_lang_names.js +0 -3
- package/dist/src/lang/ru.json +10 -1
- package/dist/src/stores.d.ts +0 -21
- package/dist/src/stories/I18nMultiLanguageTestComponent.svelte +5 -3
- package/dist/src/stories/I18nMultiLanguageTestComponent.svelte.d.ts +16 -14
- package/dist/src/stories/I18nTestSetup.svelte +14 -10
- package/dist/src/stories/I18nTestSetup.svelte.d.ts +18 -16
- package/dist/src/types.d.ts +31 -26
- package/index.ts +1 -1
- package/package.json +62 -63
- package/src/Blocks.svelte +360 -1063
- package/src/MountComponents.svelte +17 -27
- package/src/{init.ts → _init.ts} +49 -126
- package/src/api_docs/ApiDocs.svelte +84 -62
- package/src/api_docs/CodeSnippet.svelte +83 -24
- package/src/api_docs/CopyButton.svelte +61 -7
- package/src/api_docs/CopyMarkdown.svelte +734 -0
- package/src/api_docs/EndpointDetail.svelte +73 -17
- package/src/api_docs/IconArrowUpRight.svelte +34 -0
- package/src/api_docs/IconCaret.svelte +39 -0
- package/src/api_docs/IconHuggingChat.svelte +62 -0
- package/src/api_docs/MCPSnippet.svelte +44 -73
- package/src/api_docs/ParametersSnippet.svelte +1 -1
- package/src/api_docs/PercentileChart.svelte +125 -0
- package/src/api_docs/ResponseSnippet.svelte +1 -1
- package/src/api_docs/Settings.svelte +11 -11
- package/src/api_docs/img/IconCheck.svelte +33 -0
- package/src/api_docs/img/IconCopy.svelte +40 -0
- package/src/dependency.ts +909 -0
- package/src/init.svelte.ts +717 -0
- package/src/init_utils.ts +99 -0
- package/src/lang/en.json +10 -1
- package/src/lang/get_lang_names.js +0 -3
- package/src/lang/ru.json +10 -1
- package/src/stores.ts +22 -22
- package/src/types.ts +55 -43
- package/dist/src/Render.svelte +0 -105
- package/dist/src/Render.svelte.d.ts +0 -31
- package/dist/src/RenderComponent.svelte +0 -72
- package/dist/src/RenderComponent.svelte.d.ts +0 -33
- package/src/Render.svelte +0 -126
- package/src/RenderComponent.svelte +0 -91
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { ComponentMeta, Dependency } from "../types";
|
|
2
|
+
import type { ComponentMeta, Dependency, Payload } from "../types";
|
|
3
3
|
import CopyButton from "./CopyButton.svelte";
|
|
4
4
|
import { represent_value, is_potentially_nested_file_data } from "./utils";
|
|
5
5
|
import { Block } from "@gradio/atoms";
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
export let space_id: string | null;
|
|
21
21
|
export let endpoint_parameters: any;
|
|
22
22
|
export let username: string | null;
|
|
23
|
-
export let current_language: "python" | "javascript" | "bash";
|
|
23
|
+
export let current_language: "python" | "javascript" | "bash" | "mcp";
|
|
24
24
|
export let api_description: string | null = null;
|
|
25
25
|
export let analytics: Record<string, any>;
|
|
26
|
+
export let markdown_code_snippets: Record<string, Record<string, string>>;
|
|
27
|
+
export let last_api_call: Payload | null = null;
|
|
26
28
|
|
|
27
29
|
let python_code: HTMLElement;
|
|
28
30
|
let js_code: HTMLElement;
|
|
@@ -39,6 +41,35 @@
|
|
|
39
41
|
|
|
40
42
|
$: normalised_api_prefix = api_prefix ? api_prefix : "/";
|
|
41
43
|
$: normalised_root = root.replace(/\/$/, "");
|
|
44
|
+
|
|
45
|
+
$: is_most_recently_used = last_api_call?.fn_index === dependency.id;
|
|
46
|
+
|
|
47
|
+
$: actual_data =
|
|
48
|
+
is_most_recently_used && last_api_call?.data
|
|
49
|
+
? last_api_call.data.filter((d) => typeof d !== "undefined")
|
|
50
|
+
: null;
|
|
51
|
+
|
|
52
|
+
function getParameterValue(param: any, index: number): any {
|
|
53
|
+
if (
|
|
54
|
+
is_most_recently_used &&
|
|
55
|
+
actual_data &&
|
|
56
|
+
actual_data[index] !== undefined
|
|
57
|
+
) {
|
|
58
|
+
return actual_data[index];
|
|
59
|
+
}
|
|
60
|
+
return param.parameter_has_default !== undefined &&
|
|
61
|
+
param.parameter_has_default
|
|
62
|
+
? param.parameter_default
|
|
63
|
+
: param.example_input;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
$: markdown_code_snippets[
|
|
67
|
+
dependency.api_name as keyof typeof markdown_code_snippets
|
|
68
|
+
] = {
|
|
69
|
+
python: python_code?.innerText || "",
|
|
70
|
+
javascript: js_code?.innerText || "",
|
|
71
|
+
bash: bash_post_code?.innerText || ""
|
|
72
|
+
};
|
|
42
73
|
</script>
|
|
43
74
|
|
|
44
75
|
<div class="container">
|
|
@@ -46,8 +77,10 @@
|
|
|
46
77
|
api_name={dependency.api_name}
|
|
47
78
|
description={api_description}
|
|
48
79
|
{analytics}
|
|
80
|
+
{last_api_call}
|
|
81
|
+
dependency_id={dependency.id}
|
|
49
82
|
/>
|
|
50
|
-
{
|
|
83
|
+
<div class:hidden={current_language !== "python"}>
|
|
51
84
|
<Block>
|
|
52
85
|
<code>
|
|
53
86
|
<div class="copy">
|
|
@@ -62,14 +95,16 @@ client = Client(<span class="token string">"{space_id || root}"</span
|
|
|
62
95
|
>{#if username !== null}, auth=("{username}", **password**){/if})
|
|
63
96
|
result = client.<span class="highlight">predict</span
|
|
64
97
|
>(<!--
|
|
65
|
-
-->{#each endpoint_parameters as
|
|
98
|
+
-->{#each endpoint_parameters as param, i}<!--
|
|
66
99
|
-->
|
|
67
|
-
{parameter_name
|
|
68
|
-
? parameter_name + "="
|
|
100
|
+
{param.parameter_name
|
|
101
|
+
? param.parameter_name + "="
|
|
69
102
|
: ""}<span
|
|
103
|
+
class:recent-value={is_most_recently_used &&
|
|
104
|
+
actual_data?.[i] !== undefined}
|
|
70
105
|
>{represent_value(
|
|
71
|
-
|
|
72
|
-
python_type.type,
|
|
106
|
+
getParameterValue(param, i),
|
|
107
|
+
param.python_type.type,
|
|
73
108
|
"py"
|
|
74
109
|
)}</span
|
|
75
110
|
>,{/each}<!--
|
|
@@ -82,7 +117,8 @@ result = client.<span class="highlight">predict</span
|
|
|
82
117
|
</div>
|
|
83
118
|
</code>
|
|
84
119
|
</Block>
|
|
85
|
-
|
|
120
|
+
</div>
|
|
121
|
+
<div class:hidden={current_language !== "javascript"}>
|
|
86
122
|
<Block>
|
|
87
123
|
<code>
|
|
88
124
|
<div class="copy">
|
|
@@ -102,22 +138,26 @@ result = client.<span class="highlight">predict</span
|
|
|
102
138
|
const result = await client.predict(<span class="api-name"
|
|
103
139
|
>"/{dependency.api_name}"</span
|
|
104
140
|
>, { <!--
|
|
105
|
-
-->{#each endpoint_parameters as
|
|
106
|
-
-->{#if blob_components.includes(component)}<!--
|
|
141
|
+
-->{#each endpoint_parameters as param, i}<!--
|
|
142
|
+
-->{#if blob_components.includes(param.component)}<!--
|
|
107
143
|
-->
|
|
108
144
|
<span
|
|
109
145
|
class="example-inputs"
|
|
110
|
-
>{parameter_name}: example{component}</span
|
|
146
|
+
>{param.parameter_name}: example{param.component}</span
|
|
111
147
|
>, <!--
|
|
112
148
|
--><span class="desc"><!--
|
|
113
149
|
--></span
|
|
114
150
|
><!--
|
|
115
151
|
-->{:else}<!--
|
|
116
152
|
-->
|
|
117
|
-
<span
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
<span
|
|
154
|
+
class="example-inputs {is_most_recently_used &&
|
|
155
|
+
actual_data?.[i] !== undefined
|
|
156
|
+
? 'recent-value'
|
|
157
|
+
: ''}"
|
|
158
|
+
>{param.parameter_name}: {represent_value(
|
|
159
|
+
getParameterValue(param, i),
|
|
160
|
+
param.python_type.type,
|
|
121
161
|
"js"
|
|
122
162
|
)}</span
|
|
123
163
|
>, <!--
|
|
@@ -131,7 +171,8 @@ result = client.<span class="highlight">predict</span
|
|
|
131
171
|
</div>
|
|
132
172
|
</code>
|
|
133
173
|
</Block>
|
|
134
|
-
|
|
174
|
+
</div>
|
|
175
|
+
<div class:hidden={current_language !== "bash"}>
|
|
135
176
|
<Block>
|
|
136
177
|
<code>
|
|
137
178
|
<div class="copy">
|
|
@@ -140,13 +181,18 @@ result = client.<span class="highlight">predict</span
|
|
|
140
181
|
|
|
141
182
|
<div bind:this={bash_post_code}>
|
|
142
183
|
<pre>curl -X POST {normalised_root}{normalised_api_prefix}/call/{dependency.api_name} -s -H "Content-Type: application/json" -d '{"{"}
|
|
143
|
-
"data": [{#each endpoint_parameters as
|
|
184
|
+
"data": [{#each endpoint_parameters as param, i}
|
|
144
185
|
<!--
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
186
|
+
--><span
|
|
187
|
+
class={is_most_recently_used && actual_data?.[i] !== undefined
|
|
188
|
+
? "recent-value"
|
|
189
|
+
: ""}
|
|
190
|
+
>{represent_value(
|
|
191
|
+
getParameterValue(param, i),
|
|
192
|
+
param.python_type.type,
|
|
193
|
+
"bash"
|
|
194
|
+
)}</span
|
|
195
|
+
>{#if i < endpoint_parameters.length - 1},
|
|
150
196
|
{/if}
|
|
151
197
|
{/each}
|
|
152
198
|
]{"}"}' \
|
|
@@ -155,7 +201,7 @@ result = client.<span class="highlight">predict</span
|
|
|
155
201
|
</div>
|
|
156
202
|
</code>
|
|
157
203
|
</Block>
|
|
158
|
-
|
|
204
|
+
</div>
|
|
159
205
|
</div>
|
|
160
206
|
|
|
161
207
|
<style>
|
|
@@ -199,4 +245,17 @@ result = client.<span class="highlight">predict</span
|
|
|
199
245
|
.api-name {
|
|
200
246
|
color: var(--color-accent);
|
|
201
247
|
}
|
|
248
|
+
|
|
249
|
+
.recent-value {
|
|
250
|
+
color: #fd7b00;
|
|
251
|
+
background: #fff4e6;
|
|
252
|
+
border: 1px solid #ffd9b3;
|
|
253
|
+
border-radius: var(--radius-sm);
|
|
254
|
+
padding: 1px 4px;
|
|
255
|
+
font-weight: var(--weight-medium);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.hidden {
|
|
259
|
+
display: none;
|
|
260
|
+
}
|
|
202
261
|
</style>
|
|
@@ -1,17 +1,71 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import
|
|
2
|
+
import IconCopy from "./img/IconCopy.svelte";
|
|
3
|
+
import IconCheck from "./img/IconCheck.svelte";
|
|
4
|
+
|
|
3
5
|
export let code: string;
|
|
4
|
-
|
|
6
|
+
|
|
7
|
+
let copied = false;
|
|
5
8
|
|
|
6
9
|
function copy(): void {
|
|
7
10
|
navigator.clipboard.writeText(code);
|
|
8
|
-
|
|
11
|
+
copied = true;
|
|
9
12
|
setTimeout(() => {
|
|
10
|
-
|
|
13
|
+
copied = false;
|
|
11
14
|
}, 1500);
|
|
12
15
|
}
|
|
16
|
+
|
|
17
|
+
$: copied;
|
|
13
18
|
</script>
|
|
14
19
|
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
<button on:click={copy} class="copy-button" aria-live="polite">
|
|
21
|
+
<span
|
|
22
|
+
class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0"
|
|
23
|
+
>
|
|
24
|
+
{#if copied}
|
|
25
|
+
<IconCheck classNames="w-3 h-3 max-sm:w-2.5 max-sm:h-2.5" />
|
|
26
|
+
{:else}
|
|
27
|
+
<IconCopy classNames="w-3 h-3 max-sm:w-2.5 max-sm:h-2.5" />
|
|
28
|
+
{/if}
|
|
29
|
+
</span>
|
|
30
|
+
</button>
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.copy-button {
|
|
34
|
+
display: inline-flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: 4px;
|
|
37
|
+
height: 24px;
|
|
38
|
+
padding-left: 8px;
|
|
39
|
+
padding-right: 8px;
|
|
40
|
+
font-size: 11px;
|
|
41
|
+
font-weight: 500;
|
|
42
|
+
color: rgb(31, 41, 55);
|
|
43
|
+
border: 1px solid rgb(229, 231, 235);
|
|
44
|
+
border-radius: 6px;
|
|
45
|
+
background-color: white;
|
|
46
|
+
|
|
47
|
+
@media (max-width: 640px) {
|
|
48
|
+
gap: 2px;
|
|
49
|
+
height: 20px;
|
|
50
|
+
padding-left: 6px;
|
|
51
|
+
padding-right: 6px;
|
|
52
|
+
font-size: 9px;
|
|
53
|
+
border-top-left-radius: 4px;
|
|
54
|
+
border-bottom-left-radius: 4px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&:hover {
|
|
58
|
+
box-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@media (prefers-color-scheme: dark) {
|
|
62
|
+
border-color: rgb(38, 38, 38);
|
|
63
|
+
background-color: rgb(10, 10, 10);
|
|
64
|
+
color: rgb(229, 231, 235);
|
|
65
|
+
|
|
66
|
+
&:hover {
|
|
67
|
+
background-color: rgb(38, 38, 38);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</style>
|