Skip to content

Commit 31fdf54

Browse files
authored
Merge branch 'huggingface:main' into xsn/llama_snippet
2 parents 3d5db7d + 3f9c0a9 commit 31fdf54

File tree

51 files changed

+1037
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1037
-116
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
8888

8989
```html
9090
<script type="module">
91-
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@2.7.0/+esm';
91+
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@2.8.0/+esm';
9292
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
9393
</script>
9494
```

packages/hub/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,4 @@ Under the hood, `@huggingface/hub` uses a lazy blob implementation to load the f
121121

122122
## Dependencies
123123

124-
- `hash-wasm` : Only used in the browser, when committing files over 10 MB. Browsers do not natively support streaming sha256 computations.
125124
- `@huggingface/tasks` : Typings only

packages/hub/src/lib/commit.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,80 @@ size 4194304
204204
}
205205
// https://huggingfacejs-push-model-from-web.hf.space/
206206
}, 60_000);
207+
208+
it("should be able to create a PR and then commit to it", async function () {
209+
const repoName = `${TEST_USER}/TEST-${insecureRandomString()}`;
210+
const repo: RepoId = {
211+
name: repoName,
212+
type: "model",
213+
};
214+
215+
await createRepo({
216+
credentials: {
217+
accessToken: TEST_ACCESS_TOKEN,
218+
},
219+
repo,
220+
hubUrl: TEST_HUB_URL,
221+
});
222+
223+
try {
224+
const pr = await commit({
225+
repo,
226+
credentials: {
227+
accessToken: TEST_ACCESS_TOKEN,
228+
},
229+
hubUrl: TEST_HUB_URL,
230+
title: "Create PR",
231+
isPullRequest: true,
232+
operations: [
233+
{
234+
operation: "addOrUpdate",
235+
content: new Blob(["This is me"]),
236+
path: "test.txt",
237+
},
238+
],
239+
});
240+
241+
if (!pr) {
242+
throw new Error("PR creation failed");
243+
}
244+
245+
if (!pr.pullRequestUrl) {
246+
throw new Error("No pull request url");
247+
}
248+
249+
const prNumber = pr.pullRequestUrl.split("/").pop();
250+
const prRef = `refs/pr/${prNumber}`;
251+
252+
await commit({
253+
repo,
254+
credentials: {
255+
accessToken: TEST_ACCESS_TOKEN,
256+
},
257+
hubUrl: TEST_HUB_URL,
258+
branch: prRef,
259+
title: "Some commit",
260+
operations: [
261+
{
262+
operation: "addOrUpdate",
263+
content: new URL(
264+
`https://huggingface.co/spaces/huggingfacejs/push-model-from-web/resolve/main/mobilenet/group1-shard1of2`
265+
),
266+
path: "mobilenet/group1-shard1of2",
267+
},
268+
],
269+
});
270+
271+
assert(commit, "PR commit failed");
272+
} finally {
273+
await deleteRepo({
274+
repo: {
275+
name: repoName,
276+
type: "model",
277+
},
278+
hubUrl: TEST_HUB_URL,
279+
credentials: { accessToken: TEST_ACCESS_TOKEN },
280+
});
281+
}
282+
}, 60_000);
207283
});

packages/inference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@huggingface/inference",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"packageManager": "[email protected]",
55
"license": "MIT",
66
"author": "Tim Mikeladze <[email protected]>",

packages/inference/src/tasks/nlp/textGeneration.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TextGenerationInput, TextGenerationOutput } from "@huggingface/tasks";
22
import { InferenceOutputError } from "../../lib/InferenceOutputError";
33
import type { BaseArgs, Options } from "../../types";
4+
import { toArray } from "../../utils/toArray";
45
import { request } from "../custom/request";
56

