Bartholomheow commited on
Commit
1ae0fdf
·
verified ·
1 Parent(s): 56ff81f

Upload example_web.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. example_web.js +8 -8
example_web.js CHANGED
@@ -12,7 +12,7 @@
12
  */
13
 
14
  const REPO = 'Bartholomheow/Supra2-IMG-ONNX';
15
- const fileUrl = (path) => `https://huggingface.co/${REPO}/resolve/main/${path}`;
16
 
17
  function mulberry32(seed) {
18
  let a = seed >>> 0;
@@ -78,14 +78,14 @@ function halfToFloat(h) {
78
  return f[0];
79
  }
80
 
81
- export async function loadSupra({ onProgress } = {}) {
82
  const ort = await import('onnxruntime-web');
83
  const { AutoTokenizer } = await import('@huggingface/transformers');
84
- const cfg = await (await fetch(fileUrl('pipeline_config.json'))).json();
85
  const [ditBuf, encBuf, vaeBuf] = await Promise.all([
86
- download(fileUrl(cfg.dit), cfg.dit, onProgress),
87
- download(fileUrl(cfg.text_encoder), cfg.text_encoder, onProgress),
88
- download(fileUrl(cfg.vae_decoder), cfg.vae_decoder, onProgress),
89
  ]);
90
  const opts = { executionProviders: ['webgpu'] };
91
  const [dit, enc, vae] = await Promise.all([
@@ -93,7 +93,7 @@ export async function loadSupra({ onProgress } = {}) {
93
  ort.InferenceSession.create(encBuf, opts),
94
  ort.InferenceSession.create(vaeBuf, opts),
95
  ]);
96
- const tokenize = await AutoTokenizer.from_pretrained(REPO);
97
  return { ort, cfg, dit, enc, vae, tokenize };
98
  }
99
 
@@ -165,6 +165,6 @@ export function paint(pixels, size, canvas) {
165
  }
166
 
167
  // Usage:
168
- // const model = await loadSupra({ onProgress: (p) => console.log(p.file, p.loaded) });
169
  // const { pixels, size } = await generate(model, 'a lighthouse above violet clouds at dusk');
170
  // paint(pixels, size, document.querySelector('canvas'));
 
12
  */
13
 
14
  const REPO = 'Bartholomheow/Supra2-IMG-ONNX';
15
+ const fileUrl = (repo, path) => `https://huggingface.co/${repo}/resolve/main/${path}`;
16
 
17
  function mulberry32(seed) {
18
  let a = seed >>> 0;
 
78
  return f[0];
79
  }
80
 
81
+ export async function loadSupra(repo = REPO, { onProgress } = {}) {
82
  const ort = await import('onnxruntime-web');
83
  const { AutoTokenizer } = await import('@huggingface/transformers');
84
+ const cfg = await (await fetch(fileUrl(repo, 'pipeline_config.json'))).json();
85
  const [ditBuf, encBuf, vaeBuf] = await Promise.all([
86
+ download(fileUrl(repo, cfg.dit), cfg.dit, onProgress),
87
+ download(fileUrl(repo, cfg.text_encoder), cfg.text_encoder, onProgress),
88
+ download(fileUrl(repo, cfg.vae_decoder), cfg.vae_decoder, onProgress),
89
  ]);
90
  const opts = { executionProviders: ['webgpu'] };
91
  const [dit, enc, vae] = await Promise.all([
 
93
  ort.InferenceSession.create(encBuf, opts),
94
  ort.InferenceSession.create(vaeBuf, opts),
95
  ]);
96
+ const tokenize = await AutoTokenizer.from_pretrained(repo);
97
  return { ort, cfg, dit, enc, vae, tokenize };
98
  }
99
 
 
165
  }
166
 
167
  // Usage:
168
+ // const model = await loadSupra(REPO, { onProgress: (p) => console.log(p.file, p.loaded) });
169
  // const { pixels, size } = await generate(model, 'a lighthouse above violet clouds at dusk');
170
  // paint(pixels, size, document.querySelector('canvas'));