Incorporo-user commited on
Commit
1c22c34
·
verified ·
1 Parent(s): 007169e

Count first-time model loads on the Logolabs/agate-preview-001 download counter

Browse files
Files changed (1) hide show
  1. js/agate.js +4 -0
js/agate.js CHANGED
@@ -9,6 +9,7 @@ export { ort };
9
 
10
  const BUCKETS = [64, 128, 256, 512];
11
  const CACHE_NAME = "agate-preview-001-web";
 
12
  const MODEL_FILES = ["tokenizer.json", "tokenizer_config.json", "text_encoder.onnx", "generator.onnx", "taesd_decoder.onnx"];
13
 
14
  export async function webgpuStatus() {
@@ -89,6 +90,9 @@ export class Agate {
89
  bufs[f] = buf;
90
  }
91
  this.stats = { downloadMB: total / 1e6, fromCacheMB: fromCache / 1e6, downloadMs: performance.now() - t0 };
 
 
 
92
  // drop cached files of older model versions (keys carry the sha256)
93
  try {
94
  const cache = await openCache(), keep = new Set(MODEL_FILES.map((f) => new URL(`${this.base}${real(f)}?sha256=${manifest.files[real(f)].sha256}`, location.href).href));
 
9
 
10
  const BUCKETS = [64, 128, 256, 512];
11
  const CACHE_NAME = "agate-preview-001-web";
12
+ const COUNT_URL = "https://huggingface.co/Logolabs/agate-preview-001/resolve/main/config.json";
13
  const MODEL_FILES = ["tokenizer.json", "tokenizer_config.json", "text_encoder.onnx", "generator.onnx", "taesd_decoder.onnx"];
14
 
15
  export async function webgpuStatus() {
 
90
  bufs[f] = buf;
91
  }
92
  this.stats = { downloadMB: total / 1e6, fromCacheMB: fromCache / 1e6, downloadMs: performance.now() - t0 };
93
+ // The Hub counts a model download only on a request for the model repo's root config.json; the ONNX files
94
+ // come from this Space, so a first (uncached) load pings it once to show up on the model page.
95
+ if (fromCache < total) fetch(COUNT_URL, { method: "HEAD", cache: "no-store" }).catch(() => {});
96
  // drop cached files of older model versions (keys carry the sha256)
97
  try {
98
  const cache = await openCache(), keep = new Set(MODEL_FILES.map((f) => new URL(`${this.base}${real(f)}?sha256=${manifest.files[real(f)].sha256}`, location.href).href));