Skip to content

Commit

Permalink
Merge branch 'main' into add-image-text-to-image
Browse files Browse the repository at this point in the history
  • Loading branch information
merveenoyan authored Jun 19, 2024
2 parents a60fcba + 392a091 commit 6ddc7a0
Show file tree
Hide file tree
Showing 29 changed files with 225 additions and 38 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/trufflehog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@ name: Secret Leaks
on:
push:

permissions:
contents: read

jobs:
trufflehog:
runs-on: ubuntu-latest
steps:
- shell: bash
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "depth=$(($(jq length <<< '${{ toJson(github.event.commits) }}') + 2))" >> $GITHUB_ENV
echo "branch=${{ github.ref_name }}" >> $GITHUB_ENV
fi
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "depth=$((${{ github.event.pull_request.commits }}+2))" >> $GITHUB_ENV
echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
fi
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{env.branch}}
fetch-depth: ${{env.depth}}
fetch-depth: 0
- name: Secret Scanning
uses: trufflesecurity/trufflehog@main
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"cSpell.words": ["huggingface"],
"deno.enablePaths": ["./e2e/deno"]
"deno.enablePaths": ["./e2e/deno"],
"typescript.tsdk": "node_modules/typescript/lib"
}
3 changes: 3 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
# Ownership for the gguf Package

/packages/gguf @mishig25 @julien-c

# Ownership for the space-header Package
/packages/space-header @enzostvs
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This is a collection of JS libraries to interact with the Hugging Face API, with
- [@huggingface/agents](packages/agents/README.md): Interact with HF models through a natural language interface
- [@huggingface/gguf](packages/gguf/README.md): A GGUF parser that works on remotely hosted files.
- [@huggingface/tasks](packages/tasks/README.md): The definition files and source-of-truth for the Hub's main primitives like pipeline tasks, model libraries, etc.
- [@huggingface/space-header](packages/space-header/README.md): Use the Space `mini_header` outside Hugging Face


We use modern features to avoid polyfills and dependencies, so the libraries will only work on modern browsers / Node.js >= 18 / Bun / Deno.
Expand Down
10 changes: 10 additions & 0 deletions docs/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@
title: Use Agents to run multi-modal workflows from a natural language API
- local: agents/modules
title: API Reference
- title: "@huggingface/space-header"
isExpanded: true
sections:
- local: space-header/README
title: Use Space mini_header in your app
- title: "@huggingface/gguf"
isExpanded: true
sections:
- local: gguf/README
title: Parse local and remote GGUF files
4 changes: 3 additions & 1 deletion packages/doc-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"description": "Package to generate doc for other @huggingface packages",
"private": true,
"scripts": {
"start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-agents && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-agents && pnpm run doc-space-header && pnpm run doc-gguf && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
"lint:check": "eslint --ext .cjs,.ts .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"doc-hub": "typedoc --tsconfig ../hub/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/hub --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../hub/index.ts",
"doc-inference": "typedoc --tsconfig ../inference/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/inference --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../inference/src/index.ts",
"doc-agents": "typedoc --tsconfig ../agents/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/agents --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../agents/src/index.ts",
"doc-gguf": "mkdir -p ../../docs/gguf && cp ../../packages/gguf/README.md ../../docs/gguf/README.md",
"doc-space-header": "mkdir -p ../../docs/space-header && cp ../../packages/space-header/README.md ../../docs/space-header/README.md",
"update-toc": "tsx update-toc.ts",
"fix-cdn-versions": "tsx fix-cdn-versions.ts",
"fix-md-links": "tsx fix-md-links.ts",
Expand Down
59 changes: 59 additions & 0 deletions packages/space-header/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 🤗 Hugging Face Space Header

A Typescript powered wrapper for the Space `mini_header` feature.

## Install

```console
pnpm add @huggingface/space-header

npm add @huggingface/space-header

yarn add @huggingface/space-header
```

### Deno

```ts
// esm.sh
import { init } from "https://esm.sh/@huggingface/space-header"
// or npm:
import { init } from "npm:@huggingface/space-header"
```

### Initialize
```ts
import { init } from "@huggingface/space-header";

// ...

init(":user/:spaceId");
// init("enzostvs/lora-studio") for example
```
❗Important note: The `init` method must be called on the client side.

## Usage

Uses the `target` option to inject the space-header into another DOM element

```ts
const app = document.getElementById("app");

// ...

init(":user/:spaceId", {
target: app
});
```

If you already have the space data, you can also pass it as a parameter to avoid a fetch

```ts
init(space);

// space = {
// id: string;
// likes: number;
// author: string;
// }
```
1 change: 1 addition & 0 deletions packages/space-header/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src";
39 changes: 29 additions & 10 deletions packages/space-header/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
{
"name": "@huggingface/space-header",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"types": "dist/index.d.ts",
"module": "dist/index.js",
"version": "1.0.1",
"packageManager": "[email protected]",
"description": "Use the Space mini_header outside Hugging Face",
"repository": "https://github.com/huggingface/huggingface.js.git",
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
}
},
"browser": {
"./dist/index.js": "./dist/browser/index.js",
"./dist/index.mjs": "./dist/browser/index.mjs"
},
"scripts": {
"build": "tsup ./src",
"build": "tsup && tsc --emitDeclarationOnly --declaration",
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
"lint:check": "eslint --ext .cjs,.ts .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublishOnly": "pnpm run build"
},
"keywords": [],
"author": "",
"license": "ISC",
"keywords": [
"huggingface",
"spaces",
"space-header"
],
"author": "Hugging Face",
"license": "MIT",
"devDependencies": {
"tsup": "^8.1.0",
"typescript": "^5.4.5"
Expand Down
2 changes: 2 additions & 0 deletions packages/space-header/src/get_space.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Space } from "./type";
export declare const get_space: (space_id: string) => Promise<Space | null>;
1 change: 1 addition & 0 deletions packages/space-header/src/header/components/avatar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Avatar: (username: string) => HTMLImageElement;
1 change: 1 addition & 0 deletions packages/space-header/src/header/components/box.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Box: () => HTMLDivElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Count: (count: number) => HTMLParagraphElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Heart: () => SVGElement;
2 changes: 2 additions & 0 deletions packages/space-header/src/header/components/like/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Space } from "../../../type";
export declare const Like: (space: Space) => HTMLAnchorElement;
1 change: 1 addition & 0 deletions packages/space-header/src/header/components/namespace.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Namespace: (id: string) => HTMLAnchorElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Separation: () => HTMLDivElement;
1 change: 1 addition & 0 deletions packages/space-header/src/header/components/username.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Username: (username: string) => HTMLAnchorElement;
2 changes: 2 additions & 0 deletions packages/space-header/src/header/create.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Space } from "../type";
export declare const create: (space: Space) => HTMLElement;
2 changes: 2 additions & 0 deletions packages/space-header/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Options, Space } from "./type";
export declare const init: (space: string | Space, options?: Options) => Promise<void>;
2 changes: 2 additions & 0 deletions packages/space-header/src/inject.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Options } from "./type";
export declare const inject: (element: HTMLElement, options?: Options) => void;
1 change: 1 addition & 0 deletions packages/space-header/src/inject_fonts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const inject_fonts: () => void;
11 changes: 11 additions & 0 deletions packages/space-header/src/type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface Space {
id: string;
likes: number;
author: string;
}
export interface User {
avatarUrl: string;
}
export interface Options {
target?: HTMLElement | null | undefined;
}
21 changes: 15 additions & 6 deletions packages/space-header/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"declaration": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["ES2022", "DOM"],
"module": "CommonJS",
"moduleResolution": "node",
"target": "ES2022",
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
"noImplicitAny": true,
"strictNullChecks": true,
"skipLibCheck": true,
"noImplicitOverride": true,
"outDir": "./dist",
"declaration": true,
"declarationMap": true
},
"include": ["src", "index.ts"],
"exclude": ["dist"]
}
3 changes: 3 additions & 0 deletions packages/space-header/tsup.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { Options } from "tsup";
declare const _default: Options[];
export default _default;
27 changes: 20 additions & 7 deletions packages/space-header/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { defineConfig } from "tsup";
import type { Options } from "tsup";

