julien-c HF staff commited on
Commit
081a4b3
1 Parent(s): 431b4de

temp snapshot

Browse files
Files changed (3) hide show
  1. app.ts +56 -2
  2. dist/app.js +47 -1
  3. index.html +52 -19
app.ts CHANGED
@@ -1,7 +1,61 @@
1
  const c = console;
2
 
3
- document.addEventListener("load", function () {
4
- c.log("Hello");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  });
6
 
7
 
 
1
  const c = console;
2
 
3
+ // const ENDPOINT = "https://huggingface.co";
4
+ const ENDPOINT = "http://localhost:5564";
5
+
6
+ async function whoami(token: string): Promise<{ name: string }> {
7
+ const path = `${ENDPOINT}/api/whoami-v2`;
8
+ const res = await fetch(path, {
9
+ headers: {
10
+ Authorization: `Bearer ${token}`,
11
+ Origin: `127.0.0.1:8000`
12
+ }
13
+ });
14
+ return await res.json();
15
+ }
16
+
17
+ async function createRepo(
18
+ token: string,
19
+ repoId: string,
20
+ repoType: "model" | "dataset" | "space",
21
+ ): Promise<string> {
22
+ const path = `${ENDPOINT}/api/repos/create`;
23
+ const res = await fetch(path, {
24
+ method: "POST",
25
+ headers: {
26
+ Authorization: `Bearer ${token}`,
27
+ },
28
+ body: JSON.stringify({
29
+ name: repoId,
30
+ type: repoType,
31
+ })
32
+ });
33
+ return (await res.json())["url"];
34
+ }
35
+
36
+ window.addEventListener("load", function () {
37
+ const tokenEl = document.querySelector<HTMLInputElement>("#token")!;
38
+ const repoNameEl = document.querySelector<HTMLInputElement>("#repo_name")!;
39
+ const button = document.querySelector("#submit")!;
40
+ const output = document.querySelector("#logs")!;
41
+
42
+ button.addEventListener("click", async function () {
43
+ const token = tokenEl.value;
44
+ const repoName = repoNameEl.value;
45
+ if (!token || !repoName) {
46
+ alert("You need a token and a repo name");
47
+ return;
48
+ }
49
+
50
+ button.setAttribute("disabled", "disabled");
51
+ try {
52
+ // c.log(await createRepo(token, repoName, "model"));
53
+ c.log(await whoami(token));
54
+ } catch (err) {
55
+ output.append(err);
56
+ }
57
+ button.removeAttribute("disabled");
58
+ });
59
  });
60
 
61
 
dist/app.js CHANGED
@@ -1,4 +1,50 @@
1
  const c = console;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  window.addEventListener("load", function () {
3
- c.log("Hello");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  });
 
1
  const c = console;
2
+ // const ENDPOINT = "https://huggingface.co";
3
+ const ENDPOINT = "http://localhost:5564";
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
+ Origin: `127.0.0.1:8000`
10
+ }
11
+ });
12
+ return await res.json();
13
+ }
14
+ async function createRepo(token, repoId, repoType) {
15
+ const path = `${ENDPOINT}/api/repos/create`;
16
+ const res = await fetch(path, {
17
+ method: "POST",
18
+ headers: {
19
+ Authorization: `Bearer ${token}`,
20
+ },
21
+ body: JSON.stringify({
22
+ name: repoId,
23
+ type: repoType,
24
+ })
25
+ });
26
+ return (await res.json())["url"];
27
+ }
28
  window.addEventListener("load", function () {
29
+ const tokenEl = document.querySelector("#token");
30
+ const repoNameEl = document.querySelector("#repo_name");
31
+ const button = document.querySelector("#submit");
32
+ const output = document.querySelector("#logs");
33
+ button.addEventListener("click", async function () {
34
+ const token = tokenEl.value;
35
+ const repoName = repoNameEl.value;
36
+ if (!token || !repoName) {
37
+ alert("You need a token and a repo name");
38
+ return;
39
+ }
40
+ button.setAttribute("disabled", "disabled");
41
+ try {
42
+ // c.log(await createRepo(token, repoName, "model"));
43
+ c.log(await whoami(token));
44
+ }
45
+ catch (err) {
46
+ output.append(err);
47
+ }
48
+ button.removeAttribute("disabled");
49
+ });
50
  });
