|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-us"> |
| 3 | + <head> |
| 4 | + <title>bench : Benchmark whisper.cpp performance in the browser</title> |
| 5 | + |
| 6 | + <style> |
| 7 | + #output { |
| 8 | + width: 100%; |
| 9 | + height: 100%; |
| 10 | + margin: 0 auto; |
| 11 | + margin-top: 10px; |
| 12 | + border-left: 0px; |
| 13 | + border-right: 0px; |
| 14 | + padding-left: 0px; |
| 15 | + padding-right: 0px; |
| 16 | + display: block; |
| 17 | + background-color: black; |
| 18 | + color: white; |
| 19 | + font-size: 10px; |
| 20 | + font-family: 'Lucida Console', Monaco, monospace; |
| 21 | + outline: none; |
| 22 | + white-space: pre; |
| 23 | + overflow-wrap: normal; |
| 24 | + overflow-x: scroll; |
| 25 | + } |
| 26 | + </style> |
| 27 | + </head> |
| 28 | + <body> |
| 29 | + <div id="main-container"> |
| 30 | + <b>bench : Benchmark whisper.cpp performance in the browser</b> |
| 31 | + |
| 32 | + <br><br> |
| 33 | + |
| 34 | + You can find more about this project on <a href="https://github.com/ggerganov/whisper.cpp/tree/master/examples/bench.wasm">GitHub</a>. |
| 35 | + |
| 36 | + <br><br> |
| 37 | + |
| 38 | + <hr> |
| 39 | + |
| 40 | + Select the model you would like to use and click the "Bench" button.<br> |
| 41 | + The results will be displayed in the textarea below. |
| 42 | + |
| 43 | + <br><br> |
| 44 | + |
| 45 | + <div id="model-whisper"> |
| 46 | + Whisper model: <span id="model-whisper-status"></span> |
| 47 | + <button id="fetch-whisper-tiny-en" onclick="loadWhisper('tiny.en')">tiny.en (75 MB)</button> |
| 48 | + <button id="fetch-whisper-base-en" onclick="loadWhisper('base.en')">base.en (142 MB)</button> |
| 49 | + <span id="fetch-whisper-progress"></span> |
| 50 | + |
| 51 | + <input type="file" id="whisper-file" name="file" onchange="loadFile(event, 'whisper.bin')" /> |
| 52 | + </div> |
| 53 | + |
| 54 | + <br> |
| 55 | + |
| 56 | + <div id="input"> |
| 57 | + <button id="bench" onclick="onBench()" disabled>Bench</button> |
| 58 | + <button id="clear" onclick="clearCache()">Clear Cache</button> |
| 59 | + </div> |
| 60 | + |
| 61 | + <hr> |
| 62 | + |
| 63 | + Debug output: |
| 64 | + <textarea id="output" rows="20"></textarea> |
| 65 | + |
| 66 | + <br> |
| 67 | + |
| 68 | + <b>Troubleshooting</b> |
| 69 | + |
| 70 | + <br><br> |
| 71 | + |
| 72 | + The page does some heavy computations, so make sure: |
| 73 | + |
| 74 | + <ul> |
| 75 | + <li>To use a modern web browser (e.g. Chrome, Firefox)</li> |
| 76 | + <li>To use a fast desktop or laptop computer (i.e. not a mobile phone)</li> |
| 77 | + <li>Your browser supports WASM <a href="https://webassembly.org/roadmap/">Fixed-width SIMD</a></li> |
| 78 | + </ul> |
| 79 | + |
| 80 | + <div class="cell-version"> |
| 81 | + <span> |
| 82 | + | |
| 83 | + Build time: <span class="nav-link">@GIT_DATE@</span> | |
| 84 | + Commit hash: <a class="nav-link" href="https://github.com/ggerganov/whisper.cpp/commit/@GIT_SHA1@">@GIT_SHA1@</a> | |
| 85 | + Commit subject: <span class="nav-link">@GIT_COMMIT_SUBJECT@</span> | |
| 86 | + <a class="nav-link" href="https://github.com/ggerganov/whisper.cpp/tree/master/examples/bench.wasm">Source Code</a> | |
| 87 | + </span> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + |
| 91 | + <script type="text/javascript" src="helpers.js"></script> |
| 92 | + <script type='text/javascript'> |
| 93 | + // the bench instance |
| 94 | + var instance = null; |
| 95 | + |
| 96 | + // model name |
| 97 | + var model_whisper = null; |
| 98 | + |
| 99 | + var Module = { |
| 100 | + print: printTextarea, |
| 101 | + printErr: printTextarea, |
| 102 | + setStatus: function(text) { |
| 103 | + printTextarea('js: ' + text); |
| 104 | + }, |
| 105 | + monitorRunDependencies: function(left) { |
| 106 | + }, |
| 107 | + preRun: function() { |
| 108 | + printTextarea('js: Preparing ...'); |
| 109 | + }, |
| 110 | + postRun: function() { |
| 111 | + printTextarea('js: Initialized successfully!'); |
| 112 | + } |
| 113 | + }; |
| 114 | + |
| 115 | + // |
| 116 | + // fetch models |
| 117 | + // |
| 118 | + |
| 119 | + let dbVersion = 1 |
| 120 | + let dbName = 'whisper.ggerganov.com'; |
| 121 | + let indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB |
| 122 | + |
| 123 | + function storeFS(fname, buf) { |
| 124 | + // write to WASM file using FS_createDataFile |
| 125 | + // if the file exists, delete it |
| 126 | + try { |
| 127 | + Module.FS_unlink(fname); |
| 128 | + } catch (e) { |
| 129 | + // ignore |
| 130 | + } |
| 131 | + |
| 132 | + Module.FS_createDataFile("/", fname, buf, true, true); |
| 133 | + |
| 134 | + printTextarea('storeFS: stored model: ' + fname + ' size: ' + buf.length); |
| 135 | + |
| 136 | + model_whisper = fname; |
| 137 | + |
| 138 | + document.getElementById('model-whisper-status').innerHTML = 'loaded "' + model_whisper + '"!'; |
| 139 | + |
| 140 | + if (model_whisper != null) { |
| 141 | + document.getElementById('bench').disabled = false; |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + function loadFile(event, fname) { |
| 146 | + var file = event.target.files[0] || null; |
| 147 | + if (file == null) { |
| 148 | + return; |
| 149 | + } |
| 150 | + |
| 151 | + printTextarea("loadFile: loading model: " + file.name + ", size: " + file.size + " bytes"); |
| 152 | + printTextarea('loadFile: please wait ...'); |
| 153 | + |
| 154 | + var reader = new FileReader(); |
| 155 | + reader.onload = function(event) { |
| 156 | + var buf = new Uint8Array(reader.result); |
| 157 | + storeFS(fname, buf); |
| 158 | + } |
| 159 | + reader.readAsArrayBuffer(file); |
| 160 | + |
| 161 | + document.getElementById('fetch-whisper-tiny-en').style.display = 'none'; |
| 162 | + document.getElementById('fetch-whisper-base-en').style.display = 'none'; |
| 163 | + document.getElementById('whisper-file' ).style.display = 'none'; |
| 164 | + document.getElementById('model-whisper-status' ).innerHTML = 'loaded model: ' + file.name; |
| 165 | + } |
| 166 | + |
| 167 | + function loadWhisper(model) { |
| 168 | + let urls = { |
| 169 | + 'tiny.en': 'https://whisper.ggerganov.com/ggml-model-whisper-tiny.en.bin', |
| 170 | + 'base.en': 'https://whisper.ggerganov.com/ggml-model-whisper-base.en.bin', |
| 171 | + }; |
| 172 | + |
| 173 | + let sizes = { |
| 174 | + 'tiny.en': 75, |
| 175 | + 'base.en': 142, |
| 176 | + }; |
| 177 | + |
| 178 | + let url = urls[model]; |
| 179 | + let dst = 'whisper.bin'; |
| 180 | + let size_mb = sizes[model]; |
| 181 | + |
| 182 | + document.getElementById('fetch-whisper-tiny-en').style.display = 'none'; |
| 183 | + document.getElementById('fetch-whisper-base-en').style.display = 'none'; |
| 184 | + document.getElementById('model-whisper-status').innerHTML = 'loading "' + model + '" ... '; |
| 185 | + |
| 186 | + cbProgress = function(p) { |
| 187 | + let el = document.getElementById('fetch-whisper-progress'); |
| 188 | + el.innerHTML = Math.round(100*p) + '%'; |
| 189 | + }; |
| 190 | + |
| 191 | + cbCancel = function() { |
| 192 | + var el; |
| 193 | + el = document.getElementById('fetch-whisper-tiny-en'); if (el) el.style.display = 'inline-block'; |
| 194 | + el = document.getElementById('fetch-whisper-base-en'); if (el) el.style.display = 'inline-block'; |
| 195 | + el = document.getElementById('model-whisper-status'); if (el) el.innerHTML = ''; |
| 196 | + }; |
| 197 | + |
| 198 | + loadRemote(url, dst, size_mb, cbProgress, storeFS, cbCancel, printTextarea); |
| 199 | + } |
| 200 | + |
| 201 | + // |
| 202 | + // main |
| 203 | + // |
| 204 | + |
| 205 | + function onBench() { |
| 206 | + if (instance) { |
| 207 | + Module.free(instance); |
| 208 | + } |
| 209 | + |
| 210 | + instance = Module.init('whisper.bin'); |
| 211 | + |
| 212 | + if (instance) { |
| 213 | + printTextarea("js: whisper initialized, instance: " + instance); |
| 214 | + } |
| 215 | + |
| 216 | + document.getElementById('bench').disabled = true; |
| 217 | + |
| 218 | + if (!instance) { |
| 219 | + printTextarea("js: failed to initialize whisper"); |
| 220 | + return; |
| 221 | + } |
| 222 | + } |
| 223 | + |
| 224 | + </script> |
| 225 | + <script type="text/javascript" src="bench.js"></script> |
| 226 | + </body> |
| 227 | +</html> |
0 commit comments