@huggingface/tasks 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +1 -1
  2. package/dist/{index.mjs → index.cjs} +2695 -2497
  3. package/dist/index.d.ts +427 -65
  4. package/dist/index.js +2660 -2532
  5. package/package.json +13 -8
  6. package/src/index.ts +2 -5
  7. package/src/library-to-tasks.ts +1 -1
  8. package/src/model-data.ts +1 -1
  9. package/src/model-libraries-downloads.ts +20 -0
  10. package/src/{library-ui-elements.ts → model-libraries-snippets.ts} +50 -296
  11. package/src/model-libraries.ts +375 -44
  12. package/src/pipelines.ts +1 -1
  13. package/src/tasks/audio-classification/about.md +1 -1
  14. package/src/tasks/audio-classification/inference.ts +51 -0
  15. package/src/tasks/audio-classification/spec/input.json +34 -0
  16. package/src/tasks/audio-classification/spec/output.json +10 -0
  17. package/src/tasks/audio-to-audio/about.md +1 -1
  18. package/src/tasks/automatic-speech-recognition/about.md +4 -2
  19. package/src/tasks/automatic-speech-recognition/inference.ts +159 -0
  20. package/src/tasks/automatic-speech-recognition/spec/input.json +34 -0
  21. package/src/tasks/automatic-speech-recognition/spec/output.json +38 -0
  22. package/src/tasks/common-definitions.json +117 -0
  23. package/src/tasks/depth-estimation/data.ts +8 -4
  24. package/src/tasks/depth-estimation/inference.ts +35 -0
  25. package/src/tasks/depth-estimation/spec/input.json +25 -0
  26. package/src/tasks/depth-estimation/spec/output.json +16 -0
  27. package/src/tasks/document-question-answering/inference.ts +110 -0
  28. package/src/tasks/document-question-answering/spec/input.json +85 -0
  29. package/src/tasks/document-question-answering/spec/output.json +36 -0
  30. package/src/tasks/feature-extraction/inference.ts +22 -0
  31. package/src/tasks/feature-extraction/spec/input.json +26 -0
  32. package/src/tasks/feature-extraction/spec/output.json +7 -0
  33. package/src/tasks/fill-mask/inference.ts +62 -0
  34. package/src/tasks/fill-mask/spec/input.json +38 -0
  35. package/src/tasks/fill-mask/spec/output.json +29 -0
  36. package/src/tasks/image-classification/inference.ts +51 -0
  37. package/src/tasks/image-classification/spec/input.json +34 -0
  38. package/src/tasks/image-classification/spec/output.json +10 -0
  39. package/src/tasks/image-segmentation/inference.ts +65 -0
  40. package/src/tasks/image-segmentation/spec/input.json +54 -0
  41. package/src/tasks/image-segmentation/spec/output.json +25 -0
  42. package/src/tasks/image-to-image/inference.ts +67 -0
  43. package/src/tasks/image-to-image/spec/input.json +54 -0
  44. package/src/tasks/image-to-image/spec/output.json +12 -0
  45. package/src/tasks/image-to-text/inference.ts +143 -0
  46. package/src/tasks/image-to-text/spec/input.json +34 -0
  47. package/src/tasks/image-to-text/spec/output.json +14 -0
  48. package/src/tasks/index.ts +5 -2
  49. package/src/tasks/mask-generation/about.md +65 -0
  50. package/src/tasks/mask-generation/data.ts +42 -5
  51. package/src/tasks/object-detection/inference.ts +62 -0
  52. package/src/tasks/object-detection/spec/input.json +30 -0
  53. package/src/tasks/object-detection/spec/output.json +46 -0
  54. package/src/tasks/placeholder/data.ts +3 -0
  55. package/src/tasks/placeholder/spec/input.json +35 -0
  56. package/src/tasks/placeholder/spec/output.json +17 -0
  57. package/src/tasks/question-answering/inference.ts +99 -0
  58. package/src/tasks/question-answering/spec/input.json +67 -0
  59. package/src/tasks/question-answering/spec/output.json +29 -0
  60. package/src/tasks/sentence-similarity/about.md +2 -2
  61. package/src/tasks/sentence-similarity/inference.ts +32 -0
  62. package/src/tasks/sentence-similarity/spec/input.json +40 -0
  63. package/src/tasks/sentence-similarity/spec/output.json +12 -0
  64. package/src/tasks/summarization/data.ts +1 -0
  65. package/src/tasks/summarization/inference.ts +59 -0
  66. package/src/tasks/summarization/spec/input.json +7 -0
  67. package/src/tasks/summarization/spec/output.json +7 -0
  68. package/src/tasks/table-question-answering/inference.ts +61 -0
  69. package/src/tasks/table-question-answering/spec/input.json +44 -0
  70. package/src/tasks/table-question-answering/spec/output.json +40 -0
  71. package/src/tasks/tabular-classification/about.md +1 -1
  72. package/src/tasks/tabular-regression/about.md +1 -1
  73. package/src/tasks/text-classification/about.md +1 -0
  74. package/src/tasks/text-classification/inference.ts +51 -0
  75. package/src/tasks/text-classification/spec/input.json +35 -0
  76. package/src/tasks/text-classification/spec/output.json +10 -0
  77. package/src/tasks/text-generation/about.md +24 -13
  78. package/src/tasks/text-generation/data.ts +22 -38
  79. package/src/tasks/text-generation/inference.ts +194 -0
  80. package/src/tasks/text-generation/spec/input.json +90 -0
  81. package/src/tasks/text-generation/spec/output.json +120 -0
  82. package/src/tasks/text-to-audio/inference.ts +143 -0
  83. package/src/tasks/text-to-audio/spec/input.json +31 -0
  84. package/src/tasks/text-to-audio/spec/output.json +17 -0
  85. package/src/tasks/text-to-image/about.md +11 -2
  86. package/src/tasks/text-to-image/data.ts +6 -2
  87. package/src/tasks/text-to-image/inference.ts +71 -0
  88. package/src/tasks/text-to-image/spec/input.json +59 -0
  89. package/src/tasks/text-to-image/spec/output.json +13 -0
  90. package/src/tasks/text-to-speech/about.md +4 -2
  91. package/src/tasks/text-to-speech/data.ts +1 -0
  92. package/src/tasks/text-to-speech/inference.ts +147 -0
  93. package/src/tasks/text-to-speech/spec/input.json +7 -0
  94. package/src/tasks/text-to-speech/spec/output.json +7 -0
  95. package/src/tasks/text2text-generation/inference.ts +55 -0
  96. package/src/tasks/text2text-generation/spec/input.json +55 -0
  97. package/src/tasks/text2text-generation/spec/output.json +14 -0
  98. package/src/tasks/token-classification/inference.ts +82 -0
  99. package/src/tasks/token-classification/spec/input.json +65 -0
  100. package/src/tasks/token-classification/spec/output.json +33 -0
  101. package/src/tasks/translation/data.ts +1 -0
  102. package/src/tasks/translation/inference.ts +59 -0
  103. package/src/tasks/translation/spec/input.json +7 -0
  104. package/src/tasks/translation/spec/output.json +7 -0
  105. package/src/tasks/video-classification/inference.ts +59 -0
  106. package/src/tasks/video-classification/spec/input.json +42 -0
  107. package/src/tasks/video-classification/spec/output.json +10 -0
  108. package/src/tasks/visual-question-answering/inference.ts +63 -0
  109. package/src/tasks/visual-question-answering/spec/input.json +41 -0
  110. package/src/tasks/visual-question-answering/spec/output.json +21 -0
  111. package/src/tasks/zero-shot-classification/inference.ts +67 -0
  112. package/src/tasks/zero-shot-classification/spec/input.json +50 -0
  113. package/src/tasks/zero-shot-classification/spec/output.json +10 -0
  114. package/src/tasks/zero-shot-image-classification/data.ts +8 -5
  115. package/src/tasks/zero-shot-image-classification/inference.ts +61 -0
  116. package/src/tasks/zero-shot-image-classification/spec/input.json +45 -0
  117. package/src/tasks/zero-shot-image-classification/spec/output.json +10 -0
  118. package/src/tasks/zero-shot-object-detection/about.md +6 -0
  119. package/src/tasks/zero-shot-object-detection/data.ts +6 -1
  120. package/src/tasks/zero-shot-object-detection/inference.ts +66 -0
  121. package/src/tasks/zero-shot-object-detection/spec/input.json +40 -0
  122. package/src/tasks/zero-shot-object-detection/spec/output.json +47 -0
  123. package/tsconfig.json +3 -3
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
2
  "name": "@huggingface/tasks",
