machineuser commited on
Commit
46d7a45
1 Parent(s): 5da0ad7

Sync widgets demo

Browse files
packages/tasks/src/default-widget-inputs.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { WidgetExample } from "./model-data";
2
  import type { PipelineType } from "./pipelines";
3
 
4
  type LanguageCode = string;
 
1
+ import type { WidgetExample } from "./widget-example";
2
  import type { PipelineType } from "./pipelines";
3
 
4
  type LanguageCode = string;
packages/tasks/src/index.ts CHANGED
@@ -16,9 +16,8 @@ export {
16
  } from "./pipelines";
17
  export { ModelLibrary, ALL_DISPLAY_MODEL_LIBRARY_KEYS } from "./model-libraries";
18
  export type { ModelLibraryKey } from "./model-libraries";
19
- export {
20
- ModelData,
21
- TransformersInfo,
22
  WidgetExample,
23
  WidgetExampleAttribute,
24
  WidgetExampleAssetAndPromptInput,
@@ -37,7 +36,7 @@ export {
37
  WidgetExampleOutputLabels,
38
  WidgetExampleOutputAnswerScore,
39
  WidgetExampleOutputText,
40
- } from "./model-data";
41
  export { InferenceDisplayability } from "./model-data";
42
 
43
  export { TAG_NFAA_CONTENT, OTHER_TAGS_SUGGESTIONS, TAG_TEXT_GENERATION_INFERENCE, TAG_CUSTOM_CODE } from "./tags";
 
16
  } from "./pipelines";
17
  export { ModelLibrary, ALL_DISPLAY_MODEL_LIBRARY_KEYS } from "./model-libraries";
18
  export type { ModelLibraryKey } from "./model-libraries";
19
+ export type { ModelData, TransformersInfo } from "./model-data";
20
+ export type {
 
21
  WidgetExample,
22
  WidgetExampleAttribute,
23
  WidgetExampleAssetAndPromptInput,
 
36
  WidgetExampleOutputLabels,
37
  WidgetExampleOutputAnswerScore,
38
  WidgetExampleOutputText,
39
+ } from "./widget-example";
40
  export { InferenceDisplayability } from "./model-data";
41
 
42
  export { TAG_NFAA_CONTENT, OTHER_TAGS_SUGGESTIONS, TAG_TEXT_GENERATION_INFERENCE, TAG_CUSTOM_CODE } from "./tags";
packages/tasks/src/model-data.ts CHANGED
@@ -1,119 +1,5 @@
1
  import type { PipelineType } from "./pipelines";
