@gradio/core 1.1.3 → 1.3.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 +51 -0
- package/dist/src/Blocks.svelte +33 -2
- package/dist/src/_init.js +2 -2
- package/dist/src/api_docs/ApiBanner.svelte +6 -2
- package/dist/src/api_docs/ApiBanner.svelte.d.ts +1 -1
- package/dist/src/api_docs/ApiDocs.svelte +41 -25
- package/dist/src/api_docs/CodeSnippet.svelte +67 -170
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +2 -6
- package/dist/src/api_docs/CopyMarkdown.svelte +7 -2
- package/dist/src/api_docs/CopyMarkdown.svelte.d.ts +1 -1
- package/dist/src/api_docs/InstallSnippet.svelte +6 -1
- package/dist/src/api_docs/InstallSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/ParametersSnippet.svelte +6 -1
- package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/RecordingSnippet.svelte +6 -1
- package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/ResponseSnippet.svelte +6 -1
- package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/Settings.svelte +2 -7
- package/dist/src/api_docs/SettingsBanner.svelte +0 -3
- package/dist/src/api_docs/SkillSnippet.svelte +125 -0
- package/dist/src/api_docs/SkillSnippet.svelte.d.ts +20 -0
- package/dist/src/api_docs/img/skill.svg +10 -0
- package/dist/src/api_docs/utils.d.ts +0 -1
- package/dist/src/api_docs/utils.js +0 -22
- package/dist/src/dependency.d.ts +3 -1
- package/dist/src/dependency.js +39 -1
- package/dist/src/gradio_helper.js +5 -13
- package/dist/src/i18n.d.ts +1 -3
- package/dist/src/i18n.js +6 -53
- package/dist/src/init.svelte.js +81 -82
- package/package.json +49 -49
- package/src/Blocks.svelte +33 -2
- package/src/_init.ts +2 -2
- package/src/api_docs/ApiBanner.svelte +6 -2
- package/src/api_docs/ApiDocs.svelte +41 -25
- package/src/api_docs/CodeSnippet.svelte +67 -170
- package/src/api_docs/CopyMarkdown.svelte +7 -2
- package/src/api_docs/InstallSnippet.svelte +6 -1
- package/src/api_docs/ParametersSnippet.svelte +6 -1
- package/src/api_docs/RecordingSnippet.svelte +6 -1
- package/src/api_docs/ResponseSnippet.svelte +6 -1
- package/src/api_docs/Settings.svelte +2 -7
- package/src/api_docs/SettingsBanner.svelte +0 -3
- package/src/api_docs/SkillSnippet.svelte +125 -0
- package/src/api_docs/img/skill.svg +10 -0
- package/src/api_docs/utils.ts +0 -25
- package/src/dependency.ts +39 -1
- package/src/gradio_helper.ts +5 -17
- package/src/i18n.test.ts +41 -9
- package/src/i18n.ts +9 -62
- package/src/init.svelte.ts +95 -99
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @gradio/core
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#12918](https://github.com/gradio-app/gradio/pull/12918) [`e29e1cc`](https://github.com/gradio-app/gradio/commit/e29e1ccd5874cb98b813ed4f7f72d9fef2935016) - Add Space-specific skill generation to `gradio skills add`. Thanks @abidlabs!
|
|
8
|
+
- [#12929](https://github.com/gradio-app/gradio/pull/12929) [`978bc6e`](https://github.com/gradio-app/gradio/commit/978bc6ea5094aa11e10994cdd662c4c663a86a83) - Add server functions support to gr.HTML. Thanks @aliabid94!
|
|
9
|
+
- [#12907](https://github.com/gradio-app/gradio/pull/12907) [`3e625a0`](https://github.com/gradio-app/gradio/commit/3e625a0ecfab6e74b7561b68adbe55341ecbc47a) - Better error handling when connection to server is lost. Thanks @abidlabs!
|
|
10
|
+
|
|
11
|
+
### Fixes
|
|
12
|
+
|
|
13
|
+
- [#12904](https://github.com/gradio-app/gradio/pull/12904) [`7c3fa2a`](https://github.com/gradio-app/gradio/commit/7c3fa2a6900cfa3c87cb61ffa9b34b75d1ae49ba) - Fix Loading Spinner Issue Caused by Events Targeting Components In Inactive Tabs. Thanks @freddyaboulton!
|
|
14
|
+
- [#12903](https://github.com/gradio-app/gradio/pull/12903) [`57707c7`](https://github.com/gradio-app/gradio/commit/57707c72edd0e9fee9821882f75ab322ce110fe3) - Fix Tab i18n issue. Thanks @freddyaboulton!
|
|
15
|
+
- [#12906](https://github.com/gradio-app/gradio/pull/12906) [`81482b5`](https://github.com/gradio-app/gradio/commit/81482b58706ee9948d0f04e84e632ebb8d4bf7ea) - Lazy load sub-tab and accordion components. Thanks @dawoodkhan82!
|
|
16
|
+
|
|
17
|
+
### Dependency updates
|
|
18
|
+
|
|
19
|
+
- @gradio/client@2.1.0
|
|
20
|
+
- @gradio/button@0.6.4
|
|
21
|
+
- @gradio/html@0.10.0
|
|
22
|
+
- @gradio/tabs@0.5.7
|
|
23
|
+
|
|
24
|
+
## 1.2.0
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
- [#12839](https://github.com/gradio-app/gradio/pull/12839) [`1c671b3`](https://github.com/gradio-app/gradio/commit/1c671b39830ccf1c87f6cfcb4669e97dfb3a7367) - Hide forms with no elements. Thanks @aliabid94!
|
|
29
|
+
|
|
30
|
+
### Fixes
|
|
31
|
+
|
|
32
|
+
- [#12875](https://github.com/gradio-app/gradio/pull/12875) [`d0b3422`](https://github.com/gradio-app/gradio/commit/d0b34228d756334d901fc34971959ea422eb55bd) - Fix stop button not switching back to submit button in chat interface. Thanks @freddyaboulton!
|
|
33
|
+
- [#12797](https://github.com/gradio-app/gradio/pull/12797) [`6a0c6ea`](https://github.com/gradio-app/gradio/commit/6a0c6eae53931ec137c0b8379428acc8a7ea27c9) - Refactor translation logic. Thanks @hannahblair!
|
|
34
|
+
|
|
35
|
+
### Dependency updates
|
|
36
|
+
|
|
37
|
+
- @gradio/utils@0.11.3
|
|
38
|
+
- @gradio/atoms@0.22.0
|
|
39
|
+
- @gradio/statustracker@0.12.4
|
|
40
|
+
- @gradio/tabs@0.5.6
|
|
41
|
+
- @gradio/code@0.17.3
|
|
42
|
+
- @gradio/paramviewer@0.9.4
|
|
43
|
+
- @gradio/upload@0.17.6
|
|
44
|
+
- @gradio/video@0.20.3
|
|
45
|
+
- @gradio/file@0.14.3
|
|
46
|
+
- @gradio/image@0.25.3
|
|
47
|
+
- @gradio/gallery@0.17.1
|
|
48
|
+
- @gradio/plot@0.10.4
|
|
49
|
+
- @gradio/checkbox@0.6.3
|
|
50
|
+
- @gradio/textbox@0.13.4
|
|
51
|
+
- @gradio/dropdown@0.11.4
|
|
52
|
+
- @gradio/audio@0.22.3
|
|
53
|
+
|
|
3
54
|
## 1.1.3
|
|
4
55
|
|
|
5
56
|
### Fixes
|
package/dist/src/Blocks.svelte
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
LayoutNode
|
|
13
13
|
} from "./types";
|
|
14
14
|
// import type { UpdateTransaction } from "./_init";
|
|
15
|
-
import { setupi18n } from "./i18n";
|
|
16
15
|
import type { ThemeMode, Payload } from "./types";
|
|
17
16
|
import { Toast } from "@gradio/statustracker";
|
|
18
17
|
import type { ToastMessage } from "@gradio/statustracker";
|
|
@@ -105,6 +104,7 @@
|
|
|
105
104
|
});
|
|
106
105
|
|
|
107
106
|
let messages: (ToastMessage & { fn_index: number })[] = $state([]);
|
|
107
|
+
let reconnect_interval: ReturnType<typeof setInterval> | null = null;
|
|
108
108
|
|
|
109
109
|
function gradio_event_dispatcher(
|
|
110
110
|
id: number,
|
|
@@ -207,6 +207,35 @@
|
|
|
207
207
|
api_calls = [...api_calls, last_api_call];
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
+
function handle_connection_lost(): void {
|
|
211
|
+
messages = messages.filter((m) => m.type !== "error");
|
|
212
|
+
|
|
213
|
+
++_error_id;
|
|
214
|
+
messages.push({
|
|
215
|
+
title: "Connection Lost",
|
|
216
|
+
message: LOST_CONNECTION_MESSAGE,
|
|
217
|
+
fn_index: -1,
|
|
218
|
+
type: "error",
|
|
219
|
+
id: _error_id,
|
|
220
|
+
duration: null,
|
|
221
|
+
visible: true
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
reconnect_interval = setInterval(async () => {
|
|
225
|
+
try {
|
|
226
|
+
const status = await app.reconnect();
|
|
227
|
+
if (status === "connected" || status === "changed") {
|
|
228
|
+
clearInterval(reconnect_interval!);
|
|
229
|
+
reconnect_interval = null;
|
|
230
|
+
window.location.reload();
|
|
231
|
+
}
|
|
232
|
+
} catch (e) {
|
|
233
|
+
// server still unreachable
|
|
234
|
+
console.debug(e);
|
|
235
|
+
}
|
|
236
|
+
}, 2000);
|
|
237
|
+
}
|
|
238
|
+
|
|
210
239
|
let dep_manager = new DependencyManager(
|
|
211
240
|
dependencies,
|
|
212
241
|
app,
|
|
@@ -214,7 +243,8 @@
|
|
|
214
243
|
app_tree.get_state.bind(app_tree),
|
|
215
244
|
app_tree.rerender.bind(app_tree),
|
|
216
245
|
new_message,
|
|
217
|
-
add_to_api_calls
|
|
246
|
+
add_to_api_calls,
|
|
247
|
+
handle_connection_lost
|
|
218
248
|
);
|
|
219
249
|
|
|
220
250
|
$effect(() => {
|
|
@@ -427,6 +457,7 @@
|
|
|
427
457
|
return () => {
|
|
428
458
|
mut.disconnect();
|
|
429
459
|
res.disconnect();
|
|
460
|
+
if (reconnect_interval) clearInterval(reconnect_interval);
|
|
430
461
|
};
|
|
431
462
|
});
|
|
432
463
|
|
package/dist/src/_init.js
CHANGED
|
@@ -3,7 +3,7 @@ import { dequal } from "dequal";
|
|
|
3
3
|
import { load_component } from "virtual:component-loader";
|
|
4
4
|
import { create_loading_status_store } from "./stores";
|
|
5
5
|
import { _ } from "svelte-i18n";
|
|
6
|
-
import {
|
|
6
|
+
import { has_i18n_marker } from "@gradio/utils";
|
|
7
7
|
const shared_props = [
|
|
8
8
|
"elem_id",
|
|
9
9
|
"elem_classes",
|
|
@@ -225,7 +225,7 @@ export function create_components({ initial_layout = undefined } = {
|
|
|
225
225
|
const _type = instance.type === "walkthrough" ? "walkthroughstep" : "tabitem";
|
|
226
226
|
const child_tab_items = tab_items_props.filter((child) => child.type === _type);
|
|
227
227
|
instance.props.initial_tabs = child_tab_items?.map((child) => ({
|
|
228
|
-
label: child.props.label
|
|
228
|
+
label: has_i18n_marker(child.props.label) ? "" : child.props.label,
|
|
229
229
|
id: child.props.id,
|
|
230
230
|
visible: typeof child.props.visible === "boolean" ||
|
|
231
231
|
child.props.visible === "hidden"
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
export let root: string;
|
|
8
8
|
export let api_count: number;
|
|
9
|
-
export let current_language:
|
|
10
|
-
"python"
|
|
9
|
+
export let current_language:
|
|
10
|
+
| "python"
|
|
11
|
+
| "javascript"
|
|
12
|
+
| "bash"
|
|
13
|
+
| "skill"
|
|
14
|
+
| "mcp" = "python";
|
|
11
15
|
|
|
12
16
|
const dispatch = createEventDispatcher();
|
|
13
17
|
</script>
|
|
@@ -14,7 +14,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
14
14
|
declare const ApiBanner: $$__sveltets_2_IsomorphicComponent<{
|
|
15
15
|
root: string;
|
|
16
16
|
api_count: number;
|
|
17
|
-
current_language?: "python" | "javascript" | "bash" | "mcp";
|
|
17
|
+
current_language?: "python" | "javascript" | "bash" | "skill" | "mcp";
|
|
18
18
|
}, {
|
|
19
19
|
close: CustomEvent<any>;
|
|
20
20
|
} & {
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
import javascript from "./img/javascript.svg";
|
|
20
20
|
import bash from "./img/bash.svg";
|
|
21
21
|
import ResponseSnippet from "./ResponseSnippet.svelte";
|
|
22
|
+
import skill from "./img/skill.svg";
|
|
23
|
+
import SkillSnippet from "./SkillSnippet.svelte";
|
|
22
24
|
import mcp from "./img/mcp.svg";
|
|
23
25
|
import MCPSnippet from "./MCPSnippet.svelte";
|
|
24
26
|
import CopyMarkdown from "./CopyMarkdown.svelte";
|
|
@@ -53,7 +55,8 @@
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export let api_calls: Payload[] = [];
|
|
56
|
-
let current_language: "python" | "javascript" | "bash" | "
|
|
58
|
+
let current_language: "python" | "javascript" | "bash" | "skill" | "mcp" =
|
|
59
|
+
"python";
|
|
57
60
|
|
|
58
61
|
$: sorted_dependencies = (() => {
|
|
59
62
|
const valid = dependencies.filter(
|
|
@@ -81,13 +84,16 @@
|
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
function is_valid_language(lang: string | null): boolean {
|
|
84
|
-
return ["python", "javascript", "bash", "mcp"].includes(
|
|
87
|
+
return ["python", "javascript", "bash", "skill", "mcp"].includes(
|
|
88
|
+
lang ?? ""
|
|
89
|
+
);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
|
|
92
|
+
$: langs = [
|
|
88
93
|
["python", "Python", python],
|
|
89
94
|
["javascript", "JavaScript", javascript],
|
|
90
95
|
["bash", "cURL", bash],
|
|
96
|
+
...(space_id ? [["skill", "Skill", skill] as const] : []),
|
|
91
97
|
["mcp", "MCP", mcp]
|
|
92
98
|
] as const;
|
|
93
99
|
|
|
@@ -277,7 +283,12 @@
|
|
|
277
283
|
|
|
278
284
|
const lang_param = get_query_param("lang");
|
|
279
285
|
if (is_valid_language(lang_param)) {
|
|
280
|
-
current_language = lang_param as
|
|
286
|
+
current_language = lang_param as
|
|
287
|
+
| "python"
|
|
288
|
+
| "javascript"
|
|
289
|
+
| "bash"
|
|
290
|
+
| "skill"
|
|
291
|
+
| "mcp";
|
|
281
292
|
}
|
|
282
293
|
|
|
283
294
|
const mcp_schema_url = `${root}gradio_api/mcp/schema`;
|
|
@@ -398,18 +409,25 @@
|
|
|
398
409
|
API Documentation
|
|
399
410
|
</p>
|
|
400
411
|
{:else}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
412
|
+
{#if current_language !== "skill"}
|
|
413
|
+
<p class="padded">
|
|
414
|
+
{#if current_language == "python" || current_language == "javascript"}
|
|
415
|
+
1. Install the
|
|
416
|
+
<span style="text-transform:capitalize">{current_language}</span
|
|
417
|
+
>
|
|
418
|
+
client (<a
|
|
419
|
+
href={current_language == "python" ? py_docs : js_docs}
|
|
420
|
+
target="_blank">docs</a
|
|
421
|
+
>) if you don't already have it installed.
|
|
422
|
+
{:else if current_language == "bash"}
|
|
423
|
+
1. Confirm that you have cURL installed on your system.
|
|
424
|
+
{/if}
|
|
425
|
+
</p>
|
|
426
|
+
{/if}
|
|
427
|
+
|
|
428
|
+
<div class:hidden={current_language !== "skill"}>
|
|
429
|
+
<SkillSnippet {space_id} />
|
|
430
|
+
</div>
|
|
413
431
|
|
|
414
432
|
<div class:hidden={current_language !== "mcp"}>
|
|
415
433
|
<MCPSnippet
|
|
@@ -427,7 +445,7 @@
|
|
|
427
445
|
/>
|
|
428
446
|
</div>
|
|
429
447
|
|
|
430
|
-
{#if current_language !== "mcp"}
|
|
448
|
+
{#if current_language !== "mcp" && current_language !== "skill"}
|
|
431
449
|
<InstallSnippet {current_language} />
|
|
432
450
|
|
|
433
451
|
<p class="padded">
|
|
@@ -480,25 +498,23 @@
|
|
|
480
498
|
{/if}
|
|
481
499
|
{/if}
|
|
482
500
|
|
|
483
|
-
<div
|
|
501
|
+
<div
|
|
502
|
+
class:hidden={current_language === "mcp" ||
|
|
503
|
+
current_language === "skill"}
|
|
504
|
+
>
|
|
484
505
|
{#each sorted_dependencies as dependency}
|
|
485
506
|
{#if info.named_endpoints["/" + dependency.api_name]}
|
|
486
507
|
<div class="endpoint-container">
|
|
487
508
|
<CodeSnippet
|
|
488
|
-
endpoint_parameters={info.named_endpoints[
|
|
489
|
-
"/" + dependency.api_name
|
|
490
|
-
].parameters}
|
|
491
509
|
{dependency}
|
|
492
510
|
{current_language}
|
|
493
|
-
{root}
|
|
494
|
-
{space_id}
|
|
495
|
-
{username}
|
|
496
|
-
api_prefix={app.api_prefix}
|
|
497
511
|
api_description={info.named_endpoints[
|
|
498
512
|
"/" + dependency.api_name
|
|
499
513
|
].description}
|
|
500
514
|
{analytics}
|
|
501
515
|
{last_api_call}
|
|
516
|
+
code_snippets={info.named_endpoints["/" + dependency.api_name]
|
|
517
|
+
.code_snippets}
|
|
502
518
|
bind:markdown_code_snippets
|
|
503
519
|
/>
|
|
504
520
|
|
|
@@ -1,75 +1,78 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type {
|
|
2
|
+
import type { Dependency, Payload } from "../types";
|
|
3
3
|
import CopyButton from "./CopyButton.svelte";
|
|
4
|
-
import { represent_value, is_potentially_nested_file_data } from "./utils";
|
|
5
4
|
import { Block } from "@gradio/atoms";
|
|
6
5
|
import EndpointDetail from "./EndpointDetail.svelte";
|
|
7
6
|
|
|
8
|
-
interface EndpointParameter {
|
|
9
|
-
label: string;
|
|
10
|
-
type: string;
|
|
11
|
-
python_type: { type: string };
|
|
12
|
-
component: string;
|
|
13
|
-
example_input: string;
|
|
14
|
-
serializer: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
7
|
export let dependency: Dependency;
|
|
18
|
-
export let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
export let current_language:
|
|
9
|
+
| "python"
|
|
10
|
+
| "javascript"
|
|
11
|
+
| "bash"
|
|
12
|
+
| "skill"
|
|
13
|
+
| "mcp";
|
|
24
14
|
export let api_description: string | null = null;
|
|
25
15
|
export let analytics: Record<string, any>;
|
|
26
16
|
export let markdown_code_snippets: Record<string, Record<string, string>>;
|
|
17
|
+
export let code_snippets: Record<string, string>;
|
|
27
18
|
export let last_api_call: Payload | null = null;
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
let blob_components = ["Audio", "File", "Image", "Video"];
|
|
38
|
-
let blob_examples: any[] = endpoint_parameters.filter(
|
|
39
|
-
(param: EndpointParameter) => blob_components.includes(param.component)
|
|
40
|
-
);
|
|
20
|
+
$: markdown_code_snippets[
|
|
21
|
+
dependency.api_name as keyof typeof markdown_code_snippets
|
|
22
|
+
] = {
|
|
23
|
+
python: code_snippets.python || "",
|
|
24
|
+
javascript: code_snippets.javascript || "",
|
|
25
|
+
bash: code_snippets.bash || ""
|
|
26
|
+
};
|
|
41
27
|
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
function escape_html(text: string): string {
|
|
29
|
+
return text
|
|
30
|
+
.replace(/&/g, "&")
|
|
31
|
+
.replace(/</g, "<")
|
|
32
|
+
.replace(/>/g, ">");
|
|
33
|
+
}
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
function highlight_python(code: string): string {
|
|
36
|
+
let html = escape_html(code);
|
|
37
|
+
html = html.replace(
|
|
38
|
+
/\b(from|import|print)\b/g,
|
|
39
|
+
'<span class="kw">$1</span>'
|
|
40
|
+
);
|
|
41
|
+
html = html.replace(
|
|
42
|
+
/(Client\()("[^"]*")(\))/g,
|
|
43
|
+
'$1<span class="str">$2</span>$3'
|
|
44
|
+
);
|
|
45
|
+
html = html.replace(
|
|
46
|
+
/(api_name=)("[^"]*")/g,
|
|
47
|
+
'$1<span class="api-name">$2</span>'
|
|
48
|
+
);
|
|
49
|
+
return html;
|
|
50
|
+
}
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
function highlight_javascript(code: string): string {
|
|
53
|
+
let html = escape_html(code);
|
|
54
|
+
html = html.replace(
|
|
55
|
+
/\b(import|from|const|await)\b/g,
|
|
56
|
+
'<span class="kw">$1</span>'
|
|
57
|
+
);
|
|
58
|
+
html = html.replace(
|
|
59
|
+
/(Client\.connect\()("[^"]*")(\))/g,
|
|
60
|
+
'$1<span class="str">$2</span>$3'
|
|
61
|
+
);
|
|
62
|
+
html = html.replace(
|
|
63
|
+
/(\.predict\()("[^"]*")/g,
|
|
64
|
+
'$1<span class="api-name">$2</span>'
|
|
65
|
+
);
|
|
66
|
+
return html;
|
|
67
|
+
}
|
|
51
68
|
|
|
52
|
-
function
|
|
53
|
-
|
|
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;
|
|
69
|
+
function highlight_bash(code: string): string {
|
|
70
|
+
return escape_html(code);
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
$:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
python: python_code?.innerText || "",
|
|
70
|
-
javascript: js_code?.innerText || "",
|
|
71
|
-
bash: bash_post_code?.innerText || ""
|
|
72
|
-
};
|
|
73
|
+
$: python_html = highlight_python(code_snippets.python || "");
|
|
74
|
+
$: js_html = highlight_javascript(code_snippets.javascript || "");
|
|
75
|
+
$: bash_html = highlight_bash(code_snippets.bash || "");
|
|
73
76
|
</script>
|
|
74
77
|
|
|
75
78
|
<div class="container">
|
|
@@ -84,37 +87,9 @@
|
|
|
84
87
|
<Block>
|
|
85
88
|
<code>
|
|
86
89
|
<div class="copy">
|
|
87
|
-
<CopyButton code={
|
|
88
|
-
</div>
|
|
89
|
-
<div bind:this={python_code}>
|
|
90
|
-
<pre><span class="highlight">from</span> gradio_client <span
|
|
91
|
-
class="highlight">import</span
|
|
92
|
-
> Client{#if has_file_path}, handle_file{/if}
|
|
93
|
-
|
|
94
|
-
client = Client(<span class="token string">"{space_id || root}"</span
|
|
95
|
-
>{#if username !== null}, auth=("{username}", **password**){/if})
|
|
96
|
-
result = client.<span class="highlight">predict</span
|
|
97
|
-
>(<!--
|
|
98
|
-
-->{#each endpoint_parameters as param, i}<!--
|
|
99
|
-
-->
|
|
100
|
-
{param.parameter_name
|
|
101
|
-
? param.parameter_name + "="
|
|
102
|
-
: ""}<span
|
|
103
|
-
class:recent-value={is_most_recently_used &&
|
|
104
|
-
actual_data?.[i] !== undefined}
|
|
105
|
-
>{represent_value(
|
|
106
|
-
getParameterValue(param, i),
|
|
107
|
-
param.python_type.type,
|
|
108
|
-
"py"
|
|
109
|
-
)}</span
|
|
110
|
-
>,{/each}<!--
|
|
111
|
-
|
|
112
|
-
-->
|
|
113
|
-
api_name=<span class="api-name">"/{dependency.api_name}"</span><!--
|
|
114
|
-
-->
|
|
115
|
-
)
|
|
116
|
-
<span class="highlight">print</span>(result)</pre>
|
|
90
|
+
<CopyButton code={code_snippets.python || ""} />
|
|
117
91
|
</div>
|
|
92
|
+
<pre>{@html python_html}</pre>
|
|
118
93
|
</code>
|
|
119
94
|
</Block>
|
|
120
95
|
</div>
|
|
@@ -122,53 +97,9 @@ result = client.<span class="highlight">predict</span
|
|
|
122
97
|
<Block>
|
|
123
98
|
<code>
|
|
124
99
|
<div class="copy">
|
|
125
|
-
<CopyButton code={
|
|
126
|
-
</div>
|
|
127
|
-
<div bind:this={js_code}>
|
|
128
|
-
<pre>import { Client } from "@gradio/client";
|
|
129
|
-
{#each blob_examples as { component, example_input }, i}<!--
|
|
130
|
-
-->
|
|
131
|
-
const response_{i} = await fetch("{example_input.url}");
|
|
132
|
-
const example{component} = await response_{i}.blob();
|
|
133
|
-
{/each}<!--
|
|
134
|
-
-->
|
|
135
|
-
const client = await Client.connect(<span class="token string"
|
|
136
|
-
>"{space_id || root}"</span
|
|
137
|
-
>{#if username !== null}, {auth: ["{username}", **password**]}{/if});
|
|
138
|
-
const result = await client.predict(<span class="api-name"
|
|
139
|
-
>"/{dependency.api_name}"</span
|
|
140
|
-
>, { <!--
|
|
141
|
-
-->{#each endpoint_parameters as param, i}<!--
|
|
142
|
-
-->{#if blob_components.includes(param.component)}<!--
|
|
143
|
-
-->
|
|
144
|
-
<span
|
|
145
|
-
class="example-inputs"
|
|
146
|
-
>{param.parameter_name}: example{param.component}</span
|
|
147
|
-
>, <!--
|
|
148
|
-
--><span class="desc"><!--
|
|
149
|
-
--></span
|
|
150
|
-
><!--
|
|
151
|
-
-->{:else}<!--
|
|
152
|
-
-->
|
|
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,
|
|
161
|
-
"js"
|
|
162
|
-
)}</span
|
|
163
|
-
>, <!--
|
|
164
|
-
--><!--
|
|
165
|
-
-->{/if}
|
|
166
|
-
{/each}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
console.log(result.data);
|
|
170
|
-
</pre>
|
|
100
|
+
<CopyButton code={code_snippets.javascript || ""} />
|
|
171
101
|
</div>
|
|
102
|
+
<pre>{@html js_html}</pre>
|
|
172
103
|
</code>
|
|
173
104
|
</Block>
|
|
174
105
|
</div>
|
|
@@ -176,29 +107,9 @@ result = client.<span class="highlight">predict</span
|
|
|
176
107
|
<Block>
|
|
177
108
|
<code>
|
|
178
109
|
<div class="copy">
|
|
179
|
-
<CopyButton code={
|
|
180
|
-
</div>
|
|
181
|
-
|
|
182
|
-
<div bind:this={bash_post_code}>
|
|
183
|
-
<pre>curl -X POST {normalised_root}{normalised_api_prefix}/call/{dependency.api_name} -s -H "Content-Type: application/json" -d '{"{"}
|
|
184
|
-
"data": [{#each endpoint_parameters as param, i}
|
|
185
|
-
<!--
|
|
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},
|
|
196
|
-
{/if}
|
|
197
|
-
{/each}
|
|
198
|
-
]{"}"}' \
|
|
199
|
-
| awk -F'"' '{"{"} print $4{"}"}' \
|
|
200
|
-
| read EVENT_ID; curl -N {normalised_root}{normalised_api_prefix}/call/{dependency.api_name}/$EVENT_ID</pre>
|
|
110
|
+
<CopyButton code={code_snippets.bash || ""} />
|
|
201
111
|
</div>
|
|
112
|
+
<pre>{@html bash_html}</pre>
|
|
202
113
|
</code>
|
|
203
114
|
</Block>
|
|
204
115
|
</div>
|
|
@@ -212,11 +123,6 @@ result = client.<span class="highlight">predict</span
|
|
|
212
123
|
tab-size: 2;
|
|
213
124
|
}
|
|
214
125
|
|
|
215
|
-
.token.string {
|
|
216
|
-
display: contents;
|
|
217
|
-
color: var(--color-accent-base);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
126
|
code {
|
|
221
127
|
position: relative;
|
|
222
128
|
display: block;
|
|
@@ -238,21 +144,12 @@ result = client.<span class="highlight">predict</span
|
|
|
238
144
|
margin-bottom: var(--size-3);
|
|
239
145
|
}
|
|
240
146
|
|
|
241
|
-
.
|
|
242
|
-
color: var(--body-text-color-subdued);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
.api-name {
|
|
147
|
+
:global(.api-name) {
|
|
246
148
|
color: var(--color-accent);
|
|
247
149
|
}
|
|
248
150
|
|
|
249
|
-
.
|
|
250
|
-
color:
|
|
251
|
-
background: #fff4e6;
|
|
252
|
-
border: 1px solid #ffd9b3;
|
|
253
|
-
border-radius: var(--radius-sm);
|
|
254
|
-
padding: 1px 4px;
|
|
255
|
-
font-weight: var(--weight-medium);
|
|
151
|
+
:global(.str) {
|
|
152
|
+
color: var(--color-accent-base);
|
|
256
153
|
}
|
|
257
154
|
|
|
258
155
|
.hidden {
|
|
@@ -14,15 +14,11 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
14
14
|
}
|
|
15
15
|
declare const CodeSnippet: $$__sveltets_2_IsomorphicComponent<{
|
|
16
16
|
dependency: Dependency;
|
|
17
|
-
|
|
18
|
-
api_prefix: string;
|
|
19
|
-
space_id: string | null;
|
|
20
|
-
endpoint_parameters: any;
|
|
21
|
-
username: string | null;
|
|
22
|
-
current_language: "python" | "javascript" | "bash" | "mcp";
|
|
17
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp";
|
|
23
18
|
api_description?: string | null;
|
|
24
19
|
analytics: Record<string, any>;
|
|
25
20
|
markdown_code_snippets: Record<string, Record<string, string>>;
|
|
21
|
+
code_snippets: Record<string, string>;
|
|
26
22
|
last_api_call?: Payload | null;
|
|
27
23
|
}, {
|
|
28
24
|
[evt: string]: CustomEvent<any>;
|
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
import { represent_value } from "./utils";
|
|
11
11
|
import type { Dependency } from "../types";
|
|
12
12
|
|
|
13
|
-
export let current_language:
|
|
13
|
+
export let current_language:
|
|
14
|
+
| "python"
|
|
15
|
+
| "javascript"
|
|
16
|
+
| "bash"
|
|
17
|
+
| "skill"
|
|
18
|
+
| "mcp";
|
|
14
19
|
export let space_id: string | null;
|
|
15
20
|
export let root: string;
|
|
16
21
|
export let api_count: number;
|
|
@@ -362,7 +367,7 @@ Read the documentation above so I can ask questions about it.`
|
|
|
362
367
|
}
|
|
363
368
|
|
|
364
369
|
async function copyMarkdown(
|
|
365
|
-
current_language: "python" | "javascript" | "bash" | "mcp"
|
|
370
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp"
|
|
366
371
|
): Promise<void> {
|
|
367
372
|
try {
|
|
368
373
|
if (!markdown_content[current_language]) {
|
|
@@ -13,7 +13,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
13
13
|
z_$$bindings?: Bindings;
|
|
14
14
|
}
|
|
15
15
|
declare const CopyMarkdown: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
-
current_language: "python" | "javascript" | "bash" | "mcp";
|
|
16
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp";
|
|
17
17
|
space_id: string | null;
|
|
18
18
|
root: string;
|
|
19
19
|
api_count: number;
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
import CopyButton from "./CopyButton.svelte";
|
|
3
3
|
import { Block } from "@gradio/atoms";
|
|
4
4
|
|
|
5
|
-
export let current_language:
|
|
5
|
+
export let current_language:
|
|
6
|
+
| "python"
|
|
7
|
+
| "javascript"
|
|
8
|
+
| "bash"
|
|
9
|
+
| "skill"
|
|
10
|
+
| "mcp";
|
|
6
11
|
|
|
7
12
|
let py_install = "pip install gradio_client";
|
|
8
13
|
let js_install = "npm i -D @gradio/client";
|
|
@@ -12,7 +12,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
12
|
z_$$bindings?: Bindings;
|
|
13
13
|
}
|
|
14
14
|
declare const InstallSnippet: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
-
current_language: "python" | "javascript" | "bash" | "mcp";
|
|
15
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp";
|
|
16
16
|
}, {
|
|
17
17
|
[evt: string]: CustomEvent<any>;
|
|
18
18
|
}, {}, {}, string>;
|