3
3
  "packageManager": "pnpm@8.10.5",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "description": "List of ML tasks for huggingface.co/tasks",
6
6
  "repository": "https://github.com/huggingface/huggingface.js.git",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
- "main": "./dist/index.js",
11
- "module": "./dist/index.mjs",
10
+ "main": "./dist/index.cjs",
11
+ "module": "./dist/index.js",
12
12
  "types": "./dist/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
- "require": "./dist/index.js",
17
- "import": "./dist/index.mjs"
16
+ "require": "./dist/index.cjs",
17
+ "import": "./dist/index.js"
18
18
  }
19
19
  },
20
20
  "source": "src/index.ts",
21
+ "type": "module",
21
22
  "files": [
22
23
  "dist",
23
24
  "src",
@@ -30,13 +31,17 @@
30
31
  ],
31
32
  "author": "Hugging Face",
32
33
  "license": "MIT",
33
- "devDependencies": {},
34
+ "devDependencies": {
35
+ "@types/node": "^20.11.5",
36
+ "quicktype-core": "https://github.com/huggingface/quicktype/raw/pack-18.0.15/packages/quicktype-core/quicktype-core-18.0.15.tgz"
37
+ },
34
38
  "scripts": {
35
39
  "lint": "eslint --quiet --fix --ext .cjs,.ts .",
36
40
  "lint:check": "eslint --ext .cjs,.ts .",
37
41
  "format": "prettier --write .",
38
42
  "format:check": "prettier --check .",
39
- "build": "tsup src/index.ts --format cjs,esm --clean --dts",
40
- "check": "tsc"
43
+ "build": "tsup src/index.ts --format cjs,esm --clean --dts && pnpm run inference-codegen",
44
+ "check": "tsc",
45
+ "inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write src/tasks/*/inference.ts"
41
46
  }
