Spaces:
Running
Running
Update dist/app.js
Browse files- dist/app.js +40 -91
dist/app.js
CHANGED
@@ -1,102 +1,51 @@
|
|
1 |
-
import {
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
`${window.location.origin}/mobilenet/group1-shard2of2`,
|
7 |
-
`${window.location.origin}/mobilenet/coffee.jpg`,
|
8 |
-
`${window.location.origin}/mobilenet/README.md`,
|
9 |
-
];
|
10 |
-
function filenameFromURL(url) {
|
11 |
-
return url.substring(url.lastIndexOf("/") + 1);
|
12 |
-
}
|
13 |
|
14 |
const lfsContent = "0123456789".repeat(1_000_000);
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
while (1) {
|
22 |
-
const { done, value } = await iterator.next();
|
23 |
-
if (done) {
|
24 |
-
console.log("one", value);
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
36 |
|
37 |
-
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
window.document.addEventListener("DOMContentLoaded", () => {
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
const storedToken = window.localStorage.getItem("hf_token");
|
47 |
-
if (storedToken) {
|
48 |
-
tokenEl.value = storedToken;
|
49 |
-
/// ^to help in dev.
|
50 |
-
}
|
51 |
-
test()
|
52 |
-
repoNameEl.value = `tfjs-mobilenet-${Date.now() % 1_000}`;
|
53 |
-
/// "random" repo name
|
54 |
-
form.addEventListener("submit", async (event) => {
|
55 |
-
event.preventDefault();
|
56 |
-
const token = tokenEl.value;
|
57 |
-
const repoName = repoNameEl.value;
|
58 |
-
if (!token || !repoName) {
|
59 |
-
alert("You need a token and a repo name");
|
60 |
-
return;
|
61 |
-
}
|
62 |
-
button.setAttribute("disabled", "disabled");
|
63 |
-
const credentials = {
|
64 |
-
accessToken: token,
|
65 |
-
};
|
66 |
-
try {
|
67 |
-
const { name: username } = await whoAmI({ credentials });
|
68 |
-
const name = `${username}/${repoName}`;
|
69 |
-
const { repoUrl } = await createRepo({
|
70 |
-
repo: {
|
71 |
-
type: "model",
|
72 |
-
name,
|
73 |
-
},
|
74 |
-
credentials,
|
75 |
-
});
|
76 |
-
const operations = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {
|
77 |
-
return {
|
78 |
-
operation: "addOrUpdate",
|
79 |
-
path: filenameFromURL(file),
|
80 |
-
// upload remote file
|
81 |
-
content: new URL(file),
|
82 |
-
};
|
83 |
-
}));
|
84 |
-
const commitOutput = await commit({
|
85 |
-
repo: {
|
86 |
-
type: "model",
|
87 |
-
name,
|
88 |
-
},
|
89 |
-
credentials,
|
90 |
-
title: "upload model",
|
91 |
-
operations,
|
92 |
-
});
|
93 |
-
c.log(commitOutput);
|
94 |
-
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>`);
|
95 |
-
}
|
96 |
-
catch (err) {
|
97 |
-
console.error(err);
|
98 |
-
output.append("\n" + err);
|
99 |
-
}
|
100 |
-
button.removeAttribute("disabled");
|
101 |
-
});
|
102 |
});
|
|
|
1 |
+
import { __internal_sha256 as shaUnbundledRegular } from "@huggingface/hub-unbundled-regular";
|
2 |
+
import { __internal_sha256 as shaUnbundled } from "@huggingface/hub-unbundled";
|
3 |
+
import { __internal_sha256 as shaRegular } from "@huggingface/hub-regular";
|
4 |
+
import { __internal_sha256 as shaEsm } from "@huggingface/hub-esm";
|
5 |
+
import { __internal_sha256 as sha } from "@huggingface/hub";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
const lfsContent = "0123456789".repeat(1_000_000);
|
8 |
|
9 |
+
const shas = {
|
10 |
+
"hub-unbundled-regular": shaUnbundledRegular,
|
11 |
+
"hub-unbundled": shaUnbundled,
|
12 |
+
"hub-regular": shaRegular,
|
13 |
+
"hub-esm": shaEsm,
|
14 |
+
"hub": sha
|
15 |
+
}
|
16 |
|
17 |
+
async function test(id) {
|
18 |
+
const blob = new Blob([lfsContent]);
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
try {
|
21 |
+
const iterator = __internal_sha256(blob, { useWebWorker: { minSize: 1 } });
|
22 |
+
// Get return value of the generator
|
23 |
+
while (1) {
|
24 |
+
const { done, value } = await iterator.next();
|
25 |
+
if (done) {
|
26 |
+
console.log("one", value);
|
27 |
+
document.getElementById(id).textContent = value;
|
28 |
|
29 |
+
const builtInResult = await crypto.subtle.digest("SHA-256", await blob.arrayBuffer());
|
30 |
+
const hex =
|
31 |
+
builtInResult instanceof ArrayBuffer
|
32 |
+
? new Uint8Array(builtInResult).reduce((acc, i) => acc + i.toString(16).padStart(2, "0"), "")
|
33 |
+
: builtInResult;
|
34 |
|
35 |
+
|
36 |
+
console.log("two", hex);
|
37 |
+
break;
|
38 |
+
}
|
39 |
|
40 |
+
}
|
41 |
+
} catch (err) {
|
42 |
+
document.getElementById(id).textContent = err.message;
|
43 |
+
}
|
44 |
}
|
45 |
window.document.addEventListener("DOMContentLoaded", () => {
|
46 |
+
test("hub-unbundled-regular");
|
47 |
+
test("hub-unbundled");
|
48 |
+
test("hub-regular");
|
49 |
+
test("hub-esm");
|
50 |
+
test("hub");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
});
|