Commit
•
b98ad90
1
Parent(s):
1f05f10
⬆️ Upgrade @huggingface/hub
Browse files- app.ts +21 -37
- dist/app.js +9 -22
- index.html +1 -1
- package-lock.json +0 -0
- package.json +18 -16
- tsconfig.json +3 -2
app.ts
CHANGED
@@ -1,20 +1,7 @@
|
|
1 |
-
import { createRepo, commit,
|
2 |
|
3 |
const c = console;
|
4 |
|
5 |
-
const ENDPOINT = "https://huggingface.co";
|
6 |
-
|
7 |
-
async function whoami(token: string): Promise<{ name: string }> {
|
8 |
-
const path = `${ENDPOINT}/api/whoami-v2`;
|
9 |
-
const res = await fetch(path, {
|
10 |
-
headers: {
|
11 |
-
Authorization: `Bearer ${token}`,
|
12 |
-
}
|
13 |
-
});
|
14 |
-
return await res.json();
|
15 |
-
}
|
16 |
-
|
17 |
-
|
18 |
const FILES_TO_UPLOAD = [
|
19 |
"./mobilenet/model.json",
|
20 |
"./mobilenet/group1-shard1of2",
|
@@ -32,16 +19,16 @@ window.addEventListener("load", function () {
|
|
32 |
const repoNameEl = document.querySelector<HTMLInputElement>("#repo_name")!;
|
33 |
const button = document.querySelector("#submit")!;
|
34 |
const output = document.querySelector("#logs")!;
|
35 |
-
|
36 |
const storedToken = window.localStorage.getItem("hf_token");
|
37 |
if (storedToken) {
|
38 |
tokenEl.value = storedToken;
|
39 |
/// ^to help in dev.
|
40 |
}
|
41 |
-
|
42 |
repoNameEl.value = `tfjs-mobilenet-${Date.now() % 1_000}`;
|
43 |
/// "random" repo name
|
44 |
-
|
45 |
button.addEventListener("click", async function () {
|
46 |
const token = tokenEl.value;
|
47 |
const repoName = repoNameEl.value;
|
@@ -51,52 +38,49 @@ window.addEventListener("load", function () {
|
|
51 |
}
|
52 |
|
53 |
button.setAttribute("disabled", "disabled");
|
|
|
|
|
|
|
|
|
|
|
54 |
try {
|
55 |
-
const { name: username } = await
|
56 |
const name = `${username}/${repoName}`;
|
57 |
-
await createRepo({
|
58 |
repo: {
|
59 |
type: "model",
|
60 |
name,
|
61 |
},
|
62 |
-
credentials
|
63 |
-
accessToken: token as AccessToken,
|
64 |
-
}
|
65 |
});
|
66 |
-
|
67 |
const operations: CommitFile[] = await Promise.all(
|
68 |
-
FILES_TO_UPLOAD.map(async file => {
|
69 |
return {
|
70 |
operation: "addOrUpdate",
|
71 |
path: filenameFromURL(file),
|
72 |
content: await (await fetch(file)).blob(),
|
73 |
-
}
|
74 |
-
}
|
75 |
-
)
|
76 |
const commitOutput = await commit({
|
77 |
repo: {
|
78 |
type: "model",
|
79 |
name,
|
80 |
},
|
81 |
-
credentials
|
82 |
-
accessToken: token as AccessToken,
|
83 |
-
},
|
84 |
title: "upload model",
|
85 |
operations,
|
86 |
});
|
87 |
c.log(commitOutput);
|
88 |
-
|
89 |
-
const fullUrl = `${ENDPOINT}/${name}`;
|
90 |
-
/// ^TODO(get it from the createRepo call)
|
91 |
button.insertAdjacentHTML(
|
92 |
"afterend",
|
93 |
-
`<div class="text-green-500 mb-6">🎉 Upload complete! Model page is <a target="_blank" class="text-bold underline" href="${
|
94 |
);
|
95 |
} catch (err) {
|
96 |
-
output.append("\n"+err);
|
97 |
}
|
98 |
button.removeAttribute("disabled");
|
99 |
});
|
100 |
});
|
101 |
-
|
102 |
-
|
|
|
1 |
+
import { createRepo, commit, CommitFile, whoAmI } from "@huggingface/hub";
|
2 |
|
3 |
const c = console;
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
const FILES_TO_UPLOAD = [
|
6 |
"./mobilenet/model.json",
|
7 |
"./mobilenet/group1-shard1of2",
|
|
|
19 |
const repoNameEl = document.querySelector<HTMLInputElement>("#repo_name")!;
|
20 |
const button = document.querySelector("#submit")!;
|
21 |
const output = document.querySelector("#logs")!;
|
22 |
+
|
23 |
const storedToken = window.localStorage.getItem("hf_token");
|
24 |
if (storedToken) {
|
25 |
tokenEl.value = storedToken;
|
26 |
/// ^to help in dev.
|
27 |
}
|
28 |
+
|
29 |
repoNameEl.value = `tfjs-mobilenet-${Date.now() % 1_000}`;
|
30 |
/// "random" repo name
|
31 |
+
|
32 |
button.addEventListener("click", async function () {
|
33 |
const token = tokenEl.value;
|
34 |
const repoName = repoNameEl.value;
|
|
|
38 |
}
|
39 |
|
40 |
button.setAttribute("disabled", "disabled");
|
41 |
+
|
42 |
+
const credentials = {
|
43 |
+
accessToken: token,
|
44 |
+
};
|
45 |
+
|
46 |
try {
|
47 |
+
const { name: username } = await whoAmI({ credentials });
|
48 |
const name = `${username}/${repoName}`;
|
49 |
+
const { repoUrl } = await createRepo({
|
50 |
repo: {
|
51 |
type: "model",
|
52 |
name,
|
53 |
},
|
54 |
+
credentials,
|
|
|
|
|
55 |
});
|
56 |
+
|
57 |
const operations: CommitFile[] = await Promise.all(
|
58 |
+
FILES_TO_UPLOAD.map(async (file) => {
|
59 |
return {
|
60 |
operation: "addOrUpdate",
|
61 |
path: filenameFromURL(file),
|
62 |
content: await (await fetch(file)).blob(),
|
63 |
+
};
|
64 |
+
})
|
65 |
+
);
|
66 |
const commitOutput = await commit({
|
67 |
repo: {
|
68 |
type: "model",
|
69 |
name,
|
70 |
},
|
71 |
+
credentials,
|
|
|
|
|
72 |
title: "upload model",
|
73 |
operations,
|
74 |
});
|
75 |
c.log(commitOutput);
|
76 |
+
|
|
|
|
|
77 |
button.insertAdjacentHTML(
|
78 |
"afterend",
|
79 |
+
`<div class="text-green-500 mb-6">🎉 Upload complete! Model page is <a target="_blank" class="text-bold underline" href="${repoUrl}">${repoUrl}</a></div>`
|
80 |
);
|
81 |
} catch (err) {
|
82 |
+
output.append("\n" + err);
|
83 |
}
|
84 |
button.removeAttribute("disabled");
|
85 |
});
|
86 |
});
|
|
|
|
dist/app.js
CHANGED
@@ -1,15 +1,5 @@
|
|
1 |
-
import { createRepo, commit } from "@huggingface/hub";
|
2 |
const c = console;
|
3 |
-
const ENDPOINT = "https://huggingface.co";
|
4 |
-
async function whoami(token) {
|
5 |
-
const path = `${ENDPOINT}/api/whoami-v2`;
|
6 |
-
const res = await fetch(path, {
|
7 |
-
headers: {
|
8 |
-
Authorization: `Bearer ${token}`,
|
9 |
-
}
|
10 |
-
});
|
11 |
-
return await res.json();
|
12 |
-
}
|
13 |
const FILES_TO_UPLOAD = [
|
14 |
"./mobilenet/model.json",
|
15 |
"./mobilenet/group1-shard1of2",
|
@@ -40,17 +30,18 @@ window.addEventListener("load", function () {
|
|
40 |
return;
|
41 |
}
|
42 |
button.setAttribute("disabled", "disabled");
|
|
|
|
|
|
|
43 |
try {
|
44 |
-
const { name: username } = await
|
45 |
const name = `${username}/${repoName}`;
|
46 |
-
await createRepo({
|
47 |
repo: {
|
48 |
type: "model",
|
49 |
name,
|
50 |
},
|
51 |
-
credentials
|
52 |
-
accessToken: token,
|
53 |
-
}
|
54 |
});
|
55 |
const operations = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {
|
56 |
return {
|
@@ -64,16 +55,12 @@ window.addEventListener("load", function () {
|
|
64 |
type: "model",
|
65 |
name,
|
66 |
},
|
67 |
-
credentials
|
68 |
-
accessToken: token,
|
69 |
-
},
|
70 |
title: "upload model",
|
71 |
operations,
|
72 |
});
|
73 |
c.log(commitOutput);
|
74 |
-
|
75 |
-
/// ^TODO(get it from the createRepo call)
|
76 |
-
button.insertAdjacentHTML("afterend", `<div class="text-green-500 mb-6">🎉 Upload complete! Model page is <a target="_blank" class="text-bold underline" href="${fullUrl}">${fullUrl}</a></div>`);
|
77 |
}
|
78 |
catch (err) {
|
79 |
output.append("\n" + err);
|
|
|
1 |
+
import { createRepo, commit, whoAmI } from "@huggingface/hub";
|
2 |
const c = console;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
const FILES_TO_UPLOAD = [
|
4 |
"./mobilenet/model.json",
|
5 |
"./mobilenet/group1-shard1of2",
|
|
|
30 |
return;
|
31 |
}
|
32 |
button.setAttribute("disabled", "disabled");
|
33 |
+
const credentials = {
|
34 |
+
accessToken: token,
|
35 |
+
};
|
36 |
try {
|
37 |
+
const { name: username } = await whoAmI({ credentials });
|
38 |
const name = `${username}/${repoName}`;
|
39 |
+
const { repoUrl } = await createRepo({
|
40 |
repo: {
|
41 |
type: "model",
|
42 |
name,
|
43 |
},
|
44 |
+
credentials,
|
|
|
|
|
45 |
});
|
46 |
const operations = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {
|
47 |
return {
|
|
|
55 |
type: "model",
|
56 |
name,
|
57 |
},
|
58 |
+
credentials,
|
|
|
|
|
59 |
title: "upload model",
|
60 |
operations,
|
61 |
});
|
62 |
c.log(commitOutput);
|
63 |
+
button.insertAdjacentHTML("afterend", `<div class="text-green-500 mb-6">🎉 Upload complete! Model page is <a target="_blank" class="text-bold underline" href="${repoUrl}">${repoUrl}</a></div>`);
|
|
|
|
|
64 |
}
|
65 |
catch (err) {
|
66 |
output.append("\n" + err);
|
index.html
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
<script type="importmap">
|
8 |
{
|
9 |
"imports": {
|
10 |
-
"@huggingface/hub": "https://cdn.skypack.dev/@huggingface/hub@0.1
|
11 |
}
|
12 |
}
|
13 |
</script>
|
|
|
7 |
<script type="importmap">
|
8 |
{
|
9 |
"imports": {
|
10 |
+
"@huggingface/hub": "https://cdn.skypack.dev/@huggingface/hub@0.2.1"
|
11 |
}
|
12 |
}
|
13 |
</script>
|
package-lock.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
package.json
CHANGED
@@ -1,18 +1,20 @@
|
|
1 |
{
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
}
|
|
|
1 |
{
|
2 |
+
"name": "push-model-from-web",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"description": "",
|
5 |
+
"main": "index.js",
|
6 |
+
"scripts": {
|
7 |
+
"build": "tsc"
|
8 |
+
},
|
9 |
+
"author": "",
|
10 |
+
"license": "ISC",
|
11 |
+
"dependencies": {
|
12 |
+
"@huggingface/hub": "^0.2.1"
|
13 |
+
},
|
14 |
+
"devDependencies": {
|
15 |
+
"@types/node": "^18.15.3",
|
16 |
+
"prettier": "^2.8.5",
|
17 |
+
"tailwindcss": "^3.2.7",
|
18 |
+
"typescript": "^5.0.2"
|
19 |
+
}
|
20 |
}
|
tsconfig.json
CHANGED
@@ -6,6 +6,7 @@
|
|
6 |
"moduleResolution": "node",
|
7 |
"strictNullChecks": true,
|
8 |
"strictBindCallApply": true,
|
9 |
-
"lib": ["DOM", "ES2021"]
|
|
|
10 |
}
|
11 |
-
}
|
|
|
6 |
"moduleResolution": "node",
|
7 |
"strictNullChecks": true,
|
8 |
"strictBindCallApply": true,
|
9 |
+
"lib": ["DOM", "ES2021"],
|
10 |
+
"skipLibCheck": true
|
11 |
}
|
12 |
+
}
|