42
47
  }
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { LIBRARY_TASK_MAPPING_EXCLUDING_TRANSFORMERS } from "./library-to-tasks";
2
- export { MODEL_LIBRARIES_UI_ELEMENTS } from "./library-ui-elements";
3
2
  export { MAPPING_DEFAULT_WIDGET } from "./default-widget-inputs";
4
3
  export type { TaskData, TaskDemo, TaskDemoEntry, ExampleRepo } from "./tasks";
5
4
  export * from "./tasks";
@@ -14,8 +13,8 @@ export {
14
13
  SUBTASK_TYPES,
15
14
  PIPELINE_TYPES_SET,
16
15
  } from "./pipelines";
17
- export { ModelLibrary, ALL_DISPLAY_MODEL_LIBRARY_KEYS } from "./model-libraries";
18
- export type { ModelLibraryKey } from "./model-libraries";
16
+ export { ALL_DISPLAY_MODEL_LIBRARY_KEYS, ALL_MODEL_LIBRARY_KEYS, MODEL_LIBRARIES_UI_ELEMENTS } from "./model-libraries";
17
+ export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries";
19
18
  export type { ModelData, TransformersInfo } from "./model-data";
20
19
  export type {
21
20
  WidgetExample,
@@ -41,5 +40,3 @@ export { InferenceDisplayability } from "./model-data";
41
40
 
42
41
  import * as snippets from "./snippets";
43
42
  export { snippets };
44
-
45
- export type { LibraryUiElement } from "./library-ui-elements";
@@ -3,7 +3,7 @@ import type { PipelineType } from "./pipelines";
3
3
 
4
4
  /**
5
5
  * Mapping from library name (excluding Transformers) to its supported tasks.
6
- * Inference API should be disabled for all other (library, task) pairs beyond this mapping.
6
+ * Inference API (serverless) should be disabled for all other (library, task) pairs beyond this mapping.
7
7
  * As an exception, we assume Transformers supports all inference tasks.
8
8
  * This mapping is generated automatically by "python-api-export-tasks" action in huggingface/api-inference-community repo upon merge.
9
9
  * Ref: https://github.com/huggingface/api-inference-community/pull/158
package/src/model-data.ts CHANGED
@@ -78,7 +78,7 @@ export interface ModelData {
78
78
  */
79
79
  widgetData?: WidgetExample[] | undefined;
80
80
  /**
81
- * Parameters that will be used by the widget when calling Inference API
81
+ * Parameters that will be used by the widget when calling Inference Endpoints (serverless)
82
82
  * https://huggingface.co/docs/api-inference/detailed_parameters
83
83
  *
84
84
  * can be set in the model card metadata (under `inference/parameters`)
@@ -0,0 +1,20 @@
1
+ /**
2
+ * This file contains the (simplified) types used
3
+ * to represent queries that are made to Elastic
4
+ * in order to count number of model downloads
5
+ *
6
+ * Read this doc about download stats on the Hub:
7
+ *
8
+ * https://huggingface.co/docs/hub/models-download-stats
9
+ *
10
+ * see also:
11
+ * https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
12
+ */
13
+
14
+ export type ElasticBoolQueryFilter =
15
+ // match a single filename
16
+ | { term?: { path: string } }
17
+ // match multiple possible filenames
18
+ | { terms?: { path: string[] } }
19
+ // match a wildcard
20
+ | { wildcard?: { path: string } };