Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
machineuser
commited on
Commit
·
49cc62d
1
Parent(s):
0b0ec4d
Sync widgets demo
Browse files- packages/widgets/src/additional-svelte-typings.d.ts +9 -0
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetQuickInput/WidgetQuickInput.svelte +3 -0
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetSubmitBtn/WidgetSubmitBtn.svelte +0 -13
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetTextInput/WidgetTextInput.svelte +4 -0
- packages/widgets/src/lib/components/InferenceWidget/shared/WidgetTextarea/WidgetTextarea.svelte +3 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte +1 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte +1 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte +1 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte +2 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte +2 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte +11 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte +1 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte +1 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte +1 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte +7 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte +1 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte +1 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte +1 -0
- packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte +9 -1
- packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte +2 -0
- packages/widgets/src/lib/utils/ViewUtils.ts +28 -0
packages/widgets/src/additional-svelte-typings.d.ts
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// eslint-disable-next-line @typescript-eslint/no-namespace, @typescript-eslint/no-unused-vars
|
2 |
+
declare namespace svelteHTML {
|
3 |
+
// enhance attributes
|
4 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
5 |
+
interface HTMLAttributes<T> {
|
6 |
+
// If you want to use on:beforeinstallprompt
|
7 |
+
"on:cmdEnter"?: () => void;
|
8 |
+
}
|
9 |
+
}
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetQuickInput/WidgetQuickInput.svelte
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<script lang="ts">
|
|
|
2 |
import WidgetSubmitBtn from "../WidgetSubmitBtn/WidgetSubmitBtn.svelte";
|
3 |
|
4 |
export let flatTop = false;
|
@@ -19,6 +20,8 @@
|
|
19 |
type="text"
|
20 |
disabled={isLoading || isDisabled}
|
21 |
autocomplete="off"
|
|
|
|
|
22 |
/>
|
23 |
<WidgetSubmitBtn
|
24 |
classNames="rounded-l-none border-l-0 {flatTop ? 'rounded-t-none' : ''}"
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { onCmdEnter } from "../../../../utils/ViewUtils.js";
|
3 |
import WidgetSubmitBtn from "../WidgetSubmitBtn/WidgetSubmitBtn.svelte";
|
4 |
|
5 |
export let flatTop = false;
|
|
|
20 |
type="text"
|
21 |
disabled={isLoading || isDisabled}
|
22 |
autocomplete="off"
|
23 |
+
use:onCmdEnter={{ disabled: isLoading || isDisabled }}
|
24 |
+
on:cmdEnter
|
25 |
/>
|
26 |
<WidgetSubmitBtn
|
27 |
classNames="rounded-l-none border-l-0 {flatTop ? 'rounded-t-none' : ''}"
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetSubmitBtn/WidgetSubmitBtn.svelte
CHANGED
@@ -6,21 +6,8 @@
|
|
6 |
export let isLoading: boolean;
|
7 |
export let label = "Compute";
|
8 |
export let onClick: () => void;
|
9 |
-
|
10 |
-
function onKeyDown(e: KeyboardEvent) {
|
11 |
-
if (isLoading || isDisabled) {
|
12 |
-
return;
|
13 |
-
}
|
14 |
-
// run inference on cmd+Enter
|
15 |
-
if (e.code === "Enter" && (e.metaKey || e.ctrlKey)) {
|
16 |
-
e.preventDefault();
|
17 |
-
onClick();
|
18 |
-
}
|
19 |
-
}
|
20 |
</script>
|
21 |
|
22 |
-
<svelte:window on:keydown={onKeyDown} />
|
23 |
-
|
24 |
{#if !isDisabled}
|
25 |
<button
|
26 |
class="btn-widget h-10 w-24 px-5 {classNames}"
|
|
|
6 |
export let isLoading: boolean;
|
7 |
export let label = "Compute";
|
8 |
export let onClick: () => void;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
</script>
|
10 |
|
|
|
|
|
11 |
{#if !isDisabled}
|
12 |
<button
|
13 |
class="btn-widget h-10 w-24 px-5 {classNames}"
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetTextInput/WidgetTextInput.svelte
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
<script lang="ts">
|
|
|
2 |
import WidgetLabel from "../WidgetLabel/WidgetLabel.svelte";
|
3 |
|
4 |
export let label: string | undefined = undefined;
|
5 |
export let placeholder: string = "Your sentence here...";
|
|
|
6 |
export let isDisabled = false;
|
7 |
export let value: string;
|
8 |
</script>
|
@@ -15,6 +17,8 @@
|
|
15 |
placeholder={isDisabled ? "" : placeholder}
|
16 |
disabled={isDisabled}
|
17 |
type="text"
|
|
|
|
|
18 |
/>
|
19 |
</svelte:fragment>
|
20 |
</WidgetLabel>
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { onCmdEnter } from "../../../../utils/ViewUtils.js";
|
3 |
import WidgetLabel from "../WidgetLabel/WidgetLabel.svelte";
|
4 |
|
5 |
export let label: string | undefined = undefined;
|
6 |
export let placeholder: string = "Your sentence here...";
|
7 |
+
export let isLoading = false;
|
8 |
export let isDisabled = false;
|
9 |
export let value: string;
|
10 |
</script>
|
|
|
17 |
placeholder={isDisabled ? "" : placeholder}
|
18 |
disabled={isDisabled}
|
19 |
type="text"
|
20 |
+
use:onCmdEnter={{ disabled: isLoading || isDisabled }}
|
21 |
+
on:cmdEnter
|
22 |
/>
|
23 |
</svelte:fragment>
|
24 |
</WidgetLabel>
|
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetTextarea/WidgetTextarea.svelte
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<script lang="ts">
|
2 |
import { tick } from "svelte";
|
3 |
|
4 |
-
import { delay } from "../../../../utils/ViewUtils.js";
|
5 |
import WidgetLabel from "../WidgetLabel/WidgetLabel.svelte";
|
6 |
|
7 |
export let label: string = "";
|
@@ -103,6 +103,8 @@
|
|
103 |
dir="auto"
|
104 |
contenteditable
|
105 |
class:pointer-events-none={isLoading || isDisabled}
|
|
|
|
|
106 |
bind:this={containerSpanEl}
|
107 |
on:paste|preventDefault={handlePaste}
|
108 |
on:input={updateInnerTextValue}
|
|
|
1 |
<script lang="ts">
|
2 |
import { tick } from "svelte";
|
3 |
|
4 |
+
import { delay, onCmdEnter } from "../../../../utils/ViewUtils.js";
|
5 |
import WidgetLabel from "../WidgetLabel/WidgetLabel.svelte";
|
6 |
|
7 |
export let label: string = "";
|
|
|
103 |
dir="auto"
|
104 |
contenteditable
|
105 |
class:pointer-events-none={isLoading || isDisabled}
|
106 |
+
use:onCmdEnter={{ disabled: isLoading || isDisabled }}
|
107 |
+
on:cmdEnter
|
108 |
bind:this={containerSpanEl}
|
109 |
on:paste|preventDefault={handlePaste}
|
110 |
on:input={updateInnerTextValue}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
CHANGED
@@ -268,6 +268,7 @@
|
|
268 |
{isDisabled}
|
269 |
onClickSubmitBtn={handleNewMessage}
|
270 |
submitButtonLabel="Send"
|
|
|
271 |
/>
|
272 |
|
273 |
<WidgetInfo {model} {error} />
|
|
|
268 |
{isDisabled}
|
269 |
onClickSubmitBtn={handleNewMessage}
|
270 |
submitButtonLabel="Send"
|
271 |
+
on:cmdEnter={handleNewMessage}
|
272 |
/>
|
273 |
|
274 |
<WidgetInfo {model} {error} />
|
packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/FeatureExtractionWidget.svelte
CHANGED
@@ -141,6 +141,7 @@
|
|
141 |
onClickSubmitBtn={() => {
|
142 |
getOutput();
|
143 |
}}
|
|
|
144 |
/>
|
145 |
|
146 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
|
|
141 |
onClickSubmitBtn={() => {
|
142 |
getOutput();
|
143 |
}}
|
144 |
+
on:cmdEnter={() => getOutput()}
|
145 |
/>
|
146 |
|
147 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
packages/widgets/src/lib/components/InferenceWidget/widgets/FillMaskWidget/FillMaskWidget.svelte
CHANGED
@@ -142,7 +142,7 @@
|
|
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}
|
|
|
142 |
Mask token: <code>{model.mask_token}</code>
|
143 |
</div>
|
144 |
{/if}
|
145 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} on:cmdEnter={() => getOutput()} />
|
146 |
<WidgetSubmitBtn
|
147 |
classNames="mt-2"
|
148 |
{isLoading}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ImageToImageWidget/ImageToImageWidget.svelte
CHANGED
@@ -177,9 +177,11 @@
|
|
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}
|
|
|
177 |
/>
|
178 |
<WidgetTextInput
|
179 |
bind:value={prompt}
|
180 |
+
{isLoading}
|
181 |
{isDisabled}
|
182 |
label="(Optional) Text-guidance if the model has support for it"
|
183 |
placeholder="Your prompt here..."
|
184 |
+
on:cmdEnter={() => getOutput()}
|
185 |
/>
|
186 |
<WidgetSubmitBtn
|
187 |
{isLoading}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/QuestionAnsweringWidget/QuestionAnsweringWidget.svelte
CHANGED
@@ -141,6 +141,7 @@
|
|
141 |
onClickSubmitBtn={() => {
|
142 |
getOutput();
|
143 |
}}
|
|
|
144 |
/>
|
145 |
<WidgetTextarea
|
146 |
bind:value={context}
|
@@ -148,6 +149,7 @@
|
|
148 |
{isDisabled}
|
149 |
placeholder="Please input some context..."
|
150 |
label="Context"
|
|
|
151 |
/>
|
152 |
</div>
|
153 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
|
|
141 |
onClickSubmitBtn={() => {
|
142 |
getOutput();
|
143 |
}}
|
144 |
+
on:cmdEnter={() => getOutput()}
|
145 |
/>
|
146 |
<WidgetTextarea
|
147 |
bind:value={context}
|
|
|
149 |
{isDisabled}
|
150 |
placeholder="Please input some context..."
|
151 |
label="Context"
|
152 |
+
on:cmdEnter={() => getOutput()}
|
153 |
/>
|
154 |
</div>
|
155 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
packages/widgets/src/lib/components/InferenceWidget/widgets/SentenceSimilarityWidget/SentenceSimilarityWidget.svelte
CHANGED
@@ -149,18 +149,28 @@
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
{/each}
|
165 |
<WidgetAddSentenceBtn
|
166 |
isDisabled={nComparisonSentences === maxComparisonSentences || isDisabled}
|
|
|
149 |
<div class="flex flex-col space-y-2">
|
150 |
<WidgetTextInput
|
151 |
bind:value={sourceSentence}
|
152 |
+
{isLoading}
|
153 |
{isDisabled}
|
154 |
label="Source Sentence"
|
155 |
placeholder={isDisabled ? "" : "Your sentence here..."}
|
156 |
+
on:cmdEnter={() => getOutput()}
|
157 |
/>
|
158 |
<WidgetTextInput
|
159 |
bind:value={comparisonSentences[0]}
|
160 |
+
{isLoading}
|
161 |
{isDisabled}
|
162 |
label="Sentences to compare to"
|
163 |
placeholder={isDisabled ? "" : "Your sentence here..."}
|
164 |
+
on:cmdEnter={() => getOutput()}
|
165 |
/>
|
166 |
{#each Array(nComparisonSentences - 1) as _, idx}
|
167 |
+
<WidgetTextInput
|
168 |
+
bind:value={comparisonSentences[idx + 1]}
|
169 |
+
{isLoading}
|
170 |
+
{isDisabled}
|
171 |
+
placeholder="Your sentence here..."
|
172 |
+
on:cmdEnter={() => getOutput()}
|
173 |
+
/>
|
174 |
{/each}
|
175 |
<WidgetAddSentenceBtn
|
176 |
isDisabled={nComparisonSentences === maxComparisonSentences || isDisabled}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/SummarizationWidget/SummarizationWidget.svelte
CHANGED
@@ -117,7 +117,7 @@
|
|
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}
|
|
|
117 |
validateExample={isTextInput}
|
118 |
/>
|
119 |
<div class="space-y-2">
|
120 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} on:cmdEnter={() => getOutput()} />
|
121 |
<WidgetSubmitBtn
|
122 |
{isLoading}
|
123 |
{isDisabled}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TableQuestionAnsweringWidget/TableQuestionAnsweringWidget.svelte
CHANGED
@@ -174,6 +174,7 @@
|
|
174 |
onClickSubmitBtn={() => {
|
175 |
getOutput();
|
176 |
}}
|
|
|
177 |
/>
|
178 |
|
179 |
<div class="mt-4">
|
|
|
174 |
onClickSubmitBtn={() => {
|
175 |
getOutput();
|
176 |
}}
|
177 |
+
on:cmdEnter={() => getOutput()}
|
178 |
/>
|
179 |
|
180 |
<div class="mt-4">
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TextGenerationWidget/TextGenerationWidget.svelte
CHANGED
@@ -213,6 +213,7 @@
|
|
213 |
{isDisabled}
|
214 |
size="big"
|
215 |
bind:renderTextOutput
|
|
|
216 |
/>
|
217 |
{#if model.id === "bigscience/bloom"}
|
218 |
<WidgetBloomDecoding bind:decodingStrategy />
|
|
|
213 |
{isDisabled}
|
214 |
size="big"
|
215 |
bind:renderTextOutput
|
216 |
+
on:cmdEnter={() => getOutput({ useCache })}
|
217 |
/>
|
218 |
{#if model.id === "bigscience/bloom"}
|
219 |
<WidgetBloomDecoding bind:decodingStrategy />
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TextToImageWidget/TextToImageWidget.svelte
CHANGED
@@ -122,7 +122,13 @@
|
|
122 |
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
123 |
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
124 |
|
125 |
-
<WidgetQuickInput
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
128 |
|
|
|
122 |
<WidgetWrapper {apiUrl} {includeCredentials} {model} let:WidgetInfo let:WidgetHeader let:WidgetFooter>
|
123 |
<WidgetHeader {noTitle} {model} {isLoading} {isDisabled} {callApiOnMount} {applyWidgetExample} {validateExample} />
|
124 |
|
125 |
+
<WidgetQuickInput
|
126 |
+
bind:value={text}
|
127 |
+
{isLoading}
|
128 |
+
{isDisabled}
|
129 |
+
onClickSubmitBtn={() => getOutput()}
|
130 |
+
on:cmdEnter={() => getOutput()}
|
131 |
+
/>
|
132 |
|
133 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
134 |
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TextToSpeechWidget/TextToSpeechWidget.svelte
CHANGED
@@ -116,7 +116,7 @@
|
|
116 |
validateExample={isTextInput}
|
117 |
/>
|
118 |
|
119 |
-
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} />
|
120 |
<WidgetSubmitBtn
|
121 |
classNames="mt-2"
|
122 |
{isLoading}
|
|
|
116 |
validateExample={isTextInput}
|
117 |
/>
|
118 |
|
119 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} on:cmdEnter={() => getOutput()} />
|
120 |
<WidgetSubmitBtn
|
121 |
classNames="mt-2"
|
122 |
{isLoading}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/TokenClassificationWidget/TokenClassificationWidget.svelte
CHANGED
@@ -237,7 +237,7 @@
|
|
237 |
validateExample={isTextInput}
|
238 |
/>
|
239 |
|
240 |
-
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} />
|
241 |
<WidgetSubmitBtn
|
242 |
classNames="mt-2"
|
243 |
{isLoading}
|
|
|
237 |
validateExample={isTextInput}
|
238 |
/>
|
239 |
|
240 |
+
<WidgetTextarea bind:value={text} bind:setValue={setTextAreaValue} {isDisabled} on:cmdEnter={() => getOutput()} />
|
241 |
<WidgetSubmitBtn
|
242 |
classNames="mt-2"
|
243 |
{isLoading}
|
packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte
CHANGED
@@ -193,6 +193,7 @@
|
|
193 |
onClickSubmitBtn={() => {
|
194 |
getOutput();
|
195 |
}}
|
|
|
196 |
/>
|
197 |
</div>
|
198 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
|
|
193 |
onClickSubmitBtn={() => {
|
194 |
getOutput();
|
195 |
}}
|
196 |
+
on:cmdEnter={() => getOutput()}
|
197 |
/>
|
198 |
</div>
|
199 |
<WidgetInfo {model} {computeTime} {error} {modelLoading} />
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotClassificationWidget/ZeroShotClassificationWidget.svelte
CHANGED
@@ -159,12 +159,20 @@
|
|
159 |
validateExample={isZeroShotTextInput}
|
160 |
/>
|
161 |
<div class="flex flex-col space-y-2">
|
162 |
-
<WidgetTextarea
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
159 |
validateExample={isZeroShotTextInput}
|
160 |
/>
|
161 |
<div class="flex flex-col space-y-2">
|
162 |
+
<WidgetTextarea
|
163 |
+
bind:value={text}
|
164 |
+
bind:setValue={setTextAreaValue}
|
165 |
+
{isDisabled}
|
166 |
+
placeholder="Text to classify..."
|
167 |
+
on:cmdEnter={() => getOutput()}
|
168 |
+
/>
|
169 |
<WidgetTextInput
|
170 |
bind:value={candidateLabels}
|
171 |
+
{isLoading}
|
172 |
{isDisabled}
|
173 |
label="Possible class names (comma-separated)"
|
174 |
placeholder="Possible class names..."
|
175 |
+
on:cmdEnter={() => getOutput()}
|
176 |
/>
|
177 |
<WidgetCheckbox bind:checked={multiClass} label="Allow multiple true classes" />
|
178 |
<WidgetSubmitBtn
|
packages/widgets/src/lib/components/InferenceWidget/widgets/ZeroShotImageClassificationWidget/ZeroShotImageClassificationWidget.svelte
CHANGED
@@ -189,9 +189,11 @@
|
|
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}
|
|
|
189 |
/>
|
190 |
<WidgetTextInput
|
191 |
bind:value={candidateLabels}
|
192 |
+
{isLoading}
|
193 |
{isDisabled}
|
194 |
label="Possible class names (comma-separated)"
|
195 |
placeholder="Possible class names..."
|
196 |
+
on:cmdEnter={() => getOutput()}
|
197 |
/>
|
198 |
<WidgetSubmitBtn
|
199 |
{isLoading}
|
packages/widgets/src/lib/utils/ViewUtils.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import type { PipelineType } from "@huggingface/tasks";
|
|
|
2 |
|
3 |
const ESCAPED = {
|
4 |
'"': """,
|
@@ -128,6 +129,33 @@ export function getPipelineTask(modelPipeline: PipelineType): PipelineType {
|
|
128 |
return modelPipeline === "text2text-generation" ? "text-generation" : modelPipeline;
|
129 |
}
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
/**
|
132 |
* For Tailwind:
|
133 |
bg-blue-100 border-blue-100 dark:bg-blue-800 dark:border-blue-800
|
|
|
1 |
import type { PipelineType } from "@huggingface/tasks";
|
2 |
+
import type { ActionReturn } from "svelte/action";
|
3 |
|
4 |
const ESCAPED = {
|
5 |
'"': """,
|
|
|
129 |
return modelPipeline === "text2text-generation" ? "text-generation" : modelPipeline;
|
130 |
}
|
131 |
|
132 |
+
/**
|
133 |
+
* Svelte action that will call inference endpoint when a user hits cmd+Enter on a current html element
|
134 |
+
*/
|
135 |
+
export function onCmdEnter(node: HTMLElement, opts: { disabled: boolean }): ActionReturn {
|
136 |
+
let currentOpts = opts;
|
137 |
+
|
138 |
+
function onKeyDown(e: KeyboardEvent) {
|
139 |
+
if ((node as HTMLInputElement)?.disabled || currentOpts.disabled) {
|
140 |
+
return;
|
141 |
+
}
|
142 |
+
// run inference on cmd+Enter
|
143 |
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
144 |
+
e.preventDefault();
|
145 |
+
node.dispatchEvent(new CustomEvent("cmdEnter"));
|
146 |
+
}
|
147 |
+
}
|
148 |
+
node.addEventListener("keydown", onKeyDown);
|
149 |
+
return {
|
150 |
+
update(updatedOps: { disabled: boolean }) {
|
151 |
+
currentOpts = updatedOps;
|
152 |
+
},
|
153 |
+
destroy() {
|
154 |
+
node.removeEventListener("keydown", onKeyDown);
|
155 |
+
},
|
156 |
+
};
|
157 |
+
}
|
158 |
+
|
159 |
/**
|
160 |
* For Tailwind:
|
161 |
bg-blue-100 border-blue-100 dark:bg-blue-800 dark:border-blue-800
|