coyotte508 commited on
Commit ·
b98ad90
1
Parent(s): 1f05f10
⬆️ Upgrade @huggingface/hub
Browse filesFiles changed (6)
- app.ts+21-37
- dist/app.js+9-22
- index.html+1-1
- package-lock.json
- package.json+18-16
- tsconfig.json+3-2
123456789101112131415161718192011 unmodified lines323334353637383940414243444546473 unmodified lines51525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102import { createRepo, commit, AccessToken, CommitFile } from "@huggingface/hub";const c = console;const ENDPOINT = "https://huggingface.co";async function whoami(token: string): Promise<{ name: string }> {const path = `${ENDPOINT}/api/whoami-v2`;const res = await fetch(path, {headers: {Authorization: `Bearer ${token}`,}});return await res.json();}const FILES_TO_UPLOAD = ["./mobilenet/model.json","./mobilenet/group1-shard1of2",11 unmodified linesconst repoNameEl = document.querySelector<HTMLInputElement>("#repo_name")!;const button = document.querySelector("#submit")!;const output = document.querySelector("#logs")!;const storedToken = window.localStorage.getItem("hf_token");if (storedToken) {tokenEl.value = storedToken;/// ^to help in dev.}repoNameEl.value = `tfjs-mobilenet-${Date.now() % 1_000}`;/// "random" repo namebutton.addEventListener("click", async function () {const token = tokenEl.value;const repoName = repoNameEl.value;3 unmodified lines}button.setAttribute("disabled", "disabled");try {const { name: username } = await whoami(token);const name = `${username}/${repoName}`;await createRepo({repo: {type: "model",name,},credentials: {accessToken: token as AccessToken,}});const operations: CommitFile[] = await Promise.all(FILES_TO_UPLOAD.map(async file => {return {operation: "addOrUpdate",path: filenameFromURL(file),content: await (await fetch(file)).blob(),}}));const commitOutput = await commit({repo: {type: "model",name,},credentials: {accessToken: token as AccessToken,},title: "upload model",operations,});c.log(commitOutput);const fullUrl = `${ENDPOINT}/${name}`;/// ^TODO(get it from the createRepo call)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>`);} catch (err) {output.append("\n"+err);}button.removeAttribute("disabled");});});123456711 unmodified lines192021222324252627282930313233343 unmodified lines38394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { createRepo, commit, CommitFile, whoAmI } from "@huggingface/hub";const c = console;const FILES_TO_UPLOAD = ["./mobilenet/model.json","./mobilenet/group1-shard1of2",11 unmodified linesconst repoNameEl = document.querySelector<HTMLInputElement>("#repo_name")!;const button = document.querySelector("#submit")!;const output = document.querySelector("#logs")!;const storedToken = window.localStorage.getItem("hf_token");if (storedToken) {tokenEl.value = storedToken;/// ^to help in dev.}repoNameEl.value = `tfjs-mobilenet-${Date.now() % 1_000}`;/// "random" repo namebutton.addEventListener("click", async function () {const token = tokenEl.value;const repoName = repoNameEl.value;3 unmodified lines}button.setAttribute("disabled", "disabled");const credentials = {accessToken: token,};try {const { name: username } = await whoAmI({ credentials });const name = `${username}/${repoName}`;const { repoUrl } = await createRepo({repo: {type: "model",name,},credentials,});const operations: CommitFile[] = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {return {operation: "addOrUpdate",path: filenameFromURL(file),content: await (await fetch(file)).blob(),};}));const commitOutput = await commit({repo: {type: "model",name,},credentials,title: "upload model",operations,});c.log(commitOutput);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>`);} catch (err) {output.append("\n" + err);}button.removeAttribute("disabled");});});
12345678910111213141524 unmodified lines40414243444546474849505152535455567 unmodified lines64656667686970717273747576777879import { createRepo, commit } from "@huggingface/hub";const c = console;const ENDPOINT = "https://huggingface.co";async function whoami(token) {const path = `${ENDPOINT}/api/whoami-v2`;const res = await fetch(path, {headers: {Authorization: `Bearer ${token}`,}});return await res.json();}const FILES_TO_UPLOAD = ["./mobilenet/model.json","./mobilenet/group1-shard1of2",24 unmodified linesreturn;}button.setAttribute("disabled", "disabled");try {const { name: username } = await whoami(token);const name = `${username}/${repoName}`;await createRepo({repo: {type: "model",name,},credentials: {accessToken: token,}});const operations = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {return {7 unmodified linestype: "model",name,},credentials: {accessToken: token,},title: "upload model",operations,});c.log(commitOutput);const fullUrl = `${ENDPOINT}/${name}`;/// ^TODO(get it from the createRepo call)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>`);}catch (err) {output.append("\n" + err);1234524 unmodified lines3031323334353637383940414243444546477 unmodified lines555657585960616263646566import { createRepo, commit, whoAmI } from "@huggingface/hub";const c = console;const FILES_TO_UPLOAD = ["./mobilenet/model.json","./mobilenet/group1-shard1of2",24 unmodified linesreturn;}button.setAttribute("disabled", "disabled");const credentials = {accessToken: token,};try {const { name: username } = await whoAmI({ credentials });const name = `${username}/${repoName}`;const { repoUrl } = await createRepo({repo: {type: "model",name,},credentials,});const operations = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {return {7 unmodified linestype: "model",name,},credentials,title: "upload model",operations,});c.log(commitOutput);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>`);}catch (err) {output.append("\n" + err);
6 unmodified lines789101112136 unmodified lines<script type="importmap">{"imports": {"@huggingface/hub": "https://cdn.skypack.dev/@huggingface/hub@0.1.6"}}</script>6 unmodified lines789101112136 unmodified lines<script type="importmap">{"imports": {"@huggingface/hub": "https://cdn.skypack.dev/@huggingface/hub@0.2.1"}}</script>
123456789101112131415161718{"name": "push-model-from-web","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1"},"author": "","license": "ISC","dependencies": {"@huggingface/hub": "^0.1.5"},"devDependencies": {"prettier": "^2.8.4","tailwindcss": "^3.2.7"}}1234567891011121314151617181920{"name": "push-model-from-web","version": "1.0.0","description": "","main": "index.js","scripts": {"build": "tsc"},"author": "","license": "ISC","dependencies": {"@huggingface/hub": "^0.2.1"},"devDependencies": {"@types/node": "^18.15.3","prettier": "^2.8.5","tailwindcss": "^3.2.7","typescript": "^5.0.2"}}
5 unmodified lines678910115 unmodified lines"moduleResolution": "node","strictNullChecks": true,"strictBindCallApply": true,"lib": ["DOM", "ES2021"]}}5 unmodified lines67891011125 unmodified lines"moduleResolution": "node","strictNullChecks": true,"strictBindCallApply": true,"lib": ["DOM", "ES2021"],"skipLibCheck": true}}
app.ts+21-37
dist/app.js+9-22
index.html+1-1
package-lock.json
package.json+18-16
tsconfig.json+3-2