Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
machineuser
commited on
Commit
·
86c4ad7
1
Parent(s):
89fff4c
Sync widgets demo
Browse files- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamples.svelte +170 -0
- packages/widgets/src/lib/components/InferenceWidget/shared/{WidgetInputSamplesGroup/WidgetInputSamplesGroup.svelte → WidgetExamples/WidgetExamplesGroup.svelte} +10 -8
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetFooter/WidgetFooter.svelte +10 -2
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetHeader/WidgetHeader.svelte +35 -3
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInfo/WidgetInfo.svelte +17 -8
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte +0 -98
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetWrapper/WidgetWrapper.svelte +30 -128
- packages/widgets/src/lib/components/InferenceWidget/shared/helpers.ts +2 -13
- packages/widgets/src/lib/components/InferenceWidget/shared/types.ts +6 -0
- packages/widgets/src/lib/components/InferenceWidget/stores.ts +19 -2
- packages/widgets/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte +32 -41
- packages/widgets/src/lib/components/InferenceWidget/widgets/AudioToAudioWidget/AudioToAudioWidget.svelte +42 -44
- packages/widgets/src/lib/components/InferenceWidget/widgets/AutomaticSpeechRecognitionWidget/AutomaticSpeechRecognitionWidget.svelte +48 -58
- packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte +30 -32
- packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte +66 -69
- packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte +27 -37
- packages/widgets/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte +44 -53
- packages/widgets/src/lib/components/InferenceWidget/widgets/ImageSegmentationWidget/ImageSegmentationWidget.svelte +49 -50
- packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte +63 -64
- packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToTextWidget/ImageToTextWidget.svelte +53 -54
- packages/widgets/src/lib/components/InferenceWidget/widgets/ObjectDetectionWidget/ObjectDetectionWidget.svelte +48 -49
- packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte +33 -43
- packages/widgets/src/lib/components/InferenceWidget/widgets/ReinforcementLearningWidget/ReinforcementLearningWidget.svelte +1 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte +51 -52
- packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte +29 -31
- packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte +35 -36
- packages/widgets/src/lib/components/InferenceWidget/widgets/TabularDataWidget/TabularDataWidget.svelte +35 -38
- packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte +48 -58
- packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte +18 -29
- packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte +32 -35
- packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte +33 -36
- packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte +56 -58
- packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte +40 -48
- packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte +62 -75
- packages/widgets/src/routes/+page.svelte +6 -6
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamples.svelte
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { ExampleRunOpts, WidgetProps } from "../types.js";
|
| 3 |
+
import type { WidgetExample, WidgetExampleAttribute } from "@huggingface/tasks";
|
| 4 |
+
|
| 5 |
+
type TWidgetExample = $$Generic<WidgetExample>;
|
| 6 |
+
|
| 7 |
+
import { onMount } from "svelte";
|
| 8 |
+
import { slide } from "svelte/transition";
|
| 9 |
+
|
| 10 |
+
import { randomItem } from "../../../../utils/ViewUtils.js";
|
| 11 |
+
import IconCaretDownV2 from "../../..//Icons/IconCaretDownV2.svelte";
|
| 12 |
+
import WidgetExamplesGroup from "./WidgetExamplesGroup.svelte";
|
| 13 |
+
import { getQueryParamVal } from "../../..//InferenceWidget/shared/helpers.js";
|
| 14 |
+
|
| 15 |
+
export let isLoading = false;
|
| 16 |
+
export let callApiOnMount: WidgetProps["callApiOnMount"];
|
| 17 |
+
export let exampleQueryParams: WidgetExampleAttribute[] = [];
|
| 18 |
+
export let applyWidgetExample: (sample: TWidgetExample, opts?: ExampleRunOpts) => void;
|
| 19 |
+
|
| 20 |
+
export let validExamples: TWidgetExample[];
|
| 21 |
+
|
| 22 |
+
interface ExamplesGroup {
|
| 23 |
+
group: string;
|
| 24 |
+
examples: TWidgetExample[];
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
$: exampleGroups = getExamplesGroups(validExamples);
|
| 28 |
+
$: examples = exampleGroups?.[0]?.examples ?? [];
|
| 29 |
+
// for examples with multiple groups, a group needs to be selected first, before an example can be clicked
|
| 30 |
+
$: clickable = exampleGroups?.length === 1;
|
| 31 |
+
let containerEl: HTMLElement;
|
| 32 |
+
let isOptionsVisible = false;
|
| 33 |
+
let title = "Examples";
|
| 34 |
+
|
| 35 |
+
function getExamplesGroups(_examples: TWidgetExample[]): ExamplesGroup[] {
|
| 36 |
+
const examples = _examples.map((sample, idx) => ({
|
| 37 |
+
example_title: `Example ${++idx}`,
|
| 38 |
+
group: "Group 1",
|
| 39 |
+
...sample,
|
| 40 |
+
}));
|
| 41 |
+
const examplesGroups: ExamplesGroup[] = [];
|
| 42 |
+
for (const example of examples) {
|
| 43 |
+
const groupExists = examplesGroups.find(({ group }) => group === example.group);
|
| 44 |
+
if (!groupExists) {
|
| 45 |
+
examplesGroups.push({ group: example.group as string, examples: [] });
|
| 46 |
+
}
|
| 47 |
+
examplesGroups.find(({ group }) => group === example.group)?.examples.push(example);
|
| 48 |
+
}
|
| 49 |
+
return examplesGroups;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function _applyWidgetExample(idx: number) {
|
| 53 |
+
hideOptions();
|
| 54 |
+
const sample = examples[idx];
|
| 55 |
+
title = sample.example_title as string;
|
| 56 |
+
applyWidgetExample(sample);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function _previewInputSample(idx: number) {
|
| 60 |
+
const sample = examples[idx];
|
| 61 |
+
applyWidgetExample(sample, { isPreview: true });
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function toggleOptionsVisibility() {
|
| 65 |
+
isOptionsVisible = !isOptionsVisible;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
function onClick(e: MouseEvent | TouchEvent) {
|
| 69 |
+
let targetElement = e.target;
|
| 70 |
+
do {
|
| 71 |
+
if (targetElement === containerEl) {
|
| 72 |
+
// This is a click inside. Do nothing, just return.
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
targetElement = (targetElement as HTMLElement).parentElement;
|
| 76 |
+
} while (targetElement);
|
| 77 |
+
// This is a click outside
|
| 78 |
+
hideOptions();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function hideOptions() {
|
| 82 |
+
isOptionsVisible = false;
|
| 83 |
+
}
|
| 84 |
+
function changeGroup(e: CustomEvent<string>) {
|
| 85 |
+
const selectedGroup = e.detail;
|
| 86 |
+
const newGroup = exampleGroups.find(({ group }) => group === selectedGroup);
|
| 87 |
+
if (!newGroup) {
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
examples = newGroup?.examples ?? [];
|
| 91 |
+
title = "Examples";
|
| 92 |
+
clickable = true;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
onMount(() => {
|
| 96 |
+
// run random example onMount
|
| 97 |
+
(async () => {
|
| 98 |
+
const exampleFromQueryParams = {} as TWidgetExample;
|
| 99 |
+
for (const key of exampleQueryParams) {
|
| 100 |
+
const val = getQueryParamVal(key);
|
| 101 |
+
if (val) {
|
| 102 |
+
// @ts-expect-error complicated type
|
| 103 |
+
exampleFromQueryParams[key] = val;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
if (Object.keys(exampleFromQueryParams).length) {
|
| 107 |
+
// run widget example from query params
|
| 108 |
+
applyWidgetExample(exampleFromQueryParams);
|
| 109 |
+
} else {
|
| 110 |
+
// run random widget example
|
| 111 |
+
const example = randomItem(validExamples);
|
| 112 |
+
if (callApiOnMount && example) {
|
| 113 |
+
applyWidgetExample(example, { inferenceOpts: { isOnLoadCall: true } });
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
})();
|
| 117 |
+
});
|
| 118 |
+
</script>
|
| 119 |
+
|
| 120 |
+
<svelte:window on:click={onClick} />
|
| 121 |
+
|
| 122 |
+
<div class="ml-auto flex gap-x-1">
|
| 123 |
+
<!-- Example Groups -->
|
| 124 |
+
{#if exampleGroups.length > 1}
|
| 125 |
+
<WidgetExamplesGroup
|
| 126 |
+
on:groupSelected={changeGroup}
|
| 127 |
+
{isLoading}
|
| 128 |
+
groupNames={exampleGroups.map(({ group }) => group)}
|
| 129 |
+
/>
|
| 130 |
+
{/if}
|
| 131 |
+
|
| 132 |
+
<!-- Example picker -->
|
| 133 |
+
<div
|
| 134 |
+
class="relative mb-1.5
|
| 135 |
+
{isLoading || !clickable ? 'pointer-events-none opacity-50' : ''}
|
| 136 |
+
{isOptionsVisible ? 'z-10' : ''}"
|
| 137 |
+
bind:this={containerEl}
|
| 138 |
+
>
|
| 139 |
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 140 |
+
<div
|
| 141 |
+
class="inline-flex w-32 justify-between rounded-md border border-gray-100 px-4 py-1"
|
| 142 |
+
on:click={toggleOptionsVisibility}
|
| 143 |
+
>
|
| 144 |
+
<div class="truncate text-sm">{title}</div>
|
| 145 |
+
<IconCaretDownV2
|
| 146 |
+
classNames="-mr-1 ml-2 h-5 w-5 transition ease-in-out transform {isOptionsVisible && '-rotate-180'}"
|
| 147 |
+
/>
|
| 148 |
+
</div>
|
| 149 |
+
|
| 150 |
+
{#if isOptionsVisible}
|
| 151 |
+
<div
|
| 152 |
+
class="absolute right-0 mt-1 w-full origin-top-right rounded-md ring-1 ring-black ring-opacity-10"
|
| 153 |
+
transition:slide
|
| 154 |
+
>
|
| 155 |
+
<div class="rounded-md bg-white py-1" role="none">
|
| 156 |
+
{#each examples as { example_title }, i}
|
| 157 |
+
<!-- svelte-ignore a11y-click-events-have-key-events a11y-mouse-events-have-key-events -->
|
| 158 |
+
<div
|
| 159 |
+
class="cursor-pointer truncate px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
| 160 |
+
on:mouseover={() => _previewInputSample(i)}
|
| 161 |
+
on:click={() => _applyWidgetExample(i)}
|
| 162 |
+
>
|
| 163 |
+
{example_title}
|
| 164 |
+
</div>
|
| 165 |
+
{/each}
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
{/if}
|
| 169 |
+
</div>
|
| 170 |
+
</div>
|
packages/widgets/src/lib/components/InferenceWidget/shared/{WidgetInputSamplesGroup/WidgetInputSamplesGroup.svelte → WidgetExamples/WidgetExamplesGroup.svelte}
RENAMED
|
@@ -1,22 +1,24 @@
|
|
| 1 |
<script lang="ts">
|
|
|
|
| 2 |
import { slide } from "svelte/transition";
|
| 3 |
|
| 4 |
import IconCaretDownV2 from "../../..//Icons/IconCaretDownV2.svelte";
|
| 5 |
|
| 6 |
export let classNames = "";
|
| 7 |
export let isLoading = false;
|
| 8 |
-
export let
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
let containerEl: HTMLElement;
|
| 12 |
let isOptionsVisible = false;
|
| 13 |
-
let
|
| 14 |
|
| 15 |
function chooseInputGroup(idx: number) {
|
| 16 |
hideOptions();
|
| 17 |
-
const inputGroup =
|
| 18 |
-
|
| 19 |
-
|
| 20 |
}
|
| 21 |
|
| 22 |
function toggleOptionsVisibility() {
|
|
@@ -54,7 +56,7 @@
|
|
| 54 |
class="inline-flex w-32 justify-between rounded-md border border-gray-100 px-4 py-1"
|
| 55 |
on:click={toggleOptionsVisibility}
|
| 56 |
>
|
| 57 |
-
<div class="truncate text-sm">{
|
| 58 |
<IconCaretDownV2
|
| 59 |
classNames="-mr-1 ml-2 h-5 w-5 transition ease-in-out transform {isOptionsVisible && '-rotate-180'}"
|
| 60 |
/>
|
|
@@ -66,7 +68,7 @@
|
|
| 66 |
transition:slide
|
| 67 |
>
|
| 68 |
<div class="rounded-md bg-white py-1" role="none">
|
| 69 |
-
{#each
|
| 70 |
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 71 |
<div
|
| 72 |
class="truncate px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { createEventDispatcher } from "svelte";
|
| 3 |
import { slide } from "svelte/transition";
|
| 4 |
|
| 5 |
import IconCaretDownV2 from "../../..//Icons/IconCaretDownV2.svelte";
|
| 6 |
|
| 7 |
export let classNames = "";
|
| 8 |
export let isLoading = false;
|
| 9 |
+
export let groupNames: string[];
|
| 10 |
+
|
| 11 |
+
const dispatch = createEventDispatcher<{ groupSelected: string }>();
|
| 12 |
|
| 13 |
let containerEl: HTMLElement;
|
| 14 |
let isOptionsVisible = false;
|
| 15 |
+
let selectedGroupName: string;
|
| 16 |
|
| 17 |
function chooseInputGroup(idx: number) {
|
| 18 |
hideOptions();
|
| 19 |
+
const inputGroup = groupNames[idx];
|
| 20 |
+
selectedGroupName = inputGroup;
|
| 21 |
+
dispatch("groupSelected", selectedGroupName);
|
| 22 |
}
|
| 23 |
|
| 24 |
function toggleOptionsVisibility() {
|
|
|
|
| 56 |
class="inline-flex w-32 justify-between rounded-md border border-gray-100 px-4 py-1"
|
| 57 |
on:click={toggleOptionsVisibility}
|
| 58 |
>
|
| 59 |
+
<div class="truncate text-sm">{selectedGroupName ?? "Groups"}</div>
|
| 60 |
<IconCaretDownV2
|
| 61 |
classNames="-mr-1 ml-2 h-5 w-5 transition ease-in-out transform {isOptionsVisible && '-rotate-180'}"
|
| 62 |
/>
|
|
|
|
| 68 |
transition:slide
|
| 69 |
>
|
| 70 |
<div class="rounded-md bg-white py-1" role="none">
|
| 71 |
+
{#each groupNames as inputGroup, i}
|
| 72 |
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 73 |
<div
|
| 74 |
class="truncate px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetFooter/WidgetFooter.svelte
CHANGED
|
@@ -1,11 +1,16 @@
|
|
| 1 |
<script lang="ts">
|
|
|
|
|
|
|
|
|
|
| 2 |
import IconCode from "../../..//Icons/IconCode.svelte";
|
| 3 |
import IconMaximize from "../../..//Icons/IconMaximize.svelte";
|
| 4 |
|
| 5 |
-
export let
|
| 6 |
export let outputJson: string;
|
| 7 |
export let isDisabled = false;
|
| 8 |
|
|
|
|
|
|
|
| 9 |
let isOutputJsonVisible = false;
|
| 10 |
</script>
|
| 11 |
|
|
@@ -22,7 +27,10 @@
|
|
| 22 |
JSON Output
|
| 23 |
</button>
|
| 24 |
{/if}
|
| 25 |
-
<button
|
|
|
|
|
|
|
|
|
|
| 26 |
<IconMaximize classNames="mr-1" />
|
| 27 |
{#if !isMaximized}
|
| 28 |
Maximize
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import type { WidgetProps } from "../types.js";
|
| 3 |
+
import { identity } from "svelte/internal";
|
| 4 |
+
import { widgetStates, updateWidgetState } from "../../stores.js";
|
| 5 |
import IconCode from "../../..//Icons/IconCode.svelte";
|
| 6 |
import IconMaximize from "../../..//Icons/IconMaximize.svelte";
|
| 7 |
|
| 8 |
+
export let model: WidgetProps["model"];
|
| 9 |
export let outputJson: string;
|
| 10 |
export let isDisabled = false;
|
| 11 |
|
| 12 |
+
$: isMaximized = $widgetStates?.[model.id]?.isMaximized;
|
| 13 |
+
|
| 14 |
let isOutputJsonVisible = false;
|
| 15 |
</script>
|
| 16 |
|
|
|
|
| 27 |
JSON Output
|
| 28 |
</button>
|
| 29 |
{/if}
|
| 30 |
+
<button
|
| 31 |
+
class="ml-auto flex items-center"
|
| 32 |
+
on:click|preventDefault={() => updateWidgetState(model.id, "isMaximized", true)}
|
| 33 |
+
>
|
| 34 |
<IconMaximize classNames="mr-1" />
|
| 35 |
{#if !isMaximized}
|
| 36 |
Maximize
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetHeader/WidgetHeader.svelte
CHANGED
|
@@ -1,16 +1,46 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import {
|
|
|
|
|
|
|
|
|
|
| 3 |
import { getPipelineTask } from "../../../../utils/ViewUtils.js";
|
| 4 |
import IconInfo from "../../..//Icons/IconInfo.svelte";
|
| 5 |
import IconLightning from "../../..//Icons/IconLightning.svelte";
|
| 6 |
import PipelineTag from "../../../PipelineTag/PipelineTag.svelte";
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
export let noTitle = false;
|
| 9 |
export let title: string | null = null;
|
| 10 |
-
export let
|
| 11 |
export let isDisabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
$: task = pipeline ? getPipelineTask(pipeline) : undefined;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
</script>
|
| 15 |
|
| 16 |
<div class="mb-2 flex items-center font-semibold">
|
|
@@ -45,5 +75,7 @@
|
|
| 45 |
<PipelineTag classNames="mr-2 mb-1.5" {pipeline} />
|
| 46 |
</a>
|
| 47 |
{/if}
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
</div>
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
+
import { updateWidgetState } from "../../stores.js";
|
| 3 |
+
import { TASKS_DATA } from "@huggingface/tasks";
|
| 4 |
+
import type { WidgetExample, WidgetExampleAttribute } from "@huggingface/tasks";
|
| 5 |
+
import type { WidgetProps, ExampleRunOpts } from "../types.js";
|
| 6 |
import { getPipelineTask } from "../../../../utils/ViewUtils.js";
|
| 7 |
import IconInfo from "../../..//Icons/IconInfo.svelte";
|
| 8 |
import IconLightning from "../../..//Icons/IconLightning.svelte";
|
| 9 |
import PipelineTag from "../../../PipelineTag/PipelineTag.svelte";
|
| 10 |
+
import WidgetExamples from "../WidgetExamples/WidgetExamples.svelte";
|
| 11 |
|
| 12 |
+
type TWidgetExample = $$Generic<WidgetExample>;
|
| 13 |
+
|
| 14 |
+
export let model: WidgetProps["model"];
|
| 15 |
export let noTitle = false;
|
| 16 |
export let title: string | null = null;
|
| 17 |
+
export let isLoading = false;
|
| 18 |
export let isDisabled = false;
|
| 19 |
+
export let applyWidgetExample: ((sample: TWidgetExample, opts?: ExampleRunOpts) => void) | undefined = undefined;
|
| 20 |
+
export let validateExample: ((sample: WidgetExample) => sample is TWidgetExample) | undefined = undefined;
|
| 21 |
+
export let callApiOnMount: WidgetProps["callApiOnMount"] = false;
|
| 22 |
+
export let exampleQueryParams: WidgetExampleAttribute[] = [];
|
| 23 |
+
|
| 24 |
+
const pipeline = model?.pipeline_tag;
|
| 25 |
|
| 26 |
$: task = pipeline ? getPipelineTask(pipeline) : undefined;
|
| 27 |
+
|
| 28 |
+
$: validExamples = getValidExamples(isDisabled);
|
| 29 |
+
|
| 30 |
+
function getValidExamples(isDisabled: boolean): TWidgetExample[] {
|
| 31 |
+
const examples = (model?.widgetData ?? []).filter(
|
| 32 |
+
(sample): sample is TWidgetExample =>
|
| 33 |
+
(validateExample?.(sample) ?? false) && (!isDisabled || sample.output !== undefined)
|
| 34 |
+
);
|
| 35 |
+
|
| 36 |
+
// if there are no examples with outputs AND model.inference !== InferenceDisplayability.Yes
|
| 37 |
+
// then widget will show InferenceDisplayability error to the user without showing anything else
|
| 38 |
+
if (isDisabled && !examples.length) {
|
| 39 |
+
updateWidgetState(model.id, "noInference", true);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
return examples;
|
| 43 |
+
}
|
| 44 |
</script>
|
| 45 |
|
| 46 |
<div class="mb-2 flex items-center font-semibold">
|
|
|
|
| 75 |
<PipelineTag classNames="mr-2 mb-1.5" {pipeline} />
|
| 76 |
</a>
|
| 77 |
{/if}
|
| 78 |
+
{#if validExamples.length && applyWidgetExample}
|
| 79 |
+
<WidgetExamples {validExamples} {isLoading} {applyWidgetExample} {callApiOnMount} {exampleQueryParams} />
|
| 80 |
+
{/if}
|
| 81 |
</div>
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInfo/WidgetInfo.svelte
CHANGED
|
@@ -1,14 +1,20 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { InferenceDisplayability } from "@huggingface/tasks";
|
| 3 |
import { type WidgetProps, type ModelLoadInfo, LoadState, ComputeType } from "../types.js";
|
|
|
|
| 4 |
import IconAzureML from "../../..//Icons/IconAzureML.svelte";
|
| 5 |
import IconInfo from "../../..//Icons/IconInfo.svelte";
|
|
|
|
| 6 |
|
| 7 |
export let model: WidgetProps["model"];
|
| 8 |
export let computeTime: string = "";
|
| 9 |
export let error: string = "";
|
| 10 |
-
export let
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
const state = {
|
| 14 |
[LoadState.Loadable]: "This model can be loaded on the Inference API on-demand.",
|
|
@@ -26,11 +32,11 @@
|
|
| 26 |
[LoadState.Error]: "⚠️ This model could not be loaded.",
|
| 27 |
} as const;
|
| 28 |
|
| 29 |
-
function getStatusReport(
|
| 30 |
-
if (!
|
| 31 |
return "Model state unknown";
|
| 32 |
}
|
| 33 |
-
return statuses[
|
| 34 |
}
|
| 35 |
</script>
|
| 36 |
|
|
@@ -48,13 +54,13 @@
|
|
| 48 |
</div>
|
| 49 |
<div class="border-dotter mx-2 flex flex-1 -translate-y-px border-b border-gray-100" />
|
| 50 |
<div>
|
| 51 |
-
{@html getStatusReport(
|
| 52 |
</div>
|
| 53 |
</div>
|
| 54 |
{:else if computeTime}
|
| 55 |
-
Computation time on {
|
| 56 |
{:else if (model.inference === InferenceDisplayability.Yes || model.pipeline_tag === "reinforcement-learning") && !modelTooBig}
|
| 57 |
-
{@html getStatusReport(
|
| 58 |
{:else if model.inference === InferenceDisplayability.ExplicitOptOut}
|
| 59 |
<span class="text-sm text-gray-500">Inference API has been turned off for this model.</span>
|
| 60 |
{:else if model.inference === InferenceDisplayability.CustomCode}
|
|
@@ -98,4 +104,7 @@
|
|
| 98 |
{#if error}
|
| 99 |
<div class="alert alert-error mt-3">{error}</div>
|
| 100 |
{/if}
|
|
|
|
|
|
|
|
|
|
| 101 |
</div>
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { InferenceDisplayability } from "@huggingface/tasks";
|
| 3 |
import { type WidgetProps, type ModelLoadInfo, LoadState, ComputeType } from "../types.js";
|
| 4 |
+
import WidgetModelLoading from "../WidgetModelLoading/WidgetModelLoading.svelte";
|
| 5 |
import IconAzureML from "../../..//Icons/IconAzureML.svelte";
|
| 6 |
import IconInfo from "../../..//Icons/IconInfo.svelte";
|
| 7 |
+
import { modelLoadStates } from "../../stores.js";
|
| 8 |
|
| 9 |
export let model: WidgetProps["model"];
|
| 10 |
export let computeTime: string = "";
|
| 11 |
export let error: string = "";
|
| 12 |
+
export let modelLoading = {
|
| 13 |
+
isLoading: false,
|
| 14 |
+
estimatedTime: 0,
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
$: modelTooBig = $modelLoadStates[model.id]?.state === "TooBig";
|
| 18 |
|
| 19 |
const state = {
|
| 20 |
[LoadState.Loadable]: "This model can be loaded on the Inference API on-demand.",
|
|
|
|
| 32 |
[LoadState.Error]: "⚠️ This model could not be loaded.",
|
| 33 |
} as const;
|
| 34 |
|
| 35 |
+
function getStatusReport(modelLoadStates: ModelLoadInfo | undefined, statuses: Record<LoadState, string>): string {
|
| 36 |
+
if (!modelLoadStates) {
|
| 37 |
return "Model state unknown";
|
| 38 |
}
|
| 39 |
+
return statuses[modelLoadStates.state];
|
| 40 |
}
|
| 41 |
</script>
|
| 42 |
|
|
|
|
| 54 |
</div>
|
| 55 |
<div class="border-dotter mx-2 flex flex-1 -translate-y-px border-b border-gray-100" />
|
| 56 |
<div>
|
| 57 |
+
{@html getStatusReport($modelLoadStates[model.id], azureState)}
|
| 58 |
</div>
|
| 59 |
</div>
|
| 60 |
{:else if computeTime}
|
| 61 |
+
Computation time on {$modelLoadStates[model.id]?.compute_type ?? ComputeType.CPU}: {computeTime}
|
| 62 |
{:else if (model.inference === InferenceDisplayability.Yes || model.pipeline_tag === "reinforcement-learning") && !modelTooBig}
|
| 63 |
+
{@html getStatusReport($modelLoadStates[model.id], state)}
|
| 64 |
{:else if model.inference === InferenceDisplayability.ExplicitOptOut}
|
| 65 |
<span class="text-sm text-gray-500">Inference API has been turned off for this model.</span>
|
| 66 |
{:else if model.inference === InferenceDisplayability.CustomCode}
|
|
|
|
| 104 |
{#if error}
|
| 105 |
<div class="alert alert-error mt-3">{error}</div>
|
| 106 |
{/if}
|
| 107 |
+
{#if modelLoading.isLoading}
|
| 108 |
+
<WidgetModelLoading estimatedTime={modelLoading.estimatedTime} />
|
| 109 |
+
{/if}
|
| 110 |
</div>
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte
DELETED
|
@@ -1,98 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import type { ExampleRunOpts } from "../types.js";
|
| 3 |
-
import type { WidgetExample } from "@huggingface/tasks";
|
| 4 |
-
|
| 5 |
-
type TWidgetExample = $$Generic<WidgetExample>;
|
| 6 |
-
|
| 7 |
-
import { slide } from "svelte/transition";
|
| 8 |
-
|
| 9 |
-
import IconCaretDownV2 from "../../..//Icons/IconCaretDownV2.svelte";
|
| 10 |
-
|
| 11 |
-
export let classNames = "";
|
| 12 |
-
export let isLoading = false;
|
| 13 |
-
export let inputSamples: TWidgetExample[];
|
| 14 |
-
export let applyInputSample: (sample: TWidgetExample, opts?: ExampleRunOpts) => void;
|
| 15 |
-
|
| 16 |
-
let containerEl: HTMLElement;
|
| 17 |
-
let isOptionsVisible = false;
|
| 18 |
-
let title = "Examples";
|
| 19 |
-
|
| 20 |
-
$: {
|
| 21 |
-
// reset title on inputSamples change (i.e. input group change)
|
| 22 |
-
inputSamples;
|
| 23 |
-
title = "Examples";
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
function _applyInputSample(idx: number) {
|
| 27 |
-
hideOptions();
|
| 28 |
-
const sample = inputSamples[idx];
|
| 29 |
-
title = sample.example_title as string;
|
| 30 |
-
applyInputSample(sample);
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
function _previewInputSample(idx: number) {
|
| 34 |
-
const sample = inputSamples[idx];
|
| 35 |
-
applyInputSample(sample, { isPreview: true });
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
function toggleOptionsVisibility() {
|
| 39 |
-
isOptionsVisible = !isOptionsVisible;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
function onClick(e: MouseEvent | TouchEvent) {
|
| 43 |
-
let targetElement = e.target;
|
| 44 |
-
do {
|
| 45 |
-
if (targetElement === containerEl) {
|
| 46 |
-
// This is a click inside. Do nothing, just return.
|
| 47 |
-
return;
|
| 48 |
-
}
|
| 49 |
-
targetElement = (targetElement as HTMLElement).parentElement;
|
| 50 |
-
} while (targetElement);
|
| 51 |
-
// This is a click outside
|
| 52 |
-
hideOptions();
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
function hideOptions() {
|
| 56 |
-
isOptionsVisible = false;
|
| 57 |
-
}
|
| 58 |
-
</script>
|
| 59 |
-
|
| 60 |
-
<svelte:window on:click={onClick} />
|
| 61 |
-
|
| 62 |
-
<div
|
| 63 |
-
class="relative mb-1.5 {classNames}
|
| 64 |
-
{isLoading && 'pointer-events-none opacity-50'}
|
| 65 |
-
{isOptionsVisible && 'z-10'}"
|
| 66 |
-
bind:this={containerEl}
|
| 67 |
-
>
|
| 68 |
-
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 69 |
-
<div
|
| 70 |
-
class="inline-flex w-32 justify-between rounded-md border border-gray-100 px-4 py-1"
|
| 71 |
-
on:click={toggleOptionsVisibility}
|
| 72 |
-
>
|
| 73 |
-
<div class="truncate text-sm">{title}</div>
|
| 74 |
-
<IconCaretDownV2
|
| 75 |
-
classNames="-mr-1 ml-2 h-5 w-5 transition ease-in-out transform {isOptionsVisible && '-rotate-180'}"
|
| 76 |
-
/>
|
| 77 |
-
</div>
|
| 78 |
-
|
| 79 |
-
{#if isOptionsVisible}
|
| 80 |
-
<div
|
| 81 |
-
class="absolute right-0 mt-1 w-full origin-top-right rounded-md ring-1 ring-black ring-opacity-10"
|
| 82 |
-
transition:slide
|
| 83 |
-
>
|
| 84 |
-
<div class="rounded-md bg-white py-1" role="none">
|
| 85 |
-
{#each inputSamples as { example_title }, i}
|
| 86 |
-
<!-- svelte-ignore a11y-click-events-have-key-events a11y-mouse-events-have-key-events -->
|
| 87 |
-
<div
|
| 88 |
-
class="cursor-pointer truncate px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-200"
|
| 89 |
-
on:mouseover={() => _previewInputSample(i)}
|
| 90 |
-
on:click={() => _applyInputSample(i)}
|
| 91 |
-
>
|
| 92 |
-
{example_title}
|
| 93 |
-
</div>
|
| 94 |
-
{/each}
|
| 95 |
-
</div>
|
| 96 |
-
</div>
|
| 97 |
-
{/if}
|
| 98 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetWrapper/WidgetWrapper.svelte
CHANGED
|
@@ -1,155 +1,57 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { InferenceDisplayability } from "@huggingface/tasks";
|
| 3 |
-
import type { WidgetExample
|
| 4 |
-
import type { WidgetProps
|
| 5 |
|
| 6 |
type TWidgetExample = $$Generic<WidgetExample>;
|
| 7 |
|
| 8 |
import { onMount } from "svelte";
|
| 9 |
|
| 10 |
-
import IconCross from "../../..//Icons/IconCross.svelte";
|
| 11 |
-
import WidgetInputSamples from "../WidgetInputSamples/WidgetInputSamples.svelte";
|
| 12 |
-
import WidgetInputSamplesGroup from "../WidgetInputSamplesGroup/WidgetInputSamplesGroup.svelte";
|
| 13 |
import WidgetFooter from "../WidgetFooter/WidgetFooter.svelte";
|
| 14 |
import WidgetHeader from "../WidgetHeader/WidgetHeader.svelte";
|
| 15 |
import WidgetInfo from "../WidgetInfo/WidgetInfo.svelte";
|
| 16 |
-
import
|
| 17 |
-
import { getModelLoadInfo
|
| 18 |
-
import { modelLoadStates } from "../../stores.js";
|
| 19 |
|
| 20 |
export let apiUrl: string;
|
| 21 |
-
export let callApiOnMount: WidgetProps["callApiOnMount"];
|
| 22 |
-
export let computeTime: string;
|
| 23 |
-
export let error: string;
|
| 24 |
-
export let isLoading = false;
|
| 25 |
export let model: WidgetProps["model"];
|
| 26 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 27 |
-
export let modelLoading = {
|
| 28 |
-
isLoading: false,
|
| 29 |
-
estimatedTime: 0,
|
| 30 |
-
};
|
| 31 |
-
export let noTitle = false;
|
| 32 |
-
export let outputJson: string;
|
| 33 |
-
export let applyInputSample: (sample: TWidgetExample, opts?: ExampleRunOpts) => void = () => {};
|
| 34 |
-
export let validateExample: (sample: WidgetExample) => sample is TWidgetExample;
|
| 35 |
-
export let exampleQueryParams: WidgetExampleAttribute[] = [];
|
| 36 |
-
|
| 37 |
-
let isDisabled = model.inference !== InferenceDisplayability.Yes && model.pipeline_tag !== "reinforcement-learning";
|
| 38 |
-
let isMaximized = false;
|
| 39 |
-
let modelLoadInfo: ModelLoadInfo | undefined = undefined;
|
| 40 |
-
let selectedInputGroup: string;
|
| 41 |
-
let modelTooBig = false;
|
| 42 |
|
| 43 |
-
|
| 44 |
-
group: string;
|
| 45 |
-
inputSamples: TWidgetExample[];
|
| 46 |
-
}
|
| 47 |
|
| 48 |
-
const
|
| 49 |
-
|
| 50 |
-
.sort((sample1, sample2) => (sample2.example_title ? 1 : 0) - (sample1.example_title ? 1 : 0))
|
| 51 |
-
.map((sample, idx) => ({
|
| 52 |
-
example_title: `Example ${++idx}`,
|
| 53 |
-
group: "Group 1",
|
| 54 |
-
...sample,
|
| 55 |
-
}));
|
| 56 |
-
let inputSamples = !isDisabled ? allInputSamples : allInputSamples.filter((sample) => sample.output !== undefined);
|
| 57 |
-
let inputGroups = getExamplesGroups();
|
| 58 |
-
|
| 59 |
-
$: selectedInputSamples =
|
| 60 |
-
inputGroups.length === 1 ? inputGroups[0] : inputGroups.find(({ group }) => group === selectedInputGroup);
|
| 61 |
-
|
| 62 |
-
function getExamplesGroups(): ExamplesGroup[] {
|
| 63 |
-
const inputGroups: ExamplesGroup[] = [];
|
| 64 |
-
for (const inputSample of inputSamples) {
|
| 65 |
-
const groupExists = inputGroups.find(({ group }) => group === inputSample.group);
|
| 66 |
-
if (!groupExists) {
|
| 67 |
-
inputGroups.push({ group: inputSample.group as string, inputSamples: [] });
|
| 68 |
-
}
|
| 69 |
-
inputGroups.find(({ group }) => group === inputSample.group)?.inputSamples.push(inputSample);
|
| 70 |
-
}
|
| 71 |
-
return inputGroups;
|
| 72 |
-
}
|
| 73 |
|
| 74 |
onMount(() => {
|
| 75 |
(async () => {
|
| 76 |
-
if (model.inference
|
| 77 |
-
|
| 78 |
-
$modelLoadStates[model.id] = modelLoadInfo;
|
| 79 |
-
modelTooBig = modelLoadInfo?.state === "TooBig";
|
| 80 |
-
|
| 81 |
-
if (modelTooBig) {
|
| 82 |
-
// disable the widget
|
| 83 |
-
isDisabled = true;
|
| 84 |
-
inputSamples = allInputSamples.filter((sample) => sample.output !== undefined);
|
| 85 |
-
inputGroups = getExamplesGroups();
|
| 86 |
-
}
|
| 87 |
}
|
| 88 |
|
| 89 |
-
const
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
exampleFromQueryParams[key] = val;
|
| 95 |
-
}
|
| 96 |
-
}
|
| 97 |
-
if (Object.keys(exampleFromQueryParams).length) {
|
| 98 |
-
// run widget example from query params
|
| 99 |
-
applyInputSample(exampleFromQueryParams);
|
| 100 |
-
} else {
|
| 101 |
-
// run random widget example
|
| 102 |
-
const example = getWidgetExample<TWidgetExample>(model, validateExample);
|
| 103 |
-
if (callApiOnMount && example) {
|
| 104 |
-
applyInputSample(example, { inferenceOpts: { isOnLoadCall: true } });
|
| 105 |
-
}
|
| 106 |
}
|
| 107 |
})();
|
| 108 |
});
|
| 109 |
</script>
|
| 110 |
|
| 111 |
-
{#if
|
| 112 |
-
<WidgetHeader
|
| 113 |
-
<WidgetInfo {model}
|
| 114 |
-
{:else}
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
<WidgetHeader {noTitle} pipeline={model.pipeline_tag} {isDisabled}>
|
| 127 |
-
{#if !!inputGroups.length}
|
| 128 |
-
<div class="ml-auto flex gap-x-1">
|
| 129 |
-
<!-- Show samples selector when there are more than one sample -->
|
| 130 |
-
{#if inputGroups.length > 1}
|
| 131 |
-
<WidgetInputSamplesGroup
|
| 132 |
-
bind:selectedInputGroup
|
| 133 |
-
{isLoading}
|
| 134 |
-
inputGroups={inputGroups.map(({ group }) => group)}
|
| 135 |
-
/>
|
| 136 |
-
{/if}
|
| 137 |
-
<WidgetInputSamples
|
| 138 |
-
classNames={!selectedInputSamples ? "opacity-50 pointer-events-none" : ""}
|
| 139 |
-
{isLoading}
|
| 140 |
-
inputSamples={selectedInputSamples?.inputSamples ?? []}
|
| 141 |
-
{applyInputSample}
|
| 142 |
-
/>
|
| 143 |
-
</div>
|
| 144 |
-
{/if}
|
| 145 |
-
</WidgetHeader>
|
| 146 |
-
<slot name="top" {isDisabled} />
|
| 147 |
-
<WidgetInfo {model} {computeTime} {error} {modelLoadInfo} {modelTooBig} />
|
| 148 |
-
{#if modelLoading.isLoading}
|
| 149 |
-
<WidgetModelLoading estimatedTime={modelLoading.estimatedTime} />
|
| 150 |
-
{/if}
|
| 151 |
-
<slot name="bottom" />
|
| 152 |
-
<WidgetFooter bind:isMaximized {outputJson} {isDisabled} />
|
| 153 |
-
</div>
|
| 154 |
-
{/if}
|
| 155 |
{/if}
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { InferenceDisplayability } from "@huggingface/tasks";
|
| 3 |
+
import type { WidgetExample } from "@huggingface/tasks";
|
| 4 |
+
import type { WidgetProps } from "../types.js";
|
| 5 |
|
| 6 |
type TWidgetExample = $$Generic<WidgetExample>;
|
| 7 |
|
| 8 |
import { onMount } from "svelte";
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
import WidgetFooter from "../WidgetFooter/WidgetFooter.svelte";
|
| 11 |
import WidgetHeader from "../WidgetHeader/WidgetHeader.svelte";
|
| 12 |
import WidgetInfo from "../WidgetInfo/WidgetInfo.svelte";
|
| 13 |
+
import IconCross from "../../..//Icons/IconCross.svelte";
|
| 14 |
+
import { getModelLoadInfo } from "../../..//InferenceWidget/shared/helpers.js";
|
| 15 |
+
import { modelLoadStates, widgetStates, updateWidgetState } from "../../stores.js";
|
| 16 |
|
| 17 |
export let apiUrl: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
export let model: WidgetProps["model"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
$: isMaximized = $widgetStates?.[model.id]?.isMaximized;
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
const isDisabled = model.inference !== InferenceDisplayability.Yes && model.pipeline_tag !== "reinforcement-learning";
|
| 24 |
+
updateWidgetState(model.id, "isDisabled", isDisabled);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
onMount(() => {
|
| 27 |
(async () => {
|
| 28 |
+
if (model.inference !== InferenceDisplayability.Yes) {
|
| 29 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
+
const modelLoadInfo = await getModelLoadInfo(apiUrl, model.id, includeCredentials);
|
| 33 |
+
$modelLoadStates[model.id] = modelLoadInfo;
|
| 34 |
+
|
| 35 |
+
if (modelLoadInfo?.state === "TooBig") {
|
| 36 |
+
updateWidgetState(model.id, "isDisabled", true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
})();
|
| 39 |
});
|
| 40 |
</script>
|
| 41 |
|
| 42 |
+
{#if $widgetStates?.[model.id]?.noInference}
|
| 43 |
+
<WidgetHeader {model} noTitle={true} />
|
| 44 |
+
<WidgetInfo {model} />
|
| 45 |
+
{:else if $modelLoadStates[model.id] || model.inference !== InferenceDisplayability.Yes}
|
| 46 |
+
<form
|
| 47 |
+
class="flex w-full max-w-full flex-col
|
| 48 |
+
{isMaximized ? 'fixed inset-0 z-20 bg-white p-12' : ''}"
|
| 49 |
+
>
|
| 50 |
+
{#if isMaximized}
|
| 51 |
+
<button class="absolute right-12 top-6" on:click={() => updateWidgetState(model.id, "isMaximized", false)}>
|
| 52 |
+
<IconCross classNames="text-xl text-gray-500 hover:text-black" />
|
| 53 |
+
</button>
|
| 54 |
+
{/if}
|
| 55 |
+
<slot {WidgetInfo} {WidgetHeader} {WidgetFooter} />
|
| 56 |
+
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
{/if}
|
packages/widgets/src/lib/components/InferenceWidget/shared/helpers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
import type { ModelData,
|
| 2 |
-
import {
|
| 3 |
import type { ModelLoadInfo, TableData } from "./types.js";
|
| 4 |
import { LoadState } from "./types.js";
|
| 5 |
|
|
@@ -21,16 +21,6 @@ export function getQueryParamVal(key: WidgetExampleAttribute): QueryParamVal {
|
|
| 21 |
return value;
|
| 22 |
}
|
| 23 |
|
| 24 |
-
export function getWidgetExample<TWidgetExample extends WidgetExample>(
|
| 25 |
-
model: ModelData,
|
| 26 |
-
validateExample: (sample: WidgetExample) => sample is TWidgetExample
|
| 27 |
-
): TWidgetExample | undefined {
|
| 28 |
-
const validExamples = model.widgetData?.filter(
|
| 29 |
-
(sample): sample is TWidgetExample => sample && validateExample(sample)
|
| 30 |
-
);
|
| 31 |
-
return validExamples?.length ? randomItem(validExamples) : undefined;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
// Update current url search params, keeping existing keys intact.
|
| 35 |
export function updateUrl(obj: Partial<Record<WidgetExampleAttribute, string | undefined>>): void {
|
| 36 |
if (!window) {
|
|
@@ -63,7 +53,6 @@ export async function getBlobFromUrl(url: string): Promise<Blob> {
|
|
| 63 |
const blob = await res.blob();
|
| 64 |
return blob;
|
| 65 |
}
|
| 66 |
-
|
| 67 |
interface Success<T> {
|
| 68 |
computeTime: string;
|
| 69 |
output: T;
|
|
|
|
| 1 |
+
import type { ModelData, WidgetExampleAttribute } from "@huggingface/tasks";
|
| 2 |
+
import { parseJSON } from "../../../utils/ViewUtils.js";
|
| 3 |
import type { ModelLoadInfo, TableData } from "./types.js";
|
| 4 |
import { LoadState } from "./types.js";
|
| 5 |
|
|
|
|
| 21 |
return value;
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
// Update current url search params, keeping existing keys intact.
|
| 25 |
export function updateUrl(obj: Partial<Record<WidgetExampleAttribute, string | undefined>>): void {
|
| 26 |
if (!window) {
|
|
|
|
| 53 |
const blob = await res.blob();
|
| 54 |
return blob;
|
| 55 |
}
|
|
|
|
| 56 |
interface Success<T> {
|
| 57 |
computeTime: string;
|
| 58 |
output: T;
|
packages/widgets/src/lib/components/InferenceWidget/shared/types.ts
CHANGED
|
@@ -40,6 +40,12 @@ export interface ModelLoadInfo {
|
|
| 40 |
compute_type?: ComputeType;
|
| 41 |
}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
export type TableData = Record<string, (string | number)[]>;
|
| 44 |
|
| 45 |
export type HighlightCoordinates = Record<string, string>;
|
|
|
|
| 40 |
compute_type?: ComputeType;
|
| 41 |
}
|
| 42 |
|
| 43 |
+
export interface WidgetState {
|
| 44 |
+
isDisabled?: boolean;
|
| 45 |
+
noInference?: boolean;
|
| 46 |
+
isMaximized?: boolean;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
export type TableData = Record<string, (string | number)[]>;
|
| 50 |
|
| 51 |
export type HighlightCoordinates = Record<string, string>;
|
packages/widgets/src/lib/components/InferenceWidget/stores.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
| 1 |
import { writable } from "svelte/store";
|
| 2 |
-
import type {
|
|
|
|
| 3 |
|
| 4 |
-
export const modelLoadStates = writable<Record<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import { writable } from "svelte/store";
|
| 2 |
+
import type { ModelData } from "@huggingface/tasks";
|
| 3 |
+
import type { ModelLoadInfo, WidgetState } from "./shared/types.js";
|
| 4 |
|
| 5 |
+
export const modelLoadStates = writable<Record<ModelData["id"], ModelLoadInfo>>({});
|
| 6 |
+
|
| 7 |
+
export const widgetNoInference = writable<Record<ModelData["id"], boolean>>({});
|
| 8 |
+
|
| 9 |
+
export const widgetStates = writable<Record<ModelData["id"], WidgetState>>({});
|
| 10 |
+
|
| 11 |
+
export function updateWidgetState(modelId: ModelData["id"], key: keyof WidgetState, val: boolean): void {
|
| 12 |
+
widgetStates.update((states) => {
|
| 13 |
+
// Check if the modelId exists, if not initialize it
|
| 14 |
+
if (!states[modelId]) {
|
| 15 |
+
states[modelId] = {};
|
| 16 |
+
}
|
| 17 |
+
// Update the specific property for the given modelId
|
| 18 |
+
states[modelId][key] = val;
|
| 19 |
+
return states;
|
| 20 |
+
});
|
| 21 |
+
}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte
CHANGED
|
@@ -11,6 +11,7 @@
|
|
| 11 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 12 |
import { isValidOutputLabels } from "../../shared/outputValidation.js";
|
| 13 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
|
|
|
| 14 |
|
| 15 |
export let apiToken: WidgetProps["apiToken"];
|
| 16 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -19,6 +20,8 @@
|
|
| 19 |
export let noTitle: WidgetProps["noTitle"];
|
| 20 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 21 |
|
|
|
|
|
|
|
| 22 |
let computeTime = "";
|
| 23 |
let error: string = "";
|
| 24 |
let file: Blob | File | null = null;
|
|
@@ -130,7 +133,7 @@
|
|
| 130 |
throw new TypeError("Invalid output: output must be of type Array<label: string, score:number>");
|
| 131 |
}
|
| 132 |
|
| 133 |
-
function
|
| 134 |
filename = sample.example_title!;
|
| 135 |
fileUrl = sample.src;
|
| 136 |
|
|
@@ -155,44 +158,32 @@
|
|
| 155 |
}
|
| 156 |
</script>
|
| 157 |
|
| 158 |
-
<WidgetWrapper
|
| 159 |
-
{callApiOnMount}
|
| 160 |
-
|
| 161 |
-
{
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
{
|
| 167 |
-
|
| 168 |
-
{
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
onClick={() => {
|
| 187 |
-
getOutput();
|
| 188 |
-
}}
|
| 189 |
-
/>
|
| 190 |
-
{#if warning}
|
| 191 |
-
<div class="alert alert-warning mt-2">{warning}</div>
|
| 192 |
-
{/if}
|
| 193 |
-
</form>
|
| 194 |
-
</svelte:fragment>
|
| 195 |
-
<svelte:fragment slot="bottom">
|
| 196 |
-
<WidgetOutputChart classNames="pt-4" {output} />
|
| 197 |
-
</svelte:fragment>
|
| 198 |
</WidgetWrapper>
|
|
|
|
| 11 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 12 |
import { isValidOutputLabels } from "../../shared/outputValidation.js";
|
| 13 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 14 |
+
import { widgetStates } from "../../stores.js";
|
| 15 |
|
| 16 |
export let apiToken: WidgetProps["apiToken"];
|
| 17 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 20 |
export let noTitle: WidgetProps["noTitle"];
|
| 21 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 22 |
|
| 23 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 24 |
+
|
| 25 |
let computeTime = "";
|
| 26 |
let error: string = "";
|
| 27 |
let file: Blob | File | null = null;
|
|
|
|
| 133 |
throw new TypeError("Invalid output: output must be of type Array<label: string, score:number>");
|
| 134 |
}
|
| 135 |
|
| 136 |
+
function applyWidgetExample(sample: WidgetExampleAssetInput<WidgetExampleOutputLabels>, opts: ExampleRunOpts = {}) {
|
| 137 |
filename = sample.example_title!;
|
| 138 |
fileUrl = sample.src;
|
| 139 |
|
|
|
|
| 158 |
}
|
| 159 |
</script>
|
| 160 |
|
| 161 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 162 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 163 |
+
|
| 164 |
+
<div class="flex flex-wrap items-center {isDisabled ? 'pointer-events-none hidden opacity-50' : ''}">
|
| 165 |
+
<WidgetFileInput accept="audio/*" classNames="mt-1.5 mr-2" {onSelectFile} />
|
| 166 |
+
<span class="mr-2 mt-1.5">or</span>
|
| 167 |
+
<WidgetRecorder classNames="mt-1.5" {onRecordStart} onRecordStop={onSelectFile} onError={onRecordError} />
|
| 168 |
+
</div>
|
| 169 |
+
{#if fileUrl}
|
| 170 |
+
<WidgetAudioTrack classNames="mt-3" label={filename} src={fileUrl} />
|
| 171 |
+
{/if}
|
| 172 |
+
<WidgetSubmitBtn
|
| 173 |
+
classNames="mt-2"
|
| 174 |
+
isDisabled={isRecording || isDisabled}
|
| 175 |
+
{isLoading}
|
| 176 |
+
onClick={() => {
|
| 177 |
+
getOutput();
|
| 178 |
+
}}
|
| 179 |
+
/>
|
| 180 |
+
{#if warning}
|
| 181 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 182 |
+
{/if}
|
| 183 |
+
|
| 184 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 185 |
+
|
| 186 |
+
<WidgetOutputChart classNames="pt-4" {output} />
|
| 187 |
+
|
| 188 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/AudioToAudioWidget/AudioToAudioWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 11 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
|
|
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -16,7 +17,8 @@
|
|
| 16 |
export let model: WidgetProps["model"];
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
let computeTime = "";
|
| 22 |
let error: string = "";
|
|
@@ -131,7 +133,7 @@
|
|
| 131 |
throw new TypeError("Invalid output: output must be of type Array<blob:string, label:string, content-type:string>");
|
| 132 |
}
|
| 133 |
|
| 134 |
-
function
|
| 135 |
filename = sample.example_title ?? "";
|
| 136 |
fileUrl = sample.src;
|
| 137 |
if (opts.isPreview) {
|
|
@@ -146,46 +148,42 @@
|
|
| 146 |
}
|
| 147 |
</script>
|
| 148 |
|
| 149 |
-
<WidgetWrapper
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
{
|
| 161 |
-
|
| 162 |
-
>
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
<WidgetAudioTrack classNames="" src={item.src} />
|
| 188 |
-
</div>
|
| 189 |
-
{/each}
|
| 190 |
-
</svelte:fragment>
|
| 191 |
</WidgetWrapper>
|
|
|
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 11 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 17 |
export let model: WidgetProps["model"];
|
| 18 |
export let noTitle: WidgetProps["noTitle"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
+
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
|
|
|
| 133 |
throw new TypeError("Invalid output: output must be of type Array<blob:string, label:string, content-type:string>");
|
| 134 |
}
|
| 135 |
|
| 136 |
+
function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
|
| 137 |
filename = sample.example_title ?? "";
|
| 138 |
fileUrl = sample.src;
|
| 139 |
if (opts.isPreview) {
|
|
|
|
| 148 |
}
|
| 149 |
</script>
|
| 150 |
|
| 151 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 152 |
+
<WidgetHeader
|
| 153 |
+
{noTitle}
|
| 154 |
+
{model}
|
| 155 |
+
{isLoading}
|
| 156 |
+
{isDisabled}
|
| 157 |
+
{callApiOnMount}
|
| 158 |
+
{applyWidgetExample}
|
| 159 |
+
validateExample={isAssetInput}
|
| 160 |
+
/>
|
| 161 |
+
|
| 162 |
+
<div class="flex flex-wrap items-center {isDisabled ? 'pointer-events-none hidden opacity-50' : ''}">
|
| 163 |
+
<WidgetFileInput accept="audio/*" classNames="mt-1.5 mr-2" {onSelectFile} />
|
| 164 |
+
<span class="mr-2 mt-1.5">or</span>
|
| 165 |
+
<WidgetRecorder classNames="mt-1.5" {onRecordStart} onRecordStop={onSelectFile} onError={onRecordError} />
|
| 166 |
+
</div>
|
| 167 |
+
{#if fileUrl}
|
| 168 |
+
<WidgetAudioTrack classNames="mt-3" label={filename} src={fileUrl} />
|
| 169 |
+
{/if}
|
| 170 |
+
<WidgetSubmitBtn
|
| 171 |
+
classNames="mt-2"
|
| 172 |
+
isDisabled={isRecording || isDisabled}
|
| 173 |
+
{isLoading}
|
| 174 |
+
onClick={() => {
|
| 175 |
+
getOutput();
|
| 176 |
+
}}
|
| 177 |
+
/>
|
| 178 |
+
|
| 179 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 180 |
+
|
| 181 |
+
{#each output as item}
|
| 182 |
+
<div class="mt-2 flex items-center">
|
| 183 |
+
<span class="mr-2">{item.label}:</span>
|
| 184 |
+
<WidgetAudioTrack classNames="" src={item.src} />
|
| 185 |
+
</div>
|
| 186 |
+
{/each}
|
| 187 |
+
|
| 188 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/AutomaticSpeechRecognitionWidget/AutomaticSpeechRecognitionWidget.svelte
CHANGED
|
@@ -12,6 +12,7 @@
|
|
| 12 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 13 |
import { isValidOutputText } from "../../shared/outputValidation.js";
|
| 14 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
|
|
|
| 15 |
|
| 16 |
export let apiToken: WidgetProps["apiToken"];
|
| 17 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -19,7 +20,8 @@
|
|
| 19 |
export let model: WidgetProps["model"];
|
| 20 |
export let noTitle: WidgetProps["noTitle"];
|
| 21 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
let computeTime = "";
|
| 25 |
let error: string = "";
|
|
@@ -133,7 +135,7 @@
|
|
| 133 |
throw new TypeError("Invalid output: output must be of type <text:string>");
|
| 134 |
}
|
| 135 |
|
| 136 |
-
function
|
| 137 |
filename = sample.example_title!;
|
| 138 |
fileUrl = sample.src;
|
| 139 |
if (opts.isPreview) {
|
|
@@ -161,62 +163,50 @@
|
|
| 161 |
}
|
| 162 |
</script>
|
| 163 |
|
| 164 |
-
<WidgetWrapper
|
| 165 |
-
{callApiOnMount}
|
| 166 |
-
|
| 167 |
-
{
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
{noTitle}
|
| 175 |
-
{outputJson}
|
| 176 |
-
{validateExample}
|
| 177 |
-
>
|
| 178 |
-
<svelte:fragment slot="top" let:isDisabled>
|
| 179 |
-
<form>
|
| 180 |
-
<div class="flex flex-wrap items-center {isDisabled ? 'pointer-events-none hidden opacity-50' : ''}">
|
| 181 |
-
{#if !isRealtimeRecording}
|
| 182 |
-
<WidgetFileInput accept="audio/*" classNames="mt-1.5" {onSelectFile} />
|
| 183 |
-
<span class="mx-2 mt-1.5">or</span>
|
| 184 |
-
<WidgetRecorder classNames="mt-1.5" {onRecordStart} onRecordStop={onSelectFile} onError={onRecordError} />
|
| 185 |
-
{/if}
|
| 186 |
-
{#if model?.library_name === "transformers"}
|
| 187 |
-
{#if !isRealtimeRecording}
|
| 188 |
-
<span class="mx-2 mt-1.5">or</span>
|
| 189 |
-
{/if}
|
| 190 |
-
<WidgetRealtimeRecorder
|
| 191 |
-
classNames="mt-1.5"
|
| 192 |
-
{apiToken}
|
| 193 |
-
{model}
|
| 194 |
-
{updateModelLoading}
|
| 195 |
-
onRecordStart={() => (isRealtimeRecording = true)}
|
| 196 |
-
onRecordStop={() => (isRealtimeRecording = false)}
|
| 197 |
-
onError={onRecordError}
|
| 198 |
-
/>
|
| 199 |
-
{/if}
|
| 200 |
-
</div>
|
| 201 |
{#if !isRealtimeRecording}
|
| 202 |
-
|
| 203 |
-
<WidgetAudioTrack classNames="mt-3" label={filename} src={fileUrl} />
|
| 204 |
-
{/if}
|
| 205 |
-
<WidgetSubmitBtn
|
| 206 |
-
classNames="mt-2"
|
| 207 |
-
isDisabled={isRecording || isDisabled}
|
| 208 |
-
{isLoading}
|
| 209 |
-
onClick={() => {
|
| 210 |
-
getOutput();
|
| 211 |
-
}}
|
| 212 |
-
/>
|
| 213 |
-
{#if warning}
|
| 214 |
-
<div class="alert alert-warning mt-2">{warning}</div>
|
| 215 |
-
{/if}
|
| 216 |
{/if}
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
</WidgetWrapper>
|
|
|
|
| 12 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 13 |
import { isValidOutputText } from "../../shared/outputValidation.js";
|
| 14 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 15 |
+
import { widgetStates } from "../../stores.js";
|
| 16 |
|
| 17 |
export let apiToken: WidgetProps["apiToken"];
|
| 18 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 20 |
export let model: WidgetProps["model"];
|
| 21 |
export let noTitle: WidgetProps["noTitle"];
|
| 22 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 23 |
+
|
| 24 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 25 |
|
| 26 |
let computeTime = "";
|
| 27 |
let error: string = "";
|
|
|
|
| 135 |
throw new TypeError("Invalid output: output must be of type <text:string>");
|
| 136 |
}
|
| 137 |
|
| 138 |
+
function applyWidgetExample(sample: WidgetExampleAssetInput<WidgetExampleOutputText>, opts: ExampleRunOpts = {}) {
|
| 139 |
filename = sample.example_title!;
|
| 140 |
fileUrl = sample.src;
|
| 141 |
if (opts.isPreview) {
|
|
|
|
| 163 |
}
|
| 164 |
</script>
|
| 165 |
|
| 166 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 167 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 168 |
+
|
| 169 |
+
<div class="flex flex-wrap items-center {isDisabled ? 'pointer-events-none hidden opacity-50' : ''}">
|
| 170 |
+
{#if !isRealtimeRecording}
|
| 171 |
+
<WidgetFileInput accept="audio/*" classNames="mt-1.5" {onSelectFile} />
|
| 172 |
+
<span class="mx-2 mt-1.5">or</span>
|
| 173 |
+
<WidgetRecorder classNames="mt-1.5" {onRecordStart} onRecordStop={onSelectFile} onError={onRecordError} />
|
| 174 |
+
{/if}
|
| 175 |
+
{#if model?.library_name === "transformers"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
{#if !isRealtimeRecording}
|
| 177 |
+
<span class="mx-2 mt-1.5">or</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
{/if}
|
| 179 |
+
<WidgetRealtimeRecorder
|
| 180 |
+
classNames="mt-1.5"
|
| 181 |
+
{apiToken}
|
| 182 |
+
{model}
|
| 183 |
+
{updateModelLoading}
|
| 184 |
+
onRecordStart={() => (isRealtimeRecording = true)}
|
| 185 |
+
onRecordStop={() => (isRealtimeRecording = false)}
|
| 186 |
+
onError={onRecordError}
|
| 187 |
+
/>
|
| 188 |
+
{/if}
|
| 189 |
+
</div>
|
| 190 |
+
{#if !isRealtimeRecording}
|
| 191 |
+
{#if fileUrl}
|
| 192 |
+
<WidgetAudioTrack classNames="mt-3" label={filename} src={fileUrl} />
|
| 193 |
+
{/if}
|
| 194 |
+
<WidgetSubmitBtn
|
| 195 |
+
classNames="mt-2"
|
| 196 |
+
isDisabled={isRecording || isDisabled}
|
| 197 |
+
{isLoading}
|
| 198 |
+
onClick={() => {
|
| 199 |
+
getOutput();
|
| 200 |
+
}}
|
| 201 |
+
/>
|
| 202 |
+
{#if warning}
|
| 203 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 204 |
+
{/if}
|
| 205 |
+
{/if}
|
| 206 |
+
|
| 207 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 208 |
+
|
| 209 |
+
<WidgetOutputText classNames="mt-4" {output} />
|
| 210 |
+
|
| 211 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 212 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
CHANGED
|
@@ -7,6 +7,7 @@
|
|
| 7 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 8 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 9 |
import { isTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 10 |
|
| 11 |
export let apiToken: WidgetProps["apiToken"];
|
| 12 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -15,7 +16,8 @@
|
|
| 15 |
export let noTitle: WidgetProps["noTitle"];
|
| 16 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 17 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
interface Conversation {
|
| 21 |
generated_responses: string[];
|
|
@@ -143,7 +145,7 @@
|
|
| 143 |
);
|
| 144 |
}
|
| 145 |
|
| 146 |
-
function
|
| 147 |
text = sample.text;
|
| 148 |
if (opts.isPreview) {
|
| 149 |
return;
|
|
@@ -153,34 +155,30 @@
|
|
| 153 |
}
|
| 154 |
</script>
|
| 155 |
|
| 156 |
-
<WidgetWrapper
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
{
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
submitButtonLabel="Send"
|
| 183 |
-
/>
|
| 184 |
-
</form>
|
| 185 |
-
</svelte:fragment>
|
| 186 |
</WidgetWrapper>
|
|
|
|
| 7 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 8 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 9 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 10 |
+
import { widgetStates } from "../../stores.js";
|
| 11 |
|
| 12 |
export let apiToken: WidgetProps["apiToken"];
|
| 13 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 16 |
export let noTitle: WidgetProps["noTitle"];
|
| 17 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
+
|
| 20 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 21 |
|
| 22 |
interface Conversation {
|
| 23 |
generated_responses: string[];
|
|
|
|
| 145 |
);
|
| 146 |
}
|
| 147 |
|
| 148 |
+
function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
|
| 149 |
text = sample.text;
|
| 150 |
if (opts.isPreview) {
|
| 151 |
return;
|
|
|
|
| 155 |
}
|
| 156 |
</script>
|
| 157 |
|
| 158 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 159 |
+
<WidgetHeader
|
| 160 |
+
{noTitle}
|
| 161 |
+
{model}
|
| 162 |
+
{isLoading}
|
| 163 |
+
{isDisabled}
|
| 164 |
+
{callApiOnMount}
|
| 165 |
+
{applyWidgetExample}
|
| 166 |
+
validateExample={isTextInput}
|
| 167 |
+
/>
|
| 168 |
+
<WidgetOutputConvo modelId={model.id} {output} />
|
| 169 |
+
|
| 170 |
+
<WidgetQuickInput
|
| 171 |
+
bind:value={text}
|
| 172 |
+
flatTop={true}
|
| 173 |
+
{isLoading}
|
| 174 |
+
{isDisabled}
|
| 175 |
+
onClickSubmitBtn={() => {
|
| 176 |
+
getOutput();
|
| 177 |
+
}}
|
| 178 |
+
submitButtonLabel="Send"
|
| 179 |
+
/>
|
| 180 |
+
|
| 181 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 182 |
+
|
| 183 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 9 |
|
| 10 |
import { DataTable } from "./DataTable.js";
|
|
|
|
| 11 |
|
| 12 |
export let apiToken: WidgetProps["apiToken"];
|
| 13 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -16,7 +17,8 @@
|
|
| 16 |
export let noTitle: WidgetProps["noTitle"];
|
| 17 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
let computeTime = "";
|
| 22 |
let error: string = "";
|
|
@@ -111,7 +113,7 @@
|
|
| 111 |
return Math.ceil(total_elems / SINGLE_DIM_COLS);
|
| 112 |
};
|
| 113 |
|
| 114 |
-
function
|
| 115 |
text = sample.text;
|
| 116 |
if (opts.isPreview) {
|
| 117 |
return;
|
|
@@ -121,76 +123,71 @@
|
|
| 121 |
}
|
| 122 |
</script>
|
| 123 |
|
| 124 |
-
<WidgetWrapper
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
<svelte:fragment slot="bottom">
|
| 152 |
-
{#if output}
|
| 153 |
-
{#if output.isArrLevel0}
|
| 154 |
-
<div class="mt-3 h-96 overflow-auto">
|
| 155 |
-
<table class="w-full table-auto border text-right font-mono text-xs">
|
| 156 |
-
{#each range(numOfRows(output.oneDim.length)) as i}
|
| 157 |
-
<tr>
|
| 158 |
-
{#each range(SINGLE_DIM_COLS) as j}
|
| 159 |
-
{#if j * numOfRows(output.oneDim.length) + i < output.oneDim.length}
|
| 160 |
-
<td class="bg-gray-100 px-1 text-gray-400 dark:bg-gray-900">
|
| 161 |
-
{j * numOfRows(output.oneDim.length) + i}
|
| 162 |
-
</td>
|
| 163 |
-
<td class="px-1 py-0.5 {output.bg(output.oneDim[j * numOfRows(output.oneDim.length) + i])}">
|
| 164 |
-
{output.oneDim[j * numOfRows(output.oneDim.length) + i].toFixed(3)}
|
| 165 |
-
</td>
|
| 166 |
-
{/if}
|
| 167 |
-
{/each}
|
| 168 |
-
</tr>
|
| 169 |
-
{/each}
|
| 170 |
-
</table>
|
| 171 |
-
</div>
|
| 172 |
-
{:else}
|
| 173 |
-
<div class="mt-3 overflow-auto">
|
| 174 |
-
<table class="border text-right font-mono text-xs">
|
| 175 |
<tr>
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
{/each}
|
| 180 |
</tr>
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
| 190 |
{/each}
|
| 191 |
-
</
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
{/if}
|
| 195 |
-
|
|
|
|
|
|
|
| 196 |
</WidgetWrapper>
|
|
|
|
| 8 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 9 |
|
| 10 |
import { DataTable } from "./DataTable.js";
|
| 11 |
+
import { widgetStates } from "../../stores.js";
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
+
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
|
|
|
| 113 |
return Math.ceil(total_elems / SINGLE_DIM_COLS);
|
| 114 |
};
|
| 115 |
|
| 116 |
+
function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
|
| 117 |
text = sample.text;
|
| 118 |
if (opts.isPreview) {
|
| 119 |
return;
|
|
|
|
| 123 |
}
|
| 124 |
</script>
|
| 125 |
|
| 126 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 127 |
+
<WidgetHeader
|
| 128 |
+
{noTitle}
|
| 129 |
+
{model}
|
| 130 |
+
{isLoading}
|
| 131 |
+
{isDisabled}
|
| 132 |
+
{callApiOnMount}
|
| 133 |
+
{applyWidgetExample}
|
| 134 |
+
validateExample={isTextInput}
|
| 135 |
+
/>
|
| 136 |
+
|
| 137 |
+
<WidgetQuickInput
|
| 138 |
+
bind:value={text}
|
| 139 |
+
{isLoading}
|
| 140 |
+
{isDisabled}
|
| 141 |
+
onClickSubmitBtn={() => {
|
| 142 |
+
getOutput();
|
| 143 |
+
}}
|
| 144 |
+
/>
|
| 145 |
+
|
| 146 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 147 |
+
|
| 148 |
+
{#if output}
|
| 149 |
+
{#if output.isArrLevel0}
|
| 150 |
+
<div class="mt-3 h-96 overflow-auto">
|
| 151 |
+
<table class="w-full table-auto border text-right font-mono text-xs">
|
| 152 |
+
{#each range(numOfRows(output.oneDim.length)) as i}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
<tr>
|
| 154 |
+
{#each range(SINGLE_DIM_COLS) as j}
|
| 155 |
+
{#if j * numOfRows(output.oneDim.length) + i < output.oneDim.length}
|
| 156 |
+
<td class="bg-gray-100 px-1 text-gray-400 dark:bg-gray-900">
|
| 157 |
+
{j * numOfRows(output.oneDim.length) + i}
|
| 158 |
+
</td>
|
| 159 |
+
<td class="px-1 py-0.5 {output.bg(output.oneDim[j * numOfRows(output.oneDim.length) + i])}">
|
| 160 |
+
{output.oneDim[j * numOfRows(output.oneDim.length) + i].toFixed(3)}
|
| 161 |
+
</td>
|
| 162 |
+
{/if}
|
| 163 |
{/each}
|
| 164 |
</tr>
|
| 165 |
+
{/each}
|
| 166 |
+
</table>
|
| 167 |
+
</div>
|
| 168 |
+
{:else}
|
| 169 |
+
<div class="mt-3 overflow-auto">
|
| 170 |
+
<table class="border text-right font-mono text-xs">
|
| 171 |
+
<tr>
|
| 172 |
+
<td class="bg-gray-100 dark:bg-gray-900" />
|
| 173 |
+
{#each range(output.twoDim[0].length) as j}
|
| 174 |
+
<td class="bg-gray-100 px-1 pt-1 text-gray-400 dark:bg-gray-900">{j}</td>
|
| 175 |
{/each}
|
| 176 |
+
</tr>
|
| 177 |
+
{#each output.twoDim as column, i}
|
| 178 |
+
<tr>
|
| 179 |
+
<td class="bg-gray-100 pl-4 pr-1 text-gray-400 dark:bg-gray-900">{i}</td>
|
| 180 |
+
{#each column as x}
|
| 181 |
+
<td class="px-1 py-1 {output.bg(x)}">
|
| 182 |
+
{x.toFixed(3)}
|
| 183 |
+
</td>
|
| 184 |
+
{/each}
|
| 185 |
+
</tr>
|
| 186 |
+
{/each}
|
| 187 |
+
</table>
|
| 188 |
+
</div>
|
| 189 |
{/if}
|
| 190 |
+
{/if}
|
| 191 |
+
|
| 192 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 193 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isValidOutputLabels } from "../../shared/outputValidation.js";
|
| 11 |
import { isTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -18,6 +19,8 @@
|
|
| 18 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
|
|
|
|
|
|
|
| 21 |
let computeTime = "";
|
| 22 |
let error: string = "";
|
| 23 |
let isLoading = false;
|
|
@@ -112,7 +115,7 @@
|
|
| 112 |
throw new TypeError("Invalid output: output must be of type Array");
|
| 113 |
}
|
| 114 |
|
| 115 |
-
function
|
| 116 |
setTextAreaValue(sample.text);
|
| 117 |
if (opts.isPreview) {
|
| 118 |
if (sample.output) {
|
|
@@ -131,40 +134,27 @@
|
|
| 131 |
}
|
| 132 |
</script>
|
| 133 |
|
| 134 |
-
<WidgetWrapper
|
| 135 |
-
{callApiOnMount}
|
| 136 |
-
|
| 137 |
-
{
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
{
|
| 142 |
-
{
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
<WidgetSubmitBtn
|
| 158 |
-
classNames="mt-2"
|
| 159 |
-
{isLoading}
|
| 160 |
-
{isDisabled}
|
| 161 |
-
onClick={() => {
|
| 162 |
-
getOutput();
|
| 163 |
-
}}
|
| 164 |
-
/>
|
| 165 |
-
</form>
|
| 166 |
-
</svelte:fragment>
|
| 167 |
-
<svelte:fragment slot="bottom">
|
| 168 |
-
<WidgetOutputChart classNames="pt-4" {output} />
|
| 169 |
-
</svelte:fragment>
|
| 170 |
</WidgetWrapper>
|
|
|
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isValidOutputLabels } from "../../shared/outputValidation.js";
|
| 11 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 19 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 20 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 21 |
|
| 22 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 23 |
+
|
| 24 |
let computeTime = "";
|
| 25 |
let error: string = "";
|
| 26 |
let isLoading = false;
|
|
|
|
| 115 |
throw new TypeError("Invalid output: output must be of type Array");
|
| 116 |
}
|
| 117 |
|
| 118 |
+
function applyWidgetExample(sample: WidgetExampleTextInput<WidgetExampleOutputLabels>, opts: ExampleRunOpts = {}) {
|
| 119 |
setTextAreaValue(sample.text);
|
| 120 |
if (opts.isPreview) {
|
| 121 |
if (sample.output) {
|
|
|
|
| 134 |
}
|
| 135 |
</script>
|
| 136 |
|
| 137 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 138 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 139 |
+
|
| 140 |
+
{#if model.pipeline_tag === "fill-mask"}
|
| 141 |
+
<div class="mb-1.5 text-sm text-gray-500">
|
| 142 |
+
Mask token: <code>{model.mask_token}</code>
|
| 143 |
+
</div>
|
| 144 |
+
{/if}
|
| 145 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} />
|
| 146 |
+
<WidgetSubmitBtn
|
| 147 |
+
classNames="mt-2"
|
| 148 |
+
{isLoading}
|
| 149 |
+
{isDisabled}
|
| 150 |
+
onClick={() => {
|
| 151 |
+
getOutput();
|
| 152 |
+
}}
|
| 153 |
+
/>
|
| 154 |
+
|
| 155 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 156 |
+
|
| 157 |
+
<WidgetOutputChart classNames="pt-4" {output} />
|
| 158 |
+
|
| 159 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 10 |
import { isValidOutputLabels } from "../../shared/outputValidation.js";
|
| 11 |
import { isTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -17,6 +18,8 @@
|
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
|
|
|
|
|
|
|
| 20 |
let computeTime = "";
|
| 21 |
let error: string = "";
|
| 22 |
let isLoading = false;
|
|
@@ -92,7 +95,7 @@
|
|
| 92 |
throw new TypeError("Invalid output: output must be of type Array<label: string, score:number>");
|
| 93 |
}
|
| 94 |
|
| 95 |
-
async function
|
| 96 |
sample: WidgetExampleAssetInput<WidgetExampleOutputLabels>,
|
| 97 |
opts: ExampleRunOpts = {}
|
| 98 |
) {
|
|
@@ -117,56 +120,44 @@
|
|
| 117 |
}
|
| 118 |
</script>
|
| 119 |
|
| 120 |
-
<WidgetWrapper
|
| 121 |
-
{callApiOnMount}
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
{
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
{isDisabled}
|
| 161 |
-
label="Browse for image"
|
| 162 |
-
{onSelectFile}
|
| 163 |
-
/>
|
| 164 |
-
{#if warning}
|
| 165 |
-
<div class="alert alert-warning mt-2">{warning}</div>
|
| 166 |
-
{/if}
|
| 167 |
-
</form>
|
| 168 |
-
</svelte:fragment>
|
| 169 |
-
<svelte:fragment slot="bottom">
|
| 170 |
-
<WidgetOutputChart classNames="pt-4" {output} />
|
| 171 |
-
</svelte:fragment>
|
| 172 |
</WidgetWrapper>
|
|
|
|
| 9 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 10 |
import { isValidOutputLabels } from "../../shared/outputValidation.js";
|
| 11 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 18 |
export let noTitle: WidgetProps["noTitle"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
+
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
| 25 |
let isLoading = false;
|
|
|
|
| 95 |
throw new TypeError("Invalid output: output must be of type Array<label: string, score:number>");
|
| 96 |
}
|
| 97 |
|
| 98 |
+
async function applyWidgetExample(
|
| 99 |
sample: WidgetExampleAssetInput<WidgetExampleOutputLabels>,
|
| 100 |
opts: ExampleRunOpts = {}
|
| 101 |
) {
|
|
|
|
| 120 |
}
|
| 121 |
</script>
|
| 122 |
|
| 123 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 124 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 125 |
+
|
| 126 |
+
<WidgetDropzone
|
| 127 |
+
classNames="no-hover:hidden"
|
| 128 |
+
{isLoading}
|
| 129 |
+
{isDisabled}
|
| 130 |
+
{imgSrc}
|
| 131 |
+
{onSelectFile}
|
| 132 |
+
onError={(e) => (error = e)}
|
| 133 |
+
>
|
| 134 |
+
{#if imgSrc}
|
| 135 |
+
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 136 |
+
{/if}
|
| 137 |
+
</WidgetDropzone>
|
| 138 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 139 |
+
{#if imgSrc}
|
| 140 |
+
{#if imgSrc}
|
| 141 |
+
<div class="mb-2 flex justify-center bg-gray-50 dark:bg-gray-900 md:hidden">
|
| 142 |
+
<img src={imgSrc} class="pointer-events-none max-h-44" alt="" />
|
| 143 |
+
</div>
|
| 144 |
+
{/if}
|
| 145 |
+
{/if}
|
| 146 |
+
<WidgetFileInput
|
| 147 |
+
accept="image/*"
|
| 148 |
+
classNames="mr-2 md:hidden"
|
| 149 |
+
{isLoading}
|
| 150 |
+
{isDisabled}
|
| 151 |
+
label="Browse for image"
|
| 152 |
+
{onSelectFile}
|
| 153 |
+
/>
|
| 154 |
+
{#if warning}
|
| 155 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 156 |
+
{/if}
|
| 157 |
+
|
| 158 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 159 |
+
|
| 160 |
+
<WidgetOutputChart classNames="pt-4" {output} />
|
| 161 |
+
|
| 162 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ImageSegmentationWidget/ImageSegmentationWidget.svelte
CHANGED
|
@@ -14,6 +14,7 @@
|
|
| 14 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 15 |
|
| 16 |
import Canvas from "./Canvas.svelte";
|
|
|
|
| 17 |
|
| 18 |
export let apiToken: WidgetProps["apiToken"];
|
| 19 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -22,6 +23,8 @@
|
|
| 22 |
export let noTitle: WidgetProps["noTitle"];
|
| 23 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 24 |
|
|
|
|
|
|
|
| 25 |
const maskOpacity = Math.floor(255 * 0.6);
|
| 26 |
const colorToRgb = Object.fromEntries(
|
| 27 |
COLORS.map((color) => {
|
|
@@ -210,7 +213,7 @@
|
|
| 210 |
};
|
| 211 |
}
|
| 212 |
|
| 213 |
-
async function
|
| 214 |
imgSrc = sample.src;
|
| 215 |
if (opts.isPreview) {
|
| 216 |
output = [];
|
|
@@ -229,53 +232,49 @@
|
|
| 229 |
});
|
| 230 |
</script>
|
| 231 |
|
| 232 |
-
<WidgetWrapper
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
</svelte:fragment>
|
| 278 |
-
<svelte:fragment slot="bottom">
|
| 279 |
-
<WidgetOutputChart classNames="pt-4" {output} {highlightIndex} {mouseover} {mouseout} />
|
| 280 |
-
</svelte:fragment>
|
| 281 |
</WidgetWrapper>
|
|
|
|
| 14 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 15 |
|
| 16 |
import Canvas from "./Canvas.svelte";
|
| 17 |
+
import { widgetStates } from "../../stores.js";
|
| 18 |
|
| 19 |
export let apiToken: WidgetProps["apiToken"];
|
| 20 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 23 |
export let noTitle: WidgetProps["noTitle"];
|
| 24 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 25 |
|
| 26 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 27 |
+
|
| 28 |
const maskOpacity = Math.floor(255 * 0.6);
|
| 29 |
const colorToRgb = Object.fromEntries(
|
| 30 |
COLORS.map((color) => {
|
|
|
|
| 213 |
};
|
| 214 |
}
|
| 215 |
|
| 216 |
+
async function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
|
| 217 |
imgSrc = sample.src;
|
| 218 |
if (opts.isPreview) {
|
| 219 |
output = [];
|
|
|
|
| 232 |
});
|
| 233 |
</script>
|
| 234 |
|
| 235 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 236 |
+
<WidgetHeader
|
| 237 |
+
{noTitle}
|
| 238 |
+
{model}
|
| 239 |
+
{isLoading}
|
| 240 |
+
{isDisabled}
|
| 241 |
+
{callApiOnMount}
|
| 242 |
+
{applyWidgetExample}
|
| 243 |
+
validateExample={isAssetInput}
|
| 244 |
+
/>
|
| 245 |
+
|
| 246 |
+
<WidgetDropzone
|
| 247 |
+
classNames="hidden md:block"
|
| 248 |
+
{isLoading}
|
| 249 |
+
{isDisabled}
|
| 250 |
+
{imgSrc}
|
| 251 |
+
{onSelectFile}
|
| 252 |
+
onError={(e) => (error = e)}
|
| 253 |
+
>
|
| 254 |
+
{#if imgSrc}
|
| 255 |
+
<Canvas {imgSrc} {highlightIndex} {mousemove} {mouseout} {output} />
|
| 256 |
+
{/if}
|
| 257 |
+
</WidgetDropzone>
|
| 258 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 259 |
+
{#if imgSrc}
|
| 260 |
+
<Canvas classNames="mr-2 md:hidden" {imgSrc} {highlightIndex} {mousemove} {mouseout} {output} />
|
| 261 |
+
{/if}
|
| 262 |
+
<WidgetFileInput
|
| 263 |
+
accept="image/*"
|
| 264 |
+
classNames="mr-2 md:hidden"
|
| 265 |
+
{isLoading}
|
| 266 |
+
{isDisabled}
|
| 267 |
+
label="Browse for image"
|
| 268 |
+
{onSelectFile}
|
| 269 |
+
/>
|
| 270 |
+
{#if warning}
|
| 271 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 272 |
+
{/if}
|
| 273 |
+
<img alt="" bind:this={imgEl} class="hidden" src={imgSrc} />
|
| 274 |
+
|
| 275 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 276 |
+
|
| 277 |
+
<WidgetOutputChart classNames="pt-4" {output} {highlightIndex} {mouseover} {mouseout} />
|
| 278 |
+
|
| 279 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 11 |
import { isAssetAndPromptInput } from "../../shared/inputValidation.js";
|
|
|
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -17,6 +18,8 @@
|
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
|
|
|
|
|
|
|
| 20 |
let computeTime = "";
|
| 21 |
let error: string = "";
|
| 22 |
let isLoading = false;
|
|
@@ -61,7 +64,7 @@
|
|
| 61 |
throw new TypeError("Invalid output: output must be of type object & of instance Blob");
|
| 62 |
}
|
| 63 |
|
| 64 |
-
async function
|
| 65 |
prompt = sample.prompt;
|
| 66 |
imgSrc = sample.src;
|
| 67 |
if (opts.isPreview) {
|
|
@@ -133,70 +136,66 @@
|
|
| 133 |
}
|
| 134 |
</script>
|
| 135 |
|
| 136 |
-
<WidgetWrapper
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
{imgSrc}
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 162 |
-
{/if}
|
| 163 |
-
</WidgetDropzone>
|
| 164 |
-
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 165 |
{#if imgSrc}
|
| 166 |
-
|
| 167 |
-
<
|
| 168 |
-
|
| 169 |
-
</div>
|
| 170 |
-
{/if}
|
| 171 |
{/if}
|
| 172 |
-
<WidgetFileInput
|
| 173 |
-
accept="image/*"
|
| 174 |
-
classNames="mr-2 md:hidden"
|
| 175 |
-
{isLoading}
|
| 176 |
-
{isDisabled}
|
| 177 |
-
label="Browse for image"
|
| 178 |
-
{onSelectFile}
|
| 179 |
-
/>
|
| 180 |
-
<WidgetTextInput
|
| 181 |
-
bind:value={prompt}
|
| 182 |
-
{isDisabled}
|
| 183 |
-
label="(Optional) Text-guidance if the model has support for it"
|
| 184 |
-
placeholder="Your prompt here..."
|
| 185 |
-
/>
|
| 186 |
-
<WidgetSubmitBtn
|
| 187 |
-
{isLoading}
|
| 188 |
-
{isDisabled}
|
| 189 |
-
onClick={() => {
|
| 190 |
-
getOutput();
|
| 191 |
-
}}
|
| 192 |
-
/>
|
| 193 |
-
</form>
|
| 194 |
-
</svelte:fragment>
|
| 195 |
-
<svelte:fragment slot="bottom">
|
| 196 |
-
{#if output.length}
|
| 197 |
-
<div class="mt-4 flex justify-center bg-gray-50 dark:bg-gray-925">
|
| 198 |
-
<img class="max-w-sm object-contain" src={output} alt="" />
|
| 199 |
-
</div>
|
| 200 |
{/if}
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
</WidgetWrapper>
|
|
|
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 11 |
import { isAssetAndPromptInput } from "../../shared/inputValidation.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 18 |
export let noTitle: WidgetProps["noTitle"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
+
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
| 25 |
let isLoading = false;
|
|
|
|
| 64 |
throw new TypeError("Invalid output: output must be of type object & of instance Blob");
|
| 65 |
}
|
| 66 |
|
| 67 |
+
async function applyWidgetExample(sample: WidgetExampleAssetAndPromptInput, opts: ExampleRunOpts = {}) {
|
| 68 |
prompt = sample.prompt;
|
| 69 |
imgSrc = sample.src;
|
| 70 |
if (opts.isPreview) {
|
|
|
|
| 136 |
}
|
| 137 |
</script>
|
| 138 |
|
| 139 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 140 |
+
<WidgetHeader
|
| 141 |
+
{noTitle}
|
| 142 |
+
{model}
|
| 143 |
+
{isLoading}
|
| 144 |
+
{isDisabled}
|
| 145 |
+
{callApiOnMount}
|
| 146 |
+
{applyWidgetExample}
|
| 147 |
+
validateExample={isAssetAndPromptInput}
|
| 148 |
+
/>
|
| 149 |
+
<div class="space-y-2">
|
| 150 |
+
<WidgetDropzone
|
| 151 |
+
classNames="hidden md:block"
|
| 152 |
+
{isLoading}
|
| 153 |
+
{isDisabled}
|
| 154 |
+
{imgSrc}
|
| 155 |
+
{onSelectFile}
|
| 156 |
+
onError={(e) => (error = e)}
|
| 157 |
+
>
|
| 158 |
+
{#if imgSrc}
|
| 159 |
+
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 160 |
+
{/if}
|
| 161 |
+
</WidgetDropzone>
|
| 162 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 163 |
+
{#if imgSrc}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
{#if imgSrc}
|
| 165 |
+
<div class="mb-2 flex justify-center bg-gray-50 dark:bg-gray-900 md:hidden">
|
| 166 |
+
<img src={imgSrc} class="pointer-events-none max-h-44" alt="" />
|
| 167 |
+
</div>
|
|
|
|
|
|
|
| 168 |
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
{/if}
|
| 170 |
+
<WidgetFileInput
|
| 171 |
+
accept="image/*"
|
| 172 |
+
classNames="mr-2 md:hidden"
|
| 173 |
+
{isLoading}
|
| 174 |
+
{isDisabled}
|
| 175 |
+
label="Browse for image"
|
| 176 |
+
{onSelectFile}
|
| 177 |
+
/>
|
| 178 |
+
<WidgetTextInput
|
| 179 |
+
bind:value={prompt}
|
| 180 |
+
{isDisabled}
|
| 181 |
+
label="(Optional) Text-guidance if the model has support for it"
|
| 182 |
+
placeholder="Your prompt here..."
|
| 183 |
+
/>
|
| 184 |
+
<WidgetSubmitBtn
|
| 185 |
+
{isLoading}
|
| 186 |
+
{isDisabled}
|
| 187 |
+
onClick={() => {
|
| 188 |
+
getOutput();
|
| 189 |
+
}}
|
| 190 |
+
/>
|
| 191 |
+
</div>
|
| 192 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 193 |
+
|
| 194 |
+
{#if output.length}
|
| 195 |
+
<div class="mt-4 flex justify-center bg-gray-50 dark:bg-gray-925">
|
| 196 |
+
<img class="max-w-sm object-contain" src={output} alt="" />
|
| 197 |
+
</div>
|
| 198 |
+
{/if}
|
| 199 |
+
|
| 200 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 201 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToTextWidget/ImageToTextWidget.svelte
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 9 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 10 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
|
|
|
| 11 |
|
| 12 |
export let apiToken: WidgetProps["apiToken"];
|
| 13 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -16,6 +17,8 @@
|
|
| 16 |
export let noTitle: WidgetProps["noTitle"];
|
| 17 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 18 |
|
|
|
|
|
|
|
| 19 |
let computeTime = "";
|
| 20 |
let error: string = "";
|
| 21 |
let isLoading = false;
|
|
@@ -92,7 +95,7 @@
|
|
| 92 |
throw new TypeError("Invalid output: output must be of type Array & non-empty");
|
| 93 |
}
|
| 94 |
|
| 95 |
-
async function
|
| 96 |
imgSrc = sample.src;
|
| 97 |
if (opts.isPreview) {
|
| 98 |
output = "";
|
|
@@ -104,58 +107,54 @@
|
|
| 104 |
}
|
| 105 |
</script>
|
| 106 |
|
| 107 |
-
<WidgetWrapper
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
{#if imgSrc}
|
| 137 |
-
{#if imgSrc}
|
| 138 |
-
<div class="mb-2 flex justify-center bg-gray-50 dark:bg-gray-900 md:hidden">
|
| 139 |
-
<img src={imgSrc} class="pointer-events-none max-h-44" alt="" />
|
| 140 |
-
</div>
|
| 141 |
-
{/if}
|
| 142 |
-
{/if}
|
| 143 |
-
<WidgetFileInput
|
| 144 |
-
accept="image/*"
|
| 145 |
-
classNames="mr-2 md:hidden"
|
| 146 |
-
{isLoading}
|
| 147 |
-
{isDisabled}
|
| 148 |
-
label="Browse for image"
|
| 149 |
-
{onSelectFile}
|
| 150 |
-
/>
|
| 151 |
-
{#if warning}
|
| 152 |
-
<div class="alert alert-warning mt-2">{warning}</div>
|
| 153 |
-
{/if}
|
| 154 |
-
</form>
|
| 155 |
-
</svelte:fragment>
|
| 156 |
-
<svelte:fragment slot="bottom">
|
| 157 |
-
{#if model?.pipeline_tag !== "text-generation"}
|
| 158 |
-
<WidgetOutputText classNames="mt-4" {output} />
|
| 159 |
{/if}
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
</WidgetWrapper>
|
|
|
|
| 8 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 9 |
import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js";
|
| 10 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 11 |
+
import { widgetStates } from "../../stores.js";
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
|
| 20 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 21 |
+
|
| 22 |
let computeTime = "";
|
| 23 |
let error: string = "";
|
| 24 |
let isLoading = false;
|
|
|
|
| 95 |
throw new TypeError("Invalid output: output must be of type Array & non-empty");
|
| 96 |
}
|
| 97 |
|
| 98 |
+
async function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
|
| 99 |
imgSrc = sample.src;
|
| 100 |
if (opts.isPreview) {
|
| 101 |
output = "";
|
|
|
|
| 107 |
}
|
| 108 |
</script>
|
| 109 |
|
| 110 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 111 |
+
<WidgetHeader
|
| 112 |
+
{noTitle}
|
| 113 |
+
{model}
|
| 114 |
+
{isLoading}
|
| 115 |
+
{isDisabled}
|
| 116 |
+
{callApiOnMount}
|
| 117 |
+
{applyWidgetExample}
|
| 118 |
+
validateExample={isAssetInput}
|
| 119 |
+
/>
|
| 120 |
+
|
| 121 |
+
<WidgetDropzone
|
| 122 |
+
classNames="hidden md:block"
|
| 123 |
+
{isLoading}
|
| 124 |
+
{isDisabled}
|
| 125 |
+
{imgSrc}
|
| 126 |
+
{onSelectFile}
|
| 127 |
+
onError={(e) => (error = e)}
|
| 128 |
+
>
|
| 129 |
+
{#if imgSrc}
|
| 130 |
+
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 131 |
+
{/if}
|
| 132 |
+
</WidgetDropzone>
|
| 133 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 134 |
+
{#if imgSrc}
|
| 135 |
+
{#if imgSrc}
|
| 136 |
+
<div class="mb-2 flex justify-center bg-gray-50 dark:bg-gray-900 md:hidden">
|
| 137 |
+
<img src={imgSrc} class="pointer-events-none max-h-44" alt="" />
|
| 138 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
{/if}
|
| 140 |
+
{/if}
|
| 141 |
+
<WidgetFileInput
|
| 142 |
+
accept="image/*"
|
| 143 |
+
classNames="mr-2 md:hidden"
|
| 144 |
+
{isLoading}
|
| 145 |
+
{isDisabled}
|
| 146 |
+
label="Browse for image"
|
| 147 |
+
{onSelectFile}
|
| 148 |
+
/>
|
| 149 |
+
{#if warning}
|
| 150 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 151 |
+
{/if}
|
| 152 |
+
|
| 153 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 154 |
+
|
| 155 |
+
{#if model?.pipeline_tag !== "text-generation"}
|
| 156 |
+
<WidgetOutputText classNames="mt-4" {output} />
|
| 157 |
+
{/if}
|
| 158 |
+
|
| 159 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 160 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ObjectDetectionWidget/ObjectDetectionWidget.svelte
CHANGED
|
@@ -12,6 +12,7 @@
|
|
| 12 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 13 |
|
| 14 |
import BoundingBoxes from "./SvgBoundingBoxes.svelte";
|
|
|
|
| 15 |
|
| 16 |
export let apiToken: WidgetProps["apiToken"];
|
| 17 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -20,6 +21,8 @@
|
|
| 20 |
export let noTitle: WidgetProps["noTitle"];
|
| 21 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 22 |
|
|
|
|
|
|
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
| 25 |
let isLoading = false;
|
|
@@ -128,7 +131,7 @@
|
|
| 128 |
highlightIndex = index;
|
| 129 |
}
|
| 130 |
|
| 131 |
-
async function
|
| 132 |
imgSrc = sample.src;
|
| 133 |
if (opts.isPreview) {
|
| 134 |
output = [];
|
|
@@ -141,52 +144,48 @@
|
|
| 141 |
}
|
| 142 |
</script>
|
| 143 |
|
| 144 |
-
<WidgetWrapper
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
</svelte:fragment>
|
| 189 |
-
<svelte:fragment slot="bottom">
|
| 190 |
-
<WidgetOutputChart classNames="pt-4" {output} {highlightIndex} {mouseover} {mouseout} />
|
| 191 |
-
</svelte:fragment>
|
| 192 |
</WidgetWrapper>
|
|
|
|
| 12 |
import { isAssetInput } from "../../shared/inputValidation.js";
|
| 13 |
|
| 14 |
import BoundingBoxes from "./SvgBoundingBoxes.svelte";
|
| 15 |
+
import { widgetStates } from "../../stores.js";
|
| 16 |
|
| 17 |
export let apiToken: WidgetProps["apiToken"];
|
| 18 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 21 |
export let noTitle: WidgetProps["noTitle"];
|
| 22 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 23 |
|
| 24 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 25 |
+
|
| 26 |
let computeTime = "";
|
| 27 |
let error: string = "";
|
| 28 |
let isLoading = false;
|
|
|
|
| 131 |
highlightIndex = index;
|
| 132 |
}
|
| 133 |
|
| 134 |
+
async function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
|
| 135 |
imgSrc = sample.src;
|
| 136 |
if (opts.isPreview) {
|
| 137 |
output = [];
|
|
|
|
| 144 |
}
|
| 145 |
</script>
|
| 146 |
|
| 147 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 148 |
+
<WidgetHeader
|
| 149 |
+
{noTitle}
|
| 150 |
+
{model}
|
| 151 |
+
{isLoading}
|
| 152 |
+
{isDisabled}
|
| 153 |
+
{callApiOnMount}
|
| 154 |
+
{applyWidgetExample}
|
| 155 |
+
validateExample={isAssetInput}
|
| 156 |
+
/>
|
| 157 |
+
|
| 158 |
+
<WidgetDropzone
|
| 159 |
+
classNames="hidden md:block"
|
| 160 |
+
{isLoading}
|
| 161 |
+
{isDisabled}
|
| 162 |
+
{imgSrc}
|
| 163 |
+
{onSelectFile}
|
| 164 |
+
onError={(e) => (error = e)}
|
| 165 |
+
>
|
| 166 |
+
{#if imgSrc}
|
| 167 |
+
<BoundingBoxes {imgSrc} {mouseover} {mouseout} {output} {highlightIndex} />
|
| 168 |
+
{/if}
|
| 169 |
+
</WidgetDropzone>
|
| 170 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 171 |
+
{#if imgSrc}
|
| 172 |
+
<BoundingBoxes classNames="mb-2 md:hidden" {imgSrc} {mouseover} {mouseout} {output} {highlightIndex} />
|
| 173 |
+
{/if}
|
| 174 |
+
<WidgetFileInput
|
| 175 |
+
accept="image/*"
|
| 176 |
+
classNames="mr-2 md:hidden"
|
| 177 |
+
{isLoading}
|
| 178 |
+
{isDisabled}
|
| 179 |
+
label="Browse for image"
|
| 180 |
+
{onSelectFile}
|
| 181 |
+
/>
|
| 182 |
+
{#if warning}
|
| 183 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 184 |
+
{/if}
|
| 185 |
+
|
| 186 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 187 |
+
|
| 188 |
+
<WidgetOutputChart classNames="pt-4" {output} {highlightIndex} {mouseover} {mouseout} />
|
| 189 |
+
|
| 190 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte
CHANGED
|
@@ -12,6 +12,7 @@
|
|
| 12 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 13 |
import { isValidOutputAnswerScore } from "../../shared/outputValidation.js";
|
| 14 |
import { isTextAndContextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 15 |
|
| 16 |
export let apiToken: WidgetProps["apiToken"];
|
| 17 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -21,6 +22,8 @@
|
|
| 21 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 22 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 23 |
|
|
|
|
|
|
|
| 24 |
let context = "";
|
| 25 |
let computeTime = "";
|
| 26 |
let error: string = "";
|
|
@@ -108,7 +111,7 @@
|
|
| 108 |
throw new TypeError("Invalid output: output must be of type <answer:string; score:number>");
|
| 109 |
}
|
| 110 |
|
| 111 |
-
function
|
| 112 |
sample: WidgetExampleTextAndContextInput<WidgetExampleOutputAnswerScore>,
|
| 113 |
opts: ExampleRunOpts = {}
|
| 114 |
) {
|
|
@@ -128,46 +131,33 @@
|
|
| 128 |
}
|
| 129 |
</script>
|
| 130 |
|
| 131 |
-
<WidgetWrapper
|
| 132 |
-
{callApiOnMount}
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
placeholder="Please input some context..."
|
| 161 |
-
label="Context"
|
| 162 |
-
/>
|
| 163 |
-
</form>
|
| 164 |
-
</svelte:fragment>
|
| 165 |
-
<svelte:fragment slot="bottom">
|
| 166 |
-
{#if output}
|
| 167 |
-
<div class="alert alert-success mt-4 flex items-baseline">
|
| 168 |
-
<span>{output.answer}</span>
|
| 169 |
-
<span class="ml-auto font-mono text-xs">{output.score.toFixed(3)}</span>
|
| 170 |
-
</div>
|
| 171 |
-
{/if}
|
| 172 |
-
</svelte:fragment>
|
| 173 |
</WidgetWrapper>
|
|
|
|
| 12 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 13 |
import { isValidOutputAnswerScore } from "../../shared/outputValidation.js";
|
| 14 |
import { isTextAndContextInput } from "../../shared/inputValidation.js";
|
| 15 |
+
import { widgetStates } from "../../stores.js";
|
| 16 |
|
| 17 |
export let apiToken: WidgetProps["apiToken"];
|
| 18 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 22 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 23 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 24 |
|
| 25 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 26 |
+
|
| 27 |
let context = "";
|
| 28 |
let computeTime = "";
|
| 29 |
let error: string = "";
|
|
|
|
| 111 |
throw new TypeError("Invalid output: output must be of type <answer:string; score:number>");
|
| 112 |
}
|
| 113 |
|
| 114 |
+
function applyWidgetExample(
|
| 115 |
sample: WidgetExampleTextAndContextInput<WidgetExampleOutputAnswerScore>,
|
| 116 |
opts: ExampleRunOpts = {}
|
| 117 |
) {
|
|
|
|
| 131 |
}
|
| 132 |
</script>
|
| 133 |
|
| 134 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 135 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 136 |
+
<div class="space-y-2">
|
| 137 |
+
<WidgetQuickInput
|
| 138 |
+
bind:value={question}
|
| 139 |
+
{isLoading}
|
| 140 |
+
{isDisabled}
|
| 141 |
+
onClickSubmitBtn={() => {
|
| 142 |
+
getOutput();
|
| 143 |
+
}}
|
| 144 |
+
/>
|
| 145 |
+
<WidgetTextarea
|
| 146 |
+
bind:value={context}
|
| 147 |
+
bind:setValue={setTextAreaValue}
|
| 148 |
+
{isDisabled}
|
| 149 |
+
placeholder="Please input some context..."
|
| 150 |
+
label="Context"
|
| 151 |
+
/>
|
| 152 |
+
</div>
|
| 153 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 154 |
+
|
| 155 |
+
{#if output}
|
| 156 |
+
<div class="alert alert-success mt-4 flex items-baseline">
|
| 157 |
+
<span>{output.answer}</span>
|
| 158 |
+
<span class="ml-auto font-mono text-xs">{output.score.toFixed(3)}</span>
|
| 159 |
+
</div>
|
| 160 |
+
{/if}
|
| 161 |
+
|
| 162 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ReinforcementLearningWidget/ReinforcementLearningWidget.svelte
CHANGED
|
@@ -38,7 +38,7 @@
|
|
| 38 |
does NOT use InferenceAPI (unlike other pipelines widgets)
|
| 39 |
-->
|
| 40 |
<div class="flex w-full max-w-full flex-col">
|
| 41 |
-
<WidgetHeader title="Video Preview"
|
| 42 |
<div class="w-full overflow-hidden rounded-lg">
|
| 43 |
{#if replay === Replay.Available}
|
| 44 |
<!-- svelte-ignore a11y-media-has-caption -->
|
|
|
|
| 38 |
does NOT use InferenceAPI (unlike other pipelines widgets)
|
| 39 |
-->
|
| 40 |
<div class="flex w-full max-w-full flex-col">
|
| 41 |
+
<WidgetHeader title="Video Preview" {model} />
|
| 42 |
<div class="w-full overflow-hidden rounded-lg">
|
| 43 |
{#if replay === Replay.Available}
|
| 44 |
<!-- svelte-ignore a11y-media-has-caption -->
|
packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 11 |
import { isSentenceSimilarityInput } from "../../shared/inputValidation.js";
|
|
|
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -17,6 +18,8 @@
|
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
|
|
|
|
|
|
|
| 20 |
let sourceSentence = "";
|
| 21 |
let comparisonSentences: Array<string> = [];
|
| 22 |
let nComparisonSentences = 2;
|
|
@@ -121,7 +124,7 @@
|
|
| 121 |
throw new TypeError("Invalid output: output must be of type Array");
|
| 122 |
}
|
| 123 |
|
| 124 |
-
function
|
| 125 |
sourceSentence = sample.source_sentence;
|
| 126 |
comparisonSentences = sample.sentences;
|
| 127 |
nComparisonSentences = comparisonSentences.length;
|
|
@@ -133,55 +136,51 @@
|
|
| 133 |
}
|
| 134 |
</script>
|
| 135 |
|
| 136 |
-
<WidgetWrapper
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
{
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
<
|
| 183 |
-
{#if output.length}
|
| 184 |
-
<WidgetOutputChart classNames="pt-4" {output} />
|
| 185 |
-
{/if}
|
| 186 |
-
</svelte:fragment>
|
| 187 |
</WidgetWrapper>
|
|
|
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 11 |
import { isSentenceSimilarityInput } from "../../shared/inputValidation.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 18 |
export let noTitle: WidgetProps["noTitle"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
+
|
| 23 |
let sourceSentence = "";
|
| 24 |
let comparisonSentences: Array<string> = [];
|
| 25 |
let nComparisonSentences = 2;
|
|
|
|
| 124 |
throw new TypeError("Invalid output: output must be of type Array");
|
| 125 |
}
|
| 126 |
|
| 127 |
+
function applyWidgetExample(sample: WidgetExampleSentenceSimilarityInput, opts: ExampleRunOpts = {}) {
|
| 128 |
sourceSentence = sample.source_sentence;
|
| 129 |
comparisonSentences = sample.sentences;
|
| 130 |
nComparisonSentences = comparisonSentences.length;
|
|
|
|
| 136 |
}
|
| 137 |
</script>
|
| 138 |
|
| 139 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 140 |
+
<WidgetHeader
|
| 141 |
+
{noTitle}
|
| 142 |
+
{model}
|
| 143 |
+
{isLoading}
|
| 144 |
+
{isDisabled}
|
| 145 |
+
{callApiOnMount}
|
| 146 |
+
{applyWidgetExample}
|
| 147 |
+
validateExample={isSentenceSimilarityInput}
|
| 148 |
+
/>
|
| 149 |
+
<div class="flex flex-col space-y-2">
|
| 150 |
+
<WidgetTextInput
|
| 151 |
+
bind:value={sourceSentence}
|
| 152 |
+
{isDisabled}
|
| 153 |
+
label="Source Sentence"
|
| 154 |
+
placeholder={isDisabled ? "" : "Your sentence here..."}
|
| 155 |
+
/>
|
| 156 |
+
<WidgetTextInput
|
| 157 |
+
bind:value={comparisonSentences[0]}
|
| 158 |
+
{isDisabled}
|
| 159 |
+
label="Sentences to compare to"
|
| 160 |
+
placeholder={isDisabled ? "" : "Your sentence here..."}
|
| 161 |
+
/>
|
| 162 |
+
{#each Array(nComparisonSentences - 1) as _, idx}
|
| 163 |
+
<WidgetTextInput bind:value={comparisonSentences[idx + 1]} {isDisabled} placeholder="Your sentence here..." />
|
| 164 |
+
{/each}
|
| 165 |
+
<WidgetAddSentenceBtn
|
| 166 |
+
isDisabled={nComparisonSentences === maxComparisonSentences || isDisabled}
|
| 167 |
+
onClick={() => {
|
| 168 |
+
nComparisonSentences++;
|
| 169 |
+
}}
|
| 170 |
+
/>
|
| 171 |
+
<WidgetSubmitBtn
|
| 172 |
+
{isLoading}
|
| 173 |
+
{isDisabled}
|
| 174 |
+
onClick={() => {
|
| 175 |
+
getOutput();
|
| 176 |
+
}}
|
| 177 |
+
/>
|
| 178 |
+
</div>
|
| 179 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 180 |
+
|
| 181 |
+
{#if output.length}
|
| 182 |
+
<WidgetOutputChart classNames="pt-4" {output} />
|
| 183 |
+
{/if}
|
| 184 |
+
|
| 185 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 11 |
|
| 12 |
export let apiToken: WidgetProps["apiToken"];
|
| 13 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -17,6 +18,8 @@
|
|
| 17 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
|
|
|
|
|
|
|
| 20 |
let computeTime = "";
|
| 21 |
let error: string = "";
|
| 22 |
let isLoading = false;
|
|
@@ -93,7 +96,7 @@
|
|
| 93 |
throw new TypeError("Invalid output: output must be of type Array & non-empty");
|
| 94 |
}
|
| 95 |
|
| 96 |
-
function
|
| 97 |
setTextAreaValue(sample.text);
|
| 98 |
if (opts.isPreview) {
|
| 99 |
return;
|
|
@@ -103,34 +106,29 @@
|
|
| 103 |
}
|
| 104 |
</script>
|
| 105 |
|
| 106 |
-
<WidgetWrapper
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
</form>
|
| 132 |
-
</svelte:fragment>
|
| 133 |
-
<svelte:fragment slot="bottom">
|
| 134 |
-
<WidgetOutputText classNames="mt-4" {output} />
|
| 135 |
-
</svelte:fragment>
|
| 136 |
</WidgetWrapper>
|
|
|
|
| 8 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 11 |
+
import { widgetStates } from "../../stores.js";
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 18 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
+
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
| 25 |
let isLoading = false;
|
|
|
|
| 96 |
throw new TypeError("Invalid output: output must be of type Array & non-empty");
|
| 97 |
}
|
| 98 |
|
| 99 |
+
function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
|
| 100 |
setTextAreaValue(sample.text);
|
| 101 |
if (opts.isPreview) {
|
| 102 |
return;
|
|
|
|
| 106 |
}
|
| 107 |
</script>
|
| 108 |
|
| 109 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 110 |
+
<WidgetHeader
|
| 111 |
+
{noTitle}
|
| 112 |
+
{model}
|
| 113 |
+
{isLoading}
|
| 114 |
+
{isDisabled}
|
| 115 |
+
{callApiOnMount}
|
| 116 |
+
{applyWidgetExample}
|
| 117 |
+
validateExample={isTextInput}
|
| 118 |
+
/>
|
| 119 |
+
<div class="space-y-2">
|
| 120 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} />
|
| 121 |
+
<WidgetSubmitBtn
|
| 122 |
+
{isLoading}
|
| 123 |
+
{isDisabled}
|
| 124 |
+
onClick={() => {
|
| 125 |
+
getOutput();
|
| 126 |
+
}}
|
| 127 |
+
/>
|
| 128 |
+
</div>
|
| 129 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 130 |
+
|
| 131 |
+
<WidgetOutputText classNames="mt-4" {output} />
|
| 132 |
+
|
| 133 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte
CHANGED
|
@@ -14,6 +14,7 @@
|
|
| 14 |
updateUrl,
|
| 15 |
} from "../../shared/helpers.js";
|
| 16 |
import { isTextAndTableInput } from "../../shared/inputValidation.js";
|
|
|
|
| 17 |
interface Output {
|
| 18 |
aggregator?: string;
|
| 19 |
answer: string;
|
|
@@ -29,6 +30,8 @@
|
|
| 29 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 30 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 31 |
|
|
|
|
|
|
|
| 32 |
let computeTime = "";
|
| 33 |
let error: string = "";
|
| 34 |
let isLoading = false;
|
|
@@ -142,7 +145,7 @@
|
|
| 142 |
);
|
| 143 |
}
|
| 144 |
|
| 145 |
-
function
|
| 146 |
query = sample.text;
|
| 147 |
table = convertDataToTable(sample.table);
|
| 148 |
if (opts.isPreview) {
|
|
@@ -153,39 +156,35 @@
|
|
| 153 |
}
|
| 154 |
</script>
|
| 155 |
|
| 156 |
-
<WidgetWrapper
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
<WidgetTableInput {highlighted} onChange={onChangeTable} {table} {isDisabled} />
|
| 188 |
-
{/if}
|
| 189 |
-
</div>
|
| 190 |
-
</svelte:fragment>
|
| 191 |
</WidgetWrapper>
|
|
|
|
| 14 |
updateUrl,
|
| 15 |
} from "../../shared/helpers.js";
|
| 16 |
import { isTextAndTableInput } from "../../shared/inputValidation.js";
|
| 17 |
+
import { widgetStates } from "../../stores.js";
|
| 18 |
interface Output {
|
| 19 |
aggregator?: string;
|
| 20 |
answer: string;
|
|
|
|
| 30 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 31 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 32 |
|
| 33 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 34 |
+
|
| 35 |
let computeTime = "";
|
| 36 |
let error: string = "";
|
| 37 |
let isLoading = false;
|
|
|
|
| 145 |
);
|
| 146 |
}
|
| 147 |
|
| 148 |
+
function applyWidgetExample(sample: WidgetExampleTextAndTableInput, opts: ExampleRunOpts = {}) {
|
| 149 |
query = sample.text;
|
| 150 |
table = convertDataToTable(sample.table);
|
| 151 |
if (opts.isPreview) {
|
|
|
|
| 156 |
}
|
| 157 |
</script>
|
| 158 |
|
| 159 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 160 |
+
<WidgetHeader
|
| 161 |
+
{noTitle}
|
| 162 |
+
{model}
|
| 163 |
+
{isLoading}
|
| 164 |
+
{isDisabled}
|
| 165 |
+
{callApiOnMount}
|
| 166 |
+
{applyWidgetExample}
|
| 167 |
+
validateExample={isTextAndTableInput}
|
| 168 |
+
/>
|
| 169 |
+
|
| 170 |
+
<WidgetQuickInput
|
| 171 |
+
bind:value={query}
|
| 172 |
+
{isLoading}
|
| 173 |
+
{isDisabled}
|
| 174 |
+
onClickSubmitBtn={() => {
|
| 175 |
+
getOutput();
|
| 176 |
+
}}
|
| 177 |
+
/>
|
| 178 |
+
|
| 179 |
+
<div class="mt-4">
|
| 180 |
+
{#if output}
|
| 181 |
+
<WidgetOutputTableQA {output} {isAnswerOnlyOutput} />
|
| 182 |
+
{/if}
|
| 183 |
+
{#if table.length > 1 || table[0].length > 1}
|
| 184 |
+
<WidgetTableInput {highlighted} onChange={onChangeTable} {table} {isDisabled} />
|
| 185 |
+
{/if}
|
| 186 |
+
</div>
|
| 187 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 188 |
+
|
| 189 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TabularDataWidget/TabularDataWidget.svelte
CHANGED
|
@@ -14,6 +14,7 @@
|
|
| 14 |
updateUrl,
|
| 15 |
} from "../../shared/helpers.js";
|
| 16 |
import { isStructuredDataInput } from "../../shared/inputValidation.js";
|
|
|
|
| 17 |
|
| 18 |
export let apiToken: WidgetProps["apiToken"];
|
| 19 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -23,6 +24,8 @@
|
|
| 23 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 24 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 25 |
|
|
|
|
|
|
|
| 26 |
const widgetData = model?.widgetData?.[0] as WidgetExampleStructuredDataInput<WidgetExampleOutputLabels> | undefined;
|
| 27 |
const columns: string[] = Object.keys(widgetData?.structured_data ?? {});
|
| 28 |
|
|
@@ -167,7 +170,7 @@
|
|
| 167 |
);
|
| 168 |
}
|
| 169 |
|
| 170 |
-
function
|
| 171 |
table = convertDataToTable(sample.structured_data);
|
| 172 |
if (opts.isPreview) {
|
| 173 |
return;
|
|
@@ -177,44 +180,38 @@
|
|
| 177 |
}
|
| 178 |
</script>
|
| 179 |
|
| 180 |
-
<WidgetWrapper
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
<svelte:fragment slot="top" let:isDisabled>
|
| 196 |
-
<form>
|
| 197 |
-
<div class="mt-4">
|
| 198 |
-
{#if table.length > 1 || table[1]?.length > 1}
|
| 199 |
-
<WidgetTableInput
|
| 200 |
-
{highlighted}
|
| 201 |
-
{isLoading}
|
| 202 |
-
{isDisabled}
|
| 203 |
-
onChange={onChangeTable}
|
| 204 |
-
table={tableWithOutput}
|
| 205 |
-
canAddCol={false}
|
| 206 |
-
bind:scrollTableToRight
|
| 207 |
-
/>
|
| 208 |
-
{/if}
|
| 209 |
-
</div>
|
| 210 |
-
<WidgetSubmitBtn
|
| 211 |
{isLoading}
|
| 212 |
{isDisabled}
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
}
|
|
|
|
| 216 |
/>
|
| 217 |
-
|
| 218 |
-
</
|
| 219 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
</WidgetWrapper>
|
|
|
|
| 14 |
updateUrl,
|
| 15 |
} from "../../shared/helpers.js";
|
| 16 |
import { isStructuredDataInput } from "../../shared/inputValidation.js";
|
| 17 |
+
import { widgetStates } from "../../stores.js";
|
| 18 |
|
| 19 |
export let apiToken: WidgetProps["apiToken"];
|
| 20 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 24 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 25 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 26 |
|
| 27 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 28 |
+
|
| 29 |
const widgetData = model?.widgetData?.[0] as WidgetExampleStructuredDataInput<WidgetExampleOutputLabels> | undefined;
|
| 30 |
const columns: string[] = Object.keys(widgetData?.structured_data ?? {});
|
| 31 |
|
|
|
|
| 170 |
);
|
| 171 |
}
|
| 172 |
|
| 173 |
+
function applyWidgetExample(sample: WidgetExampleStructuredDataInput, opts: ExampleRunOpts = {}) {
|
| 174 |
table = convertDataToTable(sample.structured_data);
|
| 175 |
if (opts.isPreview) {
|
| 176 |
return;
|
|
|
|
| 180 |
}
|
| 181 |
</script>
|
| 182 |
|
| 183 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 184 |
+
<WidgetHeader
|
| 185 |
+
{noTitle}
|
| 186 |
+
{model}
|
| 187 |
+
{isLoading}
|
| 188 |
+
{isDisabled}
|
| 189 |
+
{callApiOnMount}
|
| 190 |
+
{applyWidgetExample}
|
| 191 |
+
validateExample={isStructuredDataInput}
|
| 192 |
+
/>
|
| 193 |
+
|
| 194 |
+
<div class="mt-4">
|
| 195 |
+
{#if table.length > 1 || table[1]?.length > 1}
|
| 196 |
+
<WidgetTableInput
|
| 197 |
+
{highlighted}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
{isLoading}
|
| 199 |
{isDisabled}
|
| 200 |
+
onChange={onChangeTable}
|
| 201 |
+
table={tableWithOutput}
|
| 202 |
+
canAddCol={false}
|
| 203 |
+
bind:scrollTableToRight
|
| 204 |
/>
|
| 205 |
+
{/if}
|
| 206 |
+
</div>
|
| 207 |
+
<WidgetSubmitBtn
|
| 208 |
+
{isLoading}
|
| 209 |
+
{isDisabled}
|
| 210 |
+
onClick={() => {
|
| 211 |
+
getOutput();
|
| 212 |
+
}}
|
| 213 |
+
/>
|
| 214 |
+
|
| 215 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 216 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 217 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte
CHANGED
|
@@ -13,6 +13,7 @@
|
|
| 13 |
import { isValidOutputText } from "../../shared/outputValidation.js";
|
| 14 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 15 |
import type { PipelineType } from "@huggingface/tasks";
|
|
|
|
| 16 |
|
| 17 |
export let apiToken: WidgetProps["apiToken"];
|
| 18 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -23,6 +24,8 @@
|
|
| 23 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 24 |
export let isLoggedIn: WidgetProps["includeCredentials"];
|
| 25 |
|
|
|
|
|
|
|
| 26 |
const isBloomLoginRequired = isLoggedIn === false && model.id === "bigscience/bloom";
|
| 27 |
|
| 28 |
let computeTime = "";
|
|
@@ -165,7 +168,7 @@
|
|
| 165 |
renderTypingEffect(prefix + output);
|
| 166 |
}
|
| 167 |
|
| 168 |
-
function
|
| 169 |
setTextAreaValue(sample.text);
|
| 170 |
if (opts.isPreview) {
|
| 171 |
if (sample.output) {
|
|
@@ -195,66 +198,53 @@
|
|
| 195 |
}
|
| 196 |
</script>
|
| 197 |
|
| 198 |
-
<WidgetWrapper
|
| 199 |
-
{callApiOnMount}
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
>
|
| 213 |
-
|
| 214 |
-
<form class="space-y-2">
|
| 215 |
-
<WidgetTextarea
|
| 216 |
-
bind:value={text}
|
| 217 |
-
bind:setValue={setTextAreaValue}
|
| 218 |
{isLoading}
|
| 219 |
{isDisabled}
|
| 220 |
-
|
| 221 |
-
|
|
|
|
| 222 |
/>
|
| 223 |
-
{
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
<
|
| 236 |
-
|
| 237 |
-
|
|
|
|
| 238 |
</div>
|
| 239 |
-
{#if warning}
|
| 240 |
-
<div class="alert alert-warning mt-2">{warning}</div>
|
| 241 |
-
{/if}
|
| 242 |
-
{#if isBloomLoginRequired}
|
| 243 |
-
<div class="alert alert-warning mt-2">
|
| 244 |
-
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 245 |
-
Please
|
| 246 |
-
<span class="cursor-pointer underline" on:click={redirectLogin}>login</span>
|
| 247 |
-
or
|
| 248 |
-
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 249 |
-
<span class="cursor-pointer underline" on:click={redirectJoin}>register</span> to try BLOOM 🌸
|
| 250 |
-
</div>
|
| 251 |
-
{/if}
|
| 252 |
-
</form>
|
| 253 |
-
</svelte:fragment>
|
| 254 |
-
<svelte:fragment slot="bottom">
|
| 255 |
-
{#if model?.pipeline_tag !== "text-generation"}
|
| 256 |
-
<!-- for pipelines: text2text-generation & translation -->
|
| 257 |
-
<WidgetOutputText classNames="mt-4" {output} />
|
| 258 |
{/if}
|
| 259 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
</WidgetWrapper>
|
|
|
|
| 13 |
import { isValidOutputText } from "../../shared/outputValidation.js";
|
| 14 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 15 |
import type { PipelineType } from "@huggingface/tasks";
|
| 16 |
+
import { widgetStates } from "../../stores.js";
|
| 17 |
|
| 18 |
export let apiToken: WidgetProps["apiToken"];
|
| 19 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 24 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 25 |
export let isLoggedIn: WidgetProps["includeCredentials"];
|
| 26 |
|
| 27 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 28 |
+
|
| 29 |
const isBloomLoginRequired = isLoggedIn === false && model.id === "bigscience/bloom";
|
| 30 |
|
| 31 |
let computeTime = "";
|
|
|
|
| 168 |
renderTypingEffect(prefix + output);
|
| 169 |
}
|
| 170 |
|
| 171 |
+
function applyWidgetExample(sample: WidgetExampleTextInput<WidgetExampleOutputText>, opts: ExampleRunOpts = {}) {
|
| 172 |
setTextAreaValue(sample.text);
|
| 173 |
if (opts.isPreview) {
|
| 174 |
if (sample.output) {
|
|
|
|
| 198 |
}
|
| 199 |
</script>
|
| 200 |
|
| 201 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 202 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 203 |
+
<div class="space-y-2">
|
| 204 |
+
<WidgetTextarea
|
| 205 |
+
bind:value={text}
|
| 206 |
+
bind:setValue={setTextAreaValue}
|
| 207 |
+
{isLoading}
|
| 208 |
+
{isDisabled}
|
| 209 |
+
size="big"
|
| 210 |
+
bind:renderTypingEffect
|
| 211 |
+
/>
|
| 212 |
+
{#if model.id === "bigscience/bloom"}
|
| 213 |
+
<WidgetBloomDecoding bind:decodingStrategy />
|
| 214 |
+
{/if}
|
| 215 |
+
<div class="flex items-center gap-x-2 {isBloomLoginRequired ? 'pointer-events-none opacity-50' : ''}">
|
| 216 |
+
<WidgetSubmitBtn
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
{isLoading}
|
| 218 |
{isDisabled}
|
| 219 |
+
onClick={() => {
|
| 220 |
+
getOutput({ useCache });
|
| 221 |
+
}}
|
| 222 |
/>
|
| 223 |
+
<WidgetShortcutRunLabel {isLoading} {isDisabled} />
|
| 224 |
+
<div class="ml-auto self-start">
|
| 225 |
+
<WidgetTimer bind:this={inferenceTimer} {isDisabled} />
|
| 226 |
+
</div>
|
| 227 |
+
</div>
|
| 228 |
+
{#if warning}
|
| 229 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 230 |
+
{/if}
|
| 231 |
+
{#if isBloomLoginRequired}
|
| 232 |
+
<div class="alert alert-warning mt-2">
|
| 233 |
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 234 |
+
Please
|
| 235 |
+
<span class="cursor-pointer underline" on:click={redirectLogin}>login</span>
|
| 236 |
+
or
|
| 237 |
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
| 238 |
+
<span class="cursor-pointer underline" on:click={redirectJoin}>register</span> to try BLOOM 🌸
|
| 239 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
{/if}
|
| 241 |
+
</div>
|
| 242 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 243 |
+
|
| 244 |
+
{#if model?.pipeline_tag !== "text-generation"}
|
| 245 |
+
<!-- for pipelines: text2text-generation & translation -->
|
| 246 |
+
<WidgetOutputText classNames="mt-4" {output} />
|
| 247 |
+
{/if}
|
| 248 |
+
|
| 249 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 250 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte
CHANGED
|
@@ -7,6 +7,7 @@
|
|
| 7 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 8 |
import { isValidOutputUrl } from "../../shared/outputValidation.js";
|
| 9 |
import { isTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 10 |
|
| 11 |
export let apiToken: WidgetProps["apiToken"];
|
| 12 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -15,7 +16,8 @@
|
|
| 15 |
export let noTitle: WidgetProps["noTitle"];
|
| 16 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 17 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
let computeTime = "";
|
| 21 |
let error: string = "";
|
|
@@ -98,7 +100,7 @@
|
|
| 98 |
throw new TypeError("Invalid output: output must be of type object & of instance Blob");
|
| 99 |
}
|
| 100 |
|
| 101 |
-
function
|
| 102 |
text = sample.text;
|
| 103 |
if (opts.isPreview) {
|
| 104 |
if (sample.output) {
|
|
@@ -117,31 +119,18 @@
|
|
| 117 |
}
|
| 118 |
</script>
|
| 119 |
|
| 120 |
-
<WidgetWrapper
|
| 121 |
-
{callApiOnMount}
|
| 122 |
-
|
| 123 |
-
{
|
| 124 |
-
|
| 125 |
-
{computeTime}
|
| 126 |
-
|
| 127 |
-
{
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
{
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
>
|
| 135 |
-
<svelte:fragment slot="top" let:isDisabled>
|
| 136 |
-
<form>
|
| 137 |
-
<WidgetQuickInput bind:value={text} {isLoading} {isDisabled} onClickSubmitBtn={() => getOutput()} />
|
| 138 |
-
</form>
|
| 139 |
-
</svelte:fragment>
|
| 140 |
-
<svelte:fragment slot="bottom">
|
| 141 |
-
{#if output.length}
|
| 142 |
-
<div class="mt-4 flex justify-center bg-gray-50 dark:bg-gray-925">
|
| 143 |
-
<img class="max-w-sm object-contain" src={output} alt="" />
|
| 144 |
-
</div>
|
| 145 |
-
{/if}
|
| 146 |
-
</svelte:fragment>
|
| 147 |
</WidgetWrapper>
|
|
|
|
| 7 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 8 |
import { isValidOutputUrl } from "../../shared/outputValidation.js";
|
| 9 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 10 |
+
import { widgetStates } from "../../stores.js";
|
| 11 |
|
| 12 |
export let apiToken: WidgetProps["apiToken"];
|
| 13 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 16 |
export let noTitle: WidgetProps["noTitle"];
|
| 17 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
+
|
| 20 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 21 |
|
| 22 |
let computeTime = "";
|
| 23 |
let error: string = "";
|
|
|
|
| 100 |
throw new TypeError("Invalid output: output must be of type object & of instance Blob");
|
| 101 |
}
|
| 102 |
|
| 103 |
+
function applyWidgetExample(sample: WidgetExampleTextInput<WidgetExampleOutputUrl>, opts: ExampleRunOpts = {}) {
|
| 104 |
text = sample.text;
|
| 105 |
if (opts.isPreview) {
|
| 106 |
if (sample.output) {
|
|
|
|
| 119 |
}
|
| 120 |
</script>
|
| 121 |
|
| 122 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 123 |
+
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
| 124 |
+
|
| 125 |
+
<WidgetQuickInput bind:value={text} {isLoading} {isDisabled} onClickSubmitBtn={() => getOutput()} />
|
| 126 |
+
|
| 127 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 128 |
+
|
| 129 |
+
{#if output.length}
|
| 130 |
+
<div class="mt-4 flex justify-center bg-gray-50 dark:bg-gray-925">
|
| 131 |
+
<img class="max-w-sm object-contain" src={output} alt="" />
|
| 132 |
+
</div>
|
| 133 |
+
{/if}
|
| 134 |
+
|
| 135 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 11 |
|
| 12 |
export let apiToken: WidgetProps["apiToken"];
|
| 13 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -16,7 +17,8 @@
|
|
| 16 |
export let noTitle: WidgetProps["noTitle"];
|
| 17 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
let computeTime = "";
|
| 22 |
let error: string = "";
|
|
@@ -93,7 +95,7 @@
|
|
| 93 |
throw new TypeError("Invalid output: output must be of type object & instance of Blob");
|
| 94 |
}
|
| 95 |
|
| 96 |
-
function
|
| 97 |
setTextAreaValue(sample.text);
|
| 98 |
if (opts.isPreview) {
|
| 99 |
return;
|
|
@@ -103,37 +105,32 @@
|
|
| 103 |
}
|
| 104 |
</script>
|
| 105 |
|
| 106 |
-
<WidgetWrapper
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
{
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
<svelte:fragment slot="bottom">
|
| 135 |
-
{#if output.length}
|
| 136 |
-
<WidgetAudioTrack classNames="mt-4" src={output} />
|
| 137 |
-
{/if}
|
| 138 |
-
</svelte:fragment>
|
| 139 |
</WidgetWrapper>
|
|
|
|
| 8 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 11 |
+
import { widgetStates } from "../../stores.js";
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
+
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
|
|
|
| 95 |
throw new TypeError("Invalid output: output must be of type object & instance of Blob");
|
| 96 |
}
|
| 97 |
|
| 98 |
+
function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
|
| 99 |
setTextAreaValue(sample.text);
|
| 100 |
if (opts.isPreview) {
|
| 101 |
return;
|
|
|
|
| 105 |
}
|
| 106 |
</script>
|
| 107 |
|
| 108 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 109 |
+
<WidgetHeader
|
| 110 |
+
{noTitle}
|
| 111 |
+
{model}
|
| 112 |
+
{isLoading}
|
| 113 |
+
{isDisabled}
|
| 114 |
+
{callApiOnMount}
|
| 115 |
+
{applyWidgetExample}
|
| 116 |
+
validateExample={isTextInput}
|
| 117 |
+
/>
|
| 118 |
+
|
| 119 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} />
|
| 120 |
+
<WidgetSubmitBtn
|
| 121 |
+
classNames="mt-2"
|
| 122 |
+
{isLoading}
|
| 123 |
+
{isDisabled}
|
| 124 |
+
onClick={() => {
|
| 125 |
+
getOutput();
|
| 126 |
+
}}
|
| 127 |
+
/>
|
| 128 |
+
|
| 129 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 130 |
+
|
| 131 |
+
{#if output.length}
|
| 132 |
+
<WidgetAudioTrack classNames="mt-4" src={output} />
|
| 133 |
+
{/if}
|
| 134 |
+
|
| 135 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 11 |
import { uniqBy } from "../../../../utils/ViewUtils.js";
|
|
|
|
| 12 |
|
| 13 |
interface EntityGroup {
|
| 14 |
entity_group: string;
|
|
@@ -32,7 +33,8 @@
|
|
| 32 |
export let noTitle: WidgetProps["noTitle"];
|
| 33 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 34 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
let computeTime = "";
|
| 38 |
let error: string = "";
|
|
@@ -214,7 +216,7 @@
|
|
| 214 |
return a.type === b.type && a.start === b.start && a.end === b.end;
|
| 215 |
}
|
| 216 |
|
| 217 |
-
function
|
| 218 |
setTextAreaValue(sample.text);
|
| 219 |
if (opts.isPreview) {
|
| 220 |
return;
|
|
@@ -224,38 +226,33 @@
|
|
| 224 |
}
|
| 225 |
</script>
|
| 226 |
|
| 227 |
-
<WidgetWrapper
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
{
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
</form>
|
| 257 |
-
</svelte:fragment>
|
| 258 |
-
<svelte:fragment slot="bottom">
|
| 259 |
-
<WidgetOuputTokens classNames="mt-2" {output} text={outputText} />
|
| 260 |
-
</svelte:fragment>
|
| 261 |
</WidgetWrapper>
|
|
|
|
| 9 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 10 |
import { isTextInput } from "../../shared/inputValidation.js";
|
| 11 |
import { uniqBy } from "../../../../utils/ViewUtils.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
interface EntityGroup {
|
| 15 |
entity_group: string;
|
|
|
|
| 33 |
export let noTitle: WidgetProps["noTitle"];
|
| 34 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 35 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 36 |
+
|
| 37 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 38 |
|
| 39 |
let computeTime = "";
|
| 40 |
let error: string = "";
|
|
|
|
| 216 |
return a.type === b.type && a.start === b.start && a.end === b.end;
|
| 217 |
}
|
| 218 |
|
| 219 |
+
function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
|
| 220 |
setTextAreaValue(sample.text);
|
| 221 |
if (opts.isPreview) {
|
| 222 |
return;
|
|
|
|
| 226 |
}
|
| 227 |
</script>
|
| 228 |
|
| 229 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 230 |
+
<WidgetHeader
|
| 231 |
+
{noTitle}
|
| 232 |
+
{model}
|
| 233 |
+
{isLoading}
|
| 234 |
+
{isDisabled}
|
| 235 |
+
{callApiOnMount}
|
| 236 |
+
{applyWidgetExample}
|
| 237 |
+
validateExample={isTextInput}
|
| 238 |
+
/>
|
| 239 |
+
|
| 240 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} />
|
| 241 |
+
<WidgetSubmitBtn
|
| 242 |
+
classNames="mt-2"
|
| 243 |
+
{isLoading}
|
| 244 |
+
{isDisabled}
|
| 245 |
+
onClick={() => {
|
| 246 |
+
getOutput();
|
| 247 |
+
}}
|
| 248 |
+
/>
|
| 249 |
+
{#if warning}
|
| 250 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
| 251 |
+
{/if}
|
| 252 |
+
|
| 253 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 254 |
+
|
| 255 |
+
<WidgetOuputTokens classNames="mt-2" {output} text={outputText} />
|
| 256 |
+
|
| 257 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
import WidgetOutputChart from "../../shared/WidgetOutputChart/WidgetOutputChart.svelte";
|
| 10 |
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 11 |
import { isAssetAndTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 12 |
|
| 13 |
export let apiToken: WidgetProps["apiToken"];
|
| 14 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -16,7 +17,8 @@
|
|
| 16 |
export let model: WidgetProps["model"];
|
| 17 |
export let noTitle: WidgetProps["noTitle"];
|
| 18 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
let computeTime = "";
|
| 22 |
let error: string = "";
|
|
@@ -69,7 +71,7 @@
|
|
| 69 |
throw new TypeError("Invalid output: output must be of type Array<{ answer: string, score?: number }>");
|
| 70 |
}
|
| 71 |
|
| 72 |
-
async function
|
| 73 |
question = sample.text;
|
| 74 |
imgSrc = sample.src;
|
| 75 |
if (opts.isPreview) {
|
|
@@ -145,63 +147,59 @@
|
|
| 145 |
}
|
| 146 |
</script>
|
| 147 |
|
| 148 |
-
<WidgetWrapper
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
{imgSrc}
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 174 |
-
{/if}
|
| 175 |
-
</WidgetDropzone>
|
| 176 |
-
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 177 |
{#if imgSrc}
|
| 178 |
-
|
| 179 |
-
<
|
| 180 |
-
|
| 181 |
-
</div>
|
| 182 |
-
{/if}
|
| 183 |
{/if}
|
| 184 |
-
<WidgetFileInput
|
| 185 |
-
accept="image/*"
|
| 186 |
-
classNames="mr-2 md:hidden"
|
| 187 |
-
{isLoading}
|
| 188 |
-
{isDisabled}
|
| 189 |
-
label="Browse for image"
|
| 190 |
-
{onSelectFile}
|
| 191 |
-
/>
|
| 192 |
-
<WidgetQuickInput
|
| 193 |
-
bind:value={question}
|
| 194 |
-
{isLoading}
|
| 195 |
-
{isDisabled}
|
| 196 |
-
onClickSubmitBtn={() => {
|
| 197 |
-
getOutput();
|
| 198 |
-
}}
|
| 199 |
-
/>
|
| 200 |
-
</form>
|
| 201 |
-
</svelte:fragment>
|
| 202 |
-
<svelte:fragment slot="bottom">
|
| 203 |
-
{#if output}
|
| 204 |
-
<WidgetOutputChart labelField="answer" classNames="pt-4" {output} />
|
| 205 |
{/if}
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
</WidgetWrapper>
|
|
|
|
| 9 |
import WidgetOutputChart from "../../shared/WidgetOutputChart/WidgetOutputChart.svelte";
|
| 10 |
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 11 |
import { isAssetAndTextInput } from "../../shared/inputValidation.js";
|
| 12 |
+
import { widgetStates } from "../../stores.js";
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 17 |
export let model: WidgetProps["model"];
|
| 18 |
export let noTitle: WidgetProps["noTitle"];
|
| 19 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 20 |
+
|
| 21 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 22 |
|
| 23 |
let computeTime = "";
|
| 24 |
let error: string = "";
|
|
|
|
| 71 |
throw new TypeError("Invalid output: output must be of type Array<{ answer: string, score?: number }>");
|
| 72 |
}
|
| 73 |
|
| 74 |
+
async function applyWidgetExample(sample: WidgetExampleAssetAndTextInput, opts: ExampleRunOpts = {}) {
|
| 75 |
question = sample.text;
|
| 76 |
imgSrc = sample.src;
|
| 77 |
if (opts.isPreview) {
|
|
|
|
| 147 |
}
|
| 148 |
</script>
|
| 149 |
|
| 150 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 151 |
+
<WidgetHeader
|
| 152 |
+
{noTitle}
|
| 153 |
+
{model}
|
| 154 |
+
{isLoading}
|
| 155 |
+
{isDisabled}
|
| 156 |
+
{callApiOnMount}
|
| 157 |
+
{applyWidgetExample}
|
| 158 |
+
validateExample={isAssetAndTextInput}
|
| 159 |
+
/>
|
| 160 |
+
<div class="space-y-2">
|
| 161 |
+
<WidgetDropzone
|
| 162 |
+
classNames="hidden md:block"
|
| 163 |
+
{isLoading}
|
| 164 |
+
{isDisabled}
|
| 165 |
+
{imgSrc}
|
| 166 |
+
{onSelectFile}
|
| 167 |
+
onError={(e) => (error = e)}
|
| 168 |
+
>
|
| 169 |
+
{#if imgSrc}
|
| 170 |
+
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 171 |
+
{/if}
|
| 172 |
+
</WidgetDropzone>
|
| 173 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 174 |
+
{#if imgSrc}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
{#if imgSrc}
|
| 176 |
+
<div class="mb-2 flex justify-center bg-gray-50 dark:bg-gray-900 md:hidden">
|
| 177 |
+
<img src={imgSrc} class="pointer-events-none max-h-44" alt="" />
|
| 178 |
+
</div>
|
|
|
|
|
|
|
| 179 |
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
{/if}
|
| 181 |
+
<WidgetFileInput
|
| 182 |
+
accept="image/*"
|
| 183 |
+
classNames="mr-2 md:hidden"
|
| 184 |
+
{isLoading}
|
| 185 |
+
{isDisabled}
|
| 186 |
+
label="Browse for image"
|
| 187 |
+
{onSelectFile}
|
| 188 |
+
/>
|
| 189 |
+
<WidgetQuickInput
|
| 190 |
+
bind:value={question}
|
| 191 |
+
{isLoading}
|
| 192 |
+
{isDisabled}
|
| 193 |
+
onClickSubmitBtn={() => {
|
| 194 |
+
getOutput();
|
| 195 |
+
}}
|
| 196 |
+
/>
|
| 197 |
+
</div>
|
| 198 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 199 |
+
|
| 200 |
+
{#if output}
|
| 201 |
+
<WidgetOutputChart labelField="answer" classNames="pt-4" {output} />
|
| 202 |
+
{/if}
|
| 203 |
+
|
| 204 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 205 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 11 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 12 |
import { isZeroShotTextInput } from "../../shared/inputValidation.js";
|
|
|
|
| 13 |
|
| 14 |
export let apiToken: WidgetProps["apiToken"];
|
| 15 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -18,7 +19,8 @@
|
|
| 18 |
export let noTitle: WidgetProps["noTitle"];
|
| 19 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 20 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
let candidateLabels = "";
|
| 24 |
let computeTime = "";
|
|
@@ -134,7 +136,7 @@
|
|
| 134 |
throw new TypeError("Invalid output: output must be of type <labels:Array; scores:Array>");
|
| 135 |
}
|
| 136 |
|
| 137 |
-
function
|
| 138 |
candidateLabels = sample.candidate_labels;
|
| 139 |
multiClass = sample.multi_class;
|
| 140 |
setTextAreaValue(sample.text);
|
|
@@ -146,51 +148,41 @@
|
|
| 146 |
}
|
| 147 |
</script>
|
| 148 |
|
| 149 |
-
<WidgetWrapper
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
/>
|
| 178 |
-
<WidgetCheckbox bind:checked={multiClass} label="Allow multiple true classes" />
|
| 179 |
-
<WidgetSubmitBtn
|
| 180 |
-
{isLoading}
|
| 181 |
-
{isDisabled}
|
| 182 |
-
onClick={() => {
|
| 183 |
-
getOutput();
|
| 184 |
-
}}
|
| 185 |
-
/>
|
| 186 |
-
{#if warning}
|
| 187 |
-
<div class="alert alert-warning mt-2">{warning}</div>
|
| 188 |
-
{/if}
|
| 189 |
-
</form>
|
| 190 |
-
</svelte:fragment>
|
| 191 |
-
<svelte:fragment slot="bottom">
|
| 192 |
-
{#if output.length}
|
| 193 |
-
<WidgetOutputChart classNames="pt-4" {output} />
|
| 194 |
{/if}
|
| 195 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
</WidgetWrapper>
|
|
|
|
| 10 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 11 |
import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js";
|
| 12 |
import { isZeroShotTextInput } from "../../shared/inputValidation.js";
|
| 13 |
+
import { widgetStates } from "../../stores.js";
|
| 14 |
|
| 15 |
export let apiToken: WidgetProps["apiToken"];
|
| 16 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 19 |
export let noTitle: WidgetProps["noTitle"];
|
| 20 |
export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"];
|
| 21 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 22 |
+
|
| 23 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 24 |
|
| 25 |
let candidateLabels = "";
|
| 26 |
let computeTime = "";
|
|
|
|
| 136 |
throw new TypeError("Invalid output: output must be of type <labels:Array; scores:Array>");
|
| 137 |
}
|
| 138 |
|
| 139 |
+
function applyWidgetExample(sample: WidgetExampleZeroShotTextInput, opts: ExampleRunOpts = {}) {
|
| 140 |
candidateLabels = sample.candidate_labels;
|
| 141 |
multiClass = sample.multi_class;
|
| 142 |
setTextAreaValue(sample.text);
|
|
|
|
| 148 |
}
|
| 149 |
</script>
|
| 150 |
|
| 151 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 152 |
+
<WidgetHeader
|
| 153 |
+
{noTitle}
|
| 154 |
+
{model}
|
| 155 |
+
{isLoading}
|
| 156 |
+
{isDisabled}
|
| 157 |
+
{callApiOnMount}
|
| 158 |
+
{applyWidgetExample}
|
| 159 |
+
validateExample={isZeroShotTextInput}
|
| 160 |
+
/>
|
| 161 |
+
<div class="flex flex-col space-y-2">
|
| 162 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} placeholder="Text to classify..." />
|
| 163 |
+
<WidgetTextInput
|
| 164 |
+
bind:value={candidateLabels}
|
| 165 |
+
{isDisabled}
|
| 166 |
+
label="Possible class names (comma-separated)"
|
| 167 |
+
placeholder="Possible class names..."
|
| 168 |
+
/>
|
| 169 |
+
<WidgetCheckbox bind:checked={multiClass} label="Allow multiple true classes" />
|
| 170 |
+
<WidgetSubmitBtn
|
| 171 |
+
{isLoading}
|
| 172 |
+
{isDisabled}
|
| 173 |
+
onClick={() => {
|
| 174 |
+
getOutput();
|
| 175 |
+
}}
|
| 176 |
+
/>
|
| 177 |
+
{#if warning}
|
| 178 |
+
<div class="alert alert-warning mt-2">{warning}</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
{/if}
|
| 180 |
+
</div>
|
| 181 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 182 |
+
|
| 183 |
+
{#if output.length}
|
| 184 |
+
<WidgetOutputChart classNames="pt-4" {output} />
|
| 185 |
+
{/if}
|
| 186 |
+
|
| 187 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 188 |
</WidgetWrapper>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte
CHANGED
|
@@ -2,16 +2,15 @@
|
|
| 2 |
import type { WidgetProps, ExampleRunOpts, InferenceRunOpts } from "../../shared/types.js";
|
| 3 |
import type { WidgetExampleAssetAndZeroShotInput } from "@huggingface/tasks";
|
| 4 |
|
| 5 |
-
import { onMount } from "svelte";
|
| 6 |
-
|
| 7 |
import WidgetFileInput from "../../shared/WidgetFileInput/WidgetFileInput.svelte";
|
| 8 |
import WidgetDropzone from "../../shared/WidgetDropzone/WidgetDropzone.svelte";
|
| 9 |
import WidgetTextInput from "../../shared/WidgetTextInput/WidgetTextInput.svelte";
|
| 10 |
import WidgetSubmitBtn from "../../shared/WidgetSubmitBtn/WidgetSubmitBtn.svelte";
|
| 11 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 12 |
import WidgetOutputChart from "../../shared/WidgetOutputChart/WidgetOutputChart.svelte";
|
| 13 |
-
import { addInferenceParameters, callInferenceApi
|
| 14 |
import { isAssetAndZeroShotInput } from "../../shared/inputValidation.js";
|
|
|
|
| 15 |
|
| 16 |
export let apiToken: WidgetProps["apiToken"];
|
| 17 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
@@ -19,7 +18,8 @@
|
|
| 19 |
export let model: WidgetProps["model"];
|
| 20 |
export let noTitle: WidgetProps["noTitle"];
|
| 21 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
let candidateLabels = "";
|
| 25 |
let computeTime = "";
|
|
@@ -69,7 +69,7 @@
|
|
| 69 |
throw new TypeError("Invalid output: output must be of type <labels:Array; scores:Array>");
|
| 70 |
}
|
| 71 |
|
| 72 |
-
async function
|
| 73 |
candidateLabels = sample.candidate_labels;
|
| 74 |
imgSrc = sample.src;
|
| 75 |
if (opts.isPreview) {
|
|
@@ -146,79 +146,66 @@
|
|
| 146 |
error = res.error;
|
| 147 |
}
|
| 148 |
}
|
| 149 |
-
|
| 150 |
-
onMount(() => {
|
| 151 |
-
(async () => {
|
| 152 |
-
const example = getWidgetExample<WidgetExampleAssetAndZeroShotInput>(model, isAssetAndZeroShotInput);
|
| 153 |
-
if (callApiOnMount && example) {
|
| 154 |
-
await applyInputSample(example, { inferenceOpts: { isOnLoadCall: true } });
|
| 155 |
-
}
|
| 156 |
-
})();
|
| 157 |
-
});
|
| 158 |
</script>
|
| 159 |
|
| 160 |
-
<WidgetWrapper
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
{imgSrc}
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 186 |
-
{/if}
|
| 187 |
-
</WidgetDropzone>
|
| 188 |
-
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 189 |
{#if imgSrc}
|
| 190 |
-
|
| 191 |
-
<
|
| 192 |
-
|
| 193 |
-
</div>
|
| 194 |
-
{/if}
|
| 195 |
{/if}
|
| 196 |
-
<WidgetFileInput
|
| 197 |
-
accept="image/*"
|
| 198 |
-
classNames="mr-2 md:hidden"
|
| 199 |
-
{isLoading}
|
| 200 |
-
{isDisabled}
|
| 201 |
-
label="Browse for image"
|
| 202 |
-
{onSelectFile}
|
| 203 |
-
/>
|
| 204 |
-
<WidgetTextInput
|
| 205 |
-
bind:value={candidateLabels}
|
| 206 |
-
{isDisabled}
|
| 207 |
-
label="Possible class names (comma-separated)"
|
| 208 |
-
placeholder="Possible class names..."
|
| 209 |
-
/>
|
| 210 |
-
<WidgetSubmitBtn
|
| 211 |
-
{isLoading}
|
| 212 |
-
{isDisabled}
|
| 213 |
-
onClick={() => {
|
| 214 |
-
getOutput();
|
| 215 |
-
}}
|
| 216 |
-
/>
|
| 217 |
-
</form>
|
| 218 |
-
</svelte:fragment>
|
| 219 |
-
<svelte:fragment slot="bottom">
|
| 220 |
-
{#if output.length}
|
| 221 |
-
<WidgetOutputChart classNames="pt-4" {output} />
|
| 222 |
{/if}
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
</WidgetWrapper>
|
|
|
|
| 2 |
import type { WidgetProps, ExampleRunOpts, InferenceRunOpts } from "../../shared/types.js";
|
| 3 |
import type { WidgetExampleAssetAndZeroShotInput } from "@huggingface/tasks";
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import WidgetFileInput from "../../shared/WidgetFileInput/WidgetFileInput.svelte";
|
| 6 |
import WidgetDropzone from "../../shared/WidgetDropzone/WidgetDropzone.svelte";
|
| 7 |
import WidgetTextInput from "../../shared/WidgetTextInput/WidgetTextInput.svelte";
|
| 8 |
import WidgetSubmitBtn from "../../shared/WidgetSubmitBtn/WidgetSubmitBtn.svelte";
|
| 9 |
import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte";
|
| 10 |
import WidgetOutputChart from "../../shared/WidgetOutputChart/WidgetOutputChart.svelte";
|
| 11 |
+
import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js";
|
| 12 |
import { isAssetAndZeroShotInput } from "../../shared/inputValidation.js";
|
| 13 |
+
import { widgetStates } from "../../stores.js";
|
| 14 |
|
| 15 |
export let apiToken: WidgetProps["apiToken"];
|
| 16 |
export let apiUrl: WidgetProps["apiUrl"];
|
|
|
|
| 18 |
export let model: WidgetProps["model"];
|
| 19 |
export let noTitle: WidgetProps["noTitle"];
|
| 20 |
export let includeCredentials: WidgetProps["includeCredentials"];
|
| 21 |
+
|
| 22 |
+
$: isDisabled = $widgetStates?.[model.id]?.isDisabled;
|
| 23 |
|
| 24 |
let candidateLabels = "";
|
| 25 |
let computeTime = "";
|
|
|
|
| 69 |
throw new TypeError("Invalid output: output must be of type <labels:Array; scores:Array>");
|
| 70 |
}
|
| 71 |
|
| 72 |
+
async function applyWidgetExample(sample: WidgetExampleAssetAndZeroShotInput, opts: ExampleRunOpts = {}) {
|
| 73 |
candidateLabels = sample.candidate_labels;
|
| 74 |
imgSrc = sample.src;
|
| 75 |
if (opts.isPreview) {
|
|
|
|
| 146 |
error = res.error;
|
| 147 |
}
|
| 148 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
</script>
|
| 150 |
|
| 151 |
+
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
| 152 |
+
<WidgetHeader
|
| 153 |
+
{noTitle}
|
| 154 |
+
{model}
|
| 155 |
+
{isLoading}
|
| 156 |
+
{isDisabled}
|
| 157 |
+
{callApiOnMount}
|
| 158 |
+
{applyWidgetExample}
|
| 159 |
+
validateExample={isAssetAndZeroShotInput}
|
| 160 |
+
/>
|
| 161 |
+
<div class="space-y-2">
|
| 162 |
+
<WidgetDropzone
|
| 163 |
+
classNames="hidden md:block"
|
| 164 |
+
{isLoading}
|
| 165 |
+
{isDisabled}
|
| 166 |
+
{imgSrc}
|
| 167 |
+
{onSelectFile}
|
| 168 |
+
onError={(e) => (error = e)}
|
| 169 |
+
>
|
| 170 |
+
{#if imgSrc}
|
| 171 |
+
<img src={imgSrc} class="pointer-events-none mx-auto max-h-44 shadow" alt="" />
|
| 172 |
+
{/if}
|
| 173 |
+
</WidgetDropzone>
|
| 174 |
+
<!-- Better UX for mobile/table through CSS breakpoints -->
|
| 175 |
+
{#if imgSrc}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
{#if imgSrc}
|
| 177 |
+
<div class="mb-2 flex justify-center bg-gray-50 dark:bg-gray-900 md:hidden">
|
| 178 |
+
<img src={imgSrc} class="pointer-events-none max-h-44" alt="" />
|
| 179 |
+
</div>
|
|
|
|
|
|
|
| 180 |
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
{/if}
|
| 182 |
+
<WidgetFileInput
|
| 183 |
+
accept="image/*"
|
| 184 |
+
classNames="mr-2 md:hidden"
|
| 185 |
+
{isLoading}
|
| 186 |
+
{isDisabled}
|
| 187 |
+
label="Browse for image"
|
| 188 |
+
{onSelectFile}
|
| 189 |
+
/>
|
| 190 |
+
<WidgetTextInput
|
| 191 |
+
bind:value={candidateLabels}
|
| 192 |
+
{isDisabled}
|
| 193 |
+
label="Possible class names (comma-separated)"
|
| 194 |
+
placeholder="Possible class names..."
|
| 195 |
+
/>
|
| 196 |
+
<WidgetSubmitBtn
|
| 197 |
+
{isLoading}
|
| 198 |
+
{isDisabled}
|
| 199 |
+
onClick={() => {
|
| 200 |
+
getOutput();
|
| 201 |
+
}}
|
| 202 |
+
/>
|
| 203 |
+
</div>
|
| 204 |
+
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
| 205 |
+
|
| 206 |
+
{#if output.length}
|
| 207 |
+
<WidgetOutputChart classNames="pt-4" {output} />
|
| 208 |
+
{/if}
|
| 209 |
+
|
| 210 |
+
<WidgetFooter {model} {isDisabled} {outputJson} />
|
| 211 |
</WidgetWrapper>
|
packages/widgets/src/routes/+page.svelte
CHANGED
|
@@ -212,7 +212,7 @@
|
|
| 212 |
],
|
| 213 |
},
|
| 214 |
{
|
| 215 |
-
id: "
|
| 216 |
pipeline_tag: "text-generation",
|
| 217 |
inference: InferenceDisplayability.Yes,
|
| 218 |
widgetData: [
|
|
@@ -228,11 +228,11 @@
|
|
| 228 |
pipeline_tag: "text-generation",
|
| 229 |
inference: InferenceDisplayability.Yes,
|
| 230 |
widgetData: [
|
| 231 |
-
{ text: "My name is Julien and I like to" },
|
| 232 |
-
{ text: "My name is Thomas and my main" },
|
| 233 |
-
{ text: "My name is Mariama, my favorite" },
|
| 234 |
-
{ text: "My name is Clara and I am" },
|
| 235 |
-
{ text: "Once upon a time," },
|
| 236 |
],
|
| 237 |
},
|
| 238 |
{
|
|
|
|
| 212 |
],
|
| 213 |
},
|
| 214 |
{
|
| 215 |
+
id: "mistralai/Mistral-7B-v0.1",
|
| 216 |
pipeline_tag: "text-generation",
|
| 217 |
inference: InferenceDisplayability.Yes,
|
| 218 |
widgetData: [
|
|
|
|
| 228 |
pipeline_tag: "text-generation",
|
| 229 |
inference: InferenceDisplayability.Yes,
|
| 230 |
widgetData: [
|
| 231 |
+
{ text: "My name is Julien and I like to", group: "English" },
|
| 232 |
+
{ text: "My name is Thomas and my main", group: "English" },
|
| 233 |
+
{ text: "My name is Mariama, my favorite", group: "French" },
|
| 234 |
+
{ text: "My name is Clara and I am", group: "French" },
|
| 235 |
+
{ text: "Once upon a time,", group: "French" },
|
| 236 |
],
|
| 237 |
},
|
| 238 |
{
|