unit27research commited on
Commit
9cb86c0
·
verified ·
1 Parent(s): e8f656d

Add live public model picker

Browse files
Files changed (2) hide show
  1. index.html +12 -9
  2. static-app.js +67 -2
index.html CHANGED
@@ -6,6 +6,13 @@
6
  <meta name="description" content="An evidence-backed, human-reviewed contribution assistant for public Hugging Face model cards.">
7
  <title>One Good Commit</title>
8
  <link rel="stylesheet" href="static-styles.css">
 
 
 
 
 
 
 
9
  </head>
10
  <body>
11
  <main class="shell">
@@ -21,19 +28,15 @@
21
 
22
  <section class="input-card" aria-label="Review a public model card">
23
  <form id="review-form">
24
- <label for="repo-id">Public model ID</label>
25
  <div class="input-row">
26
- <input id="repo-id" name="repo-id" autocomplete="off" placeholder="owner/model-name" required>
27
  <button type="submit">Review card</button>
28
  </div>
29
  </form>
30
- <p class="example-label">Try an established public card</p>
31
- <div class="examples" aria-label="Example model cards">
32
- <button type="button" data-example="sentence-transformers/all-MiniLM-L6-v2">sentence-transformers/all-MiniLM-L6-v2</button>
33
- <button type="button" data-example="google-bert/bert-base-uncased">google-bert/bert-base-uncased</button>
34
- <button type="button" data-example="openai-community/gpt2">openai-community/gpt2</button>
35
- </div>
36
- <p class="input-note">Public repositories only. This app reads the selected README and Hub metadata; it does not run or evaluate the model.</p>
37
  </section>
38
 
39
  <section id="notice" class="notice" hidden aria-live="polite"></section>
 
6
  <meta name="description" content="An evidence-backed, human-reviewed contribution assistant for public Hugging Face model cards.">
7
  <title>One Good Commit</title>
8
  <link rel="stylesheet" href="static-styles.css">