export default defineConfig({
target: "es2020",
const baseConfig: Options = {
entry: ["./src/index.ts"],
format: ["cjs", "esm"],
splitting: false,
sourcemap: true,
outDir: "dist",
clean: true,
dts: true,
});
};

const nodeConfig: Options = {
...baseConfig,
platform: "node",
};

const browserConfig: Options = {
...baseConfig,
platform: "browser",
target: "es2018",
splitting: true,
outDir: "dist/browser",
};

export default [nodeConfig, browserConfig];
2 changes: 1 addition & 1 deletion packages/tasks/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@huggingface/tasks",
"packageManager": "[email protected]",
"version": "0.10.14",
"version": "0.10.15",
"description": "List of ML tasks for huggingface.co/tasks",
"repository": "https://github.com/huggingface/huggingface.js.git",
"publishConfig": {
Expand Down
24 changes: 24 additions & 0 deletions packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export const bertopic = (model: ModelData): string[] => [
model = BERTopic.load("${model.id}")`,
];

export const bm25s = (model: ModelData): string[] => [
`from bm25s.hf import BM25HF
retriever = BM25HF.load_from_hub("${model.id}")`,
];

const diffusers_default = (model: ModelData) => [
`from diffusers import DiffusionPipeline
Expand Down Expand Up @@ -97,6 +103,24 @@ export const diffusers = (model: ModelData): string[] => {
}
};

export const edsnlp = (model: ModelData): string[] => {
const packageName = nameWithoutNamespace(model.id).replaceAll("-", "_");
return [
`# Load it from the Hub directly
import edsnlp
nlp = edsnlp.load("${model.id}")
`,
`# Or install it as a package
!pip install git+https://huggingface.co/${model.id}
# and import it as a module
import ${packageName}
nlp = ${packageName}.load() # or edsnlp.load("${packageName}")
`,
];
};

export const espnetTTS = (model: ModelData): string[] => [
`from espnet2.bin.tts_inference import Text2Speech
Expand Down
21 changes: 21 additions & 0 deletions packages/tasks/src/model-libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ export const MODEL_LIBRARIES_UI_ELEMENTS = {
wildcard: { path: "*.npz" },
},
},
bm25s: {
prettyLabel: "BM25S",
repoName: "bm25s",
repoUrl: "https://github.com/xhluca/bm25s",
snippets: snippets.bm25s,
filter: false,
countDownloads: {
term: { path: "params.index.json" },
},
},
chat_tts: {
prettyLabel: "ChatTTS",
repoName: "ChatTTS",
Expand All @@ -133,6 +143,17 @@ export const MODEL_LIBRARIES_UI_ELEMENTS = {
repoName: "doctr",
repoUrl: "https://github.com/mindee/doctr",
},
edsnlp: {
prettyLabel: "EDS-NLP",
repoName: "edsnlp",
repoUrl: "https://github.com/aphp/edsnlp",
docsUrl: "https://aphp.github.io/edsnlp/latest/",
filter: false,
snippets: snippets.edsnlp,
countDownloads: {
wildcard: { path: "*/config.cfg" },
},
},
elm: {
prettyLabel: "ELM",
repoName: "elm",
Expand Down

0 comments on commit 6ddc7a0

Please sign in to comment.