Skip to content

Commit 730fe4a

Browse files
author
Mishig
authored
[Widget] get model status only on InferenceDisplayability.Yes models (#389)
Context: [internal slack msg](https://huggingface.slack.com/archives/C02EMARJ65P/p1701705716046049?thread_ts=1701703726.990099&cid=C02EMARJ65P) To get `model status`, GET request `https://api-inference.huggingface.co/status/{MODEL-ID}` is used to check status of a model on [hf inference api](https://huggingface.co/inference-api). This PR makes it so that only when a model.inference is [InferenceDisplayability.Yes](https://github.com/huggingface/huggingface.js/blob/get_model_status_oninfyes/packages/tasks/src/model-data.ts#L122-L123), get the `model status`.
1 parent 7bdf997 commit 730fe4a

File tree

1 file changed

+47
-43
lines changed

1 file changed

+47
-43
lines changed

packages/widgets/src/lib/components/InferenceWidget/shared/WidgetWrapper/WidgetWrapper.svelte

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@
7373
7474
onMount(() => {
7575
(async () => {
76-
modelLoadInfo = await getModelLoadInfo(apiUrl, model.id, includeCredentials);
77-
$modelLoadStates[model.id] = modelLoadInfo;
78-
modelTooBig = modelLoadInfo?.state === "TooBig";
76+
if (model.inference === InferenceDisplayability.Yes) {
77+
modelLoadInfo = await getModelLoadInfo(apiUrl, model.id, includeCredentials);
78+
$modelLoadStates[model.id] = modelLoadInfo;
79+
modelTooBig = modelLoadInfo?.state === "TooBig";
7980
80-
if (modelTooBig) {
81-
// disable the widget
82-
isDisabled = true;
83-
inputSamples = allInputSamples.filter((sample) => sample.output !== undefined);
84-
inputGroups = getExamplesGroups();
81+
if (modelTooBig) {
82+
// disable the widget
83+
isDisabled = true;
84+
inputSamples = allInputSamples.filter((sample) => sample.output !== undefined);
85+
inputGroups = getExamplesGroups();
86+
}
8587
}
8688
8789
const exampleFromQueryParams = {} as TWidgetExample;
@@ -110,42 +112,44 @@
110112
<WidgetHeader pipeline={model.pipeline_tag} noTitle={true} />
111113
<WidgetInfo {model} {computeTime} {error} {modelLoadInfo} {modelTooBig} />
112114
{:else}
113-
<div
114-
class="flex w-full max-w-full flex-col
115-
{isMaximized ? 'fixed inset-0 z-20 bg-white p-12' : ''}
116-
{!modelLoadInfo ? 'hidden' : ''}"
117-
>
118-
{#if isMaximized}
119-
<button class="absolute right-12 top-6" on:click={() => (isMaximized = !isMaximized)}>
120-
<IconCross classNames="text-xl text-gray-500 hover:text-black" />
121-
</button>
122-
{/if}
123-
<WidgetHeader {noTitle} pipeline={model.pipeline_tag} {isDisabled}>
124-
{#if !!inputGroups.length}
125-
<div class="ml-auto flex gap-x-1">
126-
<!-- Show samples selector when there are more than one sample -->
127-
{#if inputGroups.length > 1}
128-
<WidgetInputSamplesGroup
129-
bind:selectedInputGroup
115+
<!-- require that we have `modelLoadInfo` for InferenceDisplayability.Yes models -->
116+
{#if modelLoadInfo || model.inference !== InferenceDisplayability.Yes}
117+
<div
118+
class="flex w-full max-w-full flex-col
119+
{isMaximized ? 'fixed inset-0 z-20 bg-white p-12' : ''}"
120+
>
121+
{#if isMaximized}
122+
<button class="absolute right-12 top-6" on:click={() => (isMaximized = !isMaximized)}>
123+
<IconCross classNames="text-xl text-gray-500 hover:text-black" />
124+
</button>
125+
{/if}
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" : ""}
130139
{isLoading}
131-
inputGroups={inputGroups.map(({ group }) => group)}
140+
inputSamples={selectedInputSamples?.inputSamples ?? []}
141+
{applyInputSample}
132142
/>
133-
{/if}
134-
<WidgetInputSamples
135-
classNames={!selectedInputSamples ? "opacity-50 pointer-events-none" : ""}
136-
{isLoading}
137-
inputSamples={selectedInputSamples?.inputSamples ?? []}
138-
{applyInputSample}
139-
/>
140-
</div>
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} />
141150
{/if}
142-
</WidgetHeader>
143-
<slot name="top" {isDisabled} />
144-
<WidgetInfo {model} {computeTime} {error} {modelLoadInfo} {modelTooBig} />
145-
{#if modelLoading.isLoading}
146-
<WidgetModelLoading estimatedTime={modelLoading.estimatedTime} />
147-
{/if}
148-
<slot name="bottom" />
149-
<WidgetFooter bind:isMaximized {outputJson} {isDisabled} />
150-
</div>
151+
<slot name="bottom" />
152+
<WidgetFooter bind:isMaximized {outputJson} {isDisabled} />
153+
</div>
154+
{/if}
151155
{/if}

0 commit comments

Comments
 (0)