Aschen commited on
Commit
f6a76d5
1 Parent(s): 25ea5f1

build js :facepalm:

Browse files
Files changed (1) hide show
  1. dist/app.js +47 -35
dist/app.js CHANGED
@@ -1,4 +1,3 @@
1
- import { createRepo, commit, whoAmI } from "@huggingface/hub";
2
  const c = console;
3
  const FILES_TO_UPLOAD = [
4
  "./mobilenet/model.json",
@@ -21,9 +20,9 @@ window.document.addEventListener("DOMContentLoaded", () => {
21
  tokenEl.value = storedToken;
22
  /// ^to help in dev.
23
  }
24
- repoNameEl.value = `tfjs-mobilenet-${Date.now() % 1_000}`;
25
  /// "random" repo name
26
- form.addEventListener("submit", async function (event) {
27
  event.preventDefault();
28
  const token = tokenEl.value;
29
  const repoName = repoNameEl.value;
@@ -35,38 +34,51 @@ window.document.addEventListener("DOMContentLoaded", () => {
35
  const credentials = {
36
  accessToken: token,
37
  };
38
- try {
39
- const { name: username } = await whoAmI({ credentials });
40
- const name = `${username}/${repoName}`;
41
- const { repoUrl } = await createRepo({
42
- repo: {
43
- type: "model",
44
- name,
45
- },
46
- credentials,
47
- });
48
- const operations = await Promise.all(FILES_TO_UPLOAD.map(async (file) => {
49
- return {
50
- operation: "addOrUpdate",
51
- path: filenameFromURL(file),
52
- content: await (await fetch(file)).blob(),
53
- };
54
- }));
55
- const commitOutput = await commit({
56
- repo: {
57
- type: "model",
58
- name,
59
- },
60
- credentials,
61
- title: "upload model",
62
- operations,
63
- });
64
- c.log(commitOutput);
65
- 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>`);
66
- }
67
- catch (err) {
68
- output.append("\n" + err);
69
- }
 
 
 
 
 
 
 
 
 
 
 
 
70
  button.removeAttribute("disabled");
71
  });
72
  });
 
 
 
1
  const c = console;
2
  const FILES_TO_UPLOAD = [
3
  "./mobilenet/model.json",
 
20
  tokenEl.value = storedToken;
21
  /// ^to help in dev.
22
  }
23
+ repoNameEl.value = `hello-world-${Date.now() % 1_000}`;
24
  /// "random" repo name
25
+ form.addEventListener("submit", async (event) => {
26
  event.preventDefault();
27
  const token = tokenEl.value;
28
  const repoName = repoNameEl.value;
 
34
  const credentials = {
35
  accessToken: token,
36
  };
37
+ const result = await fetch("./mobilenet/model.json", {
38
+ headers: {
39
+ Range: "bytes=0-100",
40
+ },
41
+ });
42
+ const text = await result.text();
43
+ c.log(text);
44
+ output.append("\n" + text);
45
+ // try {
46
+ // const { name: username } = await whoAmI({ credentials });
47
+ // const name = `${username}/${repoName}`;
48
+ // const { repoUrl } = await createRepo({
49
+ // repo: {
50
+ // type: "model",
51
+ // name,
52
+ // },
53
+ // credentials,
54
+ // });
55
+ // const operations: CommitFile[] = await Promise.all(
56
+ // FILES_TO_UPLOAD.map(async (file) => {
57
+ // return {
58
+ // operation: "addOrUpdate",
59
+ // path: filenameFromURL(file),
60
+ // content: await (await fetch(file)).blob(),
61
+ // };
62
+ // })
63
+ // );
64
+ // const commitOutput = await commit({
65
+ // repo: {
66
+ // type: "model",
67
+ // name,
68
+ // },
69
+ // credentials,
70
+ // title: "upload model",
71
+ // operations,
72
+ // });
73
+ // c.log(commitOutput);
74
+ // button.insertAdjacentHTML(
75
+ // "afterend",
76
+ // `<div class="text-green-500 mb-6">🎉 Upload complete! Model page is <a target="_blank" class="text-bold underline" href="${repoUrl}">${repoUrl}</a></div>`
77
+ // );
78
+ // } catch (err) {
79
+ // output.append("\n" + err);
80
+ // }
81
  button.removeAttribute("disabled");
82
  });
83
  });
84
+ export {};