index.html CHANGED
@@ -82,32 +82,65 @@
82
  <code class="ml-2 text-gray-800">group1-shard2of2</code>
83
  </a>
84
  </div>
85
-
86
- <p class="mt-8">
87
- BTW, the TFJS demo of this model is <a href="https://storage.googleapis.com/tfjs-models/demos/mobilenet/index.html" class="underline" target="_blank">here</a>.
88
- </p>
89
-
90
  <p class="mt-8">
91
- Now that we have the model files, we need to get a HF user's access token.
92
- You can create a token at <a target="_blank" href="https://huggingface.co/settings/tokens" class="underline text-blue-500">hf.co/settings/tokens</a> (needs write access).
 
 
 
 
 
93
  </p>
94
-
95
- <input type="text" id="token" class="rounded border-2 border-blue-500 shadow-md px-3 py-2 w-96 mt-6" placeholder="token" required />
96
-
97
  <p class="mt-8">
98
- Finally, pick a repo name for your model:
 
 
 
 
 
 
 
 
99
  </p>
100
-
101
- <input type="text" id="repo_name" class="rounded border-2 border-blue-500 shadow-md px-3 py-2 w-96 mt-6" placeholder="repo name" required />
102
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  <p class="mt-8">
104
- Press Upload to create a repo, and upload your files. It will also upload a model card for your model (you can then update it on your model page):
 
 
105
  </p>
106
-
107
- <button id="submit" class="my-8 bg-green-500 rounded py-3 px-5 text-white shadow-md">Upload</button>
108
-
 
 
 
 
 
109
  <p class="text-gray-400 text-sm">Output logs</p>
110
- <pre id="logs" class="bg-gray-100 rounded p-3 mb-8 text-sm">Output will be here</pre>
 
 
111
  </div>
112
  </body>
113
  </html>
 
82
  <code class="ml-2 text-gray-800">group1-shard2of2</code>
83
  </a>
84
  </div>
85
+
 
 
 
 
86
  <p class="mt-8">
87
+ BTW, the TFJS demo of this model is
88
+ <a
89
+ href="https://storage.googleapis.com/tfjs-models/demos/mobilenet/index.html"
90
+ class="underline"
91
+ target="_blank"
92
+ >here</a
93
+ >.
94
  </p>
95
+
 
 
96
  <p class="mt-8">
97
+ Now that we have the model files, we need to get a HF user's access
98
+ token. You can create a token at
99
+ <a
100
+ target="_blank"
101
+ href="https://huggingface.co/settings/tokens"
102
+ class="underline text-blue-500"
103
+ >hf.co/settings/tokens</a
104
+ >
105
+ (needs write access).
106
  </p>
107
+
108
+ <input
109
+ type="text"
110
+ id="token"
111
+ class="rounded border-2 border-blue-500 shadow-md px-3 py-2 w-96 mt-6"
112
+ placeholder="token"
113
+ required
114
+ />
115
+
116
+ <p class="mt-8">Finally, pick a repo name for your model:</p>
117
+
118
+ <input
119
+ type="text"
120
+ id="repo_name"
121
+ class="rounded border-2 border-blue-500 shadow-md px-3 py-2 w-96 mt-6"
122
+ placeholder="repo name"
123
+ required
124
+ value="tfjs-mobilenet"
125
+ />
126
+
127
  <p class="mt-8">
128
+ Press Upload to create a repo, and upload your files. It will also
129
+ upload a model card for your model (you can then update it on your model
130
+ page):
131
  </p>
132
+
133
+ <button
134
+ id="submit"
135
+ class="my-8 bg-green-500 rounded py-3 px-5 text-white shadow-md disabled:bg-slate-300"
136
+ >
137
+ Upload
138
+ </button>
139
+
140
  <p class="text-gray-400 text-sm">Output logs</p>
141
+ <pre id="logs" class="bg-gray-100 rounded p-3 mb-8 text-sm">
142
+ Output will be here</pre
143
+ >
144
  </div>
145
  </body>
146
  </html>