├── packages ├── tasks │ ├── .eslintignore │ ├── .gitignore │ ├── .prettierignore │ ├── src │ │ ├── snippets │ │ │ ├── index.ts │ │ │ └── types.ts │ │ ├── tasks │ │ │ ├── translation │ │ │ │ └── spec │ │ │ │ │ ├── input.json │ │ │ │ │ └── output.json │ │ │ ├── text-to-speech │ │ │ │ └── spec │ │ │ │ │ ├── input.json │ │ │ │ │ └── output.json │ │ │ ├── summarization │ │ │ │ └── spec │ │ │ │ │ ├── input.json │ │ │ │ │ └── output.json │ │ │ ├── feature-extraction │ │ │ │ ├── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ │ └── inference.ts │ │ │ ├── image-to-image │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── audio-classification │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── text-to-image │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── text-classification │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── image-classification │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── video-classification │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── zero-shot-classification │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── image-to-text │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── zero-shot-image-classification │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── sentence-similarity │ │ │ │ ├── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ │ └── inference.ts │ │ │ ├── text2text-generation │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── depth-estimation │ │ │ │ ├── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ │ └── inference.ts │ │ │ ├── placeholder │ │ │ │ ├── about.md │ │ │ │ ├── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ │ └── data.ts │ │ │ ├── text-to-audio │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── visual-question-answering │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── image-segmentation │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── fill-mask │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── object-detection │ │ │ │ └── spec │ │ │ │ │ ├── input.json │ │ │ │ │ └── output.json │ │ │ ├── question-answering │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── token-classification │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── automatic-speech-recognition │ │ │ │ └── spec │ │ │ │ │ ├── output.json │ │ │ │ │ └── input.json │ │ │ ├── document-question-answering │ │ │ │ └── spec │ │ │ │ │ └── output.json │ │ │ ├── table-question-answering │ │ │ │ ├── spec │ │ │ │ │ └── output.json │ │ │ │ └── about.md │ │ │ └── zero-shot-object-detection │ │ │ │ └── spec │ │ │ │ ├── input.json │ │ │ │ └── output.json │ │ ├── model-libraries-downloads.ts │ │ └── tokenizer-data.ts │ ├── tsconfig.json │ └── LICENSE ├── agents │ ├── .eslintignore │ ├── index.ts │ ├── test │ │ └── vitest.d.ts │ ├── src │ │ ├── llms │ │ │ ├── index.ts │ │ │ └── LLMHF.ts │ │ ├── index.ts │ │ ├── tools │ │ │ ├── index.ts │ │ │ ├── imageToText.ts │ │ │ ├── message.ts │ │ │ ├── speechToText.ts │ │ │ ├── textToImage.ts │ │ │ └── textToSpeech.ts │ │ ├── types.d.ts │ │ └── lib │ │ │ └── generateCode.ts │ ├── .prettierignore │ ├── vitest-browser.config.mts │ ├── tsconfig.json │ ├── tsup.config.ts │ ├── pnpm-lock.yaml │ └── LICENSE ├── hub │ ├── .eslintignore │ ├── index.ts │ ├── src │ │ ├── consts.ts │ │ ├── utils │ │ │ ├── insecureRandomString.ts │ │ │ ├── typedInclude.ts │ │ │ ├── sum.ts │ │ │ ├── typedEntries.ts │ │ │ ├── hexFromBytes.ts │ │ │ ├── pick.ts │ │ │ ├── range.ts │ │ │ ├── parseLinkHeader.ts │ │ │ ├── checkCredentials.ts │ │ │ ├── omit.ts │ │ │ ├── promisesQueue.ts │ │ │ ├── chunk.ts │ │ │ ├── promisesQueueStreaming.ts │ │ │ ├── sha256-node.ts │ │ │ ├── createBlob.ts │ │ │ └── eventToGenerator.spec.ts │ │ ├── test │ │ │ └── consts.ts │ │ ├── index.ts │ │ ├── types │ │ │ └── api │ │ │ │ ├── api-create-repo.d.ts │ │ │ │ ├── api-index-tree.d.ts │ │ │ │ └── api-who-am-i.d.ts │ │ ├── lib │ │ │ ├── index.ts │ │ │ ├── file-exists.spec.ts │ │ │ ├── who-am-i.spec.ts │ │ │ ├── delete-file.ts │ │ │ ├── delete-files.ts │ │ │ ├── list-spaces.spec.ts │ │ │ ├── delete-repo.ts │ │ │ ├── file-exists.ts │ │ │ └── list-datasets.spec.ts │ │ └── error.ts │ ├── .prettierignore │ ├── vitest-browser.config.mts │ ├── tsconfig.json │ ├── tsup.config.ts │ ├── LICENSE │ └── pnpm-lock.yaml ├── jinja │ ├── .eslintignore │ ├── .gitignore │ ├── test │ │ └── .gitignore │ ├── vitest.config.ts │ ├── vite.config.js │ └── tsconfig.json ├── gguf │ ├── src │ │ └── index.ts │ ├── pnpm-lock.yaml │ ├── .prettierignore │ ├── tsconfig.json │ ├── tsup.config.ts │ └── package.json ├── inference │ ├── .eslintignore │ ├── test │ │ ├── cats.png │ │ ├── cheetah.png │ │ ├── global.d.ts │ │ ├── invoice.png │ │ ├── bird_canny.png │ │ ├── sample1.flac │ │ ├── stormtrooper_depth.png │ │ ├── test-files.ts │ │ ├── vitest.d.ts │ │ └── expect-closeto.ts │ ├── src │ │ ├── utils │ │ │ ├── typedInclude.ts │ │ │ ├── toArray.ts │ │ │ ├── pick.ts │ │ │ ├── omit.ts │ │ │ └── distributive-omit.d.ts │ │ ├── lib │ │ │ ├── isUrl.ts │ │ │ └── InferenceOutputError.ts │ │ ├── index.ts │ │ └── tasks │ │ │ ├── audio │ │ │ ├── textToSpeech.ts │ │ │ └── automaticSpeechRecognition.ts │ │ │ ├── cv │ │ │ └── imageToText.ts │ │ │ ├── nlp │ │ │ ├── translation.ts │ │ │ └── textClassification.ts │ │ │ └── tabular │ │ │ └── tabularRegression.ts │ ├── .prettierignore │ ├── tsconfig.json │ ├── pnpm-lock.yaml │ ├── vitest.config.mts │ └── LICENSE ├── shared │ ├── src │ │ ├── isFrontend.ts │ │ ├── index.ts │ │ ├── isBackend.ts │ │ └── base64FromBytes.ts │ ├── pnpm-lock.yaml │ ├── package.json │ └── tsconfig.json ├── widgets │ ├── static │ │ ├── cats.jpg │ │ ├── favicon.png │ │ └── audioProcessor.js │ ├── postcss.config.js │ ├── .gitignore │ ├── .eslintignore │ ├── .prettierignore │ ├── src │ │ ├── lib │ │ │ ├── components │ │ │ │ ├── InferenceWidget │ │ │ │ │ ├── shared │ │ │ │ │ │ ├── WidgetOutputText │ │ │ │ │ │ │ └── WidgetOutputText.svelte │ │ │ │ │ │ ├── WidgetLabel │ │ │ │ │ │ │ └── WidgetLabel.svelte │ │ │ │ │ │ ├── WidgetAddSentenceBtn │ │ │ │ │ │ │ └── WidgetAddSentenceBtn.svelte │ │ │ │ │ │ ├── WidgetAudioTrack │ │ │ │ │ │ │ └── WidgetAudioTrack.svelte │ │ │ │ │ │ ├── WidgetOuputConvoBubble │ │ │ │ │ │ │ └── WidgetOutputConvoBubble.svelte │ │ │ │ │ │ ├── consts.ts │ │ │ │ │ │ ├── WidgetShortcutRunLabel │ │ │ │ │ │ │ └── WidgetShortcutRunLabel.svelte │ │ │ │ │ │ ├── WidgetCheckbox │ │ │ │ │ │ │ └── WidgetCheckbox.svelte │ │ │ │ │ │ ├── WidgetState │ │ │ │ │ │ │ └── WidgetState.svelte │ │ │ │ │ │ ├── WidgetRadio │ │ │ │ │ │ │ └── WidgetRadio.svelte │ │ │ │ │ │ ├── WidgetTimer │ │ │ │ │ │ │ └── WidgetTimer.svelte │ │ │ │ │ │ ├── outputValidation.ts │ │ │ │ │ │ ├── WidgetModelLoading │ │ │ │ │ │ │ └── WidgetModelLoading.svelte │ │ │ │ │ │ └── WidgetTextInput │ │ │ │ │ │ │ └── WidgetTextInput.svelte │ │ │ │ │ └── widgets │ │ │ │ │ │ └── FeatureExtractionWidget │ │ │ │ │ │ └── DataTable.ts │ │ │ │ ├── Icons │ │ │ │ │ ├── IconRow.svelte │ │ │ │ │ ├── IconCaretDownV2.svelte │ │ │ │ │ ├── IconLightning.svelte │ │ │ │ │ ├── IconCaretDown.svelte │ │ │ │ │ ├── IconDepthEstimation.svelte │ │ │ │ │ ├── IconCross.svelte │ │ │ │ │ ├── IconDocumentQuestionAnswering.svelte │ │ │ │ │ ├── IconFeatureExtraction.svelte │ │ │ │ │ ├── IconTabularRegression.svelte │ │ │ │ │ ├── IconTabularClassification.svelte │ │ │ │ │ ├── IconFile.svelte │ │ │ │ │ ├── IconInfo.svelte │ │ │ │ │ ├── IconCode.svelte │ │ │ │ │ ├── IconMaximize.svelte │ │ │ │ │ ├── IconMicrophone.svelte │ │ │ │ │ ├── IconQuestionAnswering.svelte │ │ │ │ │ ├── IconAudioClassification.svelte │ │ │ │ │ ├── IconReinforcementLearning.svelte │ │ │ │ │ ├── IconUnconditionalImageGeneration.svelte │ │ │ │ │ ├── IconMagicWand.svelte │ │ │ │ │ ├── IconImageClassification.svelte │ │ │ │ │ ├── IconImageToVideo.svelte │ │ │ │ │ ├── IconTextTo3D.svelte │ │ │ │ │ ├── IconImageSegmentation.svelte │ │ │ │ │ ├── IconTextToImage.svelte │ │ │ │ │ ├── IconSpin.svelte │ │ │ │ │ ├── IconImageFeatureExtraction.svelte │ │ │ │ │ ├── IconImageToImage.svelte │ │ │ │ │ ├── IconObjectDetection.svelte │ │ │ │ │ ├── IconImageTo3D.svelte │ │ │ │ │ ├── IconSentenceSimilarity.svelte │ │ │ │ │ ├── IconTextToVideo.svelte │ │ │ │ │ ├── IconSummarization.svelte │ │ │ │ │ ├── IconZeroShotObjectDetection.svelte │ │ │ │ │ ├── IconTranslation.svelte │ │ │ │ │ ├── IconImageToText.svelte │ │ │ │ │ ├── IconAzureML.svelte │ │ │ │ │ ├── IconImageAndTextToText.svelte │ │ │ │ │ ├── IconTextClassification.svelte │ │ │ │ │ ├── IconMaskGeneration.svelte │ │ │ │ │ ├── IconRefresh.svelte │ │ │ │ │ └── IconTextGeneration.svelte │ │ │ │ └── PipelineTag │ │ │ │ │ └── PipelineTag.svelte │ │ │ └── index.ts │ │ ├── app.html │ │ ├── additional-svelte-typings.d.ts │ │ ├── routes │ │ │ ├── +layout.server.ts │ │ │ ├── +layout.svelte │ │ │ └── [...model] │ │ │ │ ├── +page.ts │ │ │ │ └── +page.svelte │ │ └── app.d.ts │ ├── tsconfig.json │ ├── svelte.config.js │ └── tailwind.config.cjs ├── languages │ ├── src │ │ ├── types.d.ts │ │ ├── wikiLink.ts │ │ ├── index.ts │ │ ├── wikiLink.spec.ts │ │ ├── language.ts │ │ └── language.spec.ts │ ├── pnpm-lock.yaml │ ├── .prettierignore │ ├── tsconfig.json │ ├── README.md │ └── package.json └── doc-internal │ ├── .prettierignore │ ├── tsconfig.json │ ├── fix-md-links.ts │ ├── fix-cdn-versions.ts │ └── README.md ├── e2e ├── svelte │ ├── .npmrc │ ├── static │ │ └── favicon.png │ ├── vite.config.ts │ ├── .gitignore │ ├── src │ │ ├── app.d.ts │ │ ├── app.html │ │ └── routes │ │ │ └── +page.svelte │ ├── tsconfig.json │ ├── package.json │ ├── svelte.config.js │ └── README.md ├── yarn │ └── package.json ├── ts │ ├── tsconfig.json │ ├── package.json │ └── src │ │ └── index.ts ├── mock-registry-config.yaml └── deno │ └── index.ts ├── .npmrc ├── .git-blame-ignore-revs ├── .vscode ├── extensions.json └── settings.json ├── .prettierignore ├── .editorconfig ├── .prettierrc ├── pnpm-workspace.yaml ├── .github └── workflows │ ├── upload-pr-documentation.yml │ ├── documentation.yml │ └── pr-documentation.yml ├── CODEOWNERS ├── docs └── _toctree.yml ├── package.json ├── LICENSE └── .eslintrc.cjs /packages/tasks/.eslintignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /packages/agents/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /packages/hub/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /packages/jinja/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /packages/tasks/.gitignore: -------------------------------------------------------------------------------- 1 | .python_generated -------------------------------------------------------------------------------- /packages/hub/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./src"; 2 | -------------------------------------------------------------------------------- /packages/jinja/.gitignore: -------------------------------------------------------------------------------- 1 | types 2 | dist 3 | -------------------------------------------------------------------------------- /packages/jinja/test/.gitignore: -------------------------------------------------------------------------------- 1 | __snapshots__ 2 | -------------------------------------------------------------------------------- /packages/agents/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./src"; 2 | -------------------------------------------------------------------------------- /packages/gguf/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./gguf"; 2 | -------------------------------------------------------------------------------- /e2e/svelte/.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | resolution-mode=highest 3 | -------------------------------------------------------------------------------- /packages/inference/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | tapes.json 3 | src/vendor -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shared-workspace-lockfile = false 2 | include-workspace-root = true -------------------------------------------------------------------------------- /packages/agents/test/vitest.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Run prettier 2 | 276993de38565e4c906212d45864a8a38c805987 -------------------------------------------------------------------------------- /packages/hub/src/consts.ts: -------------------------------------------------------------------------------- 1 | export const HUB_URL = "https://huggingface.co"; 2 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["esbenp.prettier-vscode"] 3 | } 4 | -------------------------------------------------------------------------------- /packages/agents/src/llms/index.ts: -------------------------------------------------------------------------------- 1 | export { LLMFromHub, LLMFromEndpoint } from "./LLMHF"; 2 | -------------------------------------------------------------------------------- /e2e/svelte/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/e2e/svelte/static/favicon.png -------------------------------------------------------------------------------- /packages/agents/src/index.ts: -------------------------------------------------------------------------------- 1 | export { HfAgent } from "./HfAgent"; 2 | export * from "./tools"; 3 | export * from "./llms"; 4 | -------------------------------------------------------------------------------- /packages/inference/test/cats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/inference/test/cats.png -------------------------------------------------------------------------------- /packages/shared/src/isFrontend.ts: -------------------------------------------------------------------------------- 1 | import { isBackend } from "./isBackend"; 2 | 3 | export const isFrontend = !isBackend; 4 | -------------------------------------------------------------------------------- /packages/widgets/static/cats.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/widgets/static/cats.jpg -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | -------------------------------------------------------------------------------- /packages/inference/test/cheetah.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/inference/test/cheetah.png -------------------------------------------------------------------------------- /packages/inference/test/global.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | const __TEST_FILES__: Record; 3 | } 4 | 5 | export {}; 6 | -------------------------------------------------------------------------------- /packages/inference/test/invoice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/inference/test/invoice.png -------------------------------------------------------------------------------- /packages/widgets/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /packages/widgets/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/widgets/static/favicon.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{ts}] 2 | indent_style = tab 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /packages/inference/test/bird_canny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/inference/test/bird_canny.png -------------------------------------------------------------------------------- /packages/inference/test/sample1.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/inference/test/sample1.flac -------------------------------------------------------------------------------- /packages/languages/src/types.d.ts: -------------------------------------------------------------------------------- 1 | export interface Language { 2 | code: string; 3 | name: string; 4 | nativeName?: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/shared/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base64FromBytes'; 2 | export * from './isBackend'; 3 | export * from './isFrontend'; 4 | -------------------------------------------------------------------------------- /packages/gguf/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | -------------------------------------------------------------------------------- /packages/shared/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | -------------------------------------------------------------------------------- /packages/doc-internal/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md -------------------------------------------------------------------------------- /packages/gguf/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | dist -------------------------------------------------------------------------------- /packages/hub/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | dist -------------------------------------------------------------------------------- /packages/languages/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | -------------------------------------------------------------------------------- /packages/agents/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | dist -------------------------------------------------------------------------------- /packages/languages/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | dist -------------------------------------------------------------------------------- /packages/tasks/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | dist -------------------------------------------------------------------------------- /packages/hub/src/utils/insecureRandomString.ts: -------------------------------------------------------------------------------- 1 | export function insecureRandomString(): string { 2 | return Math.random().toString(36).slice(2); 3 | } 4 | -------------------------------------------------------------------------------- /packages/inference/test/stormtrooper_depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merveenoyan/huggingface.js/main/packages/inference/test/stormtrooper_depth.png -------------------------------------------------------------------------------- /packages/hub/src/utils/typedInclude.ts: -------------------------------------------------------------------------------- 1 | export function typedInclude(arr: readonly T[], v: V): v is T { 2 | return arr.includes(v as T); 3 | } 4 | -------------------------------------------------------------------------------- /packages/inference/src/utils/typedInclude.ts: -------------------------------------------------------------------------------- 1 | export function typedInclude(arr: readonly T[], v: V): v is T { 2 | return arr.includes(v as T); 3 | } 4 | -------------------------------------------------------------------------------- /packages/inference/src/lib/isUrl.ts: -------------------------------------------------------------------------------- 1 | export function isUrl(modelOrUrl: string): boolean { 2 | return /^http(s?):/.test(modelOrUrl) || modelOrUrl.startsWith("/"); 3 | } 4 | -------------------------------------------------------------------------------- /packages/hub/src/utils/sum.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Sum of elements in array 3 | */ 4 | export function sum(arr: number[]): number { 5 | return arr.reduce((a, b) => a + b, 0); 6 | } 7 | -------------------------------------------------------------------------------- /packages/hub/src/test/consts.ts: -------------------------------------------------------------------------------- 1 | export const TEST_HUB_URL = "https://hub-ci.huggingface.co"; 2 | export const TEST_USER = "hub.js"; 3 | export const TEST_ACCESS_TOKEN = "hf_hub.js"; 4 | -------------------------------------------------------------------------------- /packages/inference/.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | # In order to avoid code samples to have tabs, they don't display well on npm 3 | README.md 4 | dist 5 | test/tapes.json 6 | src/vendor -------------------------------------------------------------------------------- /e2e/svelte/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | 4 | export default defineConfig({ 5 | plugins: [sveltekit()], 6 | }); 7 | -------------------------------------------------------------------------------- /e2e/svelte/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | vite.config.js.timestamp-* 10 | vite.config.ts.timestamp-* 11 | -------------------------------------------------------------------------------- /packages/jinja/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { configDefaults, defineConfig } from "vitest/config"; 2 | 3 | export default defineConfig({ 4 | test: { 5 | exclude: [...configDefaults.exclude], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/shared/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@huggingface/shared", 3 | "version": "1.0.0", 4 | "private": true, 5 | "main": "src/index.ts", 6 | "source": "src/index.ts", 7 | "types": "./src/index.ts" 8 | } -------------------------------------------------------------------------------- /packages/widgets/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /dist 5 | /.svelte-kit 6 | /package 7 | .env 8 | .env.* 9 | !.env.example 10 | vite.config.js.timestamp-* 11 | vite.config.ts.timestamp-* 12 | -------------------------------------------------------------------------------- /packages/jinja/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | 3 | export default defineConfig({ 4 | build: { 5 | lib: { 6 | entry: "src/index.js", 7 | name: "jinja", 8 | }, 9 | }, 10 | }); 11 | -------------------------------------------------------------------------------- /packages/inference/src/index.ts: -------------------------------------------------------------------------------- 1 | export { HfInference, HfInferenceEndpoint } from "./HfInference"; 2 | export { InferenceOutputError } from "./lib/InferenceOutputError"; 3 | export * from "./types"; 4 | export * from "./tasks"; 5 | -------------------------------------------------------------------------------- /packages/tasks/src/snippets/index.ts: -------------------------------------------------------------------------------- 1 | import * as inputs from "./inputs"; 2 | import * as curl from "./curl"; 3 | import * as python from "./python"; 4 | import * as js from "./js"; 5 | 6 | export { inputs, curl, python, js }; 7 | -------------------------------------------------------------------------------- /e2e/yarn/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yarn", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "@huggingface/inference": "*", 8 | "@huggingface/hub": "*" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/languages/src/wikiLink.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @param languageCode 2 or 3 letter language code 3 | */ 4 | export function wikiLink(languageCode: string): string { 5 | return `https://en.wikipedia.org/wiki/ISO_639:${languageCode}`; 6 | } 7 | -------------------------------------------------------------------------------- /packages/agents/vitest-browser.config.mts: -------------------------------------------------------------------------------- 1 | import { configDefaults, defineConfig } from "vitest/config"; 2 | 3 | export default defineConfig({ 4 | envPrefix: ["HF_"], 5 | test: { 6 | exclude: [...configDefaults.exclude], 7 | }, 8 | }); 9 | -------------------------------------------------------------------------------- /packages/hub/vitest-browser.config.mts: -------------------------------------------------------------------------------- 1 | import { configDefaults, defineConfig } from "vitest/config"; 2 | 3 | export default defineConfig({ 4 | test: { 5 | exclude: [...configDefaults.exclude, "src/utils/FileBlob.spec.ts"], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/inference/src/utils/toArray.ts: -------------------------------------------------------------------------------- 1 | export function toArray(obj: T): T extends unknown[] ? T : T[] { 2 | if (Array.isArray(obj)) { 3 | return obj as T extends unknown[] ? T : T[]; 4 | } 5 | return [obj] as T extends unknown[] ? T : T[]; 6 | } 7 | -------------------------------------------------------------------------------- /packages/hub/src/utils/typedEntries.ts: -------------------------------------------------------------------------------- 1 | import type { Entries } from "type-fest"; 2 | 3 | export function typedEntries>(obj: T): Entries { 4 | return Object.entries(obj) as Entries; 5 | } 6 | -------------------------------------------------------------------------------- /packages/widgets/.eslintignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | /build 5 | /.svelte-kit 6 | /package 7 | .env 8 | .env.* 9 | !.env.example 10 | 11 | # Ignore files for PNPM, NPM and YARN 12 | pnpm-lock.yaml 13 | package-lock.json 14 | yarn.lock 15 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "useTabs": true, 4 | "tabWidth": 2, 5 | "printWidth": 120, 6 | "trailingComma": "es5", 7 | "plugins": ["prettier-plugin-svelte"], 8 | "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] 9 | } 10 | -------------------------------------------------------------------------------- /packages/widgets/.prettierignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | /build 5 | /.svelte-kit 6 | /package 7 | .env 8 | .env.* 9 | !.env.example 10 | 11 | # Ignore files for PNPM, NPM and YARN 12 | pnpm-lock.yaml 13 | package-lock.json 14 | yarn.lock 15 | -------------------------------------------------------------------------------- /packages/languages/src/index.ts: -------------------------------------------------------------------------------- 1 | export type { Language } from "./types"; 2 | export { language } from "./language"; 3 | export { wikiLink } from "./wikiLink"; 4 | export { LANGUAGES_ISO_639_1 } from "./languages_iso_639_1"; 5 | export { LANGUAGES_ISO_639_3 } from "./languages_iso_639_3"; 6 | -------------------------------------------------------------------------------- /packages/doc-internal/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "module": "ESNext", 5 | "moduleResolution": "node", 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "skipLibCheck": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/tasks/src/snippets/types.ts: -------------------------------------------------------------------------------- 1 | import type { ModelData } from "../model-data"; 2 | 3 | /** 4 | * Minimal model data required for snippets. 5 | * 6 | * Add more fields as needed. 7 | */ 8 | export type ModelDataMinimal = Pick; 9 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "packages/hub" 3 | - "packages/inference" 4 | - "packages/doc-internal" 5 | - "packages/shared" 6 | - "packages/agents" 7 | - "packages/languages" 8 | - "packages/tasks" 9 | - "packages/gguf" 10 | - "packages/jinja" 11 | - "packages/widgets" 12 | -------------------------------------------------------------------------------- /packages/languages/src/wikiLink.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | import { wikiLink } from "./wikiLink"; 3 | 4 | describe("wikiLink", () => { 5 | it("should return the correct link", () => { 6 | expect(wikiLink("en")).toBe(`https://en.wikipedia.org/wiki/ISO_639:en`); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /e2e/svelte/src/app.d.ts: -------------------------------------------------------------------------------- 1 | // See https://kit.svelte.dev/docs/types#app 2 | // for information about these interfaces 3 | declare global { 4 | namespace App { 5 | // interface Error {} 6 | // interface Locals {} 7 | // interface PageData {} 8 | // interface Platform {} 9 | } 10 | } 11 | 12 | export {}; 13 | -------------------------------------------------------------------------------- /packages/shared/src/isBackend.ts: -------------------------------------------------------------------------------- 1 | const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined"; 2 | 3 | const isWebWorker = 4 | typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope"; 5 | 6 | export const isBackend = !isBrowser && !isWebWorker; 7 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetOutputText/WidgetOutputText.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | {#if output.length} 7 |

