@gradio/core 1.4.1 → 1.5.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 +74 -0
- package/dist/src/api_docs/ApiBanner.svelte +7 -5
- package/dist/src/api_docs/ApiBanner.svelte.d.ts +1 -1
- package/dist/src/api_docs/ApiDocs.svelte +96 -14
- package/dist/src/api_docs/CodeSnippet.svelte +14 -8
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +2 -2
- package/dist/src/api_docs/CopyMarkdown.svelte +17 -10
- package/dist/src/api_docs/CopyMarkdown.svelte.d.ts +1 -1
- package/dist/src/api_docs/InstallSnippet.svelte +77 -9
- package/dist/src/api_docs/InstallSnippet.svelte.d.ts +2 -1
- package/dist/src/api_docs/ParametersSnippet.svelte +8 -5
- package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/RecordingSnippet.svelte +5 -5
- package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/ResponseSnippet.svelte +9 -4
- package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +1 -1
- package/dist/src/api_docs/img/agent.svg +13 -0
- package/dist/src/api_docs/img/hf-logo.svg +8 -0
- package/dist/src/gradio_helper.js +2 -1
- package/dist/src/init.svelte.js +47 -5
- package/package.json +51 -51
- package/src/api_docs/ApiBanner.svelte +7 -5
- package/src/api_docs/ApiDocs.svelte +96 -14
- package/src/api_docs/CodeSnippet.svelte +14 -8
- package/src/api_docs/CopyMarkdown.svelte +17 -10
- package/src/api_docs/InstallSnippet.svelte +77 -9
- package/src/api_docs/ParametersSnippet.svelte +8 -5
- package/src/api_docs/RecordingSnippet.svelte +5 -5
- package/src/api_docs/ResponseSnippet.svelte +9 -4
- package/src/api_docs/img/agent.svg +13 -0
- package/src/api_docs/img/hf-logo.svg +8 -0
- package/src/gradio_helper.ts +4 -1
- package/src/init.svelte.ts +55 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,79 @@
|
|
|
1
1
|
# @gradio/core
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#13289](https://github.com/gradio-app/gradio/pull/13289) [`d6f24df`](https://github.com/gradio-app/gradio/commit/d6f24df6233e7882746ba6e49307a34a11101ea1) - Improve curl info. Thanks @freddyaboulton!
|
|
8
|
+
- [#13277](https://github.com/gradio-app/gradio/pull/13277) [`cab8be0`](https://github.com/gradio-app/gradio/commit/cab8be062deb958a718aae25175e07fb013dfd4f) - CLI/Agent API Docs. Thanks @freddyaboulton!
|
|
9
|
+
|
|
10
|
+
### Dependency updates
|
|
11
|
+
|
|
12
|
+
- @gradio/atoms@0.24.0
|
|
13
|
+
- @gradio/statustracker@0.14.1
|
|
14
|
+
- @gradio/checkbox@0.7.0
|
|
15
|
+
- @gradio/upload@0.17.9
|
|
16
|
+
- @gradio/textbox@0.13.9
|
|
17
|
+
- @gradio/tabs@0.5.10
|
|
18
|
+
- @gradio/code@0.17.8
|
|
19
|
+
- @gradio/html@0.12.3
|
|
20
|
+
- @gradio/paramviewer@0.9.9
|
|
21
|
+
- @gradio/file@0.14.8
|
|
22
|
+
- @gradio/gallery@0.17.7
|
|
23
|
+
- @gradio/plot@0.10.9
|
|
24
|
+
- @gradio/dropdown@0.12.0
|
|
25
|
+
- @gradio/image@0.26.3
|
|
26
|
+
- @gradio/video@0.20.8
|
|
27
|
+
- @gradio/audio@0.23.3
|
|
28
|
+
|
|
29
|
+
## 1.4.2
|
|
30
|
+
|
|
31
|
+
### Dependency updates
|
|
32
|
+
|
|
33
|
+
- @gradio/atoms@0.23.1
|
|
34
|
+
- @gradio/statustracker@0.14.0
|
|
35
|
+
- @gradio/client@2.2.0
|
|
36
|
+
- @gradio/textbox@0.13.8
|
|
37
|
+
- @gradio/column@0.3.3
|
|
38
|
+
- @gradio/image@0.26.2
|
|
39
|
+
- @gradio/file@0.14.7
|
|
40
|
+
- @gradio/video@0.20.7
|
|
41
|
+
- @gradio/code@0.17.7
|
|
42
|
+
- @gradio/html@0.12.2
|
|
43
|
+
- @gradio/paramviewer@0.9.8
|
|
44
|
+
- @gradio/gallery@0.17.6
|
|
45
|
+
- @gradio/plot@0.10.8
|
|
46
|
+
- @gradio/checkbox@0.6.7
|
|
47
|
+
- @gradio/dropdown@0.11.8
|
|
48
|
+
- @gradio/audio@0.23.2
|
|
49
|
+
|
|
50
|
+
## 1.4.2
|
|
51
|
+
|
|
52
|
+
### Fixes
|
|
53
|
+
|
|
54
|
+
- [#13048](https://github.com/gradio-app/gradio/pull/13048) [`a5d4096`](https://github.com/gradio-app/gradio/commit/a5d40965bba21a832da522127048926b71c1a6dd) - Fix Tab Interactive Bug. Thanks @freddyaboulton!
|
|
55
|
+
- [#13172](https://github.com/gradio-app/gradio/pull/13172) [`03a9d4c`](https://github.com/gradio-app/gradio/commit/03a9d4c99f3c9466e4fc162d02800850ed67a29e) - fix: prevent [object Object] when label matches a nested i18n key. Thanks @mango766!
|
|
56
|
+
|
|
57
|
+
### Dependency updates
|
|
58
|
+
|
|
59
|
+
- @gradio/utils@0.12.2
|
|
60
|
+
- @gradio/atoms@0.23.0
|
|
61
|
+
- @gradio/statustracker@0.13.1
|
|
62
|
+
- @gradio/upload@0.17.8
|
|
63
|
+
- @gradio/tabs@0.5.9
|
|
64
|
+
- @gradio/code@0.17.6
|
|
65
|
+
- @gradio/html@0.12.1
|
|
66
|
+
- @gradio/paramviewer@0.9.7
|
|
67
|
+
- @gradio/image@0.26.1
|
|
68
|
+
- @gradio/checkbox@0.6.6
|
|
69
|
+
- @gradio/video@0.20.6
|
|
70
|
+
- @gradio/file@0.14.6
|
|
71
|
+
- @gradio/gallery@0.17.5
|
|
72
|
+
- @gradio/plot@0.10.7
|
|
73
|
+
- @gradio/textbox@0.13.7
|
|
74
|
+
- @gradio/dropdown@0.11.7
|
|
75
|
+
- @gradio/audio@0.23.1
|
|
76
|
+
|
|
3
77
|
## 1.4.1
|
|
4
78
|
|
|
5
79
|
### Fixes
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
| "javascript"
|
|
12
12
|
| "bash"
|
|
13
13
|
| "skill"
|
|
14
|
-
| "mcp"
|
|
14
|
+
| "mcp"
|
|
15
|
+
| "cli" = "python";
|
|
15
16
|
|
|
16
17
|
const dispatch = createEventDispatcher();
|
|
17
18
|
</script>
|
|
@@ -19,13 +20,14 @@
|
|
|
19
20
|
<h2>
|
|
20
21
|
<img src={api_logo} alt="" />
|
|
21
22
|
<div class="title">
|
|
22
|
-
{#if current_language === "mcp"}MCP{:else}API{/if}
|
|
23
|
+
{#if current_language === "mcp"}MCP{:else if current_language === "cli"}CLI{:else}API{/if}
|
|
24
|
+
documentation
|
|
23
25
|
<div class="url">
|
|
24
26
|
{root}
|
|
25
27
|
</div>
|
|
26
28
|
</div>
|
|
27
29
|
<span class="counts">
|
|
28
|
-
{#if current_language !== "mcp"}
|
|
30
|
+
{#if current_language !== "mcp" && current_language !== "cli"}
|
|
29
31
|
<BaseButton
|
|
30
32
|
size="sm"
|
|
31
33
|
variant="secondary"
|
|
@@ -38,8 +40,8 @@
|
|
|
38
40
|
{/if}
|
|
39
41
|
<p>
|
|
40
42
|
<span class="url">{api_count}</span>
|
|
41
|
-
{#if current_language
|
|
42
|
-
|
|
43
|
+
{#if current_language === "mcp"}MCP Tool{:else if current_language === "cli"}CLI
|
|
44
|
+
endpoint{:else}API endpoint{/if}{#if api_count > 1}s{/if}<br />
|
|
43
45
|
</p>
|
|
44
46
|
</span>
|
|
45
47
|
</h2>
|
|
@@ -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" | "skill" | "mcp";
|
|
17
|
+
current_language?: "python" | "javascript" | "bash" | "skill" | "mcp" | "cli";
|
|
18
18
|
}, {
|
|
19
19
|
close: CustomEvent<any>;
|
|
20
20
|
} & {
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
import skill from "./img/skill.svg";
|
|
23
23
|
import SkillSnippet from "./SkillSnippet.svelte";
|
|
24
24
|
import mcp from "./img/mcp.svg";
|
|
25
|
+
import agent from "./img/agent.svg";
|
|
26
|
+
import hf_logo from "./img/hf-logo.svg";
|
|
27
|
+
import gradio_logo from "../images/logo.svg";
|
|
25
28
|
import MCPSnippet from "./MCPSnippet.svelte";
|
|
26
29
|
import CopyMarkdown from "./CopyMarkdown.svelte";
|
|
27
30
|
|
|
@@ -55,8 +58,17 @@
|
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
export let api_calls: Payload[] = [];
|
|
58
|
-
let current_language:
|
|
59
|
-
"python"
|
|
61
|
+
let current_language:
|
|
62
|
+
| "python"
|
|
63
|
+
| "javascript"
|
|
64
|
+
| "bash"
|
|
65
|
+
| "skill"
|
|
66
|
+
| "mcp"
|
|
67
|
+
| "cli" = "python";
|
|
68
|
+
|
|
69
|
+
let cli_flavor: "hf" | "gradio" = "gradio";
|
|
70
|
+
|
|
71
|
+
$: cli_command = cli_flavor === "hf" ? "hf gradio" : "gradio";
|
|
60
72
|
|
|
61
73
|
$: sorted_dependencies = (() => {
|
|
62
74
|
const valid = dependencies.filter(
|
|
@@ -84,7 +96,7 @@
|
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
function is_valid_language(lang: string | null): boolean {
|
|
87
|
-
return ["python", "javascript", "bash", "skill", "mcp"].includes(
|
|
99
|
+
return ["python", "javascript", "bash", "skill", "mcp", "cli"].includes(
|
|
88
100
|
lang ?? ""
|
|
89
101
|
);
|
|
90
102
|
}
|
|
@@ -92,6 +104,7 @@
|
|
|
92
104
|
$: langs = [
|
|
93
105
|
["python", "Python", python],
|
|
94
106
|
["javascript", "JavaScript", javascript],
|
|
107
|
+
["cli", "CLI", agent],
|
|
95
108
|
["bash", "cURL", bash],
|
|
96
109
|
...(space_id ? [["skill", "Skill", skill] as const] : []),
|
|
97
110
|
["mcp", "MCP", mcp]
|
|
@@ -264,14 +277,25 @@
|
|
|
264
277
|
}
|
|
265
278
|
}
|
|
266
279
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
280
|
+
$: markdown_code_snippets = (() => {
|
|
281
|
+
const out: Record<string, Record<string, string>> = {};
|
|
282
|
+
if (!info?.named_endpoints) return out;
|
|
283
|
+
for (const dep of dependencies) {
|
|
284
|
+
const ep = info.named_endpoints["/" + dep.api_name];
|
|
285
|
+
if (!ep?.code_snippets) continue;
|
|
286
|
+
const snippets = ep.code_snippets;
|
|
287
|
+
out[dep.api_name] = {
|
|
288
|
+
python: snippets.python || "",
|
|
289
|
+
javascript: snippets.javascript || "",
|
|
290
|
+
bash: snippets.bash || "",
|
|
291
|
+
cli: (snippets.cli || "").replace("{command}", cli_command)
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
})();
|
|
270
296
|
|
|
271
297
|
let config_snippets: Record<string, string> = {};
|
|
272
298
|
|
|
273
|
-
$: config_snippets;
|
|
274
|
-
|
|
275
299
|
onMount(() => {
|
|
276
300
|
const controller = new AbortController();
|
|
277
301
|
const signal = controller.signal;
|
|
@@ -288,6 +312,7 @@
|
|
|
288
312
|
| "javascript"
|
|
289
313
|
| "bash"
|
|
290
314
|
| "skill"
|
|
315
|
+
| "cli"
|
|
291
316
|
| "mcp";
|
|
292
317
|
}
|
|
293
318
|
|
|
@@ -367,7 +392,7 @@
|
|
|
367
392
|
set_query_param("lang", language);
|
|
368
393
|
}}
|
|
369
394
|
>
|
|
370
|
-
<img src={img} alt="" />
|
|
395
|
+
<img src={img} alt="" class:agent-icon={language === "cli"} />
|
|
371
396
|
{display_name}
|
|
372
397
|
</li>
|
|
373
398
|
{/each}
|
|
@@ -421,10 +446,39 @@
|
|
|
421
446
|
>) if you don't already have it installed.
|
|
422
447
|
{:else if current_language == "bash"}
|
|
423
448
|
1. Confirm that you have cURL installed on your system.
|
|
449
|
+
{:else if current_language == "cli"}
|
|
450
|
+
1. Install the CLI if you don't already have it installed.
|
|
424
451
|
{/if}
|
|
425
452
|
</p>
|
|
426
453
|
{/if}
|
|
427
454
|
|
|
455
|
+
{#if current_language === "cli"}
|
|
456
|
+
<div class="cli-flavor-selector">
|
|
457
|
+
<li
|
|
458
|
+
class="snippet {cli_flavor === 'gradio'
|
|
459
|
+
? 'current-lang'
|
|
460
|
+
: 'inactive-lang'}"
|
|
461
|
+
on:click={() => {
|
|
462
|
+
cli_flavor = "gradio";
|
|
463
|
+
}}
|
|
464
|
+
>
|
|
465
|
+
<img src={gradio_logo} alt="Gradio" />
|
|
466
|
+
Gradio CLI
|
|
467
|
+
</li>
|
|
468
|
+
<li
|
|
469
|
+
class="snippet {cli_flavor === 'hf'
|
|
470
|
+
? 'current-lang'
|
|
471
|
+
: 'inactive-lang'}"
|
|
472
|
+
on:click={() => {
|
|
473
|
+
cli_flavor = "hf";
|
|
474
|
+
}}
|
|
475
|
+
>
|
|
476
|
+
<img src={hf_logo} alt="HF" />
|
|
477
|
+
HF CLI
|
|
478
|
+
</li>
|
|
479
|
+
</div>
|
|
480
|
+
{/if}
|
|
481
|
+
|
|
428
482
|
<div class:hidden={current_language !== "skill"}>
|
|
429
483
|
<SkillSnippet {space_id} />
|
|
430
484
|
</div>
|
|
@@ -446,7 +500,7 @@
|
|
|
446
500
|
</div>
|
|
447
501
|
|
|
448
502
|
{#if current_language !== "mcp" && current_language !== "skill"}
|
|
449
|
-
<InstallSnippet {current_language} />
|
|
503
|
+
<InstallSnippet {current_language} {cli_flavor} />
|
|
450
504
|
|
|
451
505
|
<p class="padded">
|
|
452
506
|
2. Find the API endpoint below corresponding to your desired
|
|
@@ -483,7 +537,15 @@
|
|
|
483
537
|
<code>GET</code> request to fetch the results. In these
|
|
484
538
|
snippets, we've used <code>awk</code> and <code>read</code> to
|
|
485
539
|
parse the results, combining these two requests into one command
|
|
486
|
-
for ease of use.
|
|
540
|
+
for ease of use.
|
|
541
|
+
<br /> <br />
|
|
542
|
+
If your endpoint accepts files, you must first upload them via a
|
|
543
|
+
<code>POST</code> to <code>/upload</code>, then reference the
|
|
544
|
+
returned path with the <code>meta</code> key:
|
|
545
|
+
<code
|
|
546
|
+
>{"{"}"path": "...", "meta": {"{"}"_type": "gradio.FileData"{"}"}{"}"}
|
|
547
|
+
</code>.
|
|
548
|
+
{#if username !== null}
|
|
487
549
|
Note: connecting to an authenticated app requires an
|
|
488
550
|
additional request.{/if} See
|
|
489
551
|
<a href={bash_docs} target="_blank">curl docs</a>.
|
|
@@ -515,7 +577,7 @@
|
|
|
515
577
|
{last_api_call}
|
|
516
578
|
code_snippets={info.named_endpoints["/" + dependency.api_name]
|
|
517
579
|
.code_snippets}
|
|
518
|
-
|
|
580
|
+
{cli_command}
|
|
519
581
|
/>
|
|
520
582
|
|
|
521
583
|
<ParametersSnippet
|
|
@@ -525,7 +587,9 @@
|
|
|
525
587
|
js_returns={js_info.named_endpoints["/" + dependency.api_name]
|
|
526
588
|
.parameters}
|
|
527
589
|
{is_running}
|
|
528
|
-
{current_language
|
|
590
|
+
current_language={current_language === "cli"
|
|
591
|
+
? "python"
|
|
592
|
+
: current_language}
|
|
529
593
|
/>
|
|
530
594
|
|
|
531
595
|
<ResponseSnippet
|
|
@@ -535,7 +599,9 @@
|
|
|
535
599
|
js_returns={js_info.named_endpoints["/" + dependency.api_name]
|
|
536
600
|
.returns}
|
|
537
601
|
{is_running}
|
|
538
|
-
{current_language
|
|
602
|
+
current_language={current_language === "cli"
|
|
603
|
+
? "python"
|
|
604
|
+
: current_language}
|
|
539
605
|
/>
|
|
540
606
|
</div>
|
|
541
607
|
{/if}
|
|
@@ -739,4 +805,20 @@
|
|
|
739
805
|
.hidden {
|
|
740
806
|
display: none;
|
|
741
807
|
}
|
|
808
|
+
|
|
809
|
+
.cli-flavor-selector {
|
|
810
|
+
display: flex;
|
|
811
|
+
align-items: center;
|
|
812
|
+
margin-bottom: var(--size-4);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
.cli-flavor-selector > * + * {
|
|
816
|
+
margin-left: var(--size-2);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
@media (prefers-color-scheme: dark) {
|
|
820
|
+
.agent-icon {
|
|
821
|
+
filter: invert(1);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
742
824
|
</style>
|
|
@@ -10,20 +10,15 @@
|
|
|
10
10
|
| "javascript"
|
|
11
11
|
| "bash"
|
|
12
12
|
| "skill"
|
|
13
|
+
| "cli"
|
|
13
14
|
| "mcp";
|
|
14
15
|
export let api_description: string | null = null;
|
|
15
16
|
export let analytics: Record<string, any>;
|
|
16
|
-
export let markdown_code_snippets: Record<string, Record<string, string>>;
|
|
17
17
|
export let code_snippets: Record<string, string>;
|
|
18
18
|
export let last_api_call: Payload | null = null;
|
|
19
|
+
export let cli_command = "";
|
|
19
20
|
|
|
20
|
-
$:
|
|
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
|
-
};
|
|
21
|
+
$: cli_code = (code_snippets.cli || "").replace("{command}", cli_command);
|
|
27
22
|
|
|
28
23
|
function escape_html(text: string): string {
|
|
29
24
|
return text
|
|
@@ -73,6 +68,7 @@
|
|
|
73
68
|
$: python_html = highlight_python(code_snippets.python || "");
|
|
74
69
|
$: js_html = highlight_javascript(code_snippets.javascript || "");
|
|
75
70
|
$: bash_html = highlight_bash(code_snippets.bash || "");
|
|
71
|
+
$: cli_html = highlight_bash(cli_code);
|
|
76
72
|
</script>
|
|
77
73
|
|
|
78
74
|
<div class="container">
|
|
@@ -113,6 +109,16 @@
|
|
|
113
109
|
</code>
|
|
114
110
|
</Block>
|
|
115
111
|
</div>
|
|
112
|
+
<div class:hidden={current_language !== "cli"}>
|
|
113
|
+
<Block>
|
|
114
|
+
<code>
|
|
115
|
+
<div class="copy">
|
|
116
|
+
<CopyButton code={cli_code} />
|
|
117
|
+
</div>
|
|
118
|
+
<pre>{@html cli_html}</pre>
|
|
119
|
+
</code>
|
|
120
|
+
</Block>
|
|
121
|
+
</div>
|
|
116
122
|
</div>
|
|
117
123
|
|
|
118
124
|
<style>
|
|
@@ -14,12 +14,12 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
14
14
|
}
|
|
15
15
|
declare const CodeSnippet: $$__sveltets_2_IsomorphicComponent<{
|
|
16
16
|
dependency: Dependency;
|
|
17
|
-
current_language: "python" | "javascript" | "bash" | "skill" | "mcp";
|
|
17
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "cli" | "mcp";
|
|
18
18
|
api_description?: string | null;
|
|
19
19
|
analytics: Record<string, any>;
|
|
20
|
-
markdown_code_snippets: Record<string, Record<string, string>>;
|
|
21
20
|
code_snippets: Record<string, string>;
|
|
22
21
|
last_api_call?: Payload | null;
|
|
22
|
+
cli_command?: string;
|
|
23
23
|
}, {
|
|
24
24
|
[evt: string]: CustomEvent<any>;
|
|
25
25
|
}, {}, {}, string>;
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
| "javascript"
|
|
16
16
|
| "bash"
|
|
17
17
|
| "skill"
|
|
18
|
-
| "mcp"
|
|
18
|
+
| "mcp"
|
|
19
|
+
| "cli";
|
|
19
20
|
export let space_id: string | null;
|
|
20
21
|
export let root: string;
|
|
21
22
|
export let api_count: number;
|
|
@@ -153,7 +154,9 @@ curl --version
|
|
|
153
154
|
|
|
154
155
|
2. Find the API endpoint below corresponding to your desired function in the app. Copy the code snippet, replacing the placeholder values with your own input data.
|
|
155
156
|
|
|
156
|
-
Making a prediction and getting a result requires 2 requests: a POST and a GET request. The POST request returns an EVENT_ID, which is used in the second GET request to fetch the results. In these snippets, we've used awk and read to parse the results, combining these two requests into one command for ease of use.
|
|
157
|
+
Making a prediction and getting a result requires 2 requests: a POST and a GET request. The POST request returns an EVENT_ID, which is used in the second GET request to fetch the results. In these snippets, we've used awk and read to parse the results, combining these two requests into one command for ease of use.
|
|
158
|
+
|
|
159
|
+
If your endpoint accepts files, you must first upload them via a POST to \`/upload\`, then reference the returned path with the meta key: \`{"path": "...", "meta": {"_type": "gradio.FileData"}}\`. See [curl docs](${bash_docs}).
|
|
157
160
|
|
|
158
161
|
${dependencies
|
|
159
162
|
.filter(
|
|
@@ -169,21 +172,21 @@ ${info?.named_endpoints["/" + d.api_name]?.description ? "Description: " + info?
|
|
|
169
172
|
${markdown_code_snippets[d.api_name as keyof typeof markdown_code_snippets]?.bash}
|
|
170
173
|
\`\`\`
|
|
171
174
|
|
|
172
|
-
Accepts ${info?.named_endpoints["/" + d.api_name]?.parameters?.length}
|
|
175
|
+
Accepts a JSON object with ${info?.named_endpoints["/" + d.api_name]?.parameters?.length} key${info?.named_endpoints["/" + d.api_name]?.parameters?.length != 1 ? "s" : ""}:
|
|
173
176
|
|
|
174
177
|
${info?.named_endpoints["/" + d.api_name]?.parameters
|
|
175
178
|
?.map((p: any) => {
|
|
176
179
|
const defaultValue = "Required";
|
|
177
|
-
const type = `${
|
|
178
|
-
return `${
|
|
180
|
+
const type = `${p.python_type.type}`;
|
|
181
|
+
return `${p.parameter_name}:\n- Type: ${type}\n- ${defaultValue}\n- The input value that is provided in the ${p.label} ${p.component} component. ${p.python_type.description}`;
|
|
179
182
|
})
|
|
180
183
|
.join("\n\n")}
|
|
181
184
|
|
|
182
|
-
Returns ${info?.named_endpoints["/" + d.api_name]?.returns?.length > 1 ? `
|
|
185
|
+
Returns ${info?.named_endpoints["/" + d.api_name]?.returns?.length > 1 ? `an array of ${info?.named_endpoints["/" + d.api_name]?.returns?.length} elements` : "an array of 1 element"}:
|
|
183
186
|
|
|
184
187
|
${info?.named_endpoints["/" + d.api_name]?.returns
|
|
185
188
|
?.map((r: any, i: number) => {
|
|
186
|
-
const type =
|
|
189
|
+
const type = r.python_type.type;
|
|
187
190
|
return `${info?.named_endpoints["/" + d.api_name]?.returns?.length > 1 ? `[${i}]: ` : ""}- Type: ${type}\n- The output value that appears in the "${r.label}" ${r.component} component.`;
|
|
188
191
|
})
|
|
189
192
|
.join("\n\n")}
|
|
@@ -278,7 +281,9 @@ Read more about the MCP in the [Gradio docs](${mcp_docs}).
|
|
|
278
281
|
? "JavaScript"
|
|
279
282
|
: current_language === "bash"
|
|
280
283
|
? "Bash"
|
|
281
|
-
: "
|
|
284
|
+
: current_language === "cli"
|
|
285
|
+
? "CLI"
|
|
286
|
+
: "MCP";
|
|
282
287
|
|
|
283
288
|
$: current_language;
|
|
284
289
|
$: current_language_label =
|
|
@@ -288,7 +293,9 @@ Read more about the MCP in the [Gradio docs](${mcp_docs}).
|
|
|
288
293
|
? "JavaScript"
|
|
289
294
|
: current_language === "bash"
|
|
290
295
|
? "Bash"
|
|
291
|
-
: "
|
|
296
|
+
: current_language === "cli"
|
|
297
|
+
? "CLI"
|
|
298
|
+
: "MCP";
|
|
292
299
|
|
|
293
300
|
let label = `Copy ${current_language_label} Docs as Markdown for LLMs`;
|
|
294
301
|
$: label = `Copy ${current_language_label} Docs as Markdown for LLMs`;
|
|
@@ -367,7 +374,7 @@ Read the documentation above so I can ask questions about it.`
|
|
|
367
374
|
}
|
|
368
375
|
|
|
369
376
|
async function copyMarkdown(
|
|
370
|
-
current_language: "python" | "javascript" | "bash" | "skill" | "mcp"
|
|
377
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp" | "cli"
|
|
371
378
|
): Promise<void> {
|
|
372
379
|
try {
|
|
373
380
|
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" | "skill" | "mcp";
|
|
16
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp" | "cli";
|
|
17
17
|
space_id: string | null;
|
|
18
18
|
root: string;
|
|
19
19
|
api_count: number;
|
|
@@ -7,39 +7,93 @@
|
|
|
7
7
|
| "javascript"
|
|
8
8
|
| "bash"
|
|
9
9
|
| "skill"
|
|
10
|
-
| "mcp"
|
|
10
|
+
| "mcp"
|
|
11
|
+
| "cli";
|
|
12
|
+
export let cli_flavor: "hf" | "gradio" = "hf";
|
|
11
13
|
|
|
12
14
|
let py_install = "pip install gradio_client";
|
|
13
15
|
let js_install = "npm i -D @gradio/client";
|
|
14
16
|
let bash_install = "curl --version";
|
|
17
|
+
const hf_mac_install = "curl -LsSf https://hf.co/cli/install.sh | bash";
|
|
18
|
+
const hf_win_install =
|
|
19
|
+
'powershell -ExecutionPolicy ByPass -c "irm https://hf.co/cli/install.ps1 | iex"';
|
|
20
|
+
$: cli_install =
|
|
21
|
+
cli_flavor === "hf"
|
|
22
|
+
? "hf extensions install gradio-app/hf-gradio"
|
|
23
|
+
: "pip install gradio --upgrade";
|
|
15
24
|
</script>
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
<
|
|
19
|
-
|
|
26
|
+
{#if current_language === "python"}
|
|
27
|
+
<Block>
|
|
28
|
+
<code>
|
|
20
29
|
<div class="copy">
|
|
21
30
|
<CopyButton code={py_install} />
|
|
22
31
|
</div>
|
|
23
32
|
<div>
|
|
24
33
|
<pre>$ {py_install}</pre>
|
|
25
34
|
</div>
|
|
26
|
-
|
|
35
|
+
</code>
|
|
36
|
+
</Block>
|
|
37
|
+
{:else if current_language === "javascript"}
|
|
38
|
+
<Block>
|
|
39
|
+
<code>
|
|
27
40
|
<div class="copy">
|
|
28
41
|
<CopyButton code={js_install} />
|
|
29
42
|
</div>
|
|
30
43
|
<div>
|
|
31
44
|
<pre>$ {js_install}</pre>
|
|
32
45
|
</div>
|
|
33
|
-
|
|
46
|
+
</code>
|
|
47
|
+
</Block>
|
|
48
|
+
{:else if current_language === "bash"}
|
|
49
|
+
<Block>
|
|
50
|
+
<code>
|
|
34
51
|
<div class="copy">
|
|
35
52
|
<CopyButton code={bash_install} />
|
|
36
53
|
</div>
|
|
37
54
|
<div>
|
|
38
55
|
<pre>$ {bash_install}</pre>
|
|
39
56
|
</div>
|
|
40
|
-
|
|
41
|
-
</
|
|
42
|
-
|
|
57
|
+
</code>
|
|
58
|
+
</Block>
|
|
59
|
+
{:else if current_language === "cli"}
|
|
60
|
+
{#if cli_flavor === "hf"}
|
|
61
|
+
<p class="step">First, install the HF CLI.</p>
|
|
62
|
+
<p class="os-label">On macOS and Linux:</p>
|
|
63
|
+
<Block>
|
|
64
|
+
<code>
|
|
65
|
+
<div class="copy">
|
|
66
|
+
<CopyButton code={hf_mac_install} />
|
|
67
|
+
</div>
|
|
68
|
+
<div>
|
|
69
|
+
<pre>$ {hf_mac_install}</pre>
|
|
70
|
+
</div>
|
|
71
|
+
</code>
|
|
72
|
+
</Block>
|
|
73
|
+
<p class="os-label">On Windows:</p>
|
|
74
|
+
<Block>
|
|
75
|
+
<code>
|
|
76
|
+
<div class="copy">
|
|
77
|
+
<CopyButton code={hf_win_install} />
|
|
78
|
+
</div>
|
|
79
|
+
<div>
|
|
80
|
+
<pre>$ {hf_win_install}</pre>
|
|
81
|
+
</div>
|
|
82
|
+
</code>
|
|
83
|
+
</Block>
|
|
84
|
+
<p class="step">Then, install the Gradio extension:</p>
|
|
85
|
+
{/if}
|
|
86
|
+
<Block>
|
|
87
|
+
<code>
|
|
88
|
+
<div class="copy">
|
|
89
|
+
<CopyButton code={cli_install} />
|
|
90
|
+
</div>
|
|
91
|
+
<div>
|
|
92
|
+
<pre>$ {cli_install}</pre>
|
|
93
|
+
</div>
|
|
94
|
+
</code>
|
|
95
|
+
</Block>
|
|
96
|
+
{/if}
|
|
43
97
|
|
|
44
98
|
<style>
|
|
45
99
|
code pre {
|
|
@@ -61,4 +115,18 @@
|
|
|
61
115
|
margin-top: -5px;
|
|
62
116
|
margin-right: -5px;
|
|
63
117
|
}
|
|
118
|
+
|
|
119
|
+
.step {
|
|
120
|
+
margin-top: var(--size-3);
|
|
121
|
+
margin-bottom: var(--size-2);
|
|
122
|
+
font-weight: var(--weight-semibold);
|
|
123
|
+
color: var(--body-text-color);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.os-label {
|
|
127
|
+
margin-top: var(--size-2);
|
|
128
|
+
margin-bottom: var(--size-1);
|
|
129
|
+
font-size: var(--text-sm);
|
|
130
|
+
color: var(--body-text-color-subdued);
|
|
131
|
+
}
|
|
64
132
|
</style>
|
|
@@ -12,7 +12,8 @@ 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" | "skill" | "mcp";
|
|
15
|
+
current_language: "python" | "javascript" | "bash" | "skill" | "mcp" | "cli";
|
|
16
|
+
cli_flavor?: "hf" | "gradio";
|
|
16
17
|
}, {
|
|
17
18
|
[evt: string]: CustomEvent<any>;
|
|
18
19
|
}, {}, {}, string>;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
export let current_language:
|
|
9
9
|
| "python"
|
|
10
10
|
| "javascript"
|
|
11
|
+
| "cli"
|
|
11
12
|
| "bash"
|
|
12
13
|
| "skill"
|
|
13
14
|
| "mcp";
|
|
@@ -17,7 +18,9 @@
|
|
|
17
18
|
<div class="toggle-icon">
|
|
18
19
|
<div class="toggle-dot" />
|
|
19
20
|
</div>
|
|
20
|
-
|
|
21
|
+
{#if current_language === "bash"}Accepts a JSON object with {endpoint_returns.length}
|
|
22
|
+
key{#if endpoint_returns.length != 1}s{/if}:{:else}Accepts {endpoint_returns.length}
|
|
23
|
+
parameter{#if endpoint_returns.length != 1}s{/if}:{/if}
|
|
21
24
|
</h4>
|
|
22
25
|
|
|
23
26
|
<div class:hide={is_running}>
|
|
@@ -26,13 +29,13 @@
|
|
|
26
29
|
<div style="margin:10px;">
|
|
27
30
|
<p style="white-space: nowrap; overflow-x: auto;">
|
|
28
31
|
<span class="code" style="margin-right: 10px;"
|
|
29
|
-
>{
|
|
30
|
-
? parameter_name
|
|
31
|
-
: "[" + i + "]"}</span
|
|
32
|
+
>{parameter_name || `[${i}]`}</span
|
|
32
33
|
>
|
|
33
34
|
<span class="code highlight" style="margin-right: 10px;"
|
|
34
35
|
>{#if current_language === "python"}{python_type.type}{#if parameter_has_default && parameter_default === null} |
|
|
35
|
-
None{/if}{:else
|
|
36
|
+
None{/if}{:else if current_language === "bash"}{python_type.type}{:else}{js_returns[
|
|
37
|
+
i
|
|
38
|
+
].type || "any"}{/if}</span
|
|
36
39
|
>
|
|
37
40
|
{#if !parameter_has_default || current_language == "bash"}<span
|
|
38
41
|
style="font-weight:bold">Required</span
|
|
@@ -15,7 +15,7 @@ declare const ParametersSnippet: $$__sveltets_2_IsomorphicComponent<{
|
|
|
15
15
|
is_running: boolean;
|
|
16
16
|
endpoint_returns: any;
|
|
17
17
|
js_returns: any;
|
|
18
|
-
current_language: "python" | "javascript" | "bash" | "skill" | "mcp";
|
|
18
|
+
current_language: "python" | "javascript" | "cli" | "bash" | "skill" | "mcp";
|
|
19
19
|
}, {
|
|
20
20
|
[evt: string]: CustomEvent<any>;
|
|
21
21
|
}, {}, {}, string>;
|