67
export type { TextGenerationInput, TextGenerationOutput };
@@ -12,10 +13,12 @@ export async function textGeneration(
1213
args: BaseArgs & TextGenerationInput,
1314
options?: Options
1415
): Promise<TextGenerationOutput> {
15-
const res = await request<TextGenerationOutput[]>(args, {
16-
...options,
17-
taskHint: "text-generation",
18-
});
16+
const res = toArray(
17+
await request<TextGenerationOutput | TextGenerationOutput[]>(args, {
18+
...options,
19+
taskHint: "text-generation",
20+
})
21+
);
1922
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.generated_text === "string");
2023
if (!isValidOutput) {
2124
throw new InferenceOutputError("Expected Array<{generated_text: string}>");

packages/languages/src/languages_iso_639_3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17884,7 +17884,7 @@ export const LANGUAGES_ISO_639_3 = {
1788417884
},
1788517885
nan: {
1788617886
code: "nan",
17887-
name: "Min Nan Chinese",
17887+
name: "Southern Min (Min Nan Chinese)",
1788817888
},
1788917889
nao: {
1789017890
code: "nao",
@@ -30790,7 +30790,7 @@ export const LANGUAGES_ISO_639_3 = {
3079030790
},
3079130791
yue: {
3079230792
code: "yue",
30793-
name: "Yue Chinese",
30793+
name: "Cantonese (Yue Chinese)",
3079430794
},
3079530795
yuf: {
3079630796
code: "yuf",

packages/space-header/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@huggingface/space-header",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"packageManager": "[email protected]",
55
"description": "Use the Space mini_header outside Hugging Face",
66
"repository": "https://github.com/huggingface/huggingface.js.git",

packages/space-header/src/header/components/box.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ export const Box = (): HTMLDivElement => {
1313
box.style.justifyContent = "space-between";
1414
box.style.overflow = "hidden";
1515
box.style.position = "fixed";
16-
box.style.right = "1.5rem";
17-
box.style.top = "1.25rem";
16+
box.style.right = ".75rem";
17+
box.style.top = ".75rem";
1818
box.style.width = "auto";
1919
box.style.zIndex = "20";
20-
box.style.padding = "0.75rem";
2120
box.style.paddingLeft = "1rem";
22-
box.style.paddingRight = "0rem";
23-
2421
box.setAttribute("id", "huggingface-space-header");
2522

2623
window.matchMedia("(max-width: 768px)").addEventListener("change", (e) => {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const ArrowCollapse = (): SVGElement => {
2+
const arrow = document.createElementNS("http://www.w3.org/2000/svg", "svg");
3+
arrow.setAttribute("xmlns", "http://www.w3.org/2000/svg");
4+
arrow.setAttribute("xmlns:link", "http://www.w3.org/1999/xlink");
5+
arrow.setAttribute("aria-hidden", "true");
6+
arrow.setAttribute("focusable", "false");
7+
arrow.setAttribute("role", "img");
8+
arrow.setAttribute("width", "1em");
9+
arrow.setAttribute("height", "1em");
10+
arrow.setAttribute("preserveAspectRatio", "xMidYMid meet");
11+
arrow.setAttribute("viewBox", "0 0 12 12");
12+
arrow.setAttribute("fill", "currentColor");
13+
14+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
15+
16+
path.setAttribute(
17+
"d",
18+
"M0.375001 10.3828L0.375 1.61719C0.375 1.104 0.816001 0.687501 1.35938 0.687501L10.6406 0.6875C10.9017 0.6875 11.1521 0.785449 11.3367 0.959797C11.5213 1.13415 11.625 1.37062 11.625 1.61719V10.3828C11.625 10.6294 11.5213 10.8659 11.3367 11.0402C11.1521 11.2145 10.9017 11.3125 10.6406 11.3125H1.35938C0.816001 11.3125 0.375001 10.896 0.375001 10.3828ZM1.35938 10.5156H10.6406C10.7183 10.5156 10.7813 10.4561 10.7813 10.3828V4.40625H1.21875V10.3828C1.21875 10.418 1.23356 10.4518 1.25994 10.4767C1.28631 10.5017 1.32208 10.5156 1.35938 10.5156ZM4.61052 6.38251L5.9999 7.69472L7.38927 6.38251C7.44083 6.33007 7.50645 6.29173 7.57913 6.27153C7.6518 6.25134 7.72898 6.25003 7.8024 6.26776C7.87583 6.28549 7.9428 6.3216 7.99628 6.37227C8.04983 6.42295 8.08785 6.48631 8.10645 6.5557C8.12528 6.62497 8.12393 6.69773 8.10263 6.76635C8.0814 6.83497 8.0409 6.8969 7.98555 6.94564L6.29802 8.53936C6.21892 8.61399 6.11169 8.65592 5.9999 8.65592C5.8881 8.65592 5.78087 8.61399 5.70177 8.53936L4.01427 6.94564C3.95874 6.89694 3.91814 6.835 3.89676 6.76633C3.87538 6.69766 3.874 6.62483 3.89277 6.55549C3.91154 6.48615 3.94977 6.42287 4.00343 6.37233C4.05708 6.32179 4.12418 6.28585 4.19765 6.2683C4.27098 6.25054 4.34803 6.25178 4.42068 6.27188C4.49334 6.29198 4.55891 6.3302 4.61052 6.38251Z"
19+
);
20+
21+
arrow.appendChild(path);
22+
return arrow;
23+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Space } from "../../../type";
2+
import { ArrowCollapse } from "./arrow";
3+
4+
export const Collapse = (space: Space, callback: () => void): HTMLDivElement | SVGElement => {
5+
const box = document.createElement("div");
6+
7+
box.setAttribute("id", "space-header__collapse");
8+
9+
box.style.display = "flex";
10+
box.style.flexDirection = "row";
11+
box.style.alignItems = "center";
12+
box.style.justifyContent = "center";
13+
box.style.fontSize = "16px";
14+
box.style.paddingLeft = "10px";
15+
box.style.paddingRight = "10px";
16+
box.style.height = "40px";
17+
box.style.cursor = "pointer";
18+
box.style.color = "#40546e";
19+
box.style.transitionDuration = "0.1s";
20+
box.style.transitionProperty = "all";
21+
box.style.transitionTimingFunction = "ease-in-out";
22+
23+
box.appendChild(ArrowCollapse());
24+
25+
box.addEventListener("click", (e) => {
26+
e.preventDefault();
27+
e.stopPropagation();
28+
callback();
29+
});
30+
31+
box.addEventListener("mouseenter", () => {
32+
box.style.color = "#213551";
33+
});
34+
box.addEventListener("mouseleave", () => {
35+
box.style.color = "#40546e";
36+
});
37+
38+
return box;
39+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Space } from "../../../type";
2+
import { Like } from "../like";
3+
import { Avatar } from "./avatar";
4+
import { Namespace } from "./namespace";
5+
import { Separation } from "./separation";
6+
import { Username } from "./username";
7+
8+
export const Content = (space: Space): HTMLDivElement => {
9+
const content = document.createElement("div");
10+
content.style.display = "flex";
11+
content.style.flexDirection = "row";
12+
content.style.alignItems = "center";
13+
content.style.justifyContent = "center";
14+
content.style.borderRight = "1px solid #e5e7eb";
15+
content.style.paddingRight = "12px";
16+
content.style.height = "40px";
17+
18+
content.appendChild(Avatar(space.author));
19+
content.appendChild(Username(space.author));
20+
content.appendChild(Separation());
21+
content.appendChild(Namespace(space.id));
22+
content.appendChild(Like(space));
23+
24+
return content;
25+
};

packages/space-header/src/header/components/namespace.ts renamed to packages/space-header/src/header/components/content/namespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const Namespace = (id: string): HTMLAnchorElement => {
1010
element.style.color = "#1f2937";
1111
element.style.textDecoration = "none";
1212
element.style.fontWeight = "600";
13-
element.style.fontSize = "16px";
13+
element.style.fontSize = "15px";
1414
element.style.lineHeight = "24px";
1515
element.style.flex = "none";
1616
element.style.fontFamily = "IBM Plex Mono, sans-serif";

packages/space-header/src/header/components/like/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export const Like = (space: Space): HTMLAnchorElement => {
1414
box.style.display = "flex";
1515
box.style.flexDirection = "row";
1616
box.style.alignItems = "center";
17-
box.style.margin = "0 12px";
17+
box.style.margin = "0 0 0 12px";
1818
box.style.fontSize = "14px";
1919
box.style.paddingLeft = "4px";
20+
box.style.textDecoration = "none";
2021

2122
box.appendChild(Heart());
2223
box.appendChild(Count(space.likes));
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import type { Space } from "../type";
22

3-
import { Avatar } from "./components/avatar";
43
import { Box } from "./components/box";
5-
import { Username } from "./components/username";
6-
import { Separation } from "./components/separation";
7-
import { Namespace } from "./components/namespace";
8-
import { Like } from "./components/like";
4+
import { Collapse } from "./components/collapse";
5+
import { Content } from "./components/content";
96

107
export const create = (space: Space): HTMLElement => {
118
const box = Box();
129

13-
box.appendChild(Avatar(space.author));
14-
box.appendChild(Username(space.author));
15-
box.appendChild(Separation());
16-
box.appendChild(Namespace(space.id));
17-
box.appendChild(Like(space));
10+
const handleCollapse = () => (box.style.display = "none");
11+
12+
box.appendChild(Content(space));
13+
box.appendChild(Collapse(space, handleCollapse));
1814

1915
return box;
2016
};

packages/space-header/src/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Options, Space } from "./type";
1+
import type { Options, Space, Header } from "./type";
22

33
import { inject_fonts } from "./inject_fonts";
44

@@ -9,7 +9,12 @@ import { inject } from "./inject";
99
async function main(initialSpace: string | Space, options?: Options) {
1010
if (window === undefined) return console.error("Please run this script in a browser environment");
1111
// Don't run on huggingface.co to avoid duplicate headers
12-
if (window.location?.origin === "https://huggingface.co") return;
12+
const has_huggingface_ancestor = Object.values(
13+
window.location?.ancestorOrigins ?? {
14+
0: window.document.referrer,
15+
}
16+
).some((origin) => new URL(origin)?.origin === "https://huggingface.co");
17+
if (has_huggingface_ancestor) return;
1318

1419
inject_fonts();
1520

@@ -18,10 +23,16 @@ async function main(initialSpace: string | Space, options?: Options) {
1823
if (typeof initialSpace === "string") {
1924
space = await get_space(initialSpace);
2025
if (space === null) return console.error("Space not found");
26+
} else {
27+
space = initialSpace;
2128
}
2229

2330
const mini_header_element = create(space as Space);
2431
inject(mini_header_element, options);
32+
33+
return {
34+
element: mini_header_element,
35+
};
2536
}
2637

27-
export const init = (space: string | Space, options?: Options): Promise<void> => main(space, options);
38+
export const init = (space: string | Space, options?: Options): Promise<Header | void> => main(space, options);

packages/space-header/src/type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ export interface User {
1111
export interface Options {
1212
target?: HTMLElement | null | undefined;
1313
}
14+
15+
export interface Header {
16+
element: HTMLElement;
17+
}

packages/tasks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This package contains the definition files (written in Typescript) for the huggi
44

55
- **pipeline types** (a.k.a. **task types**) - used to determine which widget to display on the model page, and which inference API to run.
66
- **default widget inputs** - when they aren't provided in the model card.
7-
- definitions and UI elements for **model libraries** (and soon for **dataset libraries**).
7+
- definitions and UI elements for **model and dataset libraries**.
88

99
Please add any missing ones to these definitions by opening a PR. Thanks 🔥
1010

packages/tasks/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/tasks",
33
"packageManager": "[email protected]",
4-
"version": "0.10.21",
4+
"version": "0.11.6",
55
"description": "List of ML tasks for huggingface.co/tasks",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {
@@ -28,7 +28,8 @@
2828
"prepare": "pnpm run build",
2929
"check": "tsc",
3030
"inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write src/tasks/*/inference.ts",
31-
"inference-tgi-import": "tsx scripts/inference-tgi-import.ts && prettier --write src/tasks/text-generation/spec/*.json && prettier --write src/tasks/chat-completion/spec/*.json"
31+
"inference-tgi-import": "tsx scripts/inference-tgi-import.ts && prettier --write src/tasks/text-generation/spec/*.json && prettier --write src/tasks/chat-completion/spec/*.json",
32+
"inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write src/tasks/feature-extraction/spec/*.json"
3233
},
3334
"type": "module",
3435
"files": [

0 commit comments

Comments
 (0)