2
-
3
- type TableData = Record<string, (string | number)[]>;
4
-
5
- //#region outputs
6
- export type WidgetExampleOutputLabels = Array<{ label: string; score: number }>;
7
- export interface WidgetExampleOutputAnswerScore {
8
- answer: string;
9
- score: number;
10
- }
11
- export interface WidgetExampleOutputText {
12
- text: string;
13
- }
14
- export interface WidgetExampleOutputUrl {
15
- url: string;
16
- }
17
-
18
- export type WidgetExampleOutput =
19
- | WidgetExampleOutputLabels
20
- | WidgetExampleOutputAnswerScore
21
- | WidgetExampleOutputText
22
- | WidgetExampleOutputUrl;
23
- //#endregion
24
-
25
- export interface WidgetExampleBase<TOutput> {
26
- example_title?: string;
27
- group?: string;
28
- /**
29
- * Potential overrides to API parameters for this specific example
30
- * (takes precedences over the model card metadata's inference.parameters)
31
- */
32
- parameters?: {
33
- /// token-classification
34
- aggregation_strategy?: string;
35
- /// text-generation
36
- top_k?: number;
37
- top_p?: number;
38
- temperature?: number;
39
- max_new_tokens?: number;
40
- do_sample?: boolean;
41
- /// text-to-image
42
- negative_prompt?: string;
43
- guidance_scale?: number;
44
- num_inference_steps?: number;
45
- };
46
- /**
47
- * Optional output
48
- */
49
- output?: TOutput;
50
- }
51
-
52
- export interface WidgetExampleTextInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
53
- text: string;
54
- }
55
-
56
- export interface WidgetExampleTextAndContextInput<TOutput = WidgetExampleOutput>
57
- extends WidgetExampleTextInput<TOutput> {
58
- context: string;
59
- }
60
-
61
- export interface WidgetExampleTextAndTableInput<TOutput = WidgetExampleOutput> extends WidgetExampleTextInput<TOutput> {
62
- table: TableData;
63
- }
64
-
65
- export interface WidgetExampleAssetInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
66
- src: string;
67
- }
68
- export interface WidgetExampleAssetAndPromptInput<TOutput = WidgetExampleOutput>
69
- extends WidgetExampleAssetInput<TOutput> {
70
- prompt: string;
71
- }
72
-
73
- export type WidgetExampleAssetAndTextInput<TOutput = WidgetExampleOutput> = WidgetExampleAssetInput<TOutput> &
74
- WidgetExampleTextInput<TOutput>;
75
-
76
- export type WidgetExampleAssetAndZeroShotInput<TOutput = WidgetExampleOutput> = WidgetExampleAssetInput<TOutput> &
77
- WidgetExampleZeroShotTextInput<TOutput>;
78
-
79
- export interface WidgetExampleStructuredDataInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
80
- structured_data: TableData;
81
- }
82
-
83
- export interface WidgetExampleTableDataInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
84
- table: TableData;
85
- }
86
-
87
- export interface WidgetExampleZeroShotTextInput<TOutput = WidgetExampleOutput> extends WidgetExampleTextInput<TOutput> {
88
- text: string;
89
- candidate_labels: string;
90
- multi_class: boolean;
91
- }
92
-
93
- export interface WidgetExampleSentenceSimilarityInput<TOutput = WidgetExampleOutput>
94
- extends WidgetExampleBase<TOutput> {
95
- source_sentence: string;
96
- sentences: string[];
97
- }
98
-
99
- //#endregion
100
-
101
- export type WidgetExample<TOutput = WidgetExampleOutput> =
102
- | WidgetExampleTextInput<TOutput>
103
- | WidgetExampleTextAndContextInput<TOutput>
104
- | WidgetExampleTextAndTableInput<TOutput>
105
- | WidgetExampleAssetInput<TOutput>
106
- | WidgetExampleAssetAndPromptInput<TOutput>
107
- | WidgetExampleAssetAndTextInput<TOutput>
108
- | WidgetExampleAssetAndZeroShotInput<TOutput>
109
- | WidgetExampleStructuredDataInput<TOutput>
110
- | WidgetExampleTableDataInput<TOutput>
111
- | WidgetExampleZeroShotTextInput<TOutput>
112
- | WidgetExampleSentenceSimilarityInput<TOutput>;
113
-
114
- type KeysOfUnion<T> = T extends unknown ? keyof T : never;
115
-
116
- export type WidgetExampleAttribute = KeysOfUnion<WidgetExample>;
117
 
