From cfc51268119af94b0fa1fa947994c9eeb2e474e9 Mon Sep 17 00:00:00 2001 From: SBrandeis Date: Fri, 29 Sep 2023 12:58:38 +0000 Subject: [PATCH 01/12] wip --- .../InferenceWidget/shared/WidgetExample.ts | 88 +++++++------------ .../WidgetInputSamples.svelte | 8 +- .../AudioClassificationWidget.svelte | 8 +- .../AutomaticSpeechRecognitionWidget.svelte | 6 +- 4 files changed, 44 insertions(+), 66 deletions(-) diff --git a/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts b/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts index d642afd26..e9be9ef45 100644 --- a/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts +++ b/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts @@ -6,89 +6,67 @@ export interface WidgetExampleOutputAnswerScore { answer: string; score: number; } -export interface WidgetExampleOutputText { +export interface WidgetExampleOutputText { text: string; } -export interface WidgetExampleOutputUrl { +export interface WidgetExampleOutputUrl { url: string; } + +export type WidgetExampleOutput = + | WidgetExampleOutputLabels + | WidgetExampleOutputAnswerScore + | WidgetExampleOutputText + | WidgetExampleOutputUrl; //#endregion -export interface WidgetExampleBase { + +export interface WidgetExampleBase { example_title?: string; group?: string; + output?: TOutput; } -export interface WidgetExampleTextInputLabelsOutput extends WidgetExampleBase { - text: string; - output?: WidgetExampleOutputLabels; -} - -export interface WidgetExampleTextAndContextInputAnswerScoreOutput extends WidgetExampleBase { - text: string; - context: string; - output?: WidgetExampleOutputAnswerScore; -} - -export interface WidgetExampleTextInputTextOutput extends WidgetExampleBase { - text: string; - output?: WidgetExampleOutputText; -} - -export interface WidgetExampleTextInputUrlOutput extends WidgetExampleBase { - text: string; - output?: WidgetExampleOutputUrl; -} - -export interface WidgetExampleAssetInputLabelsOutput extends WidgetExampleBase { - src: string; - output?: WidgetExampleOutputLabels; +export interface WidgetExampleTextInput extends WidgetExampleBase { + text: string; } -export interface WidgetExampleAssetInputTextOutput extends WidgetExampleBase { - src: string; - output?: WidgetExampleOutputText; +export interface WidgetExampleTextAndContextInput extends WidgetExampleBase { + text: string; + context: string; } -export interface WidgetExampleAssetInputUrlOutput extends WidgetExampleBase { - src: string; - output?: WidgetExampleOutputUrl; +export interface WidgetExampleAssetInput extends WidgetExampleBase { + src: string; } -//#region more exotic stuff -export interface WidgetExampleStructuredDataInputLabelsOutput extends WidgetExampleBase { +export interface WidgetExampleStructuredDataInput extends WidgetExampleBase { structuredData: TableData; - output?: WidgetExampleOutputLabels; } -export interface WidgetExampleTableDataInputLabelsOutput extends WidgetExampleBase { - table: TableData; - output?: WidgetExampleOutputLabels; +export interface WidgetExampleTableDataInput extends WidgetExampleBase { + table: TableData; } -export interface WidgetExampleZeroShotTextInputLabelsOutput extends WidgetExampleBase { +export interface WidgetExampleZeroShotTextInput extends WidgetExampleBase { text: string; candidate_labels: string; multi_class: boolean; - output?: WidgetExampleOutputLabels; } -export interface WidgetExampleSentenceSimilarityInputLabelsOutput extends WidgetExampleBase { +export interface WidgetExampleSentenceSimilarityInput extends WidgetExampleBase { source_sentence: string; sentences: string[]; - output?: WidgetExampleOutputLabels; } + //#endregion -export type WidgetExample = - | WidgetExampleTextInputLabelsOutput - | WidgetExampleTextAndContextInputAnswerScoreOutput - | WidgetExampleTextInputTextOutput - | WidgetExampleTextInputUrlOutput - | WidgetExampleAssetInputLabelsOutput - | WidgetExampleAssetInputTextOutput - | WidgetExampleAssetInputUrlOutput - | WidgetExampleStructuredDataInputLabelsOutput - | WidgetExampleTableDataInputLabelsOutput - | WidgetExampleZeroShotTextInputLabelsOutput - | WidgetExampleSentenceSimilarityInputLabelsOutput; +export type WidgetExample = + | WidgetExampleTextInput + | WidgetExampleTextAndContextInput + | WidgetExampleTextInput + | WidgetExampleAssetInput + | WidgetExampleStructuredDataInput + | WidgetExampleTableDataInput + | WidgetExampleZeroShotTextInput + | WidgetExampleSentenceSimilarityInput; diff --git a/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte b/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte index 59985626f..f422fdcfe 100644 --- a/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte +++ b/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte @@ -7,7 +7,7 @@ export let classNames = ""; export let isLoading = false; - export let inputSamples: WidgetExample[]; + export let inputSamples: T[]; export let applyInputSample: (sample: T) => void; export let previewInputSample: (sample: T) => void; @@ -16,7 +16,7 @@ let title = "Examples"; $: { - // reset title on inputSamples change (i.e. input group change) + // reset title on inputSamples change (i.e. input group change)s inputSamples; title = "Examples"; } @@ -25,12 +25,12 @@ hideOptions(); const sample = inputSamples[idx]; title = sample.example_title as string; - applyInputSample(sample as T); + applyInputSample(sample); } function _previewInputSample(idx: number) { const sample = inputSamples[idx]; - previewInputSample(sample as T); + previewInputSample(sample); } function toggleOptionsVisibility() { diff --git a/js/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte b/js/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte index d7058a1b1..85e8d3494 100644 --- a/js/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte +++ b/js/src/lib/components/InferenceWidget/widgets/AudioClassificationWidget/AudioClassificationWidget.svelte @@ -1,6 +1,6 @@
From 921589653961efde555fddf10353224b220f1554 Mon Sep 17 00:00:00 2001 From: SBrandeis Date: Fri, 29 Sep 2023 15:50:16 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=E2=9C=A8=20Typing=20&=20validation=20for?= =?UTF-8?q?=20ALL=20widgets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InferenceWidget/shared/WidgetExample.ts | 23 ++++- .../WidgetInputSamples.svelte | 9 +- .../shared/WidgetWrapper/WidgetWrapper.svelte | 11 ++- .../InferenceWidget/shared/inputValidation.ts | 87 +++++++++++++++++++ .../AudioClassificationWidget.svelte | 3 +- .../AudioToAudioWidget.svelte | 13 +-- .../AutomaticSpeechRecognitionWidget.svelte | 3 +- .../ConversationalWidget.svelte | 7 +- .../FeatureExtractionWidget.svelte | 11 ++- .../FillMaskWidget/FillMaskWidget.svelte | 3 +- .../ImageClassificationWidget.svelte | 8 +- .../ImageSegmentationWidget.svelte | 9 +- .../ImageToImageWidget.svelte | 9 +- .../ImageToTextWidget.svelte | 7 +- .../ObjectDetectionWidget.svelte | 7 +- .../QuestionAnsweringWidget.svelte | 17 +++- .../SentenceSimilarityWidget.svelte | 7 +- .../SummarizationWidget.svelte | 7 +- .../TableQuestionAnsweringWidget.svelte | 9 +- .../TabularDataWidget.svelte | 12 ++- .../TextGenerationWidget.svelte | 10 ++- .../TextToImageWidget.svelte | 10 ++- .../TextToSpeechWidget.svelte | 7 +- .../TokenClassificationWidget.svelte | 7 +- .../VisualQuestionAnsweringWidget.svelte | 9 +- .../ZeroShotImageClassificationWidget.svelte | 9 +- .../ZeroShotClassificationWidget.svelte | 7 +- 27 files changed, 258 insertions(+), 63 deletions(-) create mode 100644 js/src/lib/components/InferenceWidget/shared/inputValidation.ts diff --git a/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts b/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts index c5b7788a3..9cbf407c6 100644 --- a/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts +++ b/js/src/lib/components/InferenceWidget/shared/WidgetExample.ts @@ -30,14 +30,26 @@ export interface WidgetExampleTextInput extends WidgetExampleBase extends WidgetExampleBase { - text: string; +export interface WidgetExampleTextAndContextInput extends WidgetExampleTextInput { context: string; } +export interface WidgetExampleTextAndTableInput extends WidgetExampleTextInput { + table: (string | number)[][]; +} + export interface WidgetExampleAssetInput extends WidgetExampleBase { src: string; } +export interface WidgetExampleAssetAndPromptInput extends WidgetExampleAssetInput { + prompt: string; +} + +export type WidgetExampleAssetAndTextInput = WidgetExampleAssetInput & + WidgetExampleTextInput; + +export type WidgetExampleAssetAndZeroShotInput = WidgetExampleAssetInput & + WidgetExampleZeroShotTextInput; export interface WidgetExampleStructuredDataInput extends WidgetExampleBase { structuredData: TableData; @@ -47,7 +59,7 @@ export interface WidgetExampleTableDataInput extends WidgetExampleBase< table: TableData; } -export interface WidgetExampleZeroShotTextInput extends WidgetExampleBase { +export interface WidgetExampleZeroShotTextInput extends WidgetExampleTextInput { text: string; candidate_labels: string; multi_class: boolean; @@ -63,8 +75,11 @@ export interface WidgetExampleSentenceSimilarityInput extends WidgetExa export type WidgetExample = | WidgetExampleTextInput | WidgetExampleTextAndContextInput - | WidgetExampleTextInput + | WidgetExampleTextAndTableInput | WidgetExampleAssetInput + | WidgetExampleAssetAndPromptInput + | WidgetExampleAssetAndTextInput + | WidgetExampleAssetAndZeroShotInput | WidgetExampleStructuredDataInput | WidgetExampleTableDataInput | WidgetExampleZeroShotTextInput diff --git a/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte b/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte index be6062889..97208115b 100644 --- a/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte +++ b/js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte @@ -1,6 +1,5 @@ - diff --git a/js/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte b/js/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte index 7a858543b..eb6ee69c6 100644 --- a/js/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte +++ b/js/src/lib/components/InferenceWidget/widgets/ImageClassificationWidget/ImageClassificationWidget.svelte @@ -1,6 +1,6 @@ diff --git a/js/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte b/js/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte index 7d3f94884..b6629f301 100644 --- a/js/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte +++ b/js/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte @@ -1,5 +1,6 @@ diff --git a/js/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte b/js/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte index f266a0c43..e7800d3ba 100644 --- a/js/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte +++ b/js/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte @@ -1,5 +1,6 @@