Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
machineuser
commited on
Commit
·
a9bb251
1
Parent(s):
eb85ce3
Sync widgets demo
Browse files
packages/widgets/src/lib/components/InferenceWidget/shared/WidgetOutputChart/WidgetOutputChart.svelte
CHANGED
|
@@ -16,13 +16,13 @@ from-yellow-400 to-yellow-200 dark:from-yellow-400 dark:to-yellow-600
|
|
| 16 |
type LabelField = "label" | "answer";
|
| 17 |
export let labelField: LabelField = "label";
|
| 18 |
export let output: Array<
|
| 19 |
-
{ label: string; score
|
| 20 |
> = [];
|
| 21 |
export let highlightIndex = -1;
|
| 22 |
export let mouseover: (index: number) => void = () => {};
|
| 23 |
export let mouseout: () => void = () => {};
|
| 24 |
|
| 25 |
-
$: scoreMax = Math.max(0, ...output.map((x) => x.score));
|
| 26 |
|
| 27 |
function text(outputItem: (typeof output)[0]) {
|
| 28 |
if (labelField in outputItem) {
|
|
@@ -54,11 +54,13 @@ from-yellow-400 to-yellow-200 dark:from-yellow-400 dark:to-yellow-600
|
|
| 54 |
to-{color ?? defaultBarColor}-200
|
| 55 |
dark:from-{color ?? defaultBarColor}-400
|
| 56 |
dark:to-{color ?? defaultBarColor}-600"
|
| 57 |
-
style={`width: ${Math.ceil((score / scoreMax) * 100 * 0.8)}%;`}
|
| 58 |
/>
|
| 59 |
<span class="leading-snug">{text(output[index])}</span>
|
| 60 |
</div>
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
</div>
|
| 63 |
{/each}
|
| 64 |
</div>
|
|
|
|
| 16 |
type LabelField = "label" | "answer";
|
| 17 |
export let labelField: LabelField = "label";
|
| 18 |
export let output: Array<
|
| 19 |
+
{ label: string; score?: number; color?: string } | { answer: string; score?: number; color?: string }
|
| 20 |
> = [];
|
| 21 |
export let highlightIndex = -1;
|
| 22 |
export let mouseover: (index: number) => void = () => {};
|
| 23 |
export let mouseout: () => void = () => {};
|
| 24 |
|
| 25 |
+
$: scoreMax = Math.max(0, ...output.map((x) => x.score ?? 0));
|
| 26 |
|
| 27 |
function text(outputItem: (typeof output)[0]) {
|
| 28 |
if (labelField in outputItem) {
|
|
|
|
| 54 |
to-{color ?? defaultBarColor}-200
|
| 55 |
dark:from-{color ?? defaultBarColor}-400
|
| 56 |
dark:to-{color ?? defaultBarColor}-600"
|
| 57 |
+
style={`width: ${score ? Math.ceil((score / scoreMax) * 100 * 0.8) : 0}%;`}
|
| 58 |
/>
|
| 59 |
<span class="leading-snug">{text(output[index])}</span>
|
| 60 |
</div>
|
| 61 |
+
{#if typeof score === "number"}
|
| 62 |
+
<span class="pl-2">{score.toFixed(3)}</span>
|
| 63 |
+
{/if}
|
| 64 |
</div>
|
| 65 |
{/each}
|
| 66 |
</div>
|
packages/widgets/src/lib/components/InferenceWidget/widgets/VisualQuestionAnsweringWidget/VisualQuestionAnsweringWidget.svelte
CHANGED
|
@@ -25,7 +25,7 @@
|
|
| 25 |
isLoading: false,
|
| 26 |
estimatedTime: 0,
|
| 27 |
};
|
| 28 |
-
let output: Array<{ answer: string; score
|
| 29 |
let outputJson: string;
|
| 30 |
let question = "";
|
| 31 |
let imgSrc = "";
|
|
@@ -55,15 +55,18 @@
|
|
| 55 |
});
|
| 56 |
}
|
| 57 |
|
| 58 |
-
function isValidOutput(arg: any): arg is { answer: string; score
|
| 59 |
-
return
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
-
function parseOutput(body: unknown): Array<{ answer: string; score
|
| 63 |
if (isValidOutput(body)) {
|
| 64 |
return body;
|
| 65 |
}
|
| 66 |
-
throw new TypeError("Invalid output: output must be of type Array<answer: string, score
|
| 67 |
}
|
| 68 |
|
| 69 |
async function applyInputSample(sample: WidgetExampleAssetAndTextInput, opts: ExampleRunOpts = {}) {
|
|
|
|
| 25 |
isLoading: false,
|
| 26 |
estimatedTime: 0,
|
| 27 |
};
|
| 28 |
+
let output: Array<{ answer: string; score?: number }> | null = [];
|
| 29 |
let outputJson: string;
|
| 30 |
let question = "";
|
| 31 |
let imgSrc = "";
|
|
|
|
| 55 |
});
|
| 56 |
}
|
| 57 |
|
| 58 |
+
function isValidOutput(arg: any): arg is { answer: string; score?: number }[] {
|
| 59 |
+
return (
|
| 60 |
+
Array.isArray(arg) &&
|
| 61 |
+
arg.every((x) => typeof x.answer === "string" && (typeof x.score === "number" || x.score === undefined))
|
| 62 |
+
);
|
| 63 |
}
|
| 64 |
|
| 65 |
+
function parseOutput(body: unknown): Array<{ answer: string; score?: number }> {
|
| 66 |
if (isValidOutput(body)) {
|
| 67 |
return body;
|
| 68 |
}
|
| 69 |
+
throw new TypeError("Invalid output: output must be of type Array<{ answer: string, score?: number }>");
|
| 70 |
}
|
| 71 |
|
| 72 |
async function applyInputSample(sample: WidgetExampleAssetAndTextInput, opts: ExampleRunOpts = {}) {
|