Monstermango commited on
Commit
cd8d94a
·
verified ·
1 Parent(s): 7dc122e

Pass HF token for ZeroGPU quota attribution

Browse files
Files changed (3) hide show
  1. app.js +18 -6
  2. index.html +5 -0
  3. style.css +1 -0
app.js CHANGED
@@ -3,6 +3,7 @@ const BACKEND = "https://monstermango-diarization.hf.space";
3
  const $ = (sel) => document.querySelector(sel);
4
  let client = null;
5
  let schluessel = localStorage.getItem("sa_key") || "";
 
6
  let audioDatei = null;
7
  let letztesMarkdown = null;
8
  let recorder = null;
@@ -31,7 +32,8 @@ async function rufe(endpunkt, daten) {
31
  if (!client) {
32
  const { Client } = await import(
33
  "https://cdn.jsdelivr.net/npm/@gradio/client/+esm");
34
- client = await Client.connect(BACKEND);
 
35
  }
36
  const res = await client.predict(endpunkt, daten);
37
  return res.data[0];
@@ -51,6 +53,9 @@ async function loginPruefen(neuerKey) {
51
  $("#btn-login").addEventListener("click", async () => {
52
  const wert = $("#key-input").value.trim();
53
  if (!wert) return;
 
 
 
54
  $("#login-fehler").textContent = "";
55
  $("#btn-login").disabled = true;
56
  try {
@@ -68,6 +73,7 @@ $("#key-input").addEventListener("keydown", (e) => {
68
 
69
  $("#btn-key").addEventListener("click", () => {
70
  $("#key-input").value = "";
 
71
  $("#login").hidden = false;
72
  });
73
 
@@ -286,12 +292,18 @@ if ("serviceWorker" in navigator) {
286
  navigator.serviceWorker.register("sw.js").catch(() => {});
287
  }
288
 
289
- // Direktlink-Anmeldung: ?key=... übernimmt den Schlüssel und entfernt ihn
290
- // sofort wieder aus der Adresszeile.
291
- const urlKey = new URLSearchParams(location.search).get("key");
292
- if (urlKey) {
293
- schluessel = urlKey.trim();
294
  localStorage.setItem("sa_key", schluessel);
 
 
 
 
 
 
295
  history.replaceState(null, "", location.pathname);
296
  }
297
 
 
3
  const $ = (sel) => document.querySelector(sel);
4
  let client = null;
5
  let schluessel = localStorage.getItem("sa_key") || "";
6
+ let hfToken = localStorage.getItem("sa_hf") || "";
7
  let audioDatei = null;
8
  let letztesMarkdown = null;
9
  let recorder = null;
 
32
  if (!client) {
33
  const { Client } = await import(
34
  "https://cdn.jsdelivr.net/npm/@gradio/client/+esm");
35
+ const optionen = hfToken ? { hf_token: hfToken } : {};
36
+ client = await Client.connect(BACKEND, optionen);
37
  }
38
  const res = await client.predict(endpunkt, daten);
39
  return res.data[0];
 
53
  $("#btn-login").addEventListener("click", async () => {
54
  const wert = $("#key-input").value.trim();
55
  if (!wert) return;
56
+ hfToken = $("#hf-input").value.trim();
57
+ if (hfToken) localStorage.setItem("sa_hf", hfToken);
58
+ client = null;
59
  $("#login-fehler").textContent = "";
60
  $("#btn-login").disabled = true;
61
  try {
 
73
 
74
  $("#btn-key").addEventListener("click", () => {
75
  $("#key-input").value = "";
76
+ $("#hf-input").value = hfToken;
77
  $("#login").hidden = false;
78
  });
79
 
 
292
  navigator.serviceWorker.register("sw.js").catch(() => {});
293
  }
294
 
295
+ // Direktlink-Anmeldung: ?key=...&hf=... übernimmt Schlüssel und HF-Token
296
+ // und entfernt beides sofort wieder aus der Adresszeile.
297
+ const urlParams = new URLSearchParams(location.search);
298
+ if (urlParams.get("key")) {
299
+ schluessel = urlParams.get("key").trim();
300
  localStorage.setItem("sa_key", schluessel);
301
+ }
302
+ if (urlParams.get("hf")) {
303
+ hfToken = urlParams.get("hf").trim();
304
+ localStorage.setItem("sa_hf", hfToken);
305
+ }
306
+ if (urlParams.get("key") || urlParams.get("hf")) {
307
  history.replaceState(null, "", location.pathname);
308
  }
309
 
index.html CHANGED
@@ -88,6 +88,11 @@
88
  <input id="key-input" type="text" placeholder="Zugangsschlüssel"
89
  autocomplete="off" autocapitalize="none" autocorrect="off"
90
  spellcheck="false">
 
 
 
 
 
91
  <button id="btn-login" class="primary">Weiter</button>
92
  <div id="login-fehler" class="fehler"></div>
93
  </div>
 
88
  <input id="key-input" type="text" placeholder="Zugangsschlüssel"
89
  autocomplete="off" autocapitalize="none" autocorrect="off"
90
  spellcheck="false">
91
+ <input id="hf-input" type="text" placeholder="Hugging-Face-Token (hf_…)"
92
+ autocomplete="off" autocapitalize="none" autocorrect="off"
93
+ spellcheck="false">
94
+ <p class="dim klein">Das HF-Token sorgt dafür, dass dein eigenes
95
+ GPU-Kontingent genutzt wird.</p>
96
  <button id="btn-login" class="primary">Weiter</button>
97
  <div id="login-fehler" class="fehler"></div>
98
  </div>
style.css CHANGED
@@ -158,6 +158,7 @@ summary { min-height: 44px; display: flex; align-items: center; color: var(--dim
158
  padding: 24px 20px; max-width: 480px;
159
  margin: max(48px, env(safe-area-inset-top)) auto auto }
160
  .sheet h2 { margin-bottom: 6px }
 
161
  .sheet input { width: 100%; min-height: 50px; margin-top: 14px; padding: 0 14px;
162
  font-size: 16px; font-family: inherit;
163
  border: 1px solid var(--linie); border-radius: 12px;
 
158
  padding: 24px 20px; max-width: 480px;
159
  margin: max(48px, env(safe-area-inset-top)) auto auto }
160
  .sheet h2 { margin-bottom: 6px }
161
+ .klein { font-size: .8rem; margin-top: 6px }
162
  .sheet input { width: 100%; min-height: 50px; margin-top: 14px; padding: 0 14px;
163
  font-size: 16px; font-family: inherit;
164
  border: 1px solid var(--linie); border-radius: 12px;