118
  export enum InferenceDisplayability {
119
  /**
 
1
  import type { PipelineType } from "./pipelines";
2
+ import type { WidgetExample } from "./widget-example";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  export enum InferenceDisplayability {
5
  /**
packages/tasks/src/widget-example.ts ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * See default-widget-inputs.ts for the default widget inputs, this files only contains the types
3
+ */
4
+
5
+ type TableData = Record<string, (string | number)[]>;
6
+
7
+ //#region outputs
8
+ export type WidgetExampleOutputLabels = Array<{ label: string; score: number }>;
9
+ export interface WidgetExampleOutputAnswerScore {
10
+ answer: string;
11
+ score: number;
12
+ }
13
+ export interface WidgetExampleOutputText {
14
+ text: string;
15
+ }
16
+ export interface WidgetExampleOutputUrl {
17
+ url: string;
18
+ }
19
+
20
+ export type WidgetExampleOutput =
21
+ | WidgetExampleOutputLabels
22
+ | WidgetExampleOutputAnswerScore
23
+ | WidgetExampleOutputText
24
+ | WidgetExampleOutputUrl;
25
+ //#endregion
26
+
27
+ export interface WidgetExampleBase<TOutput> {
28
+ example_title?: string;
29
+ group?: string;
30
+ /**
31
+ * Potential overrides to API parameters for this specific example
32
+ * (takes precedences over the model card metadata's inference.parameters)
33
+ */
34
+ parameters?: {
35
+ /// token-classification
36
+ aggregation_strategy?: string;
37
+ /// text-generation
38
+ top_k?: number;
39
+ top_p?: number;
40
+ temperature?: number;
41
+ max_new_tokens?: number;
42
+ do_sample?: boolean;
43
+ /// text-to-image
44
+ negative_prompt?: string;
45
+ guidance_scale?: number;
46
+ num_inference_steps?: number;
47
+ };
48
+ /**
49
+ * Optional output
50
+ */
51
+ output?: TOutput;
52
+ }
53
+
54
+ export interface WidgetExampleTextInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
55
+ text: string;
56
+ }
57
+
58
+ export interface WidgetExampleTextAndContextInput<TOutput = WidgetExampleOutput>
59
+ extends WidgetExampleTextInput<TOutput> {
60
+ context: string;
61
+ }
62
+
63
+ export interface WidgetExampleTextAndTableInput<TOutput = WidgetExampleOutput> extends WidgetExampleTextInput<TOutput> {
64
+ table: TableData;
65
+ }
66
+
67
+ export interface WidgetExampleAssetInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
68
+ src: string;
69
+ }
70
+ export interface WidgetExampleAssetAndPromptInput<TOutput = WidgetExampleOutput>
71
+ extends WidgetExampleAssetInput<TOutput> {
72
+ prompt: string;
73
+ }
74
+
75
+ export type WidgetExampleAssetAndTextInput<TOutput = WidgetExampleOutput> = WidgetExampleAssetInput<TOutput> &
76
+ WidgetExampleTextInput<TOutput>;
77
+
78
+ export type WidgetExampleAssetAndZeroShotInput<TOutput = WidgetExampleOutput> = WidgetExampleAssetInput<TOutput> &
79
+ WidgetExampleZeroShotTextInput<TOutput>;
80
+
81
+ export interface WidgetExampleStructuredDataInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
82
+ structured_data: TableData;
83
+ }
84
+
85
+ export interface WidgetExampleTableDataInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
86
+ table: TableData;
87
+ }
88
+
89
+ export interface WidgetExampleZeroShotTextInput<TOutput = WidgetExampleOutput> extends WidgetExampleTextInput<TOutput> {
90
+ text: string;
91
+ candidate_labels: string;
92
+ multi_class: boolean;
93
+ }
94
+
95
+ export interface WidgetExampleSentenceSimilarityInput<TOutput = WidgetExampleOutput>
96
+ extends WidgetExampleBase<TOutput> {
97
+ source_sentence: string;
98
+ sentences: string[];
99
+ }
100
+
101
+ //#endregion
102
+
103
+ export type WidgetExample<TOutput = WidgetExampleOutput> =
104
+ | WidgetExampleTextInput<TOutput>
105
+ | WidgetExampleTextAndContextInput<TOutput>
106
+ | WidgetExampleTextAndTableInput<TOutput>
107
+ | WidgetExampleAssetInput<TOutput>
108
+ | WidgetExampleAssetAndPromptInput<TOutput>
109
+ | WidgetExampleAssetAndTextInput<TOutput>
110
+ | WidgetExampleAssetAndZeroShotInput<TOutput>
111
+ | WidgetExampleStructuredDataInput<TOutput>
112
+ | WidgetExampleTableDataInput<TOutput>
113
+ | WidgetExampleZeroShotTextInput<TOutput>
114
+ | WidgetExampleSentenceSimilarityInput<TOutput>;
115
+
116
+ type KeysOfUnion<T> = T extends unknown ? keyof T : never;
117
+
118
+ export type WidgetExampleAttribute = KeysOfUnion<WidgetExample>;