dacorvo HF Staff commited on
Commit
5ae7606
·
verified ·
1 Parent(s): 4f2e40d

Keep only the models whose library is the tab's

Browse files
Files changed (1) hide show
  1. app.js +6 -4
app.js CHANGED
@@ -113,16 +113,18 @@ function hubList(library, task, view, count) {
113
  if (!hubLists.has(key)) {
114
  const query = new URLSearchParams({ library, sort, direction: "-1", limit: PAGE });
115
  if (task) query.set("pipeline_tag", task);
116
- query.append("expand[]", sort);
117
- query.append("expand[]", "safetensors");
118
  hubLists.set(key, { models: [], next: `${HUB}/api/models?${query}`, growing: Promise.resolve() });
119
  }
120
  const list = hubLists.get(key);
121
  list.growing = list.growing.catch(() => {}).then(async () => {
122
  while (list.models.length < count && list.next) {
123
  const response = await fetchOk(list.next);
124
- list.models.push(...(await response.json()).map((model) =>
125
- ({ id: model.id, score: model[sort] ?? 0, params: model.safetensors?.total })));
 
 
 
126
  list.next = response.headers.get("Link")?.match(/<([^>]+)>;\s*rel="next"/)?.[1];
127
  }
128
  });
 
113
  if (!hubLists.has(key)) {
114
  const query = new URLSearchParams({ library, sort, direction: "-1", limit: PAGE });
115
  if (task) query.set("pipeline_tag", task);
116
+ for (const field of [sort, "safetensors", "library_name"]) query.append("expand[]", field);
 
117
  hubLists.set(key, { models: [], next: `${HUB}/api/models?${query}`, growing: Promise.resolve() });
118
  }
119
  const list = hubLists.get(key);
120
  list.growing = list.growing.catch(() => {}).then(async () => {
121
  while (list.models.length < count && list.next) {
122
  const response = await fetchOk(list.next);
123
+ list.models.push(...(await response.json())
124
+ // The Hub's library filter matches a tag that models of other libraries
125
+ // carry too, such as diffusers' FLUX or sentence-transformers' MiniLM.
126
+ .filter((model) => model.library_name === library)
127
+ .map((model) => ({ id: model.id, score: model[sort] ?? 0, params: model.safetensors?.total })));
128
  list.next = response.headers.get("Link")?.match(/<([^>]+)>;\s*rel="next"/)?.[1];
129
  }
130
  });