8 | {output} 9 |

10 | {/if} 11 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/translation/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "/inference/schemas/text2text-generation/input.json", 3 | "$id": "/inference/schemas/translation/input.json", 4 | "$schema": "http://json-schema.org/draft-06/schema#", 5 | "title": "TranslationInput", 6 | "description": "Inputs for Translation inference" 7 | } 8 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-to-speech/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "/inference/schemas/text-to-audio/input.json", 3 | "$id": "/inference/schemas/text-to-speech/input.json", 4 | "$schema": "http://json-schema.org/draft-06/schema#", 5 | "title": "TextToSpeechInput", 6 | "description": "Inputs for Text to Speech inference" 7 | } 8 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/summarization/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "/inference/schemas/text2text-generation/input.json", 3 | "$id": "/inference/schemas/summarization/input.json", 4 | "$schema": "http://json-schema.org/draft-06/schema#", 5 | "title": "SummarizationInput", 6 | "description": "Inputs for Summarization inference" 7 | } 8 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-to-speech/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "/inference/schemas/text-to-audio/output.json", 3 | "$id": "/inference/schemas/text-to-speech/output.json", 4 | "$schema": "http://json-schema.org/draft-06/schema#", 5 | "title": "TextToSpeechOutput", 6 | "description": "Outputs for Text to Speech inference" 7 | } 8 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/feature-extraction/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/feature-extraction/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "The embedding for the input text, as a nested list (tensor) of floats", 5 | "type": "array", 6 | "title": "FeatureExtractionOutput" 7 | } 8 | -------------------------------------------------------------------------------- /packages/inference/src/lib/InferenceOutputError.ts: -------------------------------------------------------------------------------- 1 | export class InferenceOutputError extends TypeError { 2 | constructor(message: string) { 3 | super( 4 | `Invalid inference output: ${message}. Use the 'request' method with the same parameters to do a custom call with no type checking.` 5 | ); 6 | this.name = "InferenceOutputError"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /e2e/ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2015", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "skipLibCheck": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "outDir": "dist" 10 | }, 11 | "$schema": "https://json.schemastore.org/tsconfig", 12 | "display": "Recommended" 13 | } 14 | -------------------------------------------------------------------------------- /packages/shared/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "noEmit": false, 5 | "module": "ESNext", 6 | "target": "ESNext", 7 | "moduleResolution": "Node", 8 | "noImplicitAny": true, 9 | "strict": true, 10 | "strictNullChecks": true, 11 | "skipLibCheck": true, 12 | "composite": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/hub/src/utils/hexFromBytes.ts: -------------------------------------------------------------------------------- 1 | export function hexFromBytes(arr: Uint8Array): string { 2 | if (globalThis.Buffer) { 3 | return globalThis.Buffer.from(arr).toString("hex"); 4 | } else { 5 | const bin: string[] = []; 6 | arr.forEach((byte) => { 7 | bin.push(byte.toString(16).padStart(2, "0")); 8 | }); 9 | return bin.join(""); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/shared/src/base64FromBytes.ts: -------------------------------------------------------------------------------- 1 | export function base64FromBytes(arr: Uint8Array): string { 2 | if (globalThis.Buffer) { 3 | return globalThis.Buffer.from(arr).toString("base64"); 4 | } else { 5 | const bin: string[] = []; 6 | arr.forEach((byte) => { 7 | bin.push(String.fromCharCode(byte)); 8 | }); 9 | return globalThis.btoa(bin.join("")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/hub/src/utils/pick.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Return copy of object, only keeping whitelisted properties. 3 | */ 4 | export function pick(o: T, props: K[] | ReadonlyArray): Pick { 5 | return Object.assign( 6 | {}, 7 | ...props.map((prop) => { 8 | if (o[prop] !== undefined) { 9 | return { [prop]: o[prop] }; 10 | } 11 | }) 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /packages/inference/src/utils/pick.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Return copy of object, only keeping allowlisted properties. 3 | */ 4 | export function pick(o: T, props: K[] | ReadonlyArray): Pick { 5 | return Object.assign( 6 | {}, 7 | ...props.map((prop) => { 8 | if (o[prop] !== undefined) { 9 | return { [prop]: o[prop] }; 10 | } 11 | }) 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /e2e/svelte/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %sveltekit.head% 8 | 9 | 10 |
%sveltekit.body%
11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/widgets/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %sveltekit.head% 8 | 9 | 10 |
%sveltekit.body%
11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/inference/test/test-files.ts: -------------------------------------------------------------------------------- 1 | // https://vitejs.dev/config/shared-options.html#define 2 | const files = __TEST_FILES__; 3 | 4 | export const readTestFile = (filename: string): Uint8Array => { 5 | if (!(filename in files)) { 6 | throw new Error(`File is not pre-loaded for unit tests: ${filename}`); 7 | } 8 | return Uint8Array.from(atob(files[filename]), (c) => c.charCodeAt(0)); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/widgets/src/additional-svelte-typings.d.ts: -------------------------------------------------------------------------------- 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 { 6 | // If you want to use on:beforeinstallprompt 7 | "on:cmdEnter"?: () => void; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/image-to-image/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/image-to-image/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Image To Image task", 5 | "title": "ImageToImageOutput", 6 | "type": "object", 7 | "properties": { 8 | "image": { 9 | "description": "The output image" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/hub/src/utils/range.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * One param: create list of integers from 0 (inclusive) to n (exclusive) 3 | * Two params: create list of integers from a (inclusive) to b (exclusive) 4 | */ 5 | export function range(n: number, b?: number): number[] { 6 | return b 7 | ? Array(b - n) 8 | .fill(0) 9 | .map((_, i) => n + i) 10 | : Array(n) 11 | .fill(0) 12 | .map((_, i) => i); 13 | } 14 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconRow.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 17 | -------------------------------------------------------------------------------- /packages/widgets/src/routes/+layout.server.ts: -------------------------------------------------------------------------------- 1 | import { env } from "$env/dynamic/private"; 2 | import type { LayoutServerLoad } from "./$types.js"; 3 | 4 | const supportsOAuth = !!env.OAUTH_CLIENT_ID && !!env.OAUTH_CLIENT_SECRET; 5 | 6 | export const load: LayoutServerLoad = async ({ locals }) => { 7 | return { 8 | session: supportsOAuth ? locals.getSession() : undefined, 9 | supportsOAuth, 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /packages/hub/src/utils/parseLinkHeader.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Parse Link HTTP header, eg `; rel="next"` 3 | */ 4 | export function parseLinkHeader(header: string): Record { 5 | const regex = /<(https?:[/][/][^>]+)>;\s+rel="([^"]+)"/g; 6 | 7 | return Object.fromEntries([...header.matchAll(regex)].map(([, url, rel]) => [rel, url])); 8 | } 9 | -------------------------------------------------------------------------------- /packages/widgets/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "checkJs": true, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "resolveJsonModule": true, 9 | "skipLibCheck": true, 10 | "sourceMap": true, 11 | "strict": true, 12 | "module": "NodeNext", 13 | "moduleResolution": "NodeNext" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/hub/src/utils/checkCredentials.ts: -------------------------------------------------------------------------------- 1 | import type { Credentials } from "../types/public"; 2 | 3 | export function checkCredentials(credentials?: Credentials): void { 4 | if (!credentials || credentials.accessToken === undefined || credentials.accessToken === null) { 5 | return; 6 | } 7 | 8 | if (!credentials.accessToken.startsWith("hf_")) { 9 | throw new TypeError("Your access token must start with 'hf_'"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/audio-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/audio-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "title": "AudioClassificationOutput", 5 | "description": "Outputs for Audio Classification inference", 6 | "type": "array", 7 | "items": { 8 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-to-image/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/text-to-image/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Text To Image task", 5 | "title": "TextToImageOutput", 6 | "type": "object", 7 | "properties": { 8 | "image": { 9 | "description": "The generated image" 10 | } 11 | }, 12 | "required": ["image"] 13 | } 14 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true, 4 | "editor.codeActionsOnSave": { 5 | "source.fixAll": "explicit" 6 | }, 7 | "[svelte]": { 8 | "editor.defaultFormatter": "esbenp.prettier-vscode" 9 | }, 10 | "prettier.configPath": ".prettierrc", 11 | "json.format.enable": false, 12 | "[json]": { 13 | "editor.defaultFormatter": "esbenp.prettier-vscode" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/inference/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "noEmit": true, 5 | "module": "ESNext", 6 | "target": "ESNext", 7 | "moduleResolution": "Node", 8 | "noImplicitAny": true, 9 | "strict": true, 10 | "strictNullChecks": true, 11 | "skipLibCheck": true, 12 | "noImplicitOverride": true 13 | }, 14 | "include": ["src", "test", "index.ts", "../shared/src"], 15 | "exclude": ["dist"] 16 | } 17 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/text-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Text Classification task", 5 | "title": "TextClassificationOutput", 6 | "type": "array", 7 | "items": { 8 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /e2e/mock-registry-config.yaml: -------------------------------------------------------------------------------- 1 | auth: 2 | auth-memory: 3 | users: 4 | foo: 5 | name: test 6 | password: test 7 | store: 8 | memory: 9 | limit: 1000 10 | uplinks: 11 | npmjs: 12 | url: https://registry.npmjs.org/ 13 | packages: 14 | "@huggingface/*": 15 | access: $all 16 | publish: $all 17 | "**": 18 | access: $all 19 | proxy: npmjs 20 | log: 21 | - { type: stdout, format: pretty, level: trace } 22 | -------------------------------------------------------------------------------- /e2e/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "tsc && node ./dist/index.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@types/node": "^18.16.1", 14 | "typescript": "^5.0.4" 15 | }, 16 | "dependencies": { 17 | "@huggingface/inference": "*", 18 | "@huggingface/hub": "*" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/image-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/image-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Image Classification task", 5 | "title": "ImageClassificationOutput", 6 | "type": "array", 7 | "items": { 8 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/video-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/video-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Video Classification task", 5 | "title": "VideoClassificationOutput", 6 | "type": "array", 7 | "items": { 8 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconCaretDownV2.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/zero-shot-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/zero-shot-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Zero Shot Classification task", 5 | "title": "ZeroShotClassificationOutput", 6 | "type": "array", 7 | "items": { 8 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetLabel/WidgetLabel.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 | 14 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/image-to-text/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/image-to-text/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Image To Text task", 5 | "title": "ImageToTextOutput", 6 | "type": "object", 7 | "properties": { 8 | "generated_text": { 9 | "type": "string", 10 | "description": "The generated text." 11 | } 12 | }, 13 | "required": ["generatedText"] 14 | } 15 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/summarization/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/summarization/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Summarization task", 5 | "title": "SummarizationOutput", 6 | "type": "object", 7 | "properties": { 8 | "summary_text": { 9 | "type": "string", 10 | "description": "The summarized text." 11 | } 12 | }, 13 | "required": ["summary_text"] 14 | } 15 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/translation/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/translation/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Translation task", 5 | "title": "TranslationOutput", 6 | "type": "object", 7 | "properties": { 8 | "translation_text": { 9 | "type": "string", 10 | "description": "The translated text." 11 | } 12 | }, 13 | "required": ["translation_text"] 14 | } 15 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetAddSentenceBtn/WidgetAddSentenceBtn.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 | {#if !isDisabled} 8 | 9 | 12 | {/if} 13 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/zero-shot-image-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/zero-shot-image-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Zero Shot Image Classification task", 5 | "title": "ZeroShotImageClassificationOutput", 6 | "type": "array", 7 | "items": { 8 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.github/workflows/upload-pr-documentation.yml: -------------------------------------------------------------------------------- 1 | name: Upload PR Documentation 2 | 3 | on: 4 | workflow_run: 5 | workflows: ["Build PR Documentation"] 6 | types: 7 | - completed 8 | 9 | jobs: 10 | build: 11 | uses: huggingface/doc-builder/.github/workflows/upload_pr_documentation.yml@main 12 | with: 13 | package_name: huggingface.js 14 | secrets: 15 | hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }} 16 | comment_bot_token: ${{ secrets.COMMENT_BOT_TOKEN }} 17 | -------------------------------------------------------------------------------- /packages/gguf/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["ES2022", "DOM"], 5 | "module": "CommonJS", 6 | "moduleResolution": "node", 7 | "target": "ES2022", 8 | "forceConsistentCasingInFileNames": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "skipLibCheck": true, 13 | "noImplicitOverride": true, 14 | "outDir": "./dist" 15 | }, 16 | "include": ["src"], 17 | "exclude": ["dist"] 18 | } 19 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/sentence-similarity/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/sentence-similarity/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "title": "SentenceSimilarityOutput", 5 | "description": "Outputs of inference for the Sentence Similarity task", 6 | "type": "array", 7 | "items": { 8 | "description": "The associated similarity score for each of the given sentences", 9 | "type": "number", 10 | "title": "SentenceSimilarityScore" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text2text-generation/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/text2text-generation/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Text2text Generation task", 5 | "title": "Text2TextGenerationOutput", 6 | "type": "object", 7 | "properties": { 8 | "generated_text": { 9 | "type": "string", 10 | "description": "The generated text." 11 | } 12 | }, 13 | "required": ["generatedText"] 14 | } 15 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconLightning.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 19 | -------------------------------------------------------------------------------- /packages/languages/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["ES2022", "DOM"], 5 | "module": "CommonJS", 6 | "moduleResolution": "node", 7 | "target": "ES2022", 8 | "forceConsistentCasingInFileNames": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "skipLibCheck": true, 13 | "noImplicitOverride": true, 14 | "outDir": "./dist" 15 | }, 16 | "include": ["src"], 17 | "exclude": ["dist"] 18 | } 19 | -------------------------------------------------------------------------------- /packages/hub/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./lib"; 2 | // Typescript 5 will add 'export type *' 3 | export type { 4 | AccessToken, 5 | AccessTokenRole, 6 | AuthType, 7 | Credentials, 8 | PipelineType, 9 | RepoDesignation, 10 | RepoFullName, 11 | RepoId, 12 | RepoType, 13 | SpaceHardwareFlavor, 14 | SpaceResourceConfig, 15 | SpaceResourceRequirement, 16 | SpaceRuntime, 17 | SpaceSdk, 18 | SpaceStage, 19 | } from "./types/public"; 20 | export { HubApiError, InvalidApiResponseFormatError } from "./error"; 21 | -------------------------------------------------------------------------------- /packages/tasks/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["ES2022", "DOM"], 5 | "module": "ESNext", 6 | "target": "ESNext", 7 | "moduleResolution": "node", 8 | "forceConsistentCasingInFileNames": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "skipLibCheck": true, 13 | "noImplicitOverride": true, 14 | "outDir": "./dist" 15 | }, 16 | "include": ["src", "scripts"], 17 | "exclude": ["dist"] 18 | } 19 | -------------------------------------------------------------------------------- /packages/inference/src/utils/omit.ts: -------------------------------------------------------------------------------- 1 | import { pick } from "./pick"; 2 | import { typedInclude } from "./typedInclude"; 3 | 4 | /** 5 | * Return copy of object, omitting blocklisted array of props 6 | */ 7 | export function omit(o: T, props: K[] | K): Pick> { 8 | const propsArr = Array.isArray(props) ? props : [props]; 9 | const letsKeep = (Object.keys(o) as (keyof T)[]).filter((prop) => !typedInclude(propsArr, prop)); 10 | return pick(o, letsKeep); 11 | } 12 | -------------------------------------------------------------------------------- /packages/widgets/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 |
12 | 13 |
14 | -------------------------------------------------------------------------------- /packages/hub/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["ES2022", "DOM"], 5 | "module": "CommonJS", 6 | "moduleResolution": "node", 7 | "target": "ES2022", 8 | "forceConsistentCasingInFileNames": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "skipLibCheck": true, 13 | "noImplicitOverride": true, 14 | "outDir": "./dist" 15 | }, 16 | "include": ["src", "index.ts", "../shared/src"], 17 | "exclude": ["dist"] 18 | } 19 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/depth-estimation/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/depth-estimation/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Depth Estimation task", 5 | "title": "DepthEstimationOutput", 6 | 7 | "type": "object", 8 | "properties": { 9 | "predicted_depth": { 10 | "description": "The predicted depth as a tensor" 11 | }, 12 | "depth": { 13 | "description": "The predicted depth as an image" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconCaretDown.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 20 | -------------------------------------------------------------------------------- /packages/inference/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | devDependencies: 8 | '@huggingface/tasks': 9 | specifier: workspace:^ 10 | version: link:../tasks 11 | '@types/node': 12 | specifier: 18.13.0 13 | version: 18.13.0 14 | 15 | packages: 16 | 17 | /@types/node@18.13.0: 18 | resolution: {integrity: sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==} 19 | dev: true 20 | -------------------------------------------------------------------------------- /packages/jinja/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["ES2022", "DOM"], 5 | "module": "ESNext", 6 | "moduleResolution": "node", 7 | "target": "ESNext", 8 | "forceConsistentCasingInFileNames": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "skipLibCheck": true, 13 | "noImplicitOverride": true, 14 | "outDir": "./dist", 15 | "declaration": true 16 | }, 17 | "include": ["src", "index.ts"], 18 | "exclude": ["dist"] 19 | } 20 | -------------------------------------------------------------------------------- /packages/hub/src/utils/omit.ts: -------------------------------------------------------------------------------- 1 | import { pick } from "./pick"; 2 | import { typedInclude } from "./typedInclude"; 3 | 4 | /** 5 | * Return copy of object, omitting blacklisted array of props 6 | */ 7 | export function omit, K extends keyof T>( 8 | o: T, 9 | props: K[] | K 10 | ): Pick> { 11 | const propsArr = Array.isArray(props) ? props : [props]; 12 | const letsKeep = (Object.keys(o) as (keyof T)[]).filter((prop) => !typedInclude(propsArr, prop)); 13 | return pick(o, letsKeep); 14 | } 15 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/placeholder/about.md: -------------------------------------------------------------------------------- 1 | ## Use Cases 2 | 3 | You can contribute this area with common use cases of the task! 4 | 5 | ## Task Variants 6 | 7 | This place can be filled with variants of this task if there's any. 8 | 9 | ## Inference 10 | 11 | This section should have useful information about how to pull a model from Hugging Face Hub that is a part of a library specialized in a task and use it. 12 | 13 | ## Useful Resources 14 | 15 | In this area, you can insert useful resources about how to train or use a model for this task. 16 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/placeholder/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas//output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs for inference", 5 | "title": "PlaceholderOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "meaningful_output_name": { 11 | "type": "string", 12 | "description": "TODO: Describe what is outputed by the inference here" 13 | } 14 | }, 15 | "required": ["meaningfulOutputName"] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/placeholder/data.ts: -------------------------------------------------------------------------------- 1 | import type { TaskDataCustom } from ".."; 2 | 3 | const taskData: TaskDataCustom = { 4 | datasets: [], 5 | demo: { 6 | inputs: [], 7 | outputs: [], 8 | }, 9 | isPlaceholder: true, 10 | metrics: [], 11 | models: [], 12 | spaces: [], 13 | summary: "", 14 | widgetModels: [], 15 | youtubeId: undefined, 16 | /// If this is a subtask, link to the most general task ID 17 | /// (eg, text2text-generation is the canonical ID of translation) 18 | canonicalId: undefined, 19 | }; 20 | 21 | export default taskData; 22 | -------------------------------------------------------------------------------- /packages/agents/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["ES2022", "DOM"], 5 | "module": "ESNext", 6 | "moduleResolution": "node", 7 | "target": "ES2022", 8 | "forceConsistentCasingInFileNames": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "skipLibCheck": true, 13 | "noImplicitOverride": true, 14 | "outDir": "./dist", 15 | "declaration": true 16 | }, 17 | "include": ["src", "test", "index.ts", "../shared/src"], 18 | "exclude": ["dist"] 19 | } 20 | -------------------------------------------------------------------------------- /packages/agents/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import type { Options } from "tsup"; 2 | 3 | const baseConfig: Options = { 4 | entry: ["./index.ts"], 5 | format: ["cjs", "esm"], 6 | outDir: "dist", 7 | clean: true, 8 | dts: { 9 | resolve: true, 10 | }, 11 | }; 12 | 13 | const nodeConfig: Options = { 14 | ...baseConfig, 15 | platform: "node", 16 | }; 17 | 18 | const browserConfig: Options = { 19 | ...baseConfig, 20 | platform: "browser", 21 | target: "es2018", 22 | splitting: true, 23 | outDir: "dist/browser", 24 | }; 25 | 26 | export default [nodeConfig, browserConfig]; 27 | -------------------------------------------------------------------------------- /packages/gguf/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import type { Options } from "tsup"; 2 | 3 | const baseConfig: Options = { 4 | entry: ["./index.ts"], 5 | format: ["cjs", "esm"], 6 | outDir: "dist", 7 | clean: true, 8 | dts: { 9 | resolve: true, 10 | }, 11 | }; 12 | 13 | const nodeConfig: Options = { 14 | ...baseConfig, 15 | platform: "node", 16 | }; 17 | 18 | const browserConfig: Options = { 19 | ...baseConfig, 20 | platform: "browser", 21 | target: "es2018", 22 | splitting: true, 23 | outDir: "dist/browser", 24 | }; 25 | 26 | export default [nodeConfig, browserConfig]; 27 | -------------------------------------------------------------------------------- /packages/hub/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import type { Options } from "tsup"; 2 | 3 | const baseConfig: Options = { 4 | entry: ["./index.ts"], 5 | format: ["cjs", "esm"], 6 | outDir: "dist", 7 | clean: true, 8 | dts: { 9 | resolve: true, 10 | }, 11 | }; 12 | 13 | const nodeConfig: Options = { 14 | ...baseConfig, 15 | platform: "node", 16 | }; 17 | 18 | const browserConfig: Options = { 19 | ...baseConfig, 20 | platform: "browser", 21 | target: "es2018", 22 | splitting: true, 23 | outDir: "dist/browser", 24 | }; 25 | 26 | export default [nodeConfig, browserConfig]; 27 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconDepthEstimation.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /packages/widgets/src/app.d.ts: -------------------------------------------------------------------------------- 1 | // See https://kit.svelte.dev/docs/types#app 2 | // for information about these interfaces 3 | declare global { 4 | namespace App { 5 | // interface Error {} 6 | // interface Locals {} 7 | // interface PageData {} 8 | // interface Platform {} 9 | } 10 | 11 | export interface Session { 12 | access_token?: string; 13 | } 14 | } 15 | 16 | declare module "@auth/core/types" { 17 | export interface Session { 18 | access_token?: string; 19 | } 20 | 21 | export interface User { 22 | username: string; 23 | } 24 | } 25 | 26 | export {}; 27 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/feature-extraction/inference.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Inference code generated from the JSON schema spec in ./spec 3 | * 4 | * Using src/scripts/inference-codegen 5 | */ 6 | 7 | export type FeatureExtractionOutput = unknown[]; 8 | 9 | /** 10 | * Inputs for Text Embedding inference 11 | */ 12 | export interface FeatureExtractionInput { 13 | /** 14 | * The text to get the embeddings of 15 | */ 16 | inputs: string; 17 | /** 18 | * Additional inference parameters 19 | */ 20 | parameters?: { [key: string]: unknown }; 21 | [property: string]: unknown; 22 | } 23 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-to-audio/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/text-to-audio/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Text To Audio task", 5 | "title": "TextToAudioOutput", 6 | "type": "object", 7 | "properties": { 8 | "audio": { 9 | "description": "The generated audio waveform." 10 | }, 11 | "sampling_rate": { 12 | "type": "number", 13 | "description": "The sampling rate of the generated audio waveform." 14 | } 15 | }, 16 | "required": ["audio", "samplingRate"] 17 | } 18 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconCross.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 22 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/index.ts: -------------------------------------------------------------------------------- 1 | import InferenceWidget from "./components/InferenceWidget/InferenceWidget.svelte"; 2 | import WidgetOutputChart from "./components/InferenceWidget/shared/WidgetOutputChart/WidgetOutputChart.svelte"; 3 | import WidgetOutputTokens from "./components/InferenceWidget/shared/WidgetOutputTokens/WidgetOutputTokens.svelte"; 4 | import PipelineIcon from "./components/PipelineIcon/PipelineIcon.svelte"; 5 | import { modelLoadStates } from "./components/InferenceWidget/stores.js"; 6 | 7 | export { InferenceWidget, WidgetOutputChart, WidgetOutputTokens, modelLoadStates, PipelineIcon }; 8 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconDocumentQuestionAnswering.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 14 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetAudioTrack/WidgetAudioTrack.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 |
10 | {#if $$slots.default} 11 | 12 | {:else if label.length} 13 |
{label}
14 | {/if} 15 | 16 |
18 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetOuputConvoBubble/WidgetOutputConvoBubble.svelte: -------------------------------------------------------------------------------- 1 | 11 | 12 |
13 | {text} 14 |
15 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/PipelineTag/PipelineTag.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 |
12 | 13 | 14 | {pipelineData ? pipelineData.name : pipeline} 15 | 16 |
17 | -------------------------------------------------------------------------------- /e2e/svelte/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "checkJs": true, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "resolveJsonModule": true, 9 | "skipLibCheck": true, 10 | "sourceMap": true, 11 | "strict": true 12 | } 13 | // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias 14 | // 15 | // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes 16 | // from the referenced tsconfig.json - TypeScript does not merge them in 17 | } 18 | -------------------------------------------------------------------------------- /packages/agents/src/tools/index.ts: -------------------------------------------------------------------------------- 1 | import { textToImageTool } from "./textToImage"; 2 | import { imageToTextTool } from "./imageToText"; 3 | import { textToSpeechTool } from "./textToSpeech"; 4 | import { speechToTextTool } from "./speechToText"; 5 | import type { Tool } from "../types"; 6 | 7 | export const defaultTools: Array = [textToImageTool, imageToTextTool, textToSpeechTool, speechToTextTool]; 8 | 9 | export { textToImageTool } from "./textToImage"; 10 | export { imageToTextTool } from "./imageToText"; 11 | export { textToSpeechTool } from "./textToSpeech"; 12 | export { speechToTextTool } from "./speechToText"; 13 | -------------------------------------------------------------------------------- /packages/widgets/src/routes/[...model]/+page.ts: -------------------------------------------------------------------------------- 1 | import type { WidgetProps } from "$lib/components/InferenceWidget/shared/types.js"; 2 | import type { Load } from "@sveltejs/kit"; 3 | 4 | export const load: Load = async ({ params, fetch }): Promise<{ model?: WidgetProps["model"]; message?: string }> => { 5 | const url = `https://huggingface.co/api/models/${params.model}`; 6 | try { 7 | const model = await (await fetch(url)).json(); 8 | return { 9 | model, 10 | }; 11 | } catch { 12 | // todo: throw error() instead 13 | return { 14 | message: `Model ${params.model} not found (probably)`, 15 | }; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconFeatureExtraction.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 22 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Ownership for the Inference Package 2 | 3 | /packages/inference/ @vvmnnnkv @radames 4 | 5 | # Ownership for the Tasks Package 6 | 7 | /packages/tasks/ @osanseviero @SBrandeis @gary149 @Wauplin @julien-c 8 | 9 | # Ownership for the Widgets Package 10 | 11 | /packages/widgets/ @mishig25 @SBrandeis 12 | 13 | # Ownership for the Hub Package 14 | 15 | /packages/hub/ @coyotte508 16 | 17 | # Ownership for the Agents Package 18 | 19 | /packages/agents/ @nsarrazin 20 | 21 | # Ownership for the Jinja Package 22 | 23 | /packages/jinja/ @xenova 24 | 25 | # Ownership for the gguf Package 26 | 27 | /packages/gguf @mishig25 @julien-c 28 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTabularRegression.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 21 | -------------------------------------------------------------------------------- /packages/languages/src/language.ts: -------------------------------------------------------------------------------- 1 | import { LANGUAGES_ISO_639_1 } from "./languages_iso_639_1"; 2 | import { LANGUAGES_ISO_639_3 } from "./languages_iso_639_3"; 3 | import type { Language } from "./types"; 4 | 5 | /** 6 | * Be careful importing this function in frontend code, as it will import all languages. 7 | */ 8 | export function language(code: string): Language | null { 9 | if (code in LANGUAGES_ISO_639_1) { 10 | return LANGUAGES_ISO_639_1[code as keyof typeof LANGUAGES_ISO_639_1]; 11 | } 12 | if (code in LANGUAGES_ISO_639_3) { 13 | return LANGUAGES_ISO_639_3[code as keyof typeof LANGUAGES_ISO_639_3]; 14 | } 15 | 16 | return null; 17 | } 18 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTabularClassification.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /packages/agents/src/tools/imageToText.ts: -------------------------------------------------------------------------------- 1 | import type { Tool } from "../types"; 2 | 3 | export const imageToTextTool: Tool = { 4 | name: "imageToText", 5 | description: "Caption an image.", 6 | examples: [ 7 | { 8 | prompt: "Describe the image", 9 | code: "imageToText(image)", 10 | tools: ["imageToText"], 11 | }, 12 | ], 13 | call: async (input, inference) => { 14 | const data = await input; 15 | if (typeof data === "string") throw "Input must be a blob."; 16 | 17 | return ( 18 | await inference.imageToText( 19 | { 20 | data, 21 | }, 22 | { wait_for_model: true } 23 | ) 24 | ).generated_text; 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/consts.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Color palette for obj-det & img-seg widgets 3 | */ 4 | export const COLORS = [ 5 | { 6 | color: "red", 7 | hex: "#f87171", 8 | }, 9 | { 10 | color: "green", 11 | hex: "#4ade80", 12 | }, 13 | { 14 | color: "yellow", 15 | hex: "#facc15", 16 | }, 17 | { 18 | color: "blue", 19 | hex: "#60a5fa", 20 | }, 21 | { 22 | color: "orange", 23 | hex: "#fb923c", 24 | }, 25 | { 26 | color: "purple", 27 | hex: "#c084fc", 28 | }, 29 | { 30 | color: "cyan", 31 | hex: "#22d3ee", 32 | }, 33 | { 34 | color: "lime", 35 | hex: "#a3e635", 36 | }, 37 | ] as const; 38 | -------------------------------------------------------------------------------- /packages/agents/src/tools/message.ts: -------------------------------------------------------------------------------- 1 | import type { Tool } from "../types"; 2 | 3 | export const messageTool: Tool = { 4 | name: "message", 5 | description: "Send data back to the user.", 6 | examples: [ 7 | { 8 | prompt: "Display the created image", 9 | code: 'message("we display the image", image)', 10 | tools: ["message"], 11 | inputs: { image: true }, 12 | }, 13 | { 14 | prompt: "Display the generated text", 15 | code: 'message("we render the text", text)', 16 | tools: ["message"], 17 | }, 18 | { 19 | prompt: 'Display the text "hello world"', 20 | code: 'message("hello world")', 21 | tools: ["message"], 22 | }, 23 | ], 24 | }; 25 | -------------------------------------------------------------------------------- /packages/inference/src/utils/distributive-omit.d.ts: -------------------------------------------------------------------------------- 1 | // https://dev.to/safareli/pick-omit-and-union-types-in-typescript-4nd9 2 | // https://github.com/microsoft/TypeScript/issues/28339#issuecomment-467393437 3 | /** 4 | * This allows omitting keys from objects inside unions, without merging the individual components of the union. 5 | */ 6 | 7 | type Keys = keyof T; 8 | type DistributiveKeys = T extends unknown ? Keys : never; 9 | type Omit_ = Omit>; 10 | 11 | export type DistributiveOmit = T extends unknown 12 | ? keyof Omit_ extends never 13 | ? never 14 | : { [P in keyof Omit_]: Omit_[P] } 15 | : never; 16 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconFile.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 22 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/visual-question-answering/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/visual-question-answering/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Visual Question Answering task", 5 | "title": "VisualQuestionAnsweringOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "answer": { 11 | "type": "string", 12 | "description": "The answer to the question" 13 | }, 14 | "score": { 15 | "type": "number", 16 | "description": "The associated score / probability" 17 | } 18 | }, 19 | "required": ["label", "score"] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/agents/src/tools/speechToText.ts: -------------------------------------------------------------------------------- 1 | import type { Tool } from "../types"; 2 | 3 | export const speechToTextTool: Tool = { 4 | name: "speechToText", 5 | description: "Transcribe an audio file and returns its text content.", 6 | examples: [ 7 | { 8 | prompt: "Transcribe the sound file", 9 | code: "speechToText(audio)", 10 | tools: ["speechToText"], 11 | }, 12 | ], 13 | call: async (input, inference) => { 14 | const data = await input; 15 | if (typeof data === "string") throw "Input must be a blob."; 16 | 17 | return ( 18 | await inference.automaticSpeechRecognition( 19 | { 20 | data, 21 | }, 22 | { wait_for_model: true } 23 | ) 24 | ).text; 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconInfo.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 21 | -------------------------------------------------------------------------------- /packages/agents/src/types.d.ts: -------------------------------------------------------------------------------- 1 | import type { HfInference } from "@huggingface/inference"; 2 | 3 | export type Data = string | Blob | ArrayBuffer; 4 | 5 | export interface Tool { 6 | name: string; 7 | description: string; 8 | examples: Array; 9 | call?: (input: Promise, inference: HfInference) => Promise; 10 | } 11 | 12 | export interface Example { 13 | prompt: string; 14 | code: string; 15 | tools: string[]; 16 | inputs?: Inputs; 17 | } 18 | 19 | export interface Update { 20 | message: string; 21 | data: undefined | string | Blob; 22 | } 23 | 24 | export type Inputs = Partial>; 25 | 26 | export type LLM = (prompt: string) => Promise; 27 | -------------------------------------------------------------------------------- /packages/tasks/src/model-libraries-downloads.ts: -------------------------------------------------------------------------------- 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 } }; 21 | -------------------------------------------------------------------------------- /packages/hub/src/types/api/api-create-repo.d.ts: -------------------------------------------------------------------------------- 1 | import type { SetRequired } from "type-fest"; 2 | import type { SpaceHardwareFlavor, SpaceSdk } from "../public"; 3 | import type { ApiCommitFile } from "./api-commit"; 4 | 5 | export type ApiCreateRepoPayload = { 6 | name: string; 7 | canonical?: boolean; 8 | license?: string; 9 | template?: string; 10 | organization?: string; 11 | /** @default false */ 12 | private?: boolean; 13 | lfsmultipartthresh?: number; 14 | files?: SetRequired[]; 15 | } & ( 16 | | { 17 | type: Exclude; 18 | } 19 | | { 20 | type: "space"; 21 | hardware?: SpaceHardwareFlavor; 22 | sdk: SpaceSdk; 23 | sdkVersion?: string; 24 | } 25 | ); 26 | -------------------------------------------------------------------------------- /packages/hub/src/utils/promisesQueue.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Execute queue of promises. 3 | * 4 | * Inspired by github.com/rxaviers/async-pool 5 | */ 6 | export async function promisesQueue(factories: (() => Promise)[], concurrency: number): Promise { 7 | const results: T[] = []; 8 | const executing: Set> = new Set(); 9 | let index = 0; 10 | for (const factory of factories) { 11 | const closureIndex = index++; 12 | const e = factory().then((r) => { 13 | results[closureIndex] = r; 14 | executing.delete(e); 15 | }); 16 | executing.add(e); 17 | if (executing.size >= concurrency) { 18 | await Promise.race(executing); 19 | } 20 | } 21 | await Promise.all(executing); 22 | return results; 23 | } 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconCode.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 22 | -------------------------------------------------------------------------------- /packages/hub/src/lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./commit"; 2 | export * from "./create-repo"; 3 | export * from "./delete-file"; 4 | export * from "./delete-files"; 5 | export * from "./delete-repo"; 6 | export * from "./download-file"; 7 | export * from "./file-download-info"; 8 | export * from "./file-exists"; 9 | export * from "./list-datasets"; 10 | export * from "./list-files"; 11 | export * from "./list-models"; 12 | export * from "./list-spaces"; 13 | export * from "./oauth-handle-redirect"; 14 | export * from "./oauth-login-url"; 15 | export * from "./parse-safetensors-metadata"; 16 | export * from "./upload-file"; 17 | export * from "./upload-files"; 18 | export * from "./upload-files-with-progress"; 19 | export * from "./who-am-i"; 20 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconMaximize.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconMicrophone.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetShortcutRunLabel/WidgetShortcutRunLabel.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | {#if !isDisabled} 16 | 22 | {/if} 23 | -------------------------------------------------------------------------------- /docs/_toctree.yml: -------------------------------------------------------------------------------- 1 | - local: index 2 | title: 🤗 Hugging Face JS Libraries 3 | - title: "@huggingface/inference" 4 | isExpanded: true 5 | sections: 6 | - local: inference/README 7 | title: Use Inference Endpoints 8 | - local: inference/modules 9 | title: API reference 10 | - title: "@huggingface/hub" 11 | isExpanded: true 12 | sections: 13 | - local: hub/README 14 | title: Interact with the Hub 15 | - local: hub/modules 16 | title: API Reference 17 | - title: "@huggingface/agent" 18 | isExpanded: true 19 | sections: 20 | - local: agents/README 21 | title: Use Agents to run multi-modal workflows from a natural language API 22 | - local: agents/modules 23 | title: API Reference 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconQuestionAnswering.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 14 | 15 | 16 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /e2e/svelte/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myapp", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "dev": "vite dev", 7 | "build": "vite build", 8 | "preview": "vite preview", 9 | "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", 10 | "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" 11 | }, 12 | "devDependencies": { 13 | "@sveltejs/adapter-auto": "^2.0.0", 14 | "@sveltejs/kit": "^1.5.0", 15 | "svelte": "^3.54.0", 16 | "svelte-check": "^3.0.1", 17 | "tslib": "^2.4.1", 18 | "typescript": "^5.0.0", 19 | "vite": "^4.3.0" 20 | }, 21 | "type": "module", 22 | "dependencies": { 23 | "@huggingface/inference": "*", 24 | "@huggingface/hub": "*" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconAudioClassification.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 22 | -------------------------------------------------------------------------------- /e2e/svelte/svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from "@sveltejs/adapter-auto"; 2 | import { vitePreprocess } from "@sveltejs/kit/vite"; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | // Consult https://kit.svelte.dev/docs/integrations#preprocessors 7 | // for more information about preprocessors 8 | preprocess: vitePreprocess(), 9 | 10 | kit: { 11 | // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. 12 | // If your environment is not supported or you settled on a specific environment, switch out the adapter. 13 | // See https://kit.svelte.dev/docs/adapters for more information about adapters. 14 | adapter: adapter(), 15 | }, 16 | }; 17 | 18 | export default config; 19 | -------------------------------------------------------------------------------- /packages/hub/src/utils/chunk.ts: -------------------------------------------------------------------------------- 1 | import { range } from "./range"; 2 | 3 | /** 4 | * Chunk array into arrays of length at most `chunkSize` 5 | * 6 | * @param chunkSize must be greater than or equal to 1 7 | */ 8 | export function chunk(arr: T, chunkSize: number): T[] { 9 | if (isNaN(chunkSize) || chunkSize < 1) { 10 | throw new RangeError("Invalid chunk size: " + chunkSize); 11 | } 12 | 13 | if (!arr.length) { 14 | return []; 15 | } 16 | 17 | /// Small optimization to not chunk buffers unless needed 18 | if (arr.length <= chunkSize) { 19 | return [arr]; 20 | } 21 | 22 | return range(Math.ceil(arr.length / chunkSize)).map((i) => { 23 | return arr.slice(i * chunkSize, (i + 1) * chunkSize); 24 | }) as T[]; 25 | } 26 | -------------------------------------------------------------------------------- /packages/widgets/svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from "@sveltejs/adapter-node"; 2 | import { vitePreprocess } from "@sveltejs/kit/vite"; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | // Consult https://kit.svelte.dev/docs/integrations#preprocessors 7 | // for more information about preprocessors 8 | preprocess: vitePreprocess(), 9 | 10 | kit: { 11 | // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. 12 | // If your environment is not supported or you settled on a specific environment, switch out the adapter. 13 | // See https://kit.svelte.dev/docs/adapters for more information about adapters. 14 | adapter: adapter(), 15 | }, 16 | }; 17 | 18 | export default config; 19 | -------------------------------------------------------------------------------- /packages/doc-internal/fix-md-links.ts: -------------------------------------------------------------------------------- 1 | import { readFileSync, writeFileSync } from "fs"; 2 | import glob from "glob"; 3 | import { join } from "path"; 4 | 5 | for (const mdFile of await glob("**/*.md", { cwd: "../../docs" })) { 6 | console.log(mdFile); 7 | const content = readFileSync(join("../../docs", mdFile)).toString(); 8 | writeFileSync( 9 | join("../../docs", mdFile), 10 | content 11 | // Fix MD links 12 | .replaceAll(/\([^)]+\.md\b(#[^)]+)?\)/g, (val) => val.replace(".md", "")) 13 | // Fix links of main page 14 | .replaceAll(/\(packages\/[^)]+\)/g, (val) => val.replace("packages/", "")) 15 | // When on HF, remove links to HF 16 | .replaceAll(/.*\[full documentation\].*\n\n/g, "") 17 | ); 18 | } 19 | 20 | // (modules.md#imagesegmentationreturnvalue) 21 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetCheckbox/WidgetCheckbox.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /packages/doc-internal/fix-cdn-versions.ts: -------------------------------------------------------------------------------- 1 | import { readFileSync, writeFileSync } from "fs"; 2 | 3 | const hubPackage = JSON.parse(readFileSync("../hub/package.json").toString()); 4 | const inferencePackage = JSON.parse(readFileSync("../inference/package.json").toString()); 5 | 6 | for (const readme of ["../../README.md", "../../packages/hub/README.md", "../../packages/inference/README.md"]) { 7 | let content = readFileSync(readme, "utf-8"); 8 | 9 | content = content.replace( 10 | /@huggingface[/]inference@\d+([.]\d+)?([.]\d+)?/g, 11 | `@huggingface/inference@${inferencePackage.version}` 12 | ); 13 | content = content.replace(/@huggingface[/]hub@\d+([.]\d+)?([.]\d+)?/g, `@huggingface/hub@${hubPackage.version}`); 14 | 15 | writeFileSync(readme, Buffer.from(content)); 16 | } 17 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetState/WidgetState.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 |
7 |
8 | This model is currently loaded and running on Inference API (serverless). 9 |
10 |
11 | ⚠️ This model could not be loaded in Inference API (serverless). ⚠️ 12 |
13 |
14 | This model can be loaded in Inference API (serverless). 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /packages/languages/README.md: -------------------------------------------------------------------------------- 1 | # 🤗 Hugging Face Languages.js 2 | 3 | The list of all languages supported by the huggingface hub. 4 | 5 | ## Install 6 | 7 | ```console 8 | pnpm add @huggingface/languages 9 | 10 | npm add @huggingface/languages 11 | 12 | yarn add @huggingface/languages 13 | ``` 14 | 15 | ### Deno 16 | 17 | ```ts 18 | // esm.sh 19 | import { language, wikiLink, type Language } from "https://esm.sh/@huggingface/languages" 20 | // or npm: 21 | import { language, wikiLink, type Language } from "npm:@huggingface/languages" 22 | ``` 23 | 24 | Check out the [full documentation](https://huggingface.co/docs/huggingface.js/languages/README). 25 | 26 | Acknowledging Loïck Bourdois (https://github.com/lbourdois)'s help with this package and more generally supporting languages on the HF Hub. 27 | -------------------------------------------------------------------------------- /packages/languages/src/language.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | import { language } from "./language"; 3 | 4 | describe("language", () => { 5 | it("should return an object for a 2-letter language code", () => { 6 | expect(language("en")).toMatchObject({ 7 | code: "en", 8 | name: "English", 9 | nativeName: "English", 10 | }); 11 | }); 12 | 13 | it("should return an object for a 3-letter language code", () => { 14 | expect(language("eng")).toMatchObject({ 15 | code: "eng", 16 | name: "English", 17 | }); 18 | 19 | expect(language("fra")).toMatchObject({ 20 | code: "fra", 21 | name: "French", 22 | }); 23 | }); 24 | 25 | it("should return null for an invalid language code", () => { 26 | expect(language("invalid")).toBeNull(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/depth-estimation/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/depth-estimation/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Depth Estimation inference", 5 | "title": "DepthEstimationInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input image data" 10 | }, 11 | "parameters": { 12 | "description": "Additional inference parameters", 13 | "$ref": "#/$defs/DepthEstimationParameters" 14 | } 15 | }, 16 | "$defs": { 17 | "DepthEstimationParameters": { 18 | "title": "DepthEstimationParameters", 19 | "description": "Additional inference parameters for Depth Estimation", 20 | "type": "object", 21 | "properties": {} 22 | } 23 | }, 24 | "required": ["inputs"] 25 | } 26 | -------------------------------------------------------------------------------- /packages/hub/src/utils/promisesQueueStreaming.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Execute queue of promises in a streaming fashion. 3 | * 4 | * Optimized for streaming: 5 | * - Expects an iterable as input 6 | * - Does not return a list of all results 7 | * 8 | * Inspired by github.com/rxaviers/async-pool 9 | */ 10 | export async function promisesQueueStreaming( 11 | factories: AsyncIterable<() => Promise> | Iterable<() => Promise>, 12 | concurrency: number 13 | ): Promise { 14 | const executing: Promise[] = []; 15 | for await (const factory of factories) { 16 | const e = factory().then(() => { 17 | executing.splice(executing.indexOf(e), 1); 18 | }); 19 | executing.push(e); 20 | if (executing.length >= concurrency) { 21 | await Promise.race(executing); 22 | } 23 | } 24 | await Promise.all(executing); 25 | } 26 | -------------------------------------------------------------------------------- /packages/agents/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | '@huggingface/inference': 9 | specifier: ^2.6.1 10 | version: link:../inference 11 | 12 | devDependencies: 13 | '@types/node': 14 | specifier: ^18.13.0 15 | version: 18.13.0 16 | type-fest: 17 | specifier: ^3.9.0 18 | version: 3.9.0 19 | 20 | packages: 21 | 22 | /@types/node@18.13.0: 23 | resolution: {integrity: sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==} 24 | dev: true 25 | 26 | /type-fest@3.9.0: 27 | resolution: {integrity: sha512-hR8JP2e8UiH7SME5JZjsobBlEiatFoxpzCP+R3ZeCo7kAaG1jXQE5X/buLzogM6GJu8le9Y4OcfNuIQX0rZskA==} 28 | engines: {node: '>=14.16'} 29 | dev: true 30 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/image-segmentation/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/image-segmentation/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Image Segmentation task", 5 | "title": "ImageSegmentationOutput", 6 | "type": "array", 7 | "items": { 8 | "description": "A predicted mask / segment", 9 | "type": "object", 10 | "properties": { 11 | "label": { 12 | "type": "string", 13 | "description": "The label of the predicted segment" 14 | }, 15 | "mask": { 16 | "description": "The corresponding mask as a black-and-white image" 17 | }, 18 | "score": { 19 | "type": "number", 20 | "description": "The score or confidence degreee the model has" 21 | } 22 | }, 23 | "required": ["label", "mask"] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconReinforcementLearning.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconUnconditionalImageGeneration.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /packages/agents/src/tools/textToImage.ts: -------------------------------------------------------------------------------- 1 | import type { Tool } from "../types"; 2 | 3 | export const textToImageTool: Tool = { 4 | name: "textToImage", 5 | description: "Generate an image from a text prompt.", 6 | examples: [ 7 | { 8 | prompt: "Generate an image of a cat wearing a top hat", 9 | code: "textToImage('cat wearing a top hat')", 10 | tools: ["textToImage"], 11 | }, 12 | { 13 | prompt: "Draw a brown dog on a beach", 14 | code: "textToImage('drawing of a brown dog on a beach')", 15 | tools: ["textToImage"], 16 | }, 17 | ], 18 | call: async (input, inference) => { 19 | const data = await input; 20 | if (typeof data !== "string") throw "Input must be a string."; 21 | 22 | return await inference.textToImage( 23 | { 24 | inputs: data, 25 | }, 26 | { wait_for_model: true } 27 | ); 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /packages/inference/test/vitest.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | // https://vitest.dev/guide/extending-matchers 3 | import "vitest"; 4 | 5 | interface MatcherResult { 6 | pass: boolean; 7 | message: () => string; 8 | // If you pass these, they will automatically appear inside a diff when 9 | // the matcher does not pass, so you don't need to print the diff yourself 10 | actual?: unknown; 11 | expected?: unknown; 12 | } 13 | 14 | interface CustomMatchers { 15 | closeTo(expected: number, precision: number): MatcherResult; 16 | } 17 | 18 | declare module "vitest" { 19 | // eslint-disable-next-line @typescript-eslint/no-empty-interface 20 | interface Assertion extends CustomMatchers {} 21 | // eslint-disable-next-line @typescript-eslint/no-empty-interface 22 | interface AsymmetricMatchersContaining extends CustomMatchers {} 23 | } 24 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/depth-estimation/inference.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Inference code generated from the JSON schema spec in ./spec 3 | * 4 | * Using src/scripts/inference-codegen 5 | */ 6 | 7 | /** 8 | * Inputs for Depth Estimation inference 9 | */ 10 | export interface DepthEstimationInput { 11 | /** 12 | * The input image data 13 | */ 14 | inputs: unknown; 15 | /** 16 | * Additional inference parameters 17 | */ 18 | parameters?: { [key: string]: unknown }; 19 | [property: string]: unknown; 20 | } 21 | 22 | /** 23 | * Outputs of inference for the Depth Estimation task 24 | */ 25 | export interface DepthEstimationOutput { 26 | /** 27 | * The predicted depth as an image 28 | */ 29 | depth?: unknown; 30 | /** 31 | * The predicted depth as a tensor 32 | */ 33 | predicted_depth?: unknown; 34 | [property: string]: unknown; 35 | } 36 | -------------------------------------------------------------------------------- /packages/inference/vitest.config.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vitest/config"; 2 | import { readFileSync } from "node:fs"; 3 | import { join } from "node:path"; 4 | 5 | // make local test files available in browser by preloading their contents 6 | const testFilesToPreload = [ 7 | "cheetah.png", 8 | "cats.png", 9 | "sample1.flac", 10 | "invoice.png", 11 | "stormtrooper_depth.png", 12 | "bird_canny.png", 13 | ]; 14 | const testFilesContents: Record = {}; 15 | for (const filename of testFilesToPreload) { 16 | testFilesContents[filename] = readFileSync(join(__dirname, "test", filename)).toString("base64"); 17 | } 18 | 19 | export default defineConfig({ 20 | test: { 21 | setupFiles: ["./test/expect-closeto.ts"], 22 | }, 23 | envPrefix: ["HF_", "VCR_"], 24 | define: { 25 | __TEST_FILES__: JSON.stringify(testFilesContents), 26 | }, 27 | }); 28 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/feature-extraction/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/feature-extraction/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Text Embedding inference", 5 | "title": "FeatureExtractionInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The text to get the embeddings of", 10 | "type": "string" 11 | }, 12 | "parameters": { 13 | "description": "Additional inference parameters", 14 | "$ref": "#/$defs/FeatureExtractionParameters" 15 | } 16 | }, 17 | "$defs": { 18 | "FeatureExtractionParameters": { 19 | "title": "FeatureExtractionParameters", 20 | "description": "Additional inference parameters for Feature Extraction", 21 | "type": "object", 22 | "properties": {} 23 | } 24 | }, 25 | "required": ["inputs"] 26 | } 27 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconMagicWand.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageClassification.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageToVideo.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 13 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTextTo3D.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageSegmentation.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 25 | -------------------------------------------------------------------------------- /packages/hub/src/utils/sha256-node.ts: -------------------------------------------------------------------------------- 1 | import { Readable } from "node:stream"; 2 | import type { ReadableStream } from "node:stream/web"; 3 | import { createHash } from "node:crypto"; 4 | 5 | export async function* sha256Node( 6 | buffer: ArrayBuffer | Blob, 7 | opts?: { 8 | abortSignal?: AbortSignal; 9 | } 10 | ): AsyncGenerator { 11 | const sha256Stream = createHash("sha256"); 12 | const size = buffer instanceof Blob ? buffer.size : buffer.byteLength; 13 | let done = 0; 14 | const readable = 15 | buffer instanceof Blob ? Readable.fromWeb(buffer.stream() as ReadableStream) : Readable.from(Buffer.from(buffer)); 16 | 17 | for await (const buffer of readable) { 18 | sha256Stream.update(buffer); 19 | done += buffer.length; 20 | yield done / size; 21 | 22 | opts?.abortSignal?.throwIfAborted(); 23 | } 24 | 25 | return sha256Stream.digest("hex"); 26 | } 27 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetRadio/WidgetRadio.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /packages/agents/src/tools/textToSpeech.ts: -------------------------------------------------------------------------------- 1 | import type { Tool } from "../types"; 2 | 3 | export const textToSpeechTool: Tool = { 4 | name: "textToSpeech", 5 | description: "This tool takes a text input and turns it into an audio file.", 6 | examples: [ 7 | { 8 | prompt: 'Say the following out loud:"Hello world!"', 9 | code: "textToSpeech('Hello world!')", 10 | tools: ["textToSpeech"], 11 | }, 12 | { 13 | prompt: "Say the content of the string txt out loud", 14 | code: "textToSpeech(txt)", 15 | tools: ["textToSpeech"], 16 | }, 17 | ], 18 | call: async (input, inference) => { 19 | const data = await input; 20 | if (typeof data !== "string") throw "Input must be a string."; 21 | 22 | return inference.textToSpeech( 23 | { 24 | inputs: data, 25 | model: "espnet/kan-bayashi_ljspeech_vits", 26 | }, 27 | { wait_for_model: true } 28 | ); 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/hub/src/lib/file-exists.spec.ts: -------------------------------------------------------------------------------- 1 | import { assert, it, describe } from "vitest"; 2 | import { fileExists } from "./file-exists"; 3 | 4 | describe("fileExists", () => { 5 | it("should return true for file that exists", async () => { 6 | const info = await fileExists({ 7 | repo: { 8 | name: "bert-base-uncased", 9 | type: "model", 10 | }, 11 | path: "tf_model.h5", 12 | revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7", 13 | }); 14 | 15 | assert(info, "file should exist"); 16 | }); 17 | 18 | it("should return false for file that does not exist", async () => { 19 | const info = await fileExists({ 20 | repo: { 21 | name: "bert-base-uncased", 22 | type: "model", 23 | }, 24 | path: "tf_model.h5dadazdzazd", 25 | revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7", 26 | }); 27 | 28 | assert(!info, "file should not exist"); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTextToImage.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /.github/workflows/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Build documentation 2 | 3 | on: 4 | workflow_dispatch: 5 | repository_dispatch: 6 | types: [doc-build] 7 | push: 8 | branches: 9 | - main 10 | paths: 11 | - "README.md" 12 | - "packages/hub/README.md" 13 | - "packages/inference/README.md" 14 | - "packages/agents/README.md" 15 | - ".github/workflows/documentation.yml" 16 | 17 | jobs: 18 | build: 19 | uses: huggingface/doc-builder/.github/workflows/build_main_documentation.yml@main 20 | with: 21 | commit_sha: ${{ github.sha }} 22 | package: huggingface.js 23 | path_to_docs: huggingface.js/docs 24 | additional_args: --not_python_module 25 | pre_command: corepack enable && cd huggingface.js && pnpm install && pnpm -r build && pnpm --filter doc-internal start 26 | secrets: 27 | hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }} 28 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconSpin.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 31 | -------------------------------------------------------------------------------- /.github/workflows/pr-documentation.yml: -------------------------------------------------------------------------------- 1 | name: Build PR Documentation 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - "README.md" 7 | - "docs/**" 8 | - "packages/hub/README.md" 9 | - "packages/doc-internal/**" 10 | - "packages/inference/README.md" 11 | - "packages/agents/README.md" 12 | 13 | concurrency: 14 | group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} 15 | cancel-in-progress: true 16 | 17 | jobs: 18 | build: 19 | uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@main 20 | with: 21 | commit_sha: ${{ github.sha }} 22 | pr_number: ${{ github.event.number }} 23 | package: huggingface.js 24 | path_to_docs: huggingface.js/docs 25 | pre_command: corepack enable && cd huggingface.js && pnpm install && pnpm -r build && pnpm --filter doc-internal start 26 | additional_args: --not_python_module 27 | -------------------------------------------------------------------------------- /packages/tasks/src/tokenizer-data.ts: -------------------------------------------------------------------------------- 1 | export const SPECIAL_TOKENS_ATTRIBUTES = [ 2 | "bos_token", 3 | "eos_token", 4 | "unk_token", 5 | "sep_token", 6 | "pad_token", 7 | "cls_token", 8 | "mask_token", 9 | // additional_special_tokens (TODO) 10 | ] as const; 11 | 12 | /** 13 | * Public interface for a tokenizer's special tokens mapping 14 | */ 15 | export interface AddedToken { 16 | __type: "AddedToken"; 17 | content?: string; 18 | lstrip?: boolean; 19 | normalized?: boolean; 20 | rstrip?: boolean; 21 | single_word?: boolean; 22 | } 23 | export type SpecialTokensMap = { 24 | [key in (typeof SPECIAL_TOKENS_ATTRIBUTES)[number]]?: string | AddedToken | null; 25 | }; 26 | /** 27 | * Public interface for tokenizer config 28 | */ 29 | export interface TokenizerConfig extends SpecialTokensMap { 30 | use_default_system_prompt?: boolean; 31 | chat_template?: string | Array<{ name: string; template: string }>; 32 | } 33 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageFeatureExtraction.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/fill-mask/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/fill-mask/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Fill Mask task", 5 | "title": "FillMaskOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "sequence": { 11 | "type": "string", 12 | "description": "The corresponding input with the mask token prediction." 13 | }, 14 | "score": { 15 | "type": "number", 16 | "description": "The corresponding probability" 17 | }, 18 | "token": { 19 | "type": "integer", 20 | "description": "The predicted token id (to replace the masked one)." 21 | }, 22 | "token_str": { 23 | "type": "string", 24 | "description": "The predicted token (to replace the masked one)." 25 | } 26 | }, 27 | "required": ["sequence", "score", "token", "tokenStr"] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageToImage.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /packages/hub/src/lib/who-am-i.spec.ts: -------------------------------------------------------------------------------- 1 | import { assert, it, describe } from "vitest"; 2 | import { TEST_ACCESS_TOKEN, TEST_HUB_URL } from "../test/consts"; 3 | import { whoAmI } from "./who-am-i"; 4 | 5 | describe("whoAmI", () => { 6 | it("should fetch identity info", async () => { 7 | const info = await whoAmI({ credentials: { accessToken: TEST_ACCESS_TOKEN }, hubUrl: TEST_HUB_URL }); 8 | 9 | assert.deepStrictEqual(info, { 10 | type: "user", 11 | id: "62f264b9f3c90f4b6514a269", 12 | name: "hub.js", 13 | fullname: "@huggingface/hub CI bot", 14 | email: "eliott@huggingface.co", 15 | emailVerified: true, 16 | canPay: false, 17 | isPro: false, 18 | periodEnd: null, 19 | avatarUrl: "/avatars/934b830e9fdaa879487852f79eef7165.svg", 20 | orgs: [], 21 | auth: { 22 | type: "access_token", 23 | accessToken: { 24 | displayName: "ci-hub.js", 25 | role: "write", 26 | }, 27 | }, 28 | }); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconObjectDetection.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /packages/widgets/src/routes/[...model]/+page.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | ← Back to index 9 | 10 | 11 |
12 | {#if data.model} 13 |
14 | 15 | {data.model.id} 16 | 17 |
18 | 19 |
20 |
21 | 22 |
23 | 			{JSON.stringify(data.model, null, 2)}
24 | 		
25 | {:else} 26 |
Error. Probably non existent model. {data.message}
27 | {/if} 28 |
29 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/object-detection/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/object-detection/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Object Detection inference", 5 | "title": "ObjectDetectionInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input image data" 10 | }, 11 | "parameters": { 12 | "description": "Additional inference parameters", 13 | "$ref": "#/$defs/ObjectDetectionParameters" 14 | } 15 | }, 16 | "$defs": { 17 | "ObjectDetectionParameters": { 18 | "title": "ObjectDetectionParameters", 19 | "description": "Additional inference parameters for Object Detection", 20 | "type": "object", 21 | "properties": { 22 | "threshold": { 23 | "type": "number", 24 | "description": "The probability necessary to make a prediction." 25 | } 26 | } 27 | } 28 | }, 29 | "required": ["inputs"] 30 | } 31 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/question-answering/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/question-answering/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "title": "QuestionAnsweringOutput", 5 | "description": "Outputs of inference for the Question Answering task", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "answer": { 11 | "type": "string", 12 | "description": "The answer to the question." 13 | }, 14 | "score": { 15 | "type": "number", 16 | "description": "The probability associated to the answer." 17 | }, 18 | "start": { 19 | "type": "integer", 20 | "description": "The character position in the input where the answer begins." 21 | }, 22 | "end": { 23 | "type": "integer", 24 | "description": "The character position in the input where the answer ends." 25 | } 26 | }, 27 | "required": ["answer", "score", "start", "end"] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageTo3D.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 27 | -------------------------------------------------------------------------------- /packages/inference/src/tasks/audio/textToSpeech.ts: -------------------------------------------------------------------------------- 1 | import { InferenceOutputError } from "../../lib/InferenceOutputError"; 2 | import type { BaseArgs, Options } from "../../types"; 3 | import { request } from "../custom/request"; 4 | 5 | export type TextToSpeechArgs = BaseArgs & { 6 | /** 7 | * The text to generate an audio from 8 | */ 9 | inputs: string; 10 | }; 11 | 12 | export type TextToSpeechOutput = Blob; 13 | 14 | /** 15 | * This task synthesize an audio of a voice pronouncing a given text. 16 | * Recommended model: espnet/kan-bayashi_ljspeech_vits 17 | */ 18 | export async function textToSpeech(args: TextToSpeechArgs, options?: Options): Promise { 19 | const res = await request(args, { 20 | ...options, 21 | taskHint: "text-to-speech", 22 | }); 23 | const isValidOutput = res && res instanceof Blob; 24 | if (!isValidOutput) { 25 | throw new InferenceOutputError("Expected Blob"); 26 | } 27 | return res; 28 | } 29 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/sentence-similarity/inference.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Inference code generated from the JSON schema spec in ./spec 3 | * 4 | * Using src/scripts/inference-codegen 5 | */ 6 | 7 | export type SentenceSimilarityOutput = number[]; 8 | 9 | /** 10 | * Inputs for Sentence similarity inference 11 | */ 12 | export interface SentenceSimilarityInput { 13 | inputs: SentenceSimilarityInputData; 14 | /** 15 | * Additional inference parameters 16 | */ 17 | parameters?: { [key: string]: unknown }; 18 | [property: string]: unknown; 19 | } 20 | 21 | export interface SentenceSimilarityInputData { 22 | /** 23 | * A list of strings which will be compared against the source_sentence. 24 | */ 25 | sentences: string[]; 26 | /** 27 | * The string that you wish to compare the other strings with. This can be a phrase, 28 | * sentence, or longer passage, depending on the model being used. 29 | */ 30 | sourceSentence: string; 31 | [property: string]: unknown; 32 | } 33 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetTimer/WidgetTimer.svelte: -------------------------------------------------------------------------------- 1 | 32 | 33 | {#if shouldDisplay && !isDisabled} 34 | {counterHuman} 35 | {/if} 36 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconSentenceSimilarity.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /e2e/ts/src/index.ts: -------------------------------------------------------------------------------- 1 | import { HfInference } from "@huggingface/inference"; 2 | import { whoAmI } from "@huggingface/hub"; 3 | 4 | const hfToken = process.env.token; 5 | 6 | const hf = new HfInference(hfToken); 7 | 8 | (async () => { 9 | const info = await whoAmI({ credentials: { accessToken: "hf_hub.js" }, hubUrl: "https://hub-ci.huggingface.co" }); 10 | console.log(info); 11 | 12 | const sum = await hf.summarization({ 13 | model: "facebook/bart-large-cnn", 14 | inputs: 15 | "The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930.", 16 | parameters: { 17 | max_length: 100, 18 | }, 19 | }); 20 | 21 | console.log(sum); 22 | })(); 23 | -------------------------------------------------------------------------------- /packages/agents/src/lib/generateCode.ts: -------------------------------------------------------------------------------- 1 | import type { Tool } from "../types"; 2 | 3 | import { generatePrompt } from "./promptGeneration"; 4 | import { messageTool } from "../tools/message"; 5 | 6 | export async function generateCode( 7 | prompt: string, 8 | tools: Tool[], 9 | files: FileList | undefined, 10 | llm: (input: string) => Promise 11 | ): Promise { 12 | const fullprompt = generatePrompt(prompt, [...tools, messageTool], { 13 | image: !!files && files[0].type.startsWith("image"), 14 | audio: !!files && files[0].type.startsWith("audio"), 15 | }); 16 | 17 | const textAnswer = await llm(fullprompt); 18 | 19 | try { 20 | const regex = /```(.*?)```/gs; 21 | const matches = [...textAnswer.matchAll(regex)]; 22 | 23 | const codeBlocks = matches.map((match) => match[1]); 24 | return codeBlocks[0].replace("js", "").replace("javascript", "").trim() ?? "nothing"; 25 | } catch { 26 | throw new Error("The generated text doesn't contain any code blocks."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/hub/src/utils/createBlob.ts: -------------------------------------------------------------------------------- 1 | import { isFrontend } from "../../../shared"; 2 | import { WebBlob } from "./WebBlob"; 3 | 4 | /** 5 | * This function allow to retrieve either a FileBlob or a WebBlob from a URL. 6 | * 7 | * From the backend: 8 | * - support local files 9 | * - support http resources with absolute URLs 10 | * 11 | * From the frontend: 12 | * - support http resources with absolute or relative URLs 13 | */ 14 | export async function createBlob(url: URL, opts?: { fetch?: typeof fetch }): Promise { 15 | if (url.protocol === "http:" || url.protocol === "https:") { 16 | return WebBlob.create(url, { fetch: opts?.fetch }); 17 | } 18 | 19 | if (isFrontend) { 20 | throw new TypeError(`Unsupported URL protocol "${url.protocol}"`); 21 | } 22 | 23 | if (url.protocol === "file:") { 24 | const { FileBlob } = await import("./FileBlob"); 25 | 26 | return FileBlob.create(url); 27 | } 28 | 29 | throw new TypeError(`Unsupported URL protocol "${url.protocol}"`); 30 | } 31 | -------------------------------------------------------------------------------- /packages/inference/src/tasks/cv/imageToText.ts: -------------------------------------------------------------------------------- 1 | import { InferenceOutputError } from "../../lib/InferenceOutputError"; 2 | import type { BaseArgs, Options } from "../../types"; 3 | import { request } from "../custom/request"; 4 | 5 | export type ImageToTextArgs = BaseArgs & { 6 | /** 7 | * Binary image data 8 | */ 9 | data: Blob | ArrayBuffer; 10 | }; 11 | 12 | export interface ImageToTextOutput { 13 | /** 14 | * The generated caption 15 | */ 16 | generated_text: string; 17 | } 18 | 19 | /** 20 | * This task reads some image input and outputs the text caption. 21 | */ 22 | export async function imageToText(args: ImageToTextArgs, options?: Options): Promise { 23 | const res = ( 24 | await request<[ImageToTextOutput]>(args, { 25 | ...options, 26 | taskHint: "image-to-text", 27 | }) 28 | )?.[0]; 29 | 30 | if (typeof res?.generated_text !== "string") { 31 | throw new InferenceOutputError("Expected {generated_text: string}"); 32 | } 33 | 34 | return res; 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "packageManager": "pnpm@8.10.5", 4 | "scripts": { 5 | "lint": "eslint --quiet --fix --ext .cjs,.ts .eslintrc.cjs", 6 | "lint:check": "eslint --ext .cjs,.ts .eslintrc.cjs", 7 | "format": "prettier --write package.json .prettierrc .vscode .eslintrc.cjs e2e .github *.md", 8 | "format:check": "prettier --check package.json .prettierrc .vscode .eslintrc.cjs .github *.md" 9 | }, 10 | "devDependencies": { 11 | "@typescript-eslint/eslint-plugin": "^7.2.0", 12 | "@typescript-eslint/parser": "^7.2.0", 13 | "@vitest/browser": "^0.34.6", 14 | "eslint": "^8.57.0", 15 | "eslint-config-prettier": "^9.0.0", 16 | "eslint-plugin-prettier": "^4.2.1", 17 | "eslint-plugin-svelte": "^2.30.0", 18 | "prettier": "^3.1.0", 19 | "prettier-plugin-svelte": "^3.1.2", 20 | "semver": "^7.5.0", 21 | "tsup": "^6.7.0", 22 | "tsx": "^4.7.0", 23 | "typescript": "^5.4.2", 24 | "vite": "^5.0.2", 25 | "vitest": "^0.34.6", 26 | "webdriverio": "^8.6.7" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-to-audio/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/text-to-audio/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Text To Audio inference", 5 | "title": "TextToAudioInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input text data", 10 | "type": "string" 11 | }, 12 | "parameters": { 13 | "description": "Additional inference parameters", 14 | "$ref": "#/$defs/TextToAudioParameters" 15 | } 16 | }, 17 | "$defs": { 18 | "TextToAudioParameters": { 19 | "title": "TextToAudioParameters", 20 | "description": "Additional inference parameters for Text To Audio", 21 | "type": "object", 22 | "properties": { 23 | "generate": { 24 | "description": "Parametrization of the text generation process", 25 | "$ref": "/inference/schemas/common-definitions.json#/definitions/GenerationParameters" 26 | } 27 | } 28 | } 29 | }, 30 | "required": ["inputs"] 31 | } 32 | -------------------------------------------------------------------------------- /e2e/deno/index.ts: -------------------------------------------------------------------------------- 1 | import { HfInference } from "npm:@huggingface/inference@*"; 2 | import { whoAmI, listFiles } from "npm:@huggingface/hub@*"; 3 | 4 | const hf = new HfInference(); 5 | 6 | const info = await whoAmI({ credentials: { accessToken: "hf_hub.js" }, hubUrl: "https://hub-ci.huggingface.co" }); 7 | console.log(info); 8 | 9 | for await (const file of listFiles({ credentials: { accessToken: "hf_hub.js" }, repo: "gpt2" })) { 10 | console.log(file); 11 | } 12 | 13 | const sum = await hf.summarization({ 14 | model: "facebook/bart-large-cnn", 15 | inputs: 16 | "The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930.", 17 | parameters: { 18 | max_length: 100, 19 | }, 20 | }); 21 | 22 | console.log(sum); 23 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTextToVideo.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconSummarization.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/token-classification/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/token-classification/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Token Classification task", 5 | "title": "TokenClassificationOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "entity_group": { 11 | "type": "string", 12 | "description": "The predicted label for that group of tokens" 13 | }, 14 | "score": { 15 | "type": "number", 16 | "description": "The associated score / probability" 17 | }, 18 | "word": { 19 | "type": "string", 20 | "description": "The corresponding text" 21 | }, 22 | "start": { 23 | "type": "integer", 24 | "description": "The character position in the input where this group begins." 25 | }, 26 | "end": { 27 | "type": "integer", 28 | "description": "The character position in the input where this group ends." 29 | } 30 | }, 31 | "required": ["label", "score"] 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/inference/test/expect-closeto.ts: -------------------------------------------------------------------------------- 1 | // https://github.com/vitest-dev/vitest/pull/4260 2 | // this file can be removed after vitest update to 1.0 3 | 4 | import { expect } from "vitest"; 5 | 6 | expect.extend({ 7 | closeTo(received: number, expected: number, precision: number) { 8 | const { isNot } = this; 9 | let pass = false; 10 | let expectedDiff = 0; 11 | let receivedDiff = 0; 12 | 13 | if (received === Infinity && expected === Infinity) { 14 | pass = true; 15 | } else if (received === -Infinity && expected === -Infinity) { 16 | pass = true; 17 | } else { 18 | expectedDiff = 10 ** -precision / 2; 19 | receivedDiff = Math.abs(expected - received); 20 | pass = receivedDiff < expectedDiff; 21 | } 22 | 23 | return { 24 | pass, 25 | message: () => 26 | isNot 27 | ? `expected ${received} to not be close to ${expected}, received difference is ${receivedDiff}, but expected ${expectedDiff}` 28 | : `expected ${received} to be close to ${expected}, received difference is ${receivedDiff}, but expected ${expectedDiff}`, 29 | }; 30 | }, 31 | }); 32 | -------------------------------------------------------------------------------- /e2e/svelte/README.md: -------------------------------------------------------------------------------- 1 | # create-svelte 2 | 3 | Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). 4 | 5 | ## Creating a project 6 | 7 | If you're seeing this, you've probably already done this step. Congrats! 8 | 9 | ```bash 10 | # create a new project in the current directory 11 | npm create svelte@latest 12 | 13 | # create a new project in my-app 14 | npm create svelte@latest my-app 15 | ``` 16 | 17 | ## Developing 18 | 19 | Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: 20 | 21 | ```bash 22 | npm run dev 23 | 24 | # or start the server and open the app in a new browser tab 25 | npm run dev -- --open 26 | ``` 27 | 28 | ## Building 29 | 30 | To create a production version of your app: 31 | 32 | ```bash 33 | npm run build 34 | ``` 35 | 36 | You can preview the production build with `npm run preview`. 37 | 38 | > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. 39 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/placeholder/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas//input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for inference", 5 | "title": "PlaceholderInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "TODO: describe the input here. This must be model & framework agnostic.", 10 | "type": "string" 11 | }, 12 | "parameters": { 13 | "description": "Additional inference parameters", 14 | "$ref": "#/$defs/Parameters" 15 | } 16 | }, 17 | "$defs": { 18 | "Parameters": { 19 | "title": "Parameters", 20 | "description": "TODO: describe additional parameters here.", 21 | "type": "object", 22 | "properties": { 23 | "dummy_parameter_name": { 24 | "type": "boolean", 25 | "description": "TODO: describe the parameter here" 26 | }, 27 | "dummy_parameter_name2": { 28 | "type": "integer", 29 | "description": "TODO: describe the parameter here" 30 | } 31 | } 32 | } 33 | }, 34 | "required": ["inputs"] 35 | } 36 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/image-to-text/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/image-to-text/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Image To Text inference", 5 | "title": "ImageToTextInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input image data" 10 | }, 11 | "parameters": { 12 | "description": "Additional inference parameters", 13 | "$ref": "#/$defs/ImageToTextParameters" 14 | } 15 | }, 16 | "$defs": { 17 | "ImageToTextParameters": { 18 | "title": "ImageToTextParameters", 19 | "description": "Additional inference parameters for Image To Text", 20 | "type": "object", 21 | "properties": { 22 | "max_new_tokens": { 23 | "type": "integer", 24 | "description": "The amount of maximum tokens to generate." 25 | }, 26 | "generate": { 27 | "description": "Parametrization of the text generation process", 28 | "$ref": "/inference/schemas/common-definitions.json#/definitions/GenerationParameters" 29 | } 30 | } 31 | } 32 | }, 33 | "required": ["inputs"] 34 | } 35 | -------------------------------------------------------------------------------- /packages/hub/src/lib/delete-file.ts: -------------------------------------------------------------------------------- 1 | import type { Credentials } from "../types/public"; 2 | import type { CommitOutput, CommitParams } from "./commit"; 3 | import { commit } from "./commit"; 4 | 5 | export function deleteFile(params: { 6 | credentials: Credentials; 7 | repo: CommitParams["repo"]; 8 | path: string; 9 | commitTitle?: CommitParams["title"]; 10 | commitDescription?: CommitParams["description"]; 11 | hubUrl?: CommitParams["hubUrl"]; 12 | fetch?: CommitParams["fetch"]; 13 | branch?: CommitParams["branch"]; 14 | isPullRequest?: CommitParams["isPullRequest"]; 15 | parentCommit?: CommitParams["parentCommit"]; 16 | }): Promise { 17 | return commit({ 18 | credentials: params.credentials, 19 | repo: params.repo, 20 | operations: [ 21 | { 22 | operation: "delete", 23 | path: params.path, 24 | }, 25 | ], 26 | title: params.commitTitle ?? `Delete ${params.path}`, 27 | description: params.commitDescription, 28 | hubUrl: params.hubUrl, 29 | branch: params.branch, 30 | isPullRequest: params.isPullRequest, 31 | parentCommit: params.parentCommit, 32 | fetch: params.fetch, 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Hugging Face 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hub/src/types/api/api-index-tree.d.ts: -------------------------------------------------------------------------------- 1 | export interface ApiIndexTreeEntry { 2 | type: "file" | "directory" | "unknown"; 3 | size: number; 4 | path: string; 5 | oid: string; 6 | lfs?: { 7 | oid: string; 8 | size: number; 9 | /** Size of the raw pointer file, 100~200 bytes */ 10 | pointerSize: number; 11 | }; 12 | lastCommit?: { 13 | date: string; 14 | id: string; 15 | title: string; 16 | }; 17 | security?: ApiFileScanResult; 18 | } 19 | 20 | export interface ApiFileScanResult { 21 | /** namespaced by repo type (models/, datasets/, spaces/) */ 22 | repositoryId: string; 23 | blobId: string; 24 | name: string; 25 | safe: boolean; 26 | avScan?: ApiAVScan; 27 | pickleImportScan?: ApiPickleImportScan; 28 | } 29 | 30 | interface AVScan { 31 | virusFound: boolean; 32 | virusNames?: string[]; 33 | } 34 | 35 | type ApiSafetyLevel = "innocuous" | "suspicious" | "dangerous"; 36 | 37 | interface ApiPickleImport { 38 | module: string; 39 | name: string; 40 | safety: ApiSafetyLevel; 41 | } 42 | 43 | interface ApiPickleImportScan { 44 | highestSafetyLevel: ApiSafetyLevelafetyLevel; 45 | imports: ApiPickleImport[]; 46 | } 47 | -------------------------------------------------------------------------------- /packages/hub/src/lib/delete-files.ts: -------------------------------------------------------------------------------- 1 | import type { Credentials } from "../types/public"; 2 | import type { CommitOutput, CommitParams } from "./commit"; 3 | import { commit } from "./commit"; 4 | 5 | export function deleteFiles(params: { 6 | credentials: Credentials; 7 | repo: CommitParams["repo"]; 8 | paths: string[]; 9 | commitTitle?: CommitParams["title"]; 10 | commitDescription?: CommitParams["description"]; 11 | hubUrl?: CommitParams["hubUrl"]; 12 | branch?: CommitParams["branch"]; 13 | isPullRequest?: CommitParams["isPullRequest"]; 14 | parentCommit?: CommitParams["parentCommit"]; 15 | fetch?: CommitParams["fetch"]; 16 | }): Promise { 17 | return commit({ 18 | credentials: params.credentials, 19 | repo: params.repo, 20 | operations: params.paths.map((path) => ({ 21 | operation: "delete", 22 | path, 23 | })), 24 | title: params.commitTitle ?? `Deletes ${params.paths.length} files`, 25 | description: params.commitDescription, 26 | hubUrl: params.hubUrl, 27 | branch: params.branch, 28 | isPullRequest: params.isPullRequest, 29 | parentCommit: params.parentCommit, 30 | fetch: params.fetch, 31 | }); 32 | } 33 | -------------------------------------------------------------------------------- /packages/tasks/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Hugging Face 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/agents/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Hugging Face 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hub/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Hugging Face 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/inference/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Tim Mikeladze 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconZeroShotObjectDetection.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 28 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTranslation.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 25 | -------------------------------------------------------------------------------- /packages/hub/src/lib/list-spaces.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | import type { SpaceEntry } from "./list-spaces"; 3 | import { listSpaces } from "./list-spaces"; 4 | 5 | describe("listSpaces", () => { 6 | it("should list spaces for Microsoft", async () => { 7 | const results: SpaceEntry[] = []; 8 | 9 | for await (const entry of listSpaces({ 10 | search: { owner: "microsoft" }, 11 | additionalFields: ["subdomain"], 12 | })) { 13 | if (entry.name !== "microsoft/visual_chatgpt") { 14 | continue; 15 | } 16 | if (typeof entry.likes === "number") { 17 | entry.likes = 0; 18 | } 19 | if (entry.updatedAt instanceof Date && !isNaN(entry.updatedAt.getTime())) { 20 | entry.updatedAt = new Date(0); 21 | } 22 | 23 | results.push(entry); 24 | } 25 | 26 | results.sort((a, b) => a.id.localeCompare(b.id)); 27 | 28 | expect(results).deep.equal([ 29 | { 30 | id: "6409a392bbc73d022c58c980", 31 | name: "microsoft/visual_chatgpt", 32 | private: false, 33 | likes: 0, 34 | sdk: "gradio", 35 | subdomain: "microsoft-visual-chatgpt", 36 | updatedAt: new Date(0), 37 | }, 38 | ]); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/audio-classification/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/audio-classification/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Audio Classification inference", 5 | "title": "AudioClassificationInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input audio data" 10 | }, 11 | "parameters": { 12 | "description": "Additional inference parameters", 13 | "$ref": "#/$defs/AudioClassificationParameters" 14 | } 15 | }, 16 | "$defs": { 17 | "AudioClassificationParameters": { 18 | "title": "AudioClassificationParameters", 19 | "description": "Additional inference parameters for Audio Classification", 20 | "type": "object", 21 | "properties": { 22 | "function_to_apply": { 23 | "title": "AudioClassificationOutputTransform", 24 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutputTransform" 25 | }, 26 | "top_k": { 27 | "type": "integer", 28 | "description": "When specified, limits the output to the top K most probable classes." 29 | } 30 | } 31 | } 32 | }, 33 | "required": ["inputs"] 34 | } 35 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/image-classification/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/image-classification/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Image Classification inference", 5 | "title": "ImageClassificationInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input image data" 10 | }, 11 | "parameters": { 12 | "description": "Additional inference parameters", 13 | "$ref": "#/$defs/ImageClassificationParameters" 14 | } 15 | }, 16 | "$defs": { 17 | "ImageClassificationParameters": { 18 | "title": "ImageClassificationParameters", 19 | "description": "Additional inference parameters for Image Classification", 20 | "type": "object", 21 | "properties": { 22 | "function_to_apply": { 23 | "title": "ImageClassificationOutputTransform", 24 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutputTransform" 25 | }, 26 | "top_k": { 27 | "type": "integer", 28 | "description": "When specified, limits the output to the top K most probable classes." 29 | } 30 | } 31 | } 32 | }, 33 | "required": ["inputs"] 34 | } 35 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/widgets/FeatureExtractionWidget/DataTable.ts: -------------------------------------------------------------------------------- 1 | export class DataTable { 2 | max: number; 3 | min: number; 4 | std: number; 5 | 6 | constructor(public body: number[] | number[][]) { 7 | const all = this.body.flat(); 8 | this.max = Math.max(...all); 9 | this.min = Math.min(...all); 10 | this.std = this.max - this.min; 11 | } 12 | 13 | get isArrLevel0(): boolean { 14 | return isArrLevel0(this.body); 15 | } 16 | 17 | get oneDim(): number[] { 18 | return this.body as number[]; 19 | } 20 | get twoDim(): number[][] { 21 | return this.body as number[][]; 22 | } 23 | 24 | bg(value: number): string { 25 | if (value > this.min + this.std * 0.7) { 26 | return "bg-green-100 dark:bg-green-800"; 27 | } 28 | if (value > this.min + this.std * 0.6) { 29 | return "bg-green-50 dark:bg-green-900"; 30 | } 31 | if (value < this.min + this.std * 0.3) { 32 | return "bg-red-100 dark:bg-red-800"; 33 | } 34 | if (value < this.min + this.std * 0.4) { 35 | return "bg-red-50 dark:bg-red-900"; 36 | } 37 | return ""; 38 | } 39 | } 40 | 41 | function isArrLevel0(x: number[] | number[][]): x is number[] { 42 | return typeof x[0] === "number"; 43 | } 44 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/text-classification/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/text-classification/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Text Classification inference", 5 | "title": "TextClassificationInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The text to classify", 10 | "type": "string" 11 | }, 12 | "parameters": { 13 | "description": "Additional inference parameters", 14 | "$ref": "#/$defs/TextClassificationParameters" 15 | } 16 | }, 17 | "$defs": { 18 | "TextClassificationParameters": { 19 | "title": "TextClassificationParameters", 20 | "description": "Additional inference parameters for Text Classification", 21 | "type": "object", 22 | "properties": { 23 | "function_to_apply": { 24 | "title": "TextClassificationOutputTransform", 25 | "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutputTransform" 26 | }, 27 | "top_k": { 28 | "type": "integer", 29 | "description": "When specified, limits the output to the top K most probable classes." 30 | } 31 | } 32 | } 33 | }, 34 | "required": ["inputs"] 35 | } 36 | -------------------------------------------------------------------------------- /packages/hub/src/lib/delete-repo.ts: -------------------------------------------------------------------------------- 1 | import { HUB_URL } from "../consts"; 2 | import { createApiError } from "../error"; 3 | import type { Credentials, RepoDesignation } from "../types/public"; 4 | import { checkCredentials } from "../utils/checkCredentials"; 5 | import { toRepoId } from "../utils/toRepoId"; 6 | 7 | export async function deleteRepo(params: { 8 | repo: RepoDesignation; 9 | credentials: Credentials; 10 | hubUrl?: string; 11 | /** 12 | * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. 13 | */ 14 | fetch?: typeof fetch; 15 | }): Promise { 16 | checkCredentials(params.credentials); 17 | const repoId = toRepoId(params.repo); 18 | const [namespace, repoName] = repoId.name.split("/"); 19 | 20 | const res = await (params.fetch ?? fetch)(`${params.hubUrl ?? HUB_URL}/api/repos/delete`, { 21 | method: "DELETE", 22 | body: JSON.stringify({ 23 | name: repoName, 24 | organization: namespace, 25 | type: repoId.type, 26 | }), 27 | headers: { 28 | Authorization: `Bearer ${params.credentials.accessToken}`, 29 | "Content-Type": "application/json", 30 | }, 31 | }); 32 | 33 | if (!res.ok) { 34 | throw await createApiError(res); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/languages/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@huggingface/languages", 3 | "packageManager": "pnpm@8.10.5", 4 | "version": "1.0.0", 5 | "description": "List of ISO-639 languages used in the Hub", 6 | "repository": "https://github.com/huggingface/huggingface.js.git", 7 | "publishConfig": { 8 | "access": "public" 9 | }, 10 | "main": "./dist/index.js", 11 | "module": "./dist/index.mjs", 12 | "types": "./dist/index.d.ts", 13 | "exports": { 14 | ".": { 15 | "types": "./dist/index.d.ts", 16 | "require": "./dist/index.js", 17 | "import": "./dist/index.mjs" 18 | } 19 | }, 20 | "source": "index.ts", 21 | "scripts": { 22 | "lint": "eslint --quiet --fix --ext .cjs,.ts .", 23 | "lint:check": "eslint --ext .cjs,.ts .", 24 | "format": "prettier --write .", 25 | "format:check": "prettier --check .", 26 | "prepublishOnly": "pnpm run build", 27 | "build": "tsup src/index.ts --format cjs,esm --clean --dts", 28 | "test": "vitest run", 29 | "check": "tsc" 30 | }, 31 | "files": [ 32 | "dist", 33 | "src", 34 | "tsconfig.json" 35 | ], 36 | "keywords": [ 37 | "huggingface", 38 | "hub", 39 | "languages" 40 | ], 41 | "author": "Hugging Face", 42 | "license": "MIT", 43 | "devDependencies": {} 44 | } 45 | -------------------------------------------------------------------------------- /packages/inference/src/tasks/audio/automaticSpeechRecognition.ts: -------------------------------------------------------------------------------- 1 | import { InferenceOutputError } from "../../lib/InferenceOutputError"; 2 | import type { BaseArgs, Options } from "../../types"; 3 | import { request } from "../custom/request"; 4 | 5 | export type AutomaticSpeechRecognitionArgs = BaseArgs & { 6 | /** 7 | * Binary audio data 8 | */ 9 | data: Blob | ArrayBuffer; 10 | }; 11 | 12 | export interface AutomaticSpeechRecognitionOutput { 13 | /** 14 | * The text that was recognized from the audio 15 | */ 16 | text: string; 17 | } 18 | 19 | /** 20 | * This task reads some audio input and outputs the said words within the audio files. 21 | * Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self 22 | */ 23 | export async function automaticSpeechRecognition( 24 | args: AutomaticSpeechRecognitionArgs, 25 | options?: Options 26 | ): Promise { 27 | const res = await request(args, { 28 | ...options, 29 | taskHint: "automatic-speech-recognition", 30 | }); 31 | const isValidOutput = typeof res?.text === "string"; 32 | if (!isValidOutput) { 33 | throw new InferenceOutputError("Expected {text: string}"); 34 | } 35 | return res; 36 | } 37 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/outputValidation.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | WidgetExampleOutputLabels, 3 | WidgetExampleOutputAnswerScore, 4 | WidgetExampleOutputText, 5 | WidgetExampleOutputUrl, 6 | } from "@huggingface/tasks"; 7 | 8 | export function isValidOutputLabels(arg: unknown): arg is WidgetExampleOutputLabels { 9 | return Array.isArray(arg) && arg.every((x) => typeof x.label === "string" && typeof x.score === "number"); 10 | } 11 | 12 | export function isValidOutputAnswerScore(arg: unknown): arg is WidgetExampleOutputAnswerScore { 13 | return ( 14 | !!arg && 15 | typeof arg === "object" && 16 | "answer" in arg && 17 | typeof arg["answer"] === "string" && 18 | "score" in arg && 19 | typeof arg["score"] === "number" 20 | ); 21 | } 22 | 23 | export function isValidOutputText(arg: unknown): arg is WidgetExampleOutputText { 24 | return !!arg && typeof arg === "object" && "text" in arg && typeof arg["text"] === "string"; 25 | } 26 | 27 | export function isValidOutputUrl(arg: unknown): arg is WidgetExampleOutputUrl { 28 | return ( 29 | !!arg && 30 | typeof arg === "object" && 31 | "url" in arg && 32 | typeof arg["url"] === "string" && 33 | arg["url"].startsWith("https://") 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:svelte/recommended", "prettier"], 3 | parser: "@typescript-eslint/parser", 4 | plugins: ["@typescript-eslint", "prettier"], 5 | root: true, 6 | env: { 7 | browser: true, 8 | es2017: true, 9 | node: true, 10 | }, 11 | parserOptions: { 12 | sourceType: "module", 13 | ecmaVersion: 2020, 14 | extraFileExtensions: [".svelte"], 15 | }, 16 | rules: { 17 | "no-constant-condition": "off", 18 | "@typescript-eslint/no-empty-function": "off", 19 | "@typescript-eslint/explicit-module-boundary-types": "error", 20 | "@typescript-eslint/consistent-type-imports": "error", 21 | "@typescript-eslint/no-unused-vars": "error", 22 | "@typescript-eslint/no-non-null-assertion": "error", 23 | "@typescript-eslint/no-explicit-any": "error", 24 | "@typescript-eslint/no-empty-interfaces": "off", 25 | // For doc purposes, prefer interfaces 26 | "@typescript-eslint/consistent-type-definitions": ["error", "interface"], 27 | }, 28 | overrides: [ 29 | { 30 | files: ["*.svelte"], 31 | parser: "svelte-eslint-parser", 32 | parserOptions: { 33 | parser: "@typescript-eslint/parser", 34 | }, 35 | }, 36 | ], 37 | }; 38 | -------------------------------------------------------------------------------- /packages/hub/src/types/api/api-who-am-i.d.ts: -------------------------------------------------------------------------------- 1 | import type { AccessTokenRole, AuthType } from "../public"; 2 | 3 | interface ApiWhoAmIBase { 4 | /** Unique ID persistent across renames */ 5 | id: string; 6 | type: "user" | "org" | "app"; 7 | name: string; 8 | } 9 | 10 | interface ApiWhoAmIEntityBase extends ApiWhoAmIBase { 11 | fullname: string; 12 | email: string | null; 13 | canPay: boolean; 14 | avatarUrl: string; 15 | /** 16 | * Unix timestamp in seconds 17 | */ 18 | periodEnd: number | null; 19 | } 20 | 21 | interface ApiWhoAmIOrg extends ApiWhoAmIEntityBase { 22 | type: "org"; 23 | } 24 | 25 | interface ApiWhoAmIUser extends ApiWhoAmIEntityBase { 26 | type: "user"; 27 | email: string; 28 | emailVerified: boolean; 29 | isPro: boolean; 30 | orgs: ApiWhoAmIOrg[]; 31 | } 32 | 33 | interface ApiWhoAmIApp extends ApiWhoAmIBase { 34 | type: "app"; 35 | name: string; 36 | scope?: { 37 | entities: string[]; 38 | role: AccessTokenRole; 39 | }; 40 | } 41 | 42 | export type ApiWhoAmIReponse = ApiWhoAmIUser | ApiWhoAmIOrg | ApiWhoAmIApp; 43 | 44 | export interface ApiWhoAmIAuthInfo { 45 | type: AuthType; 46 | accessToken?: { 47 | displayName: string; 48 | expiration?: string; 49 | role: AccessTokenRole; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /packages/agents/src/llms/LLMHF.ts: -------------------------------------------------------------------------------- 1 | import type { LLM } from "../types"; 2 | import { HfInference } from "@huggingface/inference"; 3 | 4 | export function LLMFromHub(accessToken?: string, model?: string): LLM { 5 | const inference = new HfInference(accessToken); 6 | 7 | return async (prompt: string): Promise => { 8 | const formattedPrompt = "<|user|>" + prompt + "<|end|><|assistant|>"; 9 | 10 | const output = await inference.textGeneration({ 11 | inputs: formattedPrompt, 12 | model: model ?? "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5", 13 | parameters: { 14 | max_new_tokens: 900, 15 | }, 16 | }); 17 | 18 | return output.generated_text.slice(formattedPrompt.length); 19 | }; 20 | } 21 | 22 | export function LLMFromEndpoint(accessToken: string, endpoint: string): LLM { 23 | const inference = new HfInference(accessToken).endpoint(endpoint); 24 | return async (prompt: string): Promise => { 25 | const formattedPrompt = "<|user|>" + prompt + "<|end|><|assistant|>"; 26 | 27 | const output = await inference.textGeneration({ 28 | inputs: formattedPrompt, 29 | parameters: { 30 | max_new_tokens: 900, 31 | }, 32 | }); 33 | 34 | return output.generated_text.slice(formattedPrompt.length); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /packages/doc-internal/README.md: -------------------------------------------------------------------------------- 1 | # Internal package for doc generation 2 | 3 | This package generates `.md` files inside the [docs](../../docs) folder using [typedoc](https://typedoc.org/) and [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown). 4 | 5 | The `.md` files are generated when releasing packages. They are then published to [hugginface.co](https://huggingface.co/docs/huggingface.js/index) through the [doc-builder](https://github.com/huggingface/doc-builder)'s github action. 6 | 7 | We run a few scripts in between, [fix-md-links](./fix-md-links.ts) and [update-toc](./update-toc.ts) to preprocess the files for `doc-builder`. 8 | 9 | ## Commands 10 | 11 | ```console 12 | # Generate all docs 13 | pnpm run start 14 | ``` 15 | 16 | ## HTML docs 17 | 18 | If you want to see the final HTML docs, there are a few steps: 19 | 20 | - Generate the docs with `pnpm run start` 21 | - Clone https://github.com/huggingface/doc-builder and put it in the same folder as huggingface.js 22 | - Follow the instructions to install it from source 23 | - Go in its `kit` folder and run `npm install` 24 | 25 | Then: 26 | 27 | ```console 28 | # Inside the doc-builder folder 29 | doc-builder preview huggingface.js ../huggingface.js/docs --not_python_module 30 | ``` -------------------------------------------------------------------------------- /packages/inference/src/tasks/nlp/translation.ts: -------------------------------------------------------------------------------- 1 | import { InferenceOutputError } from "../../lib/InferenceOutputError"; 2 | import type { BaseArgs, Options } from "../../types"; 3 | import { request } from "../custom/request"; 4 | 5 | export type TranslationArgs = BaseArgs & { 6 | /** 7 | * A string to be translated 8 | */ 9 | inputs: string | string[]; 10 | }; 11 | 12 | export interface TranslationOutputValue { 13 | /** 14 | * The string after translation 15 | */ 16 | translation_text: string; 17 | } 18 | 19 | export type TranslationOutput = TranslationOutputValue | TranslationOutputValue[]; 20 | 21 | /** 22 | * This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en. 23 | */ 24 | export async function translation(args: TranslationArgs, options?: Options): Promise { 25 | const res = await request(args, { 26 | ...options, 27 | taskHint: "translation", 28 | }); 29 | const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.translation_text === "string"); 30 | if (!isValidOutput) { 31 | throw new InferenceOutputError("Expected type Array<{translation_text: string}>"); 32 | } 33 | return res?.length === 1 ? res?.[0] : res; 34 | } 35 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetModelLoading/WidgetModelLoading.svelte: -------------------------------------------------------------------------------- 1 | 26 | 27 |
28 |
31 |
35 | 36 | Model is loading 37 |
38 |
39 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/automatic-speech-recognition/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/automatic-speech-recognition/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Automatic Speech Recognition task", 5 | "title": "AutomaticSpeechRecognitionOutput", 6 | "type": "object", 7 | "properties": { 8 | "text": { 9 | "type": "string", 10 | "description": "The recognized text." 11 | }, 12 | "chunks": { 13 | "type": "array", 14 | "description": "When returnTimestamps is enabled, chunks contains a list of audio chunks identified by the model.", 15 | "items": { 16 | "type": "object", 17 | "title": "AutomaticSpeechRecognitionOutputChunk", 18 | "properties": { 19 | "text": { 20 | "type": "string", 21 | "description": "A chunk of text identified by the model" 22 | }, 23 | "timestamps": { 24 | "type": "array", 25 | "description": "The start and end timestamps corresponding with the text", 26 | "items": { 27 | "type": "number" 28 | }, 29 | "minLength": 2, 30 | "maxLength": 2 31 | } 32 | }, 33 | "required": ["text", "timestamps"] 34 | } 35 | } 36 | }, 37 | "required": ["text"] 38 | } 39 | -------------------------------------------------------------------------------- /packages/widgets/tailwind.config.cjs: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line @typescript-eslint/no-var-requires 2 | const defaultTheme = require("tailwindcss/defaultTheme"); 3 | // eslint-disable-next-line @typescript-eslint/no-var-requires 4 | const colors = require("tailwindcss/colors"); 5 | 6 | module.exports = { 7 | content: ["./src/**/*.{html,js,svelte,ts}"], 8 | darkMode: "class", 9 | theme: { 10 | container: { 11 | center: true, 12 | padding: { DEFAULT: "1rem" }, 13 | }, 14 | extend: { 15 | colors: { 16 | green: colors.emerald, 17 | yellow: colors.amber, 18 | purple: colors.violet, 19 | gray: { 20 | 350: "#b3bcc9", 21 | // Dark blue 22 | // 925: '#131f3d', 23 | // 950: '#0a1226', 24 | // Darker 25 | 850: "#141c2e", 26 | 925: "#101623", 27 | 950: "#0b0f19", 28 | // Darkest 29 | // 925: '#081122', 30 | // 950: '#000511', 31 | }, 32 | }, 33 | gridTemplateRows: { 34 | full: "100%", 35 | }, 36 | fontFamily: { 37 | sans: ["Source Sans Pro", ...defaultTheme.fontFamily.sans], 38 | mono: ["IBM Plex Mono", ...defaultTheme.fontFamily.mono], 39 | }, 40 | fontSize: { 41 | smd: "0.94rem", 42 | }, 43 | }, 44 | }, 45 | plugins: [require("@tailwindcss/forms")], 46 | }; 47 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/automatic-speech-recognition/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/automatic-speech-recognition/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Automatic Speech Recognition inference", 5 | "title": "AutomaticSpeechRecognitionInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input audio data" 10 | }, 11 | "parameters": { 12 | "description": "Additional inference parameters", 13 | "$ref": "#/$defs/AutomaticSpeechRecognitionParameters" 14 | } 15 | }, 16 | "$defs": { 17 | "AutomaticSpeechRecognitionParameters": { 18 | "title": "AutomaticSpeechRecognitionParameters", 19 | "description": "Additional inference parameters for Automatic Speech Recognition", 20 | "type": "object", 21 | "properties": { 22 | "return_timestamps": { 23 | "type": "boolean", 24 | "description": "Whether to output corresponding timestamps with the generated text" 25 | }, 26 | "generate": { 27 | "description": "Parametrization of the text generation process", 28 | "$ref": "/inference/schemas/common-definitions.json#/definitions/GenerationParameters" 29 | } 30 | } 31 | } 32 | }, 33 | "required": ["inputs"] 34 | } 35 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/document-question-answering/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/document-question-answering/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Document Question Answering task", 5 | "title": "DocumentQuestionAnsweringOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "answer": { 11 | "type": "string", 12 | "description": "The answer to the question." 13 | }, 14 | "score": { 15 | "type": "number", 16 | "description": "The probability associated to the answer." 17 | }, 18 | "start": { 19 | "type": "integer", 20 | "description": "The start word index of the answer (in the OCR\u2019d version of the input or provided word boxes)." 21 | }, 22 | "end": { 23 | "type": "integer", 24 | "description": "The end word index of the answer (in the OCR\u2019d version of the input or provided word boxes)." 25 | }, 26 | "words": { 27 | "type": "array", 28 | "items": { 29 | "type": "integer" 30 | }, 31 | "description": "The index of each word/box pair that is in the answer" 32 | } 33 | }, 34 | "required": ["answer", "score", "start", "end", "words"] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageToText.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 29 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/object-detection/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/object-detection/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Object Detection task", 5 | "title": "ObjectDetectionOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "label": { 11 | "type": "string", 12 | "description": "The predicted label for the bounding box" 13 | }, 14 | "score": { 15 | "type": "number", 16 | "description": "The associated score / probability" 17 | }, 18 | "box": { 19 | "$ref": "#/$defs/BoundingBox", 20 | "description": "The predicted bounding box. Coordinates are relative to the top left corner of the input image." 21 | } 22 | }, 23 | "required": ["box", "label", "score"] 24 | }, 25 | "$defs": { 26 | "BoundingBox": { 27 | "type": "object", 28 | "title": "BoundingBox", 29 | "properties": { 30 | "xmin": { 31 | "type": "integer" 32 | }, 33 | "xmax": { 34 | "type": "integer" 35 | }, 36 | "ymin": { 37 | "type": "integer" 38 | }, 39 | "ymax": { 40 | "type": "integer" 41 | } 42 | }, 43 | "required": ["xmin", "xmax", "ymin", "ymax"] 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconAzureML.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 41 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconImageAndTextToText.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 29 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/table-question-answering/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/table-question-answering/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Table Question Answering task", 5 | "title": "TableQuestionAnsweringOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "answer": { 11 | "type": "string", 12 | "description": "The answer of the question given the table. If there is an aggregator, the answer will be preceded by `AGGREGATOR >`." 13 | }, 14 | "coordinates": { 15 | "type": "array", 16 | "description": "Coordinates of the cells of the answers.", 17 | "items": { 18 | "type": "array", 19 | "items": { 20 | "type": "integer" 21 | }, 22 | "minLength": 2, 23 | "maxLength": 2 24 | } 25 | }, 26 | "cells": { 27 | "type": "array", 28 | "description": "List of strings made up of the answer cell values.", 29 | "items": { 30 | "type": "string" 31 | } 32 | }, 33 | "aggregator": { 34 | "type": "string", 35 | "description": "If the model has an aggregator, this returns the aggregator." 36 | } 37 | }, 38 | "required": ["answer", "cells", "coordinates"] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/hub/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | hash-wasm: 9 | specifier: ^4.9.0 10 | version: 4.9.0 11 | 12 | devDependencies: 13 | '@huggingface/tasks': 14 | specifier: workspace:^ 15 | version: link:../tasks 16 | '@types/node': 17 | specifier: ^20.11.28 18 | version: 20.11.28 19 | type-fest: 20 | specifier: ^3.9.0 21 | version: 3.9.0 22 | 23 | packages: 24 | 25 | /@types/node@20.11.28: 26 | resolution: {integrity: sha512-M/GPWVS2wLkSkNHVeLkrF2fD5Lx5UC4PxA0uZcKc6QqbIQUJyW1jVjueJYi1z8n0I5PxYrtpnPnWglE+y9A0KA==} 27 | dependencies: 28 | undici-types: 5.26.5 29 | dev: true 30 | 31 | /hash-wasm@4.9.0: 32 | resolution: {integrity: sha512-7SW7ejyfnRxuOc7ptQHSf4LDoZaWOivfzqw+5rpcQku0nHfmicPKE51ra9BiRLAmT8+gGLestr1XroUkqdjL6w==} 33 | dev: false 34 | 35 | /type-fest@3.9.0: 36 | resolution: {integrity: sha512-hR8JP2e8UiH7SME5JZjsobBlEiatFoxpzCP+R3ZeCo7kAaG1jXQE5X/buLzogM6GJu8le9Y4OcfNuIQX0rZskA==} 37 | engines: {node: '>=14.16'} 38 | dev: true 39 | 40 | /undici-types@5.26.5: 41 | resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} 42 | dev: true 43 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTextClassification.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 34 | -------------------------------------------------------------------------------- /e2e/svelte/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 29 | 30 |

Welcome to SvelteKit

31 |

Visit kit.svelte.dev to read the documentation

32 | -------------------------------------------------------------------------------- /packages/hub/src/lib/file-exists.ts: -------------------------------------------------------------------------------- 1 | import { HUB_URL } from "../consts"; 2 | import { createApiError } from "../error"; 3 | import type { Credentials, RepoDesignation } from "../types/public"; 4 | import { checkCredentials } from "../utils/checkCredentials"; 5 | import { toRepoId } from "../utils/toRepoId"; 6 | 7 | export async function fileExists(params: { 8 | repo: RepoDesignation; 9 | path: string; 10 | revision?: string; 11 | credentials?: Credentials; 12 | hubUrl?: string; 13 | /** 14 | * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. 15 | */ 16 | fetch?: typeof fetch; 17 | }): Promise { 18 | checkCredentials(params.credentials); 19 | const repoId = toRepoId(params.repo); 20 | 21 | const hubUrl = params.hubUrl ?? HUB_URL; 22 | const url = `${hubUrl}/${repoId.type === "model" ? "" : `${repoId.type}s/`}${repoId.name}/raw/${encodeURIComponent( 23 | params.revision ?? "main" 24 | )}/${params.path}`; 25 | 26 | const resp = await (params.fetch ?? fetch)(url, { 27 | method: "HEAD", 28 | headers: params.credentials ? { Authorization: `Bearer ${params.credentials.accessToken}` } : {}, 29 | }); 30 | 31 | if (resp.status === 404) { 32 | return false; 33 | } 34 | 35 | if (!resp.ok) { 36 | throw await createApiError(resp); 37 | } 38 | 39 | return true; 40 | } 41 | -------------------------------------------------------------------------------- /packages/hub/src/utils/eventToGenerator.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | import { eventToGenerator } from "./eventToGenerator"; 3 | 4 | describe("eventToGenerator", () => { 5 | it("should handle synchronous events", async () => { 6 | const it = eventToGenerator((yieldCallback, returnCallback) => { 7 | yieldCallback(1); 8 | yieldCallback(2); 9 | returnCallback(3); 10 | }); 11 | 12 | const results = []; 13 | let res: IteratorResult; 14 | do { 15 | res = await it.next(); 16 | if (!res.done) { 17 | results.push(res.value); 18 | } 19 | } while (!res.done); 20 | 21 | expect(results).toEqual([1, 2]); 22 | expect(res.value).toBe(3); 23 | }); 24 | 25 | it("should handle asynchronous events", async () => { 26 | const it = eventToGenerator((yieldCallback, returnCallback) => { 27 | setTimeout(() => yieldCallback(1), 100); 28 | setTimeout(() => yieldCallback(2), 200); 29 | setTimeout(() => returnCallback(3), 300); 30 | }); 31 | 32 | const results = []; 33 | let res: IteratorResult; 34 | do { 35 | res = await it.next(); 36 | if (!res.done) { 37 | results.push(res.value); 38 | } 39 | } while (!res.done); 40 | 41 | expect(results).toEqual([1, 2]); 42 | expect(res.value).toBe(3); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconMaskGeneration.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/fill-mask/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/fill-mask/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Fill Mask inference", 5 | "title": "FillMaskInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The text with masked tokens", 10 | "type": "string" 11 | }, 12 | "parameters": { 13 | "description": "Additional inference parameters", 14 | "$ref": "#/$defs/FillMaskParameters" 15 | } 16 | }, 17 | "$defs": { 18 | "FillMaskParameters": { 19 | "title": "FillMaskParameters", 20 | "description": "Additional inference parameters for Fill Mask", 21 | "type": "object", 22 | "properties": { 23 | "top_k": { 24 | "type": "integer", 25 | "description": "When passed, overrides the number of predictions to return." 26 | }, 27 | "targets": { 28 | "description": "When passed, the model will limit the scores to the passed targets instead of looking up in the whole vocabulary. If the provided targets are not in the model vocab, they will be tokenized and the first resulting token will be used (with a warning, and that might be slower).", 29 | "type": "array", 30 | "items": { 31 | "type": "string" 32 | } 33 | } 34 | } 35 | } 36 | }, 37 | "required": ["inputs"] 38 | } 39 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/zero-shot-object-detection/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/zero-shot-object-detection/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Zero Shot Object Detection inference", 5 | "title": "ZeroShotObjectDetectionInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "description": "The input image data, with candidate labels", 10 | "type": "object", 11 | "title": "ZeroShotObjectDetectionInputData", 12 | "properties": { 13 | "image": { 14 | "description": "The image data to generate bounding boxes from" 15 | }, 16 | "candidateLabels": { 17 | "description": "The candidate labels for this image", 18 | "type": "array", 19 | "items": { 20 | "type": "string" 21 | } 22 | } 23 | }, 24 | "required": ["image", "candidateLabels"] 25 | }, 26 | "parameters": { 27 | "description": "Additional inference parameters", 28 | "$ref": "#/$defs/ZeroShotObjectDetectionParameters" 29 | } 30 | }, 31 | "$defs": { 32 | "ZeroShotObjectDetectionParameters": { 33 | "title": "ZeroShotObjectDetectionParameters", 34 | "description": "Additional inference parameters for Zero Shot Object Detection", 35 | "type": "object", 36 | "properties": {} 37 | } 38 | }, 39 | "required": ["inputs"] 40 | } 41 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/zero-shot-object-detection/spec/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/zero-shot-object-detection/output.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Outputs of inference for the Zero Shot Object Detection task", 5 | "title": "ZeroShotObjectDetectionOutput", 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "title": "ZeroShotObjectDetectionOutputElement", 10 | "properties": { 11 | "label": { 12 | "type": "string", 13 | "description": "A candidate label" 14 | }, 15 | "score": { 16 | "type": "number", 17 | "description": "The associated score / probability" 18 | }, 19 | "box": { 20 | "$ref": "#/$defs/BoundingBox", 21 | "description": "The predicted bounding box. Coordinates are relative to the top left corner of the input image." 22 | } 23 | }, 24 | "required": ["box", "label", "score"] 25 | }, 26 | "$defs": { 27 | "BoundingBox": { 28 | "title": "BoundingBox", 29 | "type": "object", 30 | "properties": { 31 | "xmin": { 32 | "type": "integer" 33 | }, 34 | "xmax": { 35 | "type": "integer" 36 | }, 37 | "ymin": { 38 | "type": "integer" 39 | }, 40 | "ymax": { 41 | "type": "integer" 42 | } 43 | }, 44 | "required": ["xmin", "xmax", "ymin", "ymax"] 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/widgets/static/audioProcessor.js: -------------------------------------------------------------------------------- 1 | // for js/src/lib/components/InferenceWidget/shared/WidgetRealtimeRecorder/Recorder.ts 2 | class AudioDataExtractor extends AudioWorkletProcessor { 3 | _updateIntervalInMS; 4 | _sampleInFrames; 5 | _index; 6 | _buffer; 7 | 8 | constructor() { 9 | super(); 10 | this._updateIntervalInMS = 50; 11 | this._sampleInFrames = parseInt((this._updateIntervalInMS / 1000.0) * sampleRate); 12 | this._index = 0; 13 | this._buffer = new Float32Array(this._sampleInFrames); 14 | } 15 | 16 | process(inputs, outputs, parameters) { 17 | // Note that the input will be down-mixed to mono; however, if no inputs are 18 | // connected then zero channels will be passed in. 19 | if (inputs.length > 0 && inputs[0].length > 0) { 20 | const rest = this._buffer.length - this._index; 21 | if (rest < inputs[0][0].length) { 22 | this._buffer.set(inputs[0][0].slice(0, rest), this._index); 23 | this.port.postMessage({ 24 | buffer: this._buffer.slice(0), 25 | sampling_rate: sampleRate, 26 | }); 27 | this._buffer.fill(0); 28 | this._index = inputs[0][0].length - rest; 29 | } else { 30 | this._buffer.set(inputs[0][0], this._index); 31 | this._index += inputs[0][0].length; 32 | } 33 | } 34 | 35 | return true; 36 | } 37 | } 38 | 39 | registerProcessor("AudioDataExtractor", AudioDataExtractor); 40 | -------------------------------------------------------------------------------- /packages/hub/src/error.ts: -------------------------------------------------------------------------------- 1 | import type { JsonObject } from "type-fest"; 2 | 3 | export async function createApiError( 4 | response: Response, 5 | opts?: { requestId?: string; message?: string } 6 | ): Promise { 7 | const error = new HubApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId); 8 | 9 | error.message = `Api error with status ${error.statusCode}.${opts?.message ? ` ${opts.message}.` : ""} Request ID: ${ 10 | error.requestId 11 | }, url: ${error.url}`; 12 | 13 | if (response.headers.get("Content-Type")?.startsWith("application/json")) { 14 | const json = await response.json(); 15 | error.message = json.error || json.message || error.message; 16 | error.data = json; 17 | } else { 18 | error.data = { message: await response.text() }; 19 | } 20 | 21 | throw error; 22 | } 23 | 24 | /** 25 | * Error thrown when an API call to the Hugging Face Hub fails. 26 | */ 27 | export class HubApiError extends Error { 28 | statusCode: number; 29 | url: string; 30 | requestId?: string; 31 | data?: JsonObject; 32 | 33 | constructor(url: string, statusCode: number, requestId?: string, message?: string) { 34 | super(message); 35 | 36 | this.statusCode = statusCode; 37 | this.requestId = requestId; 38 | this.url = url; 39 | } 40 | } 41 | 42 | export class InvalidApiResponseFormatError extends Error {} 43 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconRefresh.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 20 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/Icons/IconTextGeneration.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /packages/hub/src/lib/list-datasets.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | import type { DatasetEntry } from "./list-datasets"; 3 | import { listDatasets } from "./list-datasets"; 4 | 5 | describe("listDatasets", () => { 6 | it("should list datasets from hf-doc-builder", async () => { 7 | const results: DatasetEntry[] = []; 8 | 9 | for await (const entry of listDatasets({ search: { owner: "hf-doc-build" } })) { 10 | if (entry.name === "hf-doc-build/doc-build-dev-test") { 11 | continue; 12 | } 13 | if (typeof entry.downloads === "number") { 14 | entry.downloads = 0; 15 | } 16 | if (typeof entry.likes === "number") { 17 | entry.likes = 0; 18 | } 19 | if (entry.updatedAt instanceof Date && !isNaN(entry.updatedAt.getTime())) { 20 | entry.updatedAt = new Date(0); 21 | } 22 | 23 | results.push(entry); 24 | } 25 | 26 | expect(results).deep.equal([ 27 | { 28 | id: "6356b19985da6f13863228bd", 29 | name: "hf-doc-build/doc-build", 30 | private: false, 31 | gated: false, 32 | downloads: 0, 33 | likes: 0, 34 | updatedAt: new Date(0), 35 | }, 36 | { 37 | id: "636a1b69f2f9ec4289c4c19e", 38 | name: "hf-doc-build/doc-build-dev", 39 | gated: false, 40 | private: false, 41 | downloads: 0, 42 | likes: 0, 43 | updatedAt: new Date(0), 44 | }, 45 | ]); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /packages/widgets/src/lib/components/InferenceWidget/shared/WidgetTextInput/WidgetTextInput.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | { 30 | if (!$isLoggedIn) { 31 | popOverOpen = true; 32 | return; 33 | } 34 | dispatch("cmdEnter"); 35 | }} 36 | /> 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/table-question-answering/about.md: -------------------------------------------------------------------------------- 1 | ## Use Cases 2 | 3 | ### SQL execution 4 | 5 | You can use the Table Question Answering models to simulate SQL execution by inputting a table. 6 | 7 | ### Table Question Answering 8 | 9 | Table Question Answering models are capable of answering questions based on a table. 10 | 11 | ## Task Variants 12 | 13 | This place can be filled with variants of this task if there's any. 14 | 15 | ## Inference 16 | 17 | You can infer with TableQA models using the 🤗 Transformers library. 18 | 19 | ```python 20 | from transformers import pipeline 21 | import pandas as pd 22 | 23 | # prepare table + question 24 | data = {"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], "Number of movies": ["87", "53", "69"]} 25 | table = pd.DataFrame.from_dict(data) 26 | question = "how many movies does Leonardo Di Caprio have?" 27 | 28 | # pipeline model 29 | # Note: you must to install torch-scatter first. 30 | tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq") 31 | 32 | # result 33 | 34 | print(tqa(table=table, query=question)['cells'][0]) 35 | #53 36 | 37 | ``` 38 | 39 | ## Useful Resources 40 | 41 | In this area, you can insert useful resources about how to train or use a model for this task. 42 | 43 | This task page is complete thanks to the efforts of [Hao Kim Tieu](https://huggingface.co/haotieu). 🦸 44 | -------------------------------------------------------------------------------- /packages/inference/src/tasks/tabular/tabularRegression.ts: -------------------------------------------------------------------------------- 1 | import { InferenceOutputError } from "../../lib/InferenceOutputError"; 2 | import type { BaseArgs, Options } from "../../types"; 3 | import { request } from "../custom/request"; 4 | 5 | export type TabularRegressionArgs = BaseArgs & { 6 | inputs: { 7 | /** 8 | * A table of data represented as a dict of list where entries are headers and the lists are all the values, all lists must have the same size. 9 | */ 10 | data: Record; 11 | }; 12 | }; 13 | 14 | /** 15 | * a list of predicted values for each row 16 | */ 17 | export type TabularRegressionOutput = number[]; 18 | 19 | /** 20 | * Predicts target value for a given set of features in tabular form. 21 | * Typically, you will want to train a regression model on your training data and use it with your new data of the same format. 22 | * Example model: scikit-learn/Fish-Weight 23 | */ 24 | export async function tabularRegression( 25 | args: TabularRegressionArgs, 26 | options?: Options 27 | ): Promise { 28 | const res = await request(args, { 29 | ...options, 30 | taskHint: "tabular-regression", 31 | }); 32 | const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number"); 33 | if (!isValidOutput) { 34 | throw new InferenceOutputError("Expected number[]"); 35 | } 36 | return res; 37 | } 38 | -------------------------------------------------------------------------------- /packages/tasks/src/tasks/sentence-similarity/spec/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "/inference/schemas/sentence-similarity/input.json", 3 | "$schema": "http://json-schema.org/draft-06/schema#", 4 | "description": "Inputs for Sentence similarity inference", 5 | "title": "SentenceSimilarityInput", 6 | "type": "object", 7 | "properties": { 8 | "inputs": { 9 | "title": "SentenceSimilarityInputData", 10 | "type": "object", 11 | "properties": { 12 | "sourceSentence": { 13 | "description": "The string that you wish to compare the other strings with. This can be a phrase, sentence, or longer passage, depending on the model being used.", 14 | "type": "string" 15 | }, 16 | "sentences": { 17 | "type": "array", 18 | "description": "A list of strings which will be compared against the source_sentence.", 19 | "items": { 20 | "type": "string" 21 | } 22 | } 23 | }, 24 | "required": ["sourceSentence", "sentences"] 25 | }, 26 | "parameters": { 27 | "description": "Additional inference parameters", 28 | "$ref": "#/$defs/SentenceSimilarityParameters" 29 | } 30 | }, 31 | "$defs": { 32 | "SentenceSimilarityParameters": { 33 | "title": "SentenceSimilarityParameters", 34 | "description": "Additional inference parameters for Sentence Similarity", 35 | "type": "object", 36 | "properties": {} 37 | } 38 | }, 39 | "required": ["inputs"] 40 | } 41 | -------------------------------------------------------------------------------- /packages/gguf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@huggingface/gguf", 3 | "packageManager": "pnpm@8.10.5", 4 | "version": "0.0.11", 5 | "description": "a GGUF parser that works on remotely hosted files", 6 | "repository": "https://github.com/huggingface/huggingface.js.git", 7 | "publishConfig": { 8 | "access": "public" 9 | }, 10 | "main": "./dist/index.js", 11 | "module": "./dist/index.mjs", 12 | "types": "./dist/index.d.ts", 13 | "exports": { 14 | ".": { 15 | "types": "./dist/index.d.ts", 16 | "require": "./dist/index.js", 17 | "import": "./dist/index.mjs" 18 | } 19 | }, 20 | "browser": { 21 | "./dist/index.js": "./dist/browser/index.js", 22 | "./dist/index.mjs": "./dist/browser/index.mjs" 23 | }, 24 | "engines": { 25 | "node": ">=20" 26 | }, 27 | "source": "index.ts", 28 | "scripts": { 29 | "lint": "eslint --quiet --fix --ext .cjs,.ts .", 30 | "lint:check": "eslint --ext .cjs,.ts .", 31 | "format": "prettier --write .", 32 | "format:check": "prettier --check .", 33 | "prepublishOnly": "pnpm run build", 34 | "build": "tsup src/index.ts --format cjs,esm --clean --dts", 35 | "test": "vitest run", 36 | "check": "tsc" 37 | }, 38 | "files": [ 39 | "dist", 40 | "src", 41 | "tsconfig.json" 42 | ], 43 | "keywords": [ 44 | "huggingface", 45 | "hub", 46 | "gguf" 47 | ], 48 | "author": "Hugging Face", 49 | "license": "MIT", 50 | "devDependencies": {} 51 | } 52 | -------------------------------------------------------------------------------- /packages/inference/src/tasks/nlp/textClassification.ts: -------------------------------------------------------------------------------- 1 | import { InferenceOutputError } from "../../lib/InferenceOutputError"; 2 | import type { BaseArgs, Options } from "../../types"; 3 | import { request } from "../custom/request"; 4 | 5 | export type TextClassificationArgs = BaseArgs & { 6 | /** 7 | * A string to be classified 8 | */ 9 | inputs: string; 10 | }; 11 | 12 | export type TextClassificationOutput = { 13 | /** 14 | * The label for the class (model specific) 15 | */ 16 | label: string; 17 | /** 18 | * A floats that represents how likely is that the text belongs to this class. 19 | */ 20 | score: number; 21 | }[]; 22 | 23 | /** 24 | * Usually used for sentiment-analysis this will output the likelihood of classes of an input. Recommended model: distilbert-base-uncased-finetuned-sst-2-english 25 | */ 26 | export async function textClassification( 27 | args: TextClassificationArgs, 28 | options?: Options 29 | ): Promise { 30 | const res = ( 31 | await request(args, { 32 | ...options, 33 | taskHint: "text-classification", 34 | }) 35 | )?.[0]; 36 | const isValidOutput = 37 | Array.isArray(res) && res.every((x) => typeof x?.label === "string" && typeof x.score === "number"); 38 | if (!isValidOutput) { 39 | throw new InferenceOutputError("Expected Array<{label: string, score: number}>"); 40 | } 41 | return res; 42 | } 43 | --------------------------------------------------------------------------------