diff --git a/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamples.svelte b/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamples.svelte new file mode 100644 index 0000000000..a6cc6d6391 --- /dev/null +++ b/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamples.svelte @@ -0,0 +1,170 @@ + + + + +
+ + {#if exampleGroups.length > 1} + group)} + /> + {/if} + + +
+ +
+
{title}
+ +
+ + {#if isOptionsVisible} +
+
+ {#each examples as { example_title }, i} + +
_previewInputSample(i)} + on:click={() => _applyWidgetExample(i)} + > + {example_title} +
+ {/each} +
+
+ {/if} +
+
diff --git a/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInputSamplesGroup/WidgetInputSamplesGroup.svelte b/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamplesGroup.svelte similarity index 81% rename from packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInputSamplesGroup/WidgetInputSamplesGroup.svelte rename to packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamplesGroup.svelte index 1aea87127e..2c86fb3c75 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetInputSamplesGroup/WidgetInputSamplesGroup.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/shared/WidgetExamples/WidgetExamplesGroup.svelte @@ -1,22 +1,24 @@ @@ -22,7 +27,10 @@ JSON Output {/if} - - {/if} - - {#if !!inputGroups.length} -
- - {#if inputGroups.length > 1} - group)} - /> - {/if} - -
- {/if} -
- - - {#if modelLoading.isLoading} - - {/if} - - - - {/if} +{#if $widgetStates?.[model.id]?.noInference} + + +{:else if $modelLoadStates[model.id] || model.inference !== InferenceDisplayability.Yes} +
+ {#if isMaximized} + + {/if} + + {/if} diff --git a/packages/widgets/src/lib/components/InferenceWidget/shared/helpers.ts b/packages/widgets/src/lib/components/InferenceWidget/shared/helpers.ts index 6c1a2ca853..8d826135aa 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/shared/helpers.ts +++ b/packages/widgets/src/lib/components/InferenceWidget/shared/helpers.ts @@ -1,5 +1,5 @@ -import type { ModelData, WidgetExample, WidgetExampleAttribute } from "@huggingface/tasks"; -import { randomItem, parseJSON } from "../../../utils/ViewUtils.js"; +import type { ModelData, WidgetExampleAttribute } from "@huggingface/tasks"; +import { parseJSON } from "../../../utils/ViewUtils.js"; import type { ModelLoadInfo, TableData } from "./types.js"; import { LoadState } from "./types.js"; @@ -21,16 +21,6 @@ export function getQueryParamVal(key: WidgetExampleAttribute): QueryParamVal { return value; } -export function getWidgetExample( - model: ModelData, - validateExample: (sample: WidgetExample) => sample is TWidgetExample -): TWidgetExample | undefined { - const validExamples = model.widgetData?.filter( - (sample): sample is TWidgetExample => sample && validateExample(sample) - ); - return validExamples?.length ? randomItem(validExamples) : undefined; -} - // Update current url search params, keeping existing keys intact. export function updateUrl(obj: Partial>): void { if (!window) { @@ -63,7 +53,6 @@ export async function getBlobFromUrl(url: string): Promise { const blob = await res.blob(); return blob; } - interface Success { computeTime: string; output: T; diff --git a/packages/widgets/src/lib/components/InferenceWidget/shared/types.ts b/packages/widgets/src/lib/components/InferenceWidget/shared/types.ts index 8c6b75be73..d61f025dc4 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/shared/types.ts +++ b/packages/widgets/src/lib/components/InferenceWidget/shared/types.ts @@ -40,6 +40,12 @@ export interface ModelLoadInfo { compute_type?: ComputeType; } +export interface WidgetState { + isDisabled?: boolean; + noInference?: boolean; + isMaximized?: boolean; +} + export type TableData = Record; export type HighlightCoordinates = Record; diff --git a/packages/widgets/src/lib/components/InferenceWidget/stores.ts b/packages/widgets/src/lib/components/InferenceWidget/stores.ts index a9ed4f27e5..09a3329913 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/stores.ts +++ b/packages/widgets/src/lib/components/InferenceWidget/stores.ts @@ -1,4 +1,21 @@ import { writable } from "svelte/store"; -import type { ModelLoadInfo } from "./shared/types.js"; +import type { ModelData } from "@huggingface/tasks"; +import type { ModelLoadInfo, WidgetState } from "./shared/types.js"; -export const modelLoadStates = writable>({}); +export const modelLoadStates = writable>({}); + +export const widgetNoInference = writable>({}); + +export const widgetStates = writable>({}); + +export function updateWidgetState(modelId: ModelData["id"], key: keyof WidgetState, val: boolean): void { + widgetStates.update((states) => { + // Check if the modelId exists, if not initialize it + if (!states[modelId]) { + states[modelId] = {}; + } + // Update the specific property for the given modelId + states[modelId][key] = val; + return states; + }); +} diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte index 8571445639..960dbf81a4 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte @@ -11,6 +11,7 @@ import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js"; import { isValidOutputLabels } from "../../shared/outputValidation.js"; import { isAssetInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -19,6 +20,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let file: Blob | File | null = null; @@ -130,7 +133,7 @@ throw new TypeError("Invalid output: output must be of type Array"); } - function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { filename = sample.example_title!; fileUrl = sample.src; @@ -155,44 +158,32 @@ } - - -
- - {#if fileUrl} - - {/if} - { - getOutput(); - }} - /> - {#if warning} -
{warning}
- {/if} - -
- - - + + + + + {#if fileUrl} + + {/if} + { + getOutput(); + }} + /> + {#if warning} +
{warning}
+ {/if} + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioToAudioWidget/AudioToAudioWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioToAudioWidget/AudioToAudioWidget.svelte index a908d08928..aa27edfab3 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioToAudioWidget/AudioToAudioWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/AudioToAudioWidget/AudioToAudioWidget.svelte @@ -9,6 +9,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js"; import { isAssetInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -16,7 +17,8 @@ export let model: WidgetProps["model"]; export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -131,7 +133,7 @@ throw new TypeError("Invalid output: output must be of type Array"); } - function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { filename = sample.example_title ?? ""; fileUrl = sample.src; if (opts.isPreview) { @@ -146,46 +148,42 @@ } - - -
- - {#if fileUrl} - - {/if} - { - getOutput(); - }} - /> - -
- - {#each output as item} -
- {item.label}: - -
- {/each} -
+ + + + + {#if fileUrl} + + {/if} + { + getOutput(); + }} + /> + + + + {#each output as item} +
+ {item.label}: + +
+ {/each} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/AutomaticSpeechRecognitionWidget/AutomaticSpeechRecognitionWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/AutomaticSpeechRecognitionWidget/AutomaticSpeechRecognitionWidget.svelte index 537614f36b..94c279977e 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/AutomaticSpeechRecognitionWidget/AutomaticSpeechRecognitionWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/AutomaticSpeechRecognitionWidget/AutomaticSpeechRecognitionWidget.svelte @@ -12,6 +12,7 @@ import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js"; import { isValidOutputText } from "../../shared/outputValidation.js"; import { isAssetInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -19,7 +20,8 @@ export let model: WidgetProps["model"]; export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -133,7 +135,7 @@ throw new TypeError("Invalid output: output must be of type "); } - function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { filename = sample.example_title!; fileUrl = sample.src; if (opts.isPreview) { @@ -161,62 +163,50 @@ } - - -
- + + + + + {#if !isRealtimeRecording} + {#if fileUrl} + + {/if} + { + getOutput(); + }} + /> + {#if warning} +
{warning}
+ {/if} + {/if} + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte index ae87653297..1571bab9c1 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte @@ -7,6 +7,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -15,7 +16,8 @@ export let noTitle: WidgetProps["noTitle"]; export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; interface Conversation { generated_responses: string[]; @@ -143,7 +145,7 @@ ); } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { text = sample.text; if (opts.isPreview) { return; @@ -153,34 +155,30 @@ } - - - -
- { - getOutput(); - }} - submitButtonLabel="Send" - /> - -
+ + + + + { + getOutput(); + }} + submitButtonLabel="Send" + /> + + + + diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte index af68099516..8013d2d271 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte @@ -8,6 +8,7 @@ import { isTextInput } from "../../shared/inputValidation.js"; import { DataTable } from "./DataTable.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -16,7 +17,8 @@ export let noTitle: WidgetProps["noTitle"]; export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -111,7 +113,7 @@ return Math.ceil(total_elems / SINGLE_DIM_COLS); }; - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { text = sample.text; if (opts.isPreview) { return; @@ -121,76 +123,71 @@ } - - -
- { - getOutput(); - }} - /> - -
- - {#if output} - {#if output.isArrLevel0} -
- - {#each range(numOfRows(output.oneDim.length)) as i} - - {#each range(SINGLE_DIM_COLS) as j} - {#if j * numOfRows(output.oneDim.length) + i < output.oneDim.length} - - - {/if} - {/each} - - {/each} -
- {j * numOfRows(output.oneDim.length) + i} - - {output.oneDim[j * numOfRows(output.oneDim.length) + i].toFixed(3)} -
-
- {:else} -
- + + + + { + getOutput(); + }} + /> + + + + {#if output} + {#if output.isArrLevel0} +
+
+ {#each range(numOfRows(output.oneDim.length)) as i} - + {#each range(SINGLE_DIM_COLS) as j} + {#if j * numOfRows(output.oneDim.length) + i < output.oneDim.length} + + + {/if} {/each} - {#each output.twoDim as column, i} - - - {#each column as x} - - {/each} - + {/each} +
- {#each range(output.twoDim[0].length) as j} - {j} + {j * numOfRows(output.oneDim.length) + i} + + {output.oneDim[j * numOfRows(output.oneDim.length) + i].toFixed(3)} +
{i} - {x.toFixed(3)} -
+
+ {:else} +
+ + + {/each} -
+ {#each range(output.twoDim[0].length) as j} + {j}
-
- {/if} + + {#each output.twoDim as column, i} + + {i} + {#each column as x} + + {x.toFixed(3)} + + {/each} + + {/each} + + {/if} -
+ {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte index 4fbd6d9bcb..be71b31900 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte @@ -9,6 +9,7 @@ import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isValidOutputLabels } from "../../shared/outputValidation.js"; import { isTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -18,6 +19,8 @@ export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -112,7 +115,7 @@ throw new TypeError("Invalid output: output must be of type Array"); } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { setTextAreaValue(sample.text); if (opts.isPreview) { if (sample.output) { @@ -131,40 +134,27 @@ } - - -
- {#if model.pipeline_tag === "fill-mask"} -
- Mask token: {model.mask_token} -
- {/if} - - { - getOutput(); - }} - /> - -
- - - + + + + {#if model.pipeline_tag === "fill-mask"} +
+ Mask token: {model.mask_token} +
+ {/if} + + { + getOutput(); + }} + /> + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte index 8e1f25b319..7ad1fe582f 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte @@ -9,6 +9,7 @@ import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js"; import { isValidOutputLabels } from "../../shared/outputValidation.js"; import { isTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -17,6 +18,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -92,7 +95,7 @@ throw new TypeError("Invalid output: output must be of type Array"); } - async function applyInputSample( + async function applyWidgetExample( sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {} ) { @@ -117,56 +120,44 @@ } - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - - {#if imgSrc} - {#if imgSrc} -
- -
- {/if} - {/if} - - {#if warning} -
{warning}
- {/if} - -
- - - + + + + (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} + {#if imgSrc} +
+ +
+ {/if} + {/if} + + {#if warning} +
{warning}
+ {/if} + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageSegmentationWidget/ImageSegmentationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageSegmentationWidget/ImageSegmentationWidget.svelte index c6c1a37dfa..2c64527870 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageSegmentationWidget/ImageSegmentationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageSegmentationWidget/ImageSegmentationWidget.svelte @@ -14,6 +14,7 @@ import { isAssetInput } from "../../shared/inputValidation.js"; import Canvas from "./Canvas.svelte"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -22,6 +23,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + const maskOpacity = Math.floor(255 * 0.6); const colorToRgb = Object.fromEntries( COLORS.map((color) => { @@ -210,7 +213,7 @@ }; } - async function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { + async function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { imgSrc = sample.src; if (opts.isPreview) { output = []; @@ -229,53 +232,49 @@ }); - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - - {#if imgSrc} - - {/if} - - {#if warning} -
{warning}
- {/if} - - -
- - - + + + + (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} + + {/if} + + {#if warning} +
{warning}
+ {/if} + + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte index 53331ec56a..5090e00429 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte @@ -9,6 +9,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js"; import { isAssetAndPromptInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -17,6 +18,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -61,7 +64,7 @@ throw new TypeError("Invalid output: output must be of type object & of instance Blob"); } - async function applyInputSample(sample: WidgetExampleAssetAndPromptInput, opts: ExampleRunOpts = {}) { + async function applyWidgetExample(sample: WidgetExampleAssetAndPromptInput, opts: ExampleRunOpts = {}) { prompt = sample.prompt; imgSrc = sample.src; if (opts.isPreview) { @@ -133,70 +136,66 @@ } - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - + + +
+ (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} {#if imgSrc} - {#if imgSrc} -
- -
- {/if} +
+ +
{/if} - - - { - getOutput(); - }} - /> - - - - {#if output.length} -
- -
{/if} -
+ + + { + getOutput(); + }} + /> +
+ + + {#if output.length} +
+ +
+ {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToTextWidget/ImageToTextWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToTextWidget/ImageToTextWidget.svelte index c531b42282..ef92725630 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToTextWidget/ImageToTextWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToTextWidget/ImageToTextWidget.svelte @@ -8,6 +8,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { callInferenceApi, getBlobFromUrl } from "../../shared/helpers.js"; import { isAssetInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -16,6 +17,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -92,7 +95,7 @@ throw new TypeError("Invalid output: output must be of type Array & non-empty"); } - async function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { + async function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { imgSrc = sample.src; if (opts.isPreview) { output = ""; @@ -104,58 +107,54 @@ } - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - - {#if imgSrc} - {#if imgSrc} -
- -
- {/if} - {/if} - - {#if warning} -
{warning}
- {/if} - -
- - {#if model?.pipeline_tag !== "text-generation"} - + + + + (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} + {#if imgSrc} +
+ +
{/if} -
+ {/if} + + {#if warning} +
{warning}
+ {/if} + + + + {#if model?.pipeline_tag !== "text-generation"} + + {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ObjectDetectionWidget/ObjectDetectionWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ObjectDetectionWidget/ObjectDetectionWidget.svelte index 8c0d49ce27..709b829b58 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ObjectDetectionWidget/ObjectDetectionWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ObjectDetectionWidget/ObjectDetectionWidget.svelte @@ -12,6 +12,7 @@ import { isAssetInput } from "../../shared/inputValidation.js"; import BoundingBoxes from "./SvgBoundingBoxes.svelte"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -20,6 +21,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -128,7 +131,7 @@ highlightIndex = index; } - async function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { + async function applyWidgetExample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) { imgSrc = sample.src; if (opts.isPreview) { output = []; @@ -141,52 +144,48 @@ } - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - - {#if imgSrc} - - {/if} - - {#if warning} -
{warning}
- {/if} - -
- - - + + + + (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} + + {/if} + + {#if warning} +
{warning}
+ {/if} + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte index 2252c5d077..0e60ccd724 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte @@ -12,6 +12,7 @@ import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isValidOutputAnswerScore } from "../../shared/outputValidation.js"; import { isTextAndContextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -21,6 +22,8 @@ export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let context = ""; let computeTime = ""; let error: string = ""; @@ -108,7 +111,7 @@ throw new TypeError("Invalid output: output must be of type "); } - function applyInputSample( + function applyWidgetExample( sample: WidgetExampleTextAndContextInput, opts: ExampleRunOpts = {} ) { @@ -128,46 +131,33 @@ } - - -
- { - getOutput(); - }} - /> - - -
- - {#if output} -
- {output.answer} - {output.score.toFixed(3)} -
- {/if} -
+ + +
+ { + getOutput(); + }} + /> + +
+ + + {#if output} +
+ {output.answer} + {output.score.toFixed(3)} +
+ {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ReinforcementLearningWidget/ReinforcementLearningWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ReinforcementLearningWidget/ReinforcementLearningWidget.svelte index 348f4b65e6..f98579c52b 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ReinforcementLearningWidget/ReinforcementLearningWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ReinforcementLearningWidget/ReinforcementLearningWidget.svelte @@ -38,7 +38,7 @@ does NOT use InferenceAPI (unlike other pipelines widgets) -->
- +
{#if replay === Replay.Available} diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte index e957d33a3e..8b49bbc92f 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte @@ -9,6 +9,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js"; import { isSentenceSimilarityInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -17,6 +18,8 @@ export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let sourceSentence = ""; let comparisonSentences: Array = []; let nComparisonSentences = 2; @@ -121,7 +124,7 @@ throw new TypeError("Invalid output: output must be of type Array"); } - function applyInputSample(sample: WidgetExampleSentenceSimilarityInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleSentenceSimilarityInput, opts: ExampleRunOpts = {}) { sourceSentence = sample.source_sentence; comparisonSentences = sample.sentences; nComparisonSentences = comparisonSentences.length; @@ -133,55 +136,51 @@ } - - -
- - - {#each Array(nComparisonSentences - 1) as _, idx} - - {/each} - { - nComparisonSentences++; - }} - /> - { - getOutput(); - }} - /> - -
- - {#if output.length} - - {/if} - + + +
+ + + {#each Array(nComparisonSentences - 1) as _, idx} + + {/each} + { + nComparisonSentences++; + }} + /> + { + getOutput(); + }} + /> +
+ + + {#if output.length} + + {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte index 1179495fca..3abf8b302b 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte @@ -8,6 +8,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -17,6 +18,8 @@ export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -93,7 +96,7 @@ throw new TypeError("Invalid output: output must be of type Array & non-empty"); } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { setTextAreaValue(sample.text); if (opts.isPreview) { return; @@ -103,34 +106,29 @@ } - - -
- - { - getOutput(); - }} - /> - -
- - - + + +
+ + { + getOutput(); + }} + /> +
+ + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte index 756ee7b6b3..94f8c4ca77 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte @@ -14,6 +14,7 @@ updateUrl, } from "../../shared/helpers.js"; import { isTextAndTableInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; interface Output { aggregator?: string; answer: string; @@ -29,6 +30,8 @@ export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + let computeTime = ""; let error: string = ""; let isLoading = false; @@ -142,7 +145,7 @@ ); } - function applyInputSample(sample: WidgetExampleTextAndTableInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextAndTableInput, opts: ExampleRunOpts = {}) { query = sample.text; table = convertDataToTable(sample.table); if (opts.isPreview) { @@ -153,39 +156,35 @@ } - - -
- { - getOutput(); - }} - /> - -
- {#if output} - - {/if} - {#if table.length > 1 || table[0].length > 1} - - {/if} -
-
+ + + + { + getOutput(); + }} + /> + +
+ {#if output} + + {/if} + {#if table.length > 1 || table[0].length > 1} + + {/if} +
+ + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/TabularDataWidget/TabularDataWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/TabularDataWidget/TabularDataWidget.svelte index 9e53661747..6f91466942 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/TabularDataWidget/TabularDataWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/TabularDataWidget/TabularDataWidget.svelte @@ -14,6 +14,7 @@ updateUrl, } from "../../shared/helpers.js"; import { isStructuredDataInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -23,6 +24,8 @@ export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + const widgetData = model?.widgetData?.[0] as WidgetExampleStructuredDataInput | undefined; const columns: string[] = Object.keys(widgetData?.structured_data ?? {}); @@ -167,7 +170,7 @@ ); } - function applyInputSample(sample: WidgetExampleStructuredDataInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleStructuredDataInput, opts: ExampleRunOpts = {}) { table = convertDataToTable(sample.structured_data); if (opts.isPreview) { return; @@ -177,44 +180,38 @@ } - - -
-
- {#if table.length > 1 || table[1]?.length > 1} - - {/if} -
- + + +
+ {#if table.length > 1 || table[1]?.length > 1} + { - getOutput(); - }} + onChange={onChangeTable} + table={tableWithOutput} + canAddCol={false} + bind:scrollTableToRight /> - - - + {/if} +
+ { + getOutput(); + }} + /> + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte index a4c0059a20..2e76ae8658 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte @@ -13,6 +13,7 @@ import { isValidOutputText } from "../../shared/outputValidation.js"; import { isTextInput } from "../../shared/inputValidation.js"; import type { PipelineType } from "@huggingface/tasks"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -23,6 +24,8 @@ export let includeCredentials: WidgetProps["includeCredentials"]; export let isLoggedIn: WidgetProps["includeCredentials"]; + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; + const isBloomLoginRequired = isLoggedIn === false && model.id === "bigscience/bloom"; let computeTime = ""; @@ -165,7 +168,7 @@ renderTypingEffect(prefix + output); } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { setTextAreaValue(sample.text); if (opts.isPreview) { if (sample.output) { @@ -195,66 +198,53 @@ } - - -
- + +
+ + {#if model.id === "bigscience/bloom"} + + {/if} +
+ { + getOutput({ useCache }); + }} /> - {#if model.id === "bigscience/bloom"} - - {/if} -
- { - getOutput({ useCache }); - }} - /> - -
- -
+ +
+ +
+
+ {#if warning} +
{warning}
+ {/if} + {#if isBloomLoginRequired} +
+ + Please + login + or + + register to try BLOOM 🌸
- {#if warning} -
{warning}
- {/if} - {#if isBloomLoginRequired} -
- - Please - login - or - - register to try BLOOM 🌸 -
- {/if} - - - - {#if model?.pipeline_tag !== "text-generation"} - - {/if} - +
+ + + {#if model?.pipeline_tag !== "text-generation"} + + + {/if} + + diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte index 4bc9802d06..48ce9fec67 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte @@ -7,6 +7,7 @@ import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isValidOutputUrl } from "../../shared/outputValidation.js"; import { isTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -15,7 +16,8 @@ export let noTitle: WidgetProps["noTitle"]; export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -98,7 +100,7 @@ throw new TypeError("Invalid output: output must be of type object & of instance Blob"); } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { text = sample.text; if (opts.isPreview) { if (sample.output) { @@ -117,31 +119,18 @@ } - - -
- getOutput()} /> - -
- - {#if output.length} -
- -
- {/if} -
+ + + + getOutput()} /> + + + + {#if output.length} +
+ +
+ {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte index ef1a280bc2..225d2fdf2f 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte @@ -8,6 +8,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -16,7 +17,8 @@ export let noTitle: WidgetProps["noTitle"]; export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -93,7 +95,7 @@ throw new TypeError("Invalid output: output must be of type object & instance of Blob"); } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { setTextAreaValue(sample.text); if (opts.isPreview) { return; @@ -103,37 +105,32 @@ } - - -
- - { - getOutput(); - }} - /> - -
- - {#if output.length} - - {/if} - + + + + + { + getOutput(); + }} + /> + + + + {#if output.length} + + {/if} + + diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte index 412c77daf5..c5f5bc9e85 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte @@ -9,6 +9,7 @@ import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isTextInput } from "../../shared/inputValidation.js"; import { uniqBy } from "../../../../utils/ViewUtils.js"; + import { widgetStates } from "../../stores.js"; interface EntityGroup { entity_group: string; @@ -32,7 +33,8 @@ export let noTitle: WidgetProps["noTitle"]; export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -214,7 +216,7 @@ return a.type === b.type && a.start === b.start && a.end === b.end; } - function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) { setTextAreaValue(sample.text); if (opts.isPreview) { return; @@ -224,38 +226,33 @@ } - - -
- - { - getOutput(); - }} - /> - {#if warning} -
{warning}
- {/if} - -
- - - + + + + + { + getOutput(); + }} + /> + {#if warning} +
{warning}
+ {/if} + + + + + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte index 1a07900c74..ac346acbe1 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte @@ -9,6 +9,7 @@ import WidgetOutputChart from "../../shared/WidgetOutputChart/WidgetOutputChart.svelte"; import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js"; import { isAssetAndTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -16,7 +17,8 @@ export let model: WidgetProps["model"]; export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let computeTime = ""; let error: string = ""; @@ -69,7 +71,7 @@ throw new TypeError("Invalid output: output must be of type Array<{ answer: string, score?: number }>"); } - async function applyInputSample(sample: WidgetExampleAssetAndTextInput, opts: ExampleRunOpts = {}) { + async function applyWidgetExample(sample: WidgetExampleAssetAndTextInput, opts: ExampleRunOpts = {}) { question = sample.text; imgSrc = sample.src; if (opts.isPreview) { @@ -145,63 +147,59 @@ } - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - + + +
+ (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} {#if imgSrc} - {#if imgSrc} -
- -
- {/if} +
+ +
{/if} - - { - getOutput(); - }} - /> - - - - {#if output} - {/if} - + + { + getOutput(); + }} + /> +
+ + + {#if output} + + {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte index 1761f0da4e..e82c541fef 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte @@ -10,6 +10,7 @@ import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import { addInferenceParameters, callInferenceApi, updateUrl } from "../../shared/helpers.js"; import { isZeroShotTextInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -18,7 +19,8 @@ export let noTitle: WidgetProps["noTitle"]; export let shouldUpdateUrl: WidgetProps["shouldUpdateUrl"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let candidateLabels = ""; let computeTime = ""; @@ -134,7 +136,7 @@ throw new TypeError("Invalid output: output must be of type "); } - function applyInputSample(sample: WidgetExampleZeroShotTextInput, opts: ExampleRunOpts = {}) { + function applyWidgetExample(sample: WidgetExampleZeroShotTextInput, opts: ExampleRunOpts = {}) { candidateLabels = sample.candidate_labels; multiClass = sample.multi_class; setTextAreaValue(sample.text); @@ -146,51 +148,41 @@ } - - -
- - - - { - getOutput(); - }} - /> - {#if warning} -
{warning}
- {/if} - -
- - {#if output.length} - + + +
+ + + + { + getOutput(); + }} + /> + {#if warning} +
{warning}
{/if} - +
+ + + {#if output.length} + + {/if} + +
diff --git a/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte b/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte index 79ba0d896d..141e029b3b 100644 --- a/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte +++ b/packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte @@ -2,16 +2,15 @@ import type { WidgetProps, ExampleRunOpts, InferenceRunOpts } from "../../shared/types.js"; import type { WidgetExampleAssetAndZeroShotInput } from "@huggingface/tasks"; - import { onMount } from "svelte"; - import WidgetFileInput from "../../shared/WidgetFileInput/WidgetFileInput.svelte"; import WidgetDropzone from "../../shared/WidgetDropzone/WidgetDropzone.svelte"; import WidgetTextInput from "../../shared/WidgetTextInput/WidgetTextInput.svelte"; import WidgetSubmitBtn from "../../shared/WidgetSubmitBtn/WidgetSubmitBtn.svelte"; import WidgetWrapper from "../../shared/WidgetWrapper/WidgetWrapper.svelte"; import WidgetOutputChart from "../../shared/WidgetOutputChart/WidgetOutputChart.svelte"; - import { addInferenceParameters, callInferenceApi, getWidgetExample } from "../../shared/helpers.js"; + import { addInferenceParameters, callInferenceApi } from "../../shared/helpers.js"; import { isAssetAndZeroShotInput } from "../../shared/inputValidation.js"; + import { widgetStates } from "../../stores.js"; export let apiToken: WidgetProps["apiToken"]; export let apiUrl: WidgetProps["apiUrl"]; @@ -19,7 +18,8 @@ export let model: WidgetProps["model"]; export let noTitle: WidgetProps["noTitle"]; export let includeCredentials: WidgetProps["includeCredentials"]; - let isDisabled = false; + + $: isDisabled = $widgetStates?.[model.id]?.isDisabled; let candidateLabels = ""; let computeTime = ""; @@ -69,7 +69,7 @@ throw new TypeError("Invalid output: output must be of type "); } - async function applyInputSample(sample: WidgetExampleAssetAndZeroShotInput, opts: ExampleRunOpts = {}) { + async function applyWidgetExample(sample: WidgetExampleAssetAndZeroShotInput, opts: ExampleRunOpts = {}) { candidateLabels = sample.candidate_labels; imgSrc = sample.src; if (opts.isPreview) { @@ -146,79 +146,66 @@ error = res.error; } } - - onMount(() => { - (async () => { - const example = getWidgetExample(model, isAssetAndZeroShotInput); - if (callApiOnMount && example) { - await applyInputSample(example, { inferenceOpts: { isOnLoadCall: true } }); - } - })(); - }); - - -
- (error = e)} - > - {#if imgSrc} - - {/if} - - + + +
+ (error = e)} + > + {#if imgSrc} + + {/if} + + + {#if imgSrc} {#if imgSrc} - {#if imgSrc} -
- -
- {/if} +
+ +
{/if} - - - { - getOutput(); - }} - /> - - - - {#if output.length} - {/if} - + + + { + getOutput(); + }} + /> +
+ + + {#if output.length} + + {/if} + +
diff --git a/packages/widgets/src/routes/+page.svelte b/packages/widgets/src/routes/+page.svelte index 0966b33a01..51296c0f67 100644 --- a/packages/widgets/src/routes/+page.svelte +++ b/packages/widgets/src/routes/+page.svelte @@ -212,7 +212,7 @@ ], }, { - id: "gpt2", + id: "mistralai/Mistral-7B-v0.1", pipeline_tag: "text-generation", inference: InferenceDisplayability.Yes, widgetData: [ @@ -228,11 +228,11 @@ pipeline_tag: "text-generation", inference: InferenceDisplayability.Yes, widgetData: [ - { text: "My name is Julien and I like to" }, - { text: "My name is Thomas and my main" }, - { text: "My name is Mariama, my favorite" }, - { text: "My name is Clara and I am" }, - { text: "Once upon a time," }, + { text: "My name is Julien and I like to", group: "English" }, + { text: "My name is Thomas and my main", group: "English" }, + { text: "My name is Mariama, my favorite", group: "French" }, + { text: "My name is Clara and I am", group: "French" }, + { text: "Once upon a time,", group: "French" }, ], }, {