File size: 1,303 Bytes
a703e60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Granite ONNX Loader</title>
  </head>
  <body>
    <h3>Granite 4.0-micro-ONNX-web Test</h3>
    <button id="run">Load Model</button>
    <div id="log" style="margin-top:10px;font-family:monospace;white-space:pre-wrap;"></div>

    <script type="module">
      import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4";

      const log = document.getElementById("log");
      const btn = document.getElementById("run");
      const append = (msg) => { log.textContent += msg + "\n"; };

      btn.onclick = async () => {
        log.textContent = "";
        append("Starting…");

        try {
          append("Downloading model: onnx-community/granite-4.0-micro-ONNX-web");
          const pipe = await pipeline(
            "text-generation",
            "onnx-community/granite-4.0-micro-ONNX-web",
            { progress_callback: (p) => append(`Progress: ${p * 100}%`) }
          );

          append("Model ready. Running inference…");
          const out = await pipe("The future of AI is", { max_new_tokens: 30 });
          append("Output:\n" + out[0].generated_text);
        } catch (e) {
          append("ERROR: " + (e.message || e));
        }
      };
    </script>
  </body>
</html>