9
+ <style>
10
+ .model-options{background:#fff;border:1px solid #dfe4da;border-radius:10px;box-shadow:0 10px 26px rgba(35,50,39,.08);margin-top:10px;max-height:360px;overflow:auto}
11
+ .model-option{align-items:center;background:#fff;border:0;border-bottom:1px solid #edf0e9;color:#172419;display:grid;gap:4px;grid-template-columns:1fr auto;padding:12px 14px;text-align:left;width:100%}
12
+ .model-option:last-child{border-bottom:0}.model-option:hover,.model-option:focus-visible{background:#f4f7f0;outline:2px solid #2d6a4f;outline-offset:-2px}
13
+ .model-option strong{display:block;font-size:.93rem;overflow-wrap:anywhere}.model-option span{color:#647067;font-size:.78rem}.model-option .task{background:#f1f0e8;border-radius:999px;color:#536057;font-size:.7rem;padding:4px 7px;white-space:nowrap}
14
+ @media(max-width:720px){.model-option{grid-template-columns:1fr}.model-option .task{justify-self:start}}
15
+ </style>
16
  </head>
17
  <body>
18
  <main class="shell">
 
28
 
29
  <section class="input-card" aria-label="Review a public model card">
30
  <form id="review-form">
31
+ <label for="repo-id">Find a public model</label>
32
  <div class="input-row">
33
+ <input id="repo-id" name="repo-id" autocomplete="off" placeholder="Search a model, organization, or task" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="model-options" required>
34
  <button type="submit">Review card</button>
35
  </div>
36
  </form>
37
+ <div id="model-options" class="model-options" role="listbox" aria-label="Live public model matches" hidden></div>
38
+ <p id="picker-status" class="example-label">Loading live public models…</p>
39
+ <p class="input-note">Start with a name, organization, or task. Select a live public model; exact repository IDs also work if you already have one.</p>
 
 
 
 
40
  </section>
41
 
42
  <section id="notice" class="notice" hidden aria-live="polite"></section>
static-app.js CHANGED
@@ -26,15 +26,73 @@
26
  const worksheetPanel = document.querySelector("#worksheet-panel");
27
  const discussionPanel = document.querySelector("#discussion-panel");
28
  const downloadButton = document.querySelector("#download-review");
 
 
29
  let latestReview = null;
 
 
30
 
31
  function cleanRepoId(value) {
32
  let id = value.trim();
33
  if (id.startsWith("https://huggingface.co/")) id = id.slice("https://huggingface.co/".length).split("/").slice(0, 2).join("/");
34
- if (!REPO_ID.test(id)) throw new Error("Enter a public model ID in the form owner/model-name.");
35
  return id;
36
  }
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  function meaningful(value) {
39
  if (value === null || value === undefined || value === false) return false;
40
  if (typeof value === "string") return Boolean(value.trim());
@@ -199,7 +257,14 @@
199
  }
200
 
201
  form.addEventListener("submit", (event) => { event.preventDefault(); review(input.value); });
202
- document.querySelectorAll("[data-example]").forEach((button) => button.addEventListener("click", () => { input.value = button.dataset.example; input.focus(); }));
 
 
 
 
 
 
203
  document.querySelectorAll("[role=tab]").forEach((tab) => tab.addEventListener("click", () => { document.querySelectorAll("[role=tab]").forEach((item) => item.setAttribute("aria-selected", String(item === tab))); document.querySelectorAll("[role=tabpanel]").forEach((panel) => { panel.hidden = panel.id !== tab.dataset.tab; }); }));
204
  downloadButton.addEventListener("click", () => { if (!latestReview?.download) return; const blob = new Blob([latestReview.download], { type: "text/markdown;charset=utf-8" }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = `${latestReview.repo.replace("/", "--")}-review.md`; link.click(); URL.revokeObjectURL(link.href); });
 
205
  })();
 
26
  const worksheetPanel = document.querySelector("#worksheet-panel");
27
  const discussionPanel = document.querySelector("#discussion-panel");
28
  const downloadButton = document.querySelector("#download-review");
29
+ const modelOptions = document.querySelector("#model-options");
30
+ const pickerStatus = document.querySelector("#picker-status");
31
  let latestReview = null;
32
+ let searchTimer = null;
33
+ let searchNonce = 0;
34
 
35
  function cleanRepoId(value) {
36
  let id = value.trim();
37
  if (id.startsWith("https://huggingface.co/")) id = id.slice("https://huggingface.co/".length).split("/").slice(0, 2).join("/");
38
+ if (!REPO_ID.test(id)) throw new Error("Select a model from the live results, or enter its exact owner/model-name ID.");
39
  return id;
40
  }
41
 
42
+ function numberLabel(value) {
43
+ const number = Number(value || 0);
44
+ if (number >= 1_000_000) return `${(number / 1_000_000).toFixed(number >= 10_000_000 ? 0 : 1)}M`;
45
+ if (number >= 1_000) return `${(number / 1_000).toFixed(number >= 10_000 ? 0 : 1)}K`;
46
+ return String(number);
47
+ }
48
+
49
+ function hideModelOptions() {
50
+ modelOptions.hidden = true;
51
+ input.setAttribute("aria-expanded", "false");
52
+ }
53
+
54
+ function showModelOptions(models, label) {
55
+ modelOptions.replaceChildren();
56
+ pickerStatus.textContent = label;
57
+ if (!models.length) { hideModelOptions(); return; }
58
+ models.forEach((model) => {
59
+ const id = model.id || model.modelId;
60
+ if (!id) return;
61
+ const option = make("button", "model-option");
62
+ option.type = "button";
63
+ option.setAttribute("role", "option");
64
+ option.setAttribute("aria-label", `Select ${id}`);
65
+ const detail = model.pipeline_tag ? `${model.pipeline_tag} · ${numberLabel(model.downloads)} downloads` : `${numberLabel(model.downloads)} downloads`;
66
+ const copy = make("span");
67
+ copy.append(make("strong", "", id), make("span", "", detail));
68
+ option.append(copy);
69
+ if (model.pipeline_tag) option.append(make("span", "task", model.pipeline_tag));
70
+ option.addEventListener("click", () => { input.value = id; modelOptions.replaceChildren(); hideModelOptions(); pickerStatus.textContent = `Selected: ${id}`; input.focus(); });
71
+ modelOptions.append(option);
72
+ });
73
+ if (!modelOptions.childElementCount) { hideModelOptions(); return; }
74
+ modelOptions.hidden = false;
75
+ input.setAttribute("aria-expanded", "true");
76
+ }
77
+
78
+ async function searchModels(query = "") {
79
+ const nonce = ++searchNonce;
80
+ pickerStatus.textContent = query ? "Searching public models…" : "Loading live public models…";
81
+ const params = new URLSearchParams({ limit: "8", sort: "downloads", direction: "-1" });
82
+ if (query) params.set("search", query);
83
+ try {
84
+ const response = await fetch(`https://huggingface.co/api/models?${params}`);
85
+ if (!response.ok) throw new Error("unavailable");
86
+ const models = (await response.json()).filter((model) => !model.private && !model.gated && !model.disabled);
87
+ if (nonce !== searchNonce) return;
88
+ showModelOptions(models, query ? "Live public matches" : "Popular public models — start typing to narrow the list");
89
+ } catch (_) {
90
+ if (nonce !== searchNonce) return;
91
+ pickerStatus.textContent = "Live model picker is unavailable right now. You can still enter an exact public model ID.";
92
+ hideModelOptions();
93
+ }
94
+ }
95
+
96
  function meaningful(value) {
97
  if (value === null || value === undefined || value === false) return false;
98
  if (typeof value === "string") return Boolean(value.trim());
 
257
  }
258
 
259
  form.addEventListener("submit", (event) => { event.preventDefault(); review(input.value); });
260
+ input.addEventListener("input", () => {
261
+ window.clearTimeout(searchTimer);
262
+ const query = input.value.trim();
263
+ searchTimer = window.setTimeout(() => searchModels(query), 250);
264
+ });
265
+ input.addEventListener("focus", () => { if (modelOptions.childElementCount) { modelOptions.hidden = false; input.setAttribute("aria-expanded", "true"); } });
266
+ document.addEventListener("click", (event) => { if (!event.target.closest("#review-form") && !event.target.closest("#model-options")) hideModelOptions(); });
267
  document.querySelectorAll("[role=tab]").forEach((tab) => tab.addEventListener("click", () => { document.querySelectorAll("[role=tab]").forEach((item) => item.setAttribute("aria-selected", String(item === tab))); document.querySelectorAll("[role=tabpanel]").forEach((panel) => { panel.hidden = panel.id !== tab.dataset.tab; }); }));
268
  downloadButton.addEventListener("click", () => { if (!latestReview?.download) return; const blob = new Blob([latestReview.download], { type: "text/markdown;charset=utf-8" }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = `${latestReview.repo.replace("/", "--")}-review.md`; link.click(); URL.revokeObjectURL(link.href); });
269
+ searchModels();
270
  })();