Spaces:
Running
Running
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[587],{4699:function(e,t){"use strict";t.byteLength=function(e){var t=l(e),r=t[0],n=t[1];return(r+n)*3/4-n},t.toByteArray=function(e){var t,r,i=l(e),o=i[0],a=i[1],h=new s((o+a)*3/4-a),c=0,u=a>0?o-4:o;for(r=0;r<u;r+=4)t=n[e.charCodeAt(r)]<<18|n[e.charCodeAt(r+1)]<<12|n[e.charCodeAt(r+2)]<<6|n[e.charCodeAt(r+3)],h[c++]=t>>16&255,h[c++]=t>>8&255,h[c++]=255&t;return 2===a&&(t=n[e.charCodeAt(r)]<<2|n[e.charCodeAt(r+1)]>>4,h[c++]=255&t),1===a&&(t=n[e.charCodeAt(r)]<<10|n[e.charCodeAt(r+1)]<<4|n[e.charCodeAt(r+2)]>>2,h[c++]=t>>8&255,h[c++]=255&t),h},t.fromByteArray=function(e){for(var t,n=e.length,s=n%3,i=[],o=0,a=n-s;o<a;o+=16383)i.push(function(e,t,n){for(var s,i=[],o=t;o<n;o+=3)i.push(r[(s=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]))>>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return i.join("")}(e,o,o+16383>a?a:o+16383));return 1===s?i.push(r[(t=e[n-1])>>2]+r[t<<4&63]+"=="):2===s&&i.push(r[(t=(e[n-2]<<8)+e[n-1])>>10]+r[t>>4&63]+r[t<<2&63]+"="),i.join("")};for(var r=[],n=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,a=i.length;o<a;++o)r[o]=i[o],n[i.charCodeAt(o)]=o;function l(e){var t=e.length;if(t%4>0)throw Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");-1===r&&(r=t);var n=r===t?0:4-r%4;return[r,n]}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},7133:function(e,t,r){"use strict";/*! | |
* The buffer module from node.js, for the browser. | |
* | |
* @author Feross Aboukhadijeh <https://feross.org> | |
* @license MIT | |
*/var n=r(4699),s=r(9087),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;function o(e){if(e>2147483647)throw RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return Object.setPrototypeOf(t,a.prototype),t}function a(e,t,r){if("number"==typeof e){if("string"==typeof t)throw TypeError('The "string" argument must be of type string. Received type number');return c(e)}return l(e,t,r)}function l(e,t,r){if("string"==typeof e)return function(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!a.isEncoding(t))throw TypeError("Unknown encoding: "+t);var r=0|p(e,t),n=o(r),s=n.write(e,t);return s!==r&&(n=n.slice(0,s)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(I(e,Uint8Array)){var t=new Uint8Array(e);return d(t.buffer,t.byteOffset,t.byteLength)}return u(e)}(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(I(e,ArrayBuffer)||e&&I(e.buffer,ArrayBuffer)||"undefined"!=typeof SharedArrayBuffer&&(I(e,SharedArrayBuffer)||e&&I(e.buffer,SharedArrayBuffer)))return d(e,t,r);if("number"==typeof e)throw TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return a.from(n,t,r);var s=function(e){if(a.isBuffer(e)){var t,r=0|f(e.length),n=o(r);return 0===n.length||e.copy(n,0,0,r),n}return void 0!==e.length?"number"!=typeof e.length||(t=e.length)!=t?o(0):u(e):"Buffer"===e.type&&Array.isArray(e.data)?u(e.data):void 0}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return a.from(e[Symbol.toPrimitive]("string"),t,r);throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw TypeError('"size" argument must be of type number');if(e<0)throw RangeError('The value "'+e+'" is invalid for option "size"')}function c(e){return h(e),o(e<0?0:0|f(e))}function u(e){for(var t=e.length<0?0:0|f(e.length),r=o(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function d(e,t,r){var n;if(t<0||e.byteLength<t)throw RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw RangeError('"length" is outside of buffer bounds');return Object.setPrototypeOf(n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),a.prototype),n}function f(e){if(e>=2147483647)throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|e}function p(e,t){if(a.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||I(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var s=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return T(e).length;default:if(s)return n?-1:z(e).length;t=(""+t).toLowerCase(),s=!0}}function _(e,t,r){var s,i,o=!1;if((void 0===t||t<0)&&(t=0),t>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0||(r>>>=0)<=(t>>>=0)))return"";for(e||(e="utf8");;)switch(e){case"hex":return function(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var s="",i=t;i<r;++i)s+=B[e[i]];return s}(this,t,r);case"utf8":case"utf-8":return w(this,t,r);case"ascii":return function(e,t,r){var n="";r=Math.min(e.length,r);for(var s=t;s<r;++s)n+=String.fromCharCode(127&e[s]);return n}(this,t,r);case"latin1":case"binary":return function(e,t,r){var n="";r=Math.min(e.length,r);for(var s=t;s<r;++s)n+=String.fromCharCode(e[s]);return n}(this,t,r);case"base64":return s=t,i=r,0===s&&i===this.length?n.fromByteArray(this):n.fromByteArray(this.slice(s,i));case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return function(e,t,r){for(var n=e.slice(t,r),s="",i=0;i<n.length-1;i+=2)s+=String.fromCharCode(n[i]+256*n[i+1]);return s}(this,t,r);default:if(o)throw TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),o=!0}}function m(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function g(e,t,r,n,s){var i;if(0===e.length)return -1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),(i=r=+r)!=i&&(r=s?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(s)return -1;r=e.length-1}else if(r<0){if(!s)return -1;r=0}if("string"==typeof t&&(t=a.from(t,n)),a.isBuffer(t))return 0===t.length?-1:y(e,t,r,n,s);if("number"==typeof t)return(t&=255,"function"==typeof Uint8Array.prototype.indexOf)?s?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):y(e,[t],r,n,s);throw TypeError("val must be string, number or Buffer")}function y(e,t,r,n,s){var i,o=1,a=e.length,l=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return -1;o=2,a/=2,l/=2,r/=2}function h(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(s){var c=-1;for(i=r;i<a;i++)if(h(e,i)===h(t,-1===c?0:i-c)){if(-1===c&&(c=i),i-c+1===l)return c*o}else -1!==c&&(i-=i-c),c=-1}else for(r+l>a&&(r=a-l),i=r;i>=0;i--){for(var u=!0,d=0;d<l;d++)if(h(e,i+d)!==h(t,d)){u=!1;break}if(u)return i}return -1}function w(e,t,r){r=Math.min(e.length,r);for(var n=[],s=t;s<r;){var i,o,a,l,h=e[s],c=null,u=h>239?4:h>223?3:h>191?2:1;if(s+u<=r)switch(u){case 1:h<128&&(c=h);break;case 2:(192&(i=e[s+1]))==128&&(l=(31&h)<<6|63&i)>127&&(c=l);break;case 3:i=e[s+1],o=e[s+2],(192&i)==128&&(192&o)==128&&(l=(15&h)<<12|(63&i)<<6|63&o)>2047&&(l<55296||l>57343)&&(c=l);break;case 4:i=e[s+1],o=e[s+2],a=e[s+3],(192&i)==128&&(192&o)==128&&(192&a)==128&&(l=(15&h)<<18|(63&i)<<12|(63&o)<<6|63&a)>65535&&l<1114112&&(c=l)}null===c?(c=65533,u=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),s+=u}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return r}(n)}function b(e,t,r){if(e%1!=0||e<0)throw RangeError("offset is not uint");if(e+t>r)throw RangeError("Trying to access beyond buffer length")}function k(e,t,r,n,s,i){if(!a.isBuffer(e))throw TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<i)throw RangeError('"value" argument is out of bounds');if(r+n>e.length)throw RangeError("Index out of range")}function v(e,t,r,n,s,i){if(r+n>e.length||r<0)throw RangeError("Index out of range")}function x(e,t,r,n,i){return t=+t,r>>>=0,i||v(e,t,r,4,34028234663852886e22,-34028234663852886e22),s.write(e,t,r,n,23,4),r+4}function A(e,t,r,n,i){return t=+t,r>>>=0,i||v(e,t,r,8,17976931348623157e292,-17976931348623157e292),s.write(e,t,r,n,52,8),r+8}t.lW=a,t.h2=50,a.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}(),a.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}}),a.poolSize=8192,a.from=function(e,t,r){return l(e,t,r)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array),a.alloc=function(e,t,r){return(h(e),e<=0)?o(e):void 0!==t?"string"==typeof r?o(e).fill(t,r):o(e).fill(t):o(e)},a.allocUnsafe=function(e){return c(e)},a.allocUnsafeSlow=function(e){return c(e)},a.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==a.prototype},a.compare=function(e,t){if(I(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),I(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var r=e.length,n=t.length,s=0,i=Math.min(r,n);s<i;++s)if(e[s]!==t[s]){r=e[s],n=t[s];break}return r<n?-1:n<r?1:0},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return a.alloc(0);if(void 0===t)for(r=0,t=0;r<e.length;++r)t+=e[r].length;var r,n=a.allocUnsafe(t),s=0;for(r=0;r<e.length;++r){var i=e[r];if(I(i,Uint8Array))s+i.length>n.length?a.from(i).copy(n,s):Uint8Array.prototype.set.call(n,i,s);else if(a.isBuffer(i))i.copy(n,s);else throw TypeError('"list" argument must be an Array of Buffers');s+=i.length}return n},a.byteLength=p,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)m(this,t,t+1);return this},a.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)m(this,t,t+3),m(this,t+1,t+2);return this},a.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)m(this,t,t+7),m(this,t+1,t+6),m(this,t+2,t+5),m(this,t+3,t+4);return this},a.prototype.toString=function(){var e=this.length;return 0===e?"":0==arguments.length?w(this,0,e):_.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw TypeError("Argument must be a Buffer");return this===e||0===a.compare(this,e)},a.prototype.inspect=function(){var e="",r=t.h2;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},i&&(a.prototype[i]=a.prototype.inspect),a.prototype.compare=function(e,t,r,n,s){if(I(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===s&&(s=this.length),t<0||r>e.length||n<0||s>this.length)throw RangeError("out of range index");if(n>=s&&t>=r)return 0;if(n>=s)return -1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,s>>>=0,this===e)return 0;for(var i=s-n,o=r-t,l=Math.min(i,o),h=this.slice(n,s),c=e.slice(t,r),u=0;u<l;++u)if(h[u]!==c[u]){i=h[u],o=c[u];break}return i<o?-1:o<i?1:0},a.prototype.includes=function(e,t,r){return -1!==this.indexOf(e,t,r)},a.prototype.indexOf=function(e,t,r){return g(this,e,t,r,!0)},a.prototype.lastIndexOf=function(e,t,r){return g(this,e,t,r,!1)},a.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0);else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var s,i,o,a,l,h,c,u,d=this.length-t;if((void 0===r||r>d)&&(r=d),e.length>0&&(r<0||t<0)||t>this.length)throw RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var f=!1;;)switch(n){case"hex":return function(e,t,r,n){r=Number(r)||0;var s=e.length-r;n?(n=Number(n))>s&&(n=s):n=s;var i=t.length;n>i/2&&(n=i/2);for(var o=0;o<n;++o){var a=parseInt(t.substr(2*o,2),16);if(a!=a)break;e[r+o]=a}return o}(this,e,t,r);case"utf8":case"utf-8":return s=t,i=r,M(z(e,this.length-s),this,s,i);case"ascii":case"latin1":case"binary":return o=t,a=r,M(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(e),this,o,a);case"base64":return l=t,h=r,M(T(e),this,l,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return c=t,u=r,M(function(e,t){for(var r,n,s=[],i=0;i<e.length&&!((t-=2)<0);++i)n=(r=e.charCodeAt(i))>>8,s.push(r%256),s.push(n);return s}(e,this.length-c),this,c,u);default:if(f)throw TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),f=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},a.prototype.slice=function(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,e<0?(e+=r)<0&&(e=0):e>r&&(e=r),t<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);var n=this.subarray(e,t);return Object.setPrototypeOf(n,a.prototype),n},a.prototype.readUintLE=a.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||b(e,t,this.length);for(var n=this[e],s=1,i=0;++i<t&&(s*=256);)n+=this[e+i]*s;return n},a.prototype.readUintBE=a.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||b(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e>>>=0,t||b(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e>>>=0,t||b(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e>>>=0,t||b(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e>>>=0,t||b(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e>>>=0,t||b(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||b(e,t,this.length);for(var n=this[e],s=1,i=0;++i<t&&(s*=256);)n+=this[e+i]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*t)),n},a.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||b(e,t,this.length);for(var n=t,s=1,i=this[e+--n];n>0&&(s*=256);)i+=this[e+--n]*s;return i>=(s*=128)&&(i-=Math.pow(2,8*t)),i},a.prototype.readInt8=function(e,t){return(e>>>=0,t||b(e,1,this.length),128&this[e])?-((255-this[e]+1)*1):this[e]},a.prototype.readInt16LE=function(e,t){e>>>=0,t||b(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(e,t){e>>>=0,t||b(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(e,t){return e>>>=0,t||b(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e>>>=0,t||b(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readFloatLE=function(e,t){return e>>>=0,t||b(e,4,this.length),s.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e>>>=0,t||b(e,4,this.length),s.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e>>>=0,t||b(e,8,this.length),s.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e>>>=0,t||b(e,8,this.length),s.read(this,e,!1,52,8)},a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){var s=Math.pow(2,8*r)-1;k(this,e,t,r,s,0)}var i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){var s=Math.pow(2,8*r)-1;k(this,e,t,r,s,0)}var i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,1,255,0),this[t]=255&e,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var s=Math.pow(2,8*r-1);k(this,e,t,r,s-1,-s)}var i=0,o=1,a=0;for(this[t]=255&e;++i<r&&(o*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/o>>0)-a&255;return t+r},a.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var s=Math.pow(2,8*r-1);k(this,e,t,r,s-1,-s)}var i=r-1,o=1,a=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/o>>0)-a&255;return t+r},a.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},a.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeFloatLE=function(e,t,r){return x(this,e,t,!0,r)},a.prototype.writeFloatBE=function(e,t,r){return x(this,e,t,!1,r)},a.prototype.writeDoubleLE=function(e,t,r){return A(this,e,t,!0,r)},a.prototype.writeDoubleBE=function(e,t,r){return A(this,e,t,!1,r)},a.prototype.copy=function(e,t,r,n){if(!a.isBuffer(e))throw TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||0===e.length||0===this.length)return 0;if(t<0)throw RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw RangeError("Index out of range");if(n<0)throw RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var s=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),s},a.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw TypeError("encoding must be a string");if("string"==typeof n&&!a.isEncoding(n))throw TypeError("Unknown encoding: "+n);if(1===e.length){var s,i=e.charCodeAt(0);("utf8"===n&&i<128||"latin1"===n)&&(e=i)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw RangeError("Out of range index");if(r<=t)return this;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var o=a.isBuffer(e)?e:a.from(e,n),l=o.length;if(0===l)throw TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<r-t;++s)this[s+t]=o[s%l]}return this};var E=/[^+/0-9A-Za-z-_]/g;function z(e,t){t=t||1/0;for(var r,n=e.length,s=null,i=[],o=0;o<n;++o){if((r=e.charCodeAt(o))>55295&&r<57344){if(!s){if(r>56319||o+1===n){(t-=3)>-1&&i.push(239,191,189);continue}s=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),s=r;continue}r=(s-55296<<10|r-56320)+65536}else s&&(t-=3)>-1&&i.push(239,191,189);if(s=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}else throw Error("Invalid code point")}return i}function T(e){return n.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(E,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function M(e,t,r,n){for(var s=0;s<n&&!(s+r>=t.length)&&!(s>=e.length);++s)t[s+r]=e[s];return s}function I(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}var B=function(){for(var e="0123456789abcdef",t=Array(256),r=0;r<16;++r)for(var n=16*r,s=0;s<16;++s)t[n+s]=e[r]+e[s];return t}()},9087:function(e,t){/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */t.read=function(e,t,r,n,s){var i,o,a=8*s-n-1,l=(1<<a)-1,h=l>>1,c=-7,u=r?s-1:0,d=r?-1:1,f=e[t+u];for(u+=d,i=f&(1<<-c)-1,f>>=-c,c+=a;c>0;i=256*i+e[t+u],u+=d,c-=8);for(o=i&(1<<-c)-1,i>>=-c,c+=n;c>0;o=256*o+e[t+u],u+=d,c-=8);if(0===i)i=1-h;else{if(i===l)return o?NaN:(f?-1:1)*(1/0);o+=Math.pow(2,n),i-=h}return(f?-1:1)*o*Math.pow(2,i-n)},t.write=function(e,t,r,n,s,i){var o,a,l,h=8*i-s-1,c=(1<<h)-1,u=c>>1,d=23===s?5960464477539062e-23:0,f=n?0:i-1,p=n?1:-1,_=t<0||0===t&&1/t<0?1:0;for(isNaN(t=Math.abs(t))||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-o))<1&&(o--,l*=2),o+u>=1?t+=d/l:t+=d*Math.pow(2,1-u),t*l>=2&&(o++,l/=2),o+u>=c?(a=0,o=c):o+u>=1?(a=(t*l-1)*Math.pow(2,s),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,s),o=0));s>=8;e[r+f]=255&a,f+=p,a/=256,s-=8);for(o=o<<s|a,h+=s;h>0;e[r+f]=255&o,f+=p,o/=256,h-=8);e[r+f-p]|=128*_}},2601:function(e,t,r){"use strict";var n,s;e.exports=(null==(n=r.g.process)?void 0:n.env)&&"object"==typeof(null==(s=r.g.process)?void 0:s.env)?r.g.process:r(8960)},692:function(e,t,r){!function(){var t={452:function(e){"use strict";e.exports=r(9875)}},n={};function s(e){var r=n[e];if(void 0!==r)return r.exports;var i=n[e]={exports:{}},o=!0;try{t[e](i,i.exports,s),o=!1}finally{o&&delete n[e]}return i.exports}s.ab="//";var i={};!function(){var e,t=(e=s(452))&&"object"==typeof e&&"default"in e?e.default:e,r=/https?|ftp|gopher|file/;function n(e){"string"==typeof e&&(e=g(e));var n,s,i,o,a,l,h,c,u,d=(s=(n=e).auth,i=n.hostname,o=n.protocol||"",a=n.pathname||"",l=n.hash||"",h=n.query||"",c=!1,s=s?encodeURIComponent(s).replace(/%3A/i,":")+"@":"",n.host?c=s+n.host:i&&(c=s+(~i.indexOf(":")?"["+i+"]":i),n.port&&(c+=":"+n.port)),h&&"object"==typeof h&&(h=t.encode(h)),u=n.search||h&&"?"+h||"",o&&":"!==o.substr(-1)&&(o+=":"),n.slashes||(!o||r.test(o))&&!1!==c?(c="//"+(c||""),a&&"/"!==a[0]&&(a="/"+a)):c||(c=""),l&&"#"!==l[0]&&(l="#"+l),u&&"?"!==u[0]&&(u="?"+u),{protocol:o,host:c,pathname:a=a.replace(/[?#]/g,encodeURIComponent),search:u=u.replace("#","%23"),hash:l});return""+d.protocol+d.host+d.pathname+d.search+d.hash}var o="http://",a=o+"w.w",l=/^([a-z0-9.+-]*:\/\/\/)([a-z0-9.+-]:\/*)?/i,h=/https?|ftp|gopher|file/;function c(e,t){var r="string"==typeof e?g(e):e;e="object"==typeof e?n(e):e;var s=g(t),i="";r.protocol&&!r.slashes&&(i=r.protocol,e=e.replace(r.protocol,""),i+="/"===t[0]||"/"===e[0]?"/":""),i&&s.protocol&&(i="",s.slashes||(i=s.protocol,t=t.replace(s.protocol,"")));var c=e.match(l);c&&!s.protocol&&(e=e.substr((i=c[1]+(c[2]||"")).length),/^\/\/[^/]/.test(t)&&(i=i.slice(0,-1)));var u=new URL(e,a+"/"),d=new URL(t,u).toString().replace(a,""),f=s.protocol||r.protocol;return f+=r.slashes||s.slashes?"//":"",!i&&f?d=d.replace(o,f):i&&(d=d.replace(o,"")),h.test(d)||~t.indexOf(".")||"/"===e.slice(-1)||"/"===t.slice(-1)||"/"!==d.slice(-1)||(d=d.slice(0,-1)),i&&(d=i+("/"===d[0]?d.substr(1):d)),d}function u(){}u.prototype.parse=g,u.prototype.format=n,u.prototype.resolve=c,u.prototype.resolveObject=c;var d=/^https?|ftp|gopher|file/,f=/^(.*?)([#?].*)/,p=/^([a-z0-9.+-]*:)(\/{0,3})(.*)/i,_=/^([a-z0-9.+-]*:)?\/\/\/*/i,m=/^([a-z0-9.+-]*:)(\/{0,2})\[(.*)\]$/i;function g(e,r,s){if(void 0===r&&(r=!1),void 0===s&&(s=!1),e&&"object"==typeof e&&e instanceof u)return e;var i=(e=e.trim()).match(f);e=i?i[1].replace(/\\/g,"/")+i[2]:e.replace(/\\/g,"/"),m.test(e)&&"/"!==e.slice(-1)&&(e+="/");var o=!/(^javascript)/.test(e)&&e.match(p),l=_.test(e),h="";o&&(d.test(o[1])||(h=o[1].toLowerCase(),e=""+o[2]+o[3]),o[2]||(l=!1,d.test(o[1])?(h=o[1],e=""+o[3]):e="//"+o[3]),3!==o[2].length&&1!==o[2].length||(h=o[1],e="/"+o[3]));var c,g=(i?i[1]:e).match(/^https?:\/\/[^/]+(:[0-9]+)(?=\/|$)/),y=g&&g[1],w=new u,b="",k="";try{c=new URL(e)}catch(t){b=t,h||s||!/^\/\//.test(e)||/^\/\/.+[@.]/.test(e)||(k="/",e=e.substr(1));try{c=new URL(e,a)}catch(e){return w.protocol=h,w.href=h,w}}w.slashes=l&&!k,w.host="w.w"===c.host?"":c.host,w.hostname="w.w"===c.hostname?"":c.hostname.replace(/(\[|\])/g,""),w.protocol=b?h||null:c.protocol,w.search=c.search.replace(/\\/g,"%5C"),w.hash=c.hash.replace(/\\/g,"%5C");var v=e.split("#");!w.search&&~v[0].indexOf("?")&&(w.search="?"),w.hash||""!==v[1]||(w.hash="#"),w.query=r?t.decode(c.search.substr(1)):w.search.substr(1),w.pathname=k+(o?c.pathname.replace(/['^|`]/g,function(e){return"%"+e.charCodeAt().toString(16).toUpperCase()}).replace(/((?:%[0-9A-F]{2})+)/g,function(e,t){try{return decodeURIComponent(t).split("").map(function(e){var t=e.charCodeAt();return t>256||/^[a-z0-9]$/i.test(e)?e:"%"+t.toString(16).toUpperCase()}).join("")}catch(e){return t}}):c.pathname),"about:"===w.protocol&&"blank"===w.pathname&&(w.protocol="",w.pathname=""),b&&"/"!==e[0]&&(w.pathname=w.pathname.substr(1)),h&&!d.test(h)&&"/"!==e.slice(-1)&&"/"===w.pathname&&(w.pathname=""),w.path=w.pathname+w.search,w.auth=[c.username,c.password].map(decodeURIComponent).filter(Boolean).join(":"),w.port=c.port,y&&!w.host.endsWith(y)&&(w.host+=y,w.port=y.slice(1)),w.href=k?""+w.pathname+w.search+w.hash:n(w);var x=/^(file)/.test(w.href)?["host","hostname"]:[];return Object.keys(w).forEach(function(e){~x.indexOf(e)||(w[e]=w[e]||null)}),w}i.parse=g,i.format=n,i.resolve=c,i.resolveObject=function(e,t){return g(c(e,t))},i.Url=u}(),e.exports=i}()},8960:function(e){!function(){var t={229:function(e){var t,r,n,s=e.exports={};function i(){throw Error("setTimeout has not been defined")}function o(){throw Error("clearTimeout has not been defined")}function a(e){if(t===setTimeout)return setTimeout(e,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(r){try{return t.call(null,e,0)}catch(r){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:i}catch(e){t=i}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(e){r=o}}();var l=[],h=!1,c=-1;function u(){h&&n&&(h=!1,n.length?l=n.concat(l):c=-1,l.length&&d())}function d(){if(!h){var e=a(u);h=!0;for(var t=l.length;t;){for(n=l,l=[];++c<t;)n&&n[c].run();c=-1,t=l.length}n=null,h=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===o||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function f(e,t){this.fun=e,this.array=t}function p(){}s.nextTick=function(e){var t=Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];l.push(new f(e,t)),1!==l.length||h||a(d)},f.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=p,s.addListener=p,s.once=p,s.off=p,s.removeListener=p,s.removeAllListeners=p,s.emit=p,s.prependListener=p,s.prependOnceListener=p,s.listeners=function(e){return[]},s.binding=function(e){throw Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw Error("process.chdir is not supported")},s.umask=function(){return 0}}},r={};function n(e){var s=r[e];if(void 0!==s)return s.exports;var i=r[e]={exports:{}},o=!0;try{t[e](i,i.exports,n),o=!1}finally{o&&delete r[e]}return i.exports}n.ab="//";var s=n(229);e.exports=s}()},9875:function(e){!function(){"use strict";var t={815:function(e){e.exports=function(e,r,n,s){r=r||"&",n=n||"=";var i={};if("string"!=typeof e||0===e.length)return i;var o=/\+/g;e=e.split(r);var a=1e3;s&&"number"==typeof s.maxKeys&&(a=s.maxKeys);var l=e.length;a>0&&l>a&&(l=a);for(var h=0;h<l;++h){var c,u,d,f,p=e[h].replace(o,"%20"),_=p.indexOf(n);(_>=0?(c=p.substr(0,_),u=p.substr(_+1)):(c=p,u=""),d=decodeURIComponent(c),f=decodeURIComponent(u),Object.prototype.hasOwnProperty.call(i,d))?t(i[d])?i[d].push(f):i[d]=[i[d],f]:i[d]=f}return i};var t=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},577:function(e){var t=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,i,o,a){return(i=i||"&",o=o||"=",null===e&&(e=void 0),"object"==typeof e)?n(s(e),function(s){var a=encodeURIComponent(t(s))+o;return r(e[s])?n(e[s],function(e){return a+encodeURIComponent(t(e))}).join(i):a+encodeURIComponent(t(e[s]))}).join(i):a?encodeURIComponent(t(a))+o+encodeURIComponent(t(e)):""};var r=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n<e.length;n++)r.push(t(e[n],n));return r}var s=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t}}},r={};function n(e){var s=r[e];if(void 0!==s)return s.exports;var i=r[e]={exports:{}},o=!0;try{t[e](i,i.exports,n),o=!1}finally{o&&delete r[e]}return i.exports}n.ab="//";var s={};s.decode=s.parse=n(815),s.encode=s.stringify=n(577),e.exports=s}()},7731:function(e,t,r){"use strict";r.r(t),r.d(t,{InferenceSession:function(){return m},Tensor:function(){return p},env:function(){return a},registerBackend:function(){return i}});let n={},s=[],i=(e,t,r)=>{if(t&&"function"==typeof t.init&&"function"==typeof t.createSessionHandler){let i=n[e];if(void 0===i)n[e]={backend:t,priority:r};else if(i.priority>r)return;else if(i.priority===r&&i.backend!==t)throw Error(`cannot register backend "${e}" using priority ${r}`);if(r>=0){let t=s.indexOf(e);-1!==t&&s.splice(t,1);for(let t=0;t<s.length;t++)if(n[s[t]].priority<=r){s.splice(t,0,e);return}s.push(e)}return}throw TypeError("not a valid backend")},o=async e=>{let t=0===e.length?s:e,r=[];for(let e of t){let t=n[e];if(t){if(t.initialized)return t.backend;if(t.aborted)continue;let n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init()),await t.initPromise,t.initialized=!0,t.backend}catch(s){n||r.push({name:e,err:s}),t.aborted=!0}finally{delete t.initPromise}}}throw Error(`no available backend found. ERR: ${r.map(e=>`[${e.name}] ${e.err}`).join(", ")}`)},a=new class{constructor(){this.wasm={},this.webgl={},this.logLevelInternal="warning"}set logLevel(e){if(void 0!==e){if("string"!=typeof e||-1===["verbose","info","warning","error","fatal"].indexOf(e))throw Error(`Unsupported logging level: ${e}`);this.logLevelInternal=e}}get logLevel(){return this.logLevelInternal}},l="undefined"!=typeof BigInt64Array&&"function"==typeof BigInt64Array.from,h="undefined"!=typeof BigUint64Array&&"function"==typeof BigUint64Array.from,c=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),u=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]);l&&(c.set("int64",BigInt64Array),u.set(BigInt64Array,"int64")),h&&(c.set("uint64",BigUint64Array),u.set(BigUint64Array,"uint64"));let d=e=>{let t=1;for(let r=0;r<e.length;r++){let n=e[r];if("number"!=typeof n||!Number.isSafeInteger(n))throw TypeError(`dims[${r}] must be an integer, got: ${n}`);if(n<0)throw RangeError(`dims[${r}] must be a non-negative integer, got: ${n}`);t*=n}return t};class f{constructor(e,t,r){let n,s,i;if("string"==typeof e){if(n=e,i=r,"string"===e){if(!Array.isArray(t))throw TypeError("A string tensor's data must be a string array.");s=t}else{let r=c.get(e);if(void 0===r)throw TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t))s=r.from(t);else if(t instanceof r)s=t;else throw TypeError(`A ${n} tensor's data must be type of ${r}`)}}else if(i=t,Array.isArray(e)){if(0===e.length)throw TypeError("Tensor type cannot be inferred from an empty array.");let t=typeof e[0];if("string"===t)n="string",s=e;else if("boolean"===t)n="bool",s=Uint8Array.from(e);else throw TypeError(`Invalid element type of data array: ${t}.`)}else{let t=u.get(e.constructor);if(void 0===t)throw TypeError(`Unsupported type for tensor data: ${e.constructor}.`);n=t,s=e}if(void 0===i)i=[s.length];else if(!Array.isArray(i))throw TypeError("A tensor's dims must be a number array");let o=d(i);if(o!==s.length)throw Error(`Tensor's size(${o}) does not match data length(${s.length}).`);this.dims=i,this.type=n,this.data=s,this.size=o}static bufferToTensor(e,t){let r,n;if(void 0===e)throw Error("Image buffer must be defined");if(void 0===t.height||void 0===t.width)throw Error("Image height and width must be defined");let{height:s,width:i}=t,o=t.norm;r=void 0===o||void 0===o.mean?255:o.mean,n=void 0===o||void 0===o.bias?0:o.bias;let a=void 0!==t.bitmapFormat?t.bitmapFormat:"RGBA",l=void 0!==t.tensorFormat&&void 0!==t.tensorFormat?t.tensorFormat:"RGB",h=s*i,c=new Float32Array("RGBA"===l?4*h:3*h),u=4,d=0,p=1,_=2,m=3,g=0,y=h,w=2*h,b=-1;"RGB"===a&&(u=3,d=0,p=1,_=2,m=-1),"RGBA"===l?b=3*h:"RBG"===l?(g=0,w=h,y=2*h):"BGR"===l&&(w=0,y=h,g=2*h);for(let t=0;t<h;t++,d+=u,_+=u,p+=u,m+=u)c[g++]=(e[d]+n)/r,c[y++]=(e[p]+n)/r,c[w++]=(e[_]+n)/r,-1!==b&&-1!==m&&(c[b++]=(e[m]+n)/r);let k="RGBA"===l?new f("float32",c,[1,4,s,i]):new f("float32",c,[1,3,s,i]);return k}static async fromImage(e,t){let r;let n="undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement,s="undefined"!=typeof ImageData&&e instanceof ImageData,i="undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap,o="undefined"!=typeof String&&(e instanceof String||"string"==typeof e),a={};if(n){let n=document.createElement("canvas"),s=n.getContext("2d");if(null!=s){let i=e.naturalHeight,o=e.naturalWidth;if(void 0!==t&&void 0!==t.resizedHeight&&void 0!==t.resizedWidth&&(i=t.resizedHeight,o=t.resizedWidth),void 0!==t){if(a=t,void 0!==t.tensorFormat)throw Error("Image input config format must be RGBA for HTMLImageElement");if(a.tensorFormat="RGBA",void 0!==t.height&&t.height!==i)throw Error("Image input config height doesn't match HTMLImageElement height");if(a.height=i,void 0!==t.width&&t.width!==o)throw Error("Image input config width doesn't match HTMLImageElement width");a.width=o}else a.tensorFormat="RGBA",a.height=i,a.width=o;n.width=o,n.height=i,s.drawImage(e,0,0,o,i),r=s.getImageData(0,0,o,i).data}else throw Error("Can not access image data")}else if(s){let n,s;if(void 0!==t&&void 0!==t.resizedWidth&&void 0!==t.resizedHeight?(n=t.resizedHeight,s=t.resizedWidth):(n=e.height,s=e.width),void 0!==t){if(a=t,void 0!==t.bitmapFormat&&"RGBA"!==t.bitmapFormat)throw Error("Image input config format must be RGBA for ImageData");a.bitmapFormat="RGBA"}else a.bitmapFormat="RGBA";if(a.height=n,a.width=s,void 0!==t){let t=document.createElement("canvas");t.width=s,t.height=n;let i=t.getContext("2d");if(null!=i)i.putImageData(e,0,0),r=i.getImageData(0,0,s,n).data;else throw Error("Can not access image data")}else r=e.data}else if(i){if(void 0===t)throw Error("Please provide image config with format for Imagebitmap");if(void 0!==t.bitmapFormat)throw Error("Image input config format must be defined for ImageBitmap");let n=document.createElement("canvas").getContext("2d");if(null!=n){let s=e.height,i=e.width;if(n.drawImage(e,0,0,i,s),r=n.getImageData(0,0,i,s).data,void 0!==t){if(void 0!==t.height&&t.height!==s)throw Error("Image input config height doesn't match ImageBitmap height");if(a.height=s,void 0!==t.width&&t.width!==i)throw Error("Image input config width doesn't match ImageBitmap width");a.width=i}else a.height=s,a.width=i;return f.bufferToTensor(r,a)}throw Error("Can not access image data")}else if(o)return new Promise((r,n)=>{let s=document.createElement("canvas"),i=s.getContext("2d");if(!e||!i)return n();let o=new Image;o.crossOrigin="Anonymous",o.src=e,o.onload=()=>{s.width=o.width,s.height=o.height,i.drawImage(o,0,0,s.width,s.height);let e=i.getImageData(0,0,s.width,s.height);if(void 0!==t){if(void 0!==t.height&&t.height!==s.height)throw Error("Image input config height doesn't match ImageBitmap height");if(a.height=s.height,void 0!==t.width&&t.width!==s.width)throw Error("Image input config width doesn't match ImageBitmap width");a.width=s.width}else a.height=s.height,a.width=s.width;r(f.bufferToTensor(e.data,a))}});else throw Error("Input data provided is not supported - aborted tensor creation");if(void 0!==r)return f.bufferToTensor(r,a);throw Error("Input data provided is not supported - aborted tensor creation")}toImageData(e){var t,r;let n;let s=document.createElement("canvas").getContext("2d");if(null!=s){let i=this.dims[3],o=this.dims[2],a=this.dims[1],l=void 0!==e&&void 0!==e.format?e.format:"RGB",h=void 0!==e&&(null===(t=e.norm)||void 0===t?void 0:t.mean)!==void 0?e.norm.mean:255,c=void 0!==e&&(null===(r=e.norm)||void 0===r?void 0:r.bias)!==void 0?e.norm.bias:0,u=o*i;if(void 0!==e){if(void 0!==e.height&&e.height!==o)throw Error("Image output config height doesn't match tensor height");if(void 0!==e.width&&e.width!==i)throw Error("Image output config width doesn't match tensor width");if(void 0!==e.format&&4===a&&"RGBA"!==e.format||3===a&&"RGB"!==e.format&&"BGR"!==e.format)throw Error("Tensor format doesn't match input tensor dims")}let d=0,f=1,p=2,_=3,m=0,g=u,y=2*u,w=-1;"RGBA"===l?(m=0,g=u,y=2*u,w=3*u):"RGB"===l?(m=0,g=u,y=2*u):"RBG"===l&&(m=0,y=u,g=2*u),n=s.createImageData(i,o);for(let e=0;e<o*i;d+=4,f+=4,p+=4,_+=4,e++)n.data[d]=(this.data[m++]-c)*h,n.data[f]=(this.data[g++]-c)*h,n.data[p]=(this.data[y++]-c)*h,n.data[_]=-1===w?255:(this.data[w++]-c)*h}else throw Error("Can not access image data");return n}reshape(e){return new f(this.type,this.data,e)}}let p=f;class _{constructor(e){this.handler=e}async run(e,t,r){let n={},s={};if("object"!=typeof e||null===e||e instanceof p||Array.isArray(e))throw TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if("object"==typeof t){if(null===t)throw TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof p)throw TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(0===t.length)throw TypeError("'fetches' cannot be an empty array.");for(let e of(i=!1,t)){if("string"!=typeof e)throw TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(e))throw RangeError(`'fetches' contains invalid output name: ${e}.`);n[e]=null}if("object"==typeof r&&null!==r)s=r;else if(void 0!==r)throw TypeError("'options' must be an object.")}else{let e=!1,o=Object.getOwnPropertyNames(t);for(let r of this.outputNames)if(-1!==o.indexOf(r)){let s=t[r];(null===s||s instanceof p)&&(e=!0,i=!1,n[r]=s)}if(e){if("object"==typeof r&&null!==r)s=r;else if(void 0!==r)throw TypeError("'options' must be an object.")}else s=t}}else if(void 0!==t)throw TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let t of this.inputNames)if(void 0===e[t])throw Error(`input '${t}' is missing in 'feeds'.`);if(i)for(let e of this.outputNames)n[e]=null;let o=await this.handler.run(e,n,s),a={};for(let e in o)Object.hasOwnProperty.call(o,e)&&(a[e]=new p(o[e].type,o[e].data,o[e].dims));return a}static async create(e,t,r,n){let s;let i={};if("string"==typeof e){if(s=e,"object"==typeof t&&null!==t)i=t;else if(void 0!==t)throw TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(s=e,"object"==typeof t&&null!==t)i=t;else if(void 0!==t)throw TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer){let o=0,a=e.byteLength;if("object"==typeof t&&null!==t)i=t;else if("number"==typeof t){if(!Number.isSafeInteger(o=t))throw RangeError("'byteOffset' must be an integer.");if(o<0||o>=e.byteLength)throw RangeError(`'byteOffset' is out of range [0, ${e.byteLength}).`);if(a=e.byteLength-o,"number"==typeof r){if(!Number.isSafeInteger(a=r))throw RangeError("'byteLength' must be an integer.");if(a<=0||o+a>e.byteLength)throw RangeError(`'byteLength' is out of range (0, ${e.byteLength-o}].`);if("object"==typeof n&&null!==n)i=n;else if(void 0!==n)throw TypeError("'options' must be an object.")}else if(void 0!==r)throw TypeError("'byteLength' must be a number.")}else if(void 0!==t)throw TypeError("'options' must be an object.");s=new Uint8Array(e,o,a)}else throw TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let a=i.executionProviders||[],l=a.map(e=>"string"==typeof e?e:e.name),h=await o(l),c=await h.createSessionHandler(s,i);return new _(c)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}let m=_},4975:function(e,t,r){"use strict";let n,s,i,o;function a(e,t){null!==e&&e(t)}function l(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}r.d(t,{OBj:function(){return O},qCb:function(){return ee},EUT:function(){return nn}});let h=class{constructor(){let e=function(...t){return e._call(...t)};return Object.setPrototypeOf(e,new.target.prototype)}_call(...e){throw Error("Must implement _call method in subclass")}};function c(e){return"string"==typeof e||e instanceof String}function u(e){return Number.isInteger(e)||"bigint"==typeof e}function d(e,t,r){let n=e[t];if(void 0!==n)return delete e[t],n;if(void 0===r)throw Error(`Key ${t} does not exist in object.`);return r}function f(...e){return Array.prototype.concat.apply([],e)}var p=r(7147),_=r(1418),m=r(319),g=r(8386),y=r(3342),w=r(692),b=r(495),k=r.t(b,2),v=r(2018),x=r.t(v,2),A=r(2601);let E=["wasm"];if(void 0!==A&&A?.release?.name==="node")n=b??k,E.unshift("cpu");else{n=v??x;let e="undefined"!=typeof navigator&&/iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent);e&&(n.env.wasm.simd=!1)}let{env:z}=n,T="2.4.2",M="undefined"!=typeof self&&"caches"in self,I=!R(g),B=!R(y),S=I&&B,C=S?y.dirname(y.dirname(w.fileURLToPath("file:///workspaces/transformers.js/examples/next/node_modules/@xenova/transformers/src/env.js"))):"./",P=S?y.join(C,"/.cache/"):null,U="/models/",L=S?y.join(C,U):U;z.wasm.wasmPaths=S?y.join(C,"/dist/"):`https://cdn.jsdelivr.net/npm/@xenova/transformers@${T}/dist/`;let O={backends:{onnx:z,tfjs:{}},__dirname:C,version:T,allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!0,localModelPath:L,useFS:I,useBrowserCache:M,useFSCache:I,cacheDir:P};function R(e){return 0===Object.keys(e).length}var j=r(2601),N=r(7133).lW;globalThis.ReadableStream||(globalThis.ReadableStream=m.ReadableStream);class ${_CONTENT_TYPE_MAP={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif"};constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=p.existsSync(e),this.exists){this.status=200,this.statusText="OK";let t=p.statSync(e);this.headers.set("content-length",t.size.toString()),this.updateContentType();let r=this;this.body=new ReadableStream({start(e){r.arrayBuffer().then(t=>{e.enqueue(new Uint8Array(t)),e.close()})}})}else this.status=404,this.statusText="Not Found",this.body=null}updateContentType(){let e=this.filePath.toString().split(".").pop().toLowerCase();this.headers.set("content-type",this._CONTENT_TYPE_MAP[e]??"application/octet-stream")}clone(){let e=new $(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){let e=await p.promises.readFile(this.filePath);return e.buffer}async blob(){let e=await p.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){let e=await p.promises.readFile(this.filePath,"utf8");return e}async json(){return JSON.parse(await this.text())}}function F(e,t=null){let r;try{r=new URL(e)}catch(e){return!1}return(!t||!!t.includes(r.hostname))&&("http:"===r.protocol||"https:"===r.protocol)}async function G(e){if(O.useFS&&!F(e))return new $(e);if(void 0===j||j?.release?.name!=="node")return fetch(e);{let t=!!j.env?.TESTING_REMOTELY,r=O.version,n=new Headers;n.set("User-Agent",`transformers.js/${r}; is_ci/${t};`);let s=F(e,["huggingface.co","hf.co"]);if(s){let e=j.env?.HF_ACCESS_TOKEN;e&&n.set("Authorization",`Bearer ${e}`)}return fetch(e,{headers:n})}}let q={400:"Bad request error occurred while trying to load file",401:"Unauthorized access to file",403:"Forbidden access to file",404:"Could not locate file",408:"Request timeout error occurred while trying to load file",500:"Internal server error error occurred while trying to load file",502:"Bad gateway error occurred while trying to load file",503:"Service unavailable error occurred while trying to load file",504:"Gateway timeout error occurred while trying to load file"};class D{constructor(e){this.path=e}async match(e){let t=_.join(this.path,e),r=new $(t);return r.exists?r:void 0}async put(e,t){let r=N.from(await t.arrayBuffer()),n=_.join(this.path,e);try{await p.promises.mkdir(_.dirname(n),{recursive:!0}),await p.promises.writeFile(n,r)}catch(e){console.warn("An error occurred while writing the file to cache:",e)}}}async function W(e,...t){for(let r of t)try{let t=await e.match(r);if(t)return t}catch(e){continue}}async function K(e,t,r=!0,n={}){let s,i,o,l;if(!O.allowLocalModels){if(n.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");if(!O.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}if(a(n.progress_callback,{status:"initiate",name:e,file:t}),!s&&O.useBrowserCache){if("undefined"==typeof caches)throw Error("Browser cache is not available in this environment.");try{s=await caches.open("transformers-cache")}catch(e){console.warn("An error occurred while opening the browser cache:",e)}}!s&&O.useFSCache&&(s=new D(n.cache_dir??O.cacheDir));let h=n.revision??"main",c=V(e,t),u=V(O.localModelPath,c),d=V(O.remoteHost,O.remotePathTemplate.replaceAll("{model}",e).replaceAll("{revision}",h),t),f="main"===h?c:V(e,h,t),p=s instanceof D?f:d;if(s&&(l=await W(s,u,p)),void 0===l){if(O.allowLocalModels){let e=F(c);if(e){if(n.local_files_only)throw Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${c}.`);if(!O.allowRemoteModels)throw Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${c}.`)}else try{l=await G(u),i=u}catch(e){console.warn(`Unable to load from local path "${u}": "${e}"`)}}if(void 0===l||404===l.status){if(n.local_files_only||!O.allowRemoteModels){if(!r)return null;throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${u}".`)}if(200!==(l=await G(d)).status)return function(e,t,r){if(!r)return null;let n=q[e]??`Error (${e}) occurred while trying to load file`;throw Error(`${n}: "${t}".`)}(l.status,d,r);i=p}s&&l instanceof Response&&200===l.status&&(o=l.clone())}a(n.progress_callback,{status:"download",name:e,file:t});let _=await X(l,r=>{a(n.progress_callback,{status:"progress",...r,name:e,file:t})});return o&&i&&await s.match(i)===void 0&&await s.put(i,o).catch(e=>{console.warn(`Unable to add response to browser cache: ${e}.`)}),a(n.progress_callback,{status:"done",name:e,file:t}),_}async function H(e,t,r=!0,n={}){let s=await K(e,t,r,n);return null===s?{}:JSON.parse(new TextDecoder("utf-8").decode(s))}async function X(e,t){let r=e.headers.get("Content-Length");null===r&&console.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");let n=parseInt(r??"0"),s=new Uint8Array(n),i=0,o=e.body.getReader();async function a(){let{done:e,value:r}=await o.read();if(e)return;let l=i+r.length;if(l>n){n=l;let e=new Uint8Array(n);e.set(s),s=e}s.set(r,i),i=l;let h=i/n*100;return t({progress:h,loaded:i,total:n}),a()}return await a(),s}function V(...e){return(e=e.map((t,r)=>(r&&(t=t.replace(RegExp("^/"),"")),r!==e.length-1&&(t=t.replace(RegExp("/$"),"")),t))).join("/")}function J(e){let t=Z(e)[0],r=e.map(e=>Math.exp(e-t)),n=r.reduce((e,t)=>e+t,0),s=r.map(e=>e/n);return s}function Y(e,t=0){return e=Array.from(e).map((e,t)=>[t,e]).sort((e,t)=>t[1]-e[1]),t>0&&(e=e.slice(0,t)),e}function Z(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],r=0;for(let n=1;n<e.length;++n)e[n]>t&&(t=e[n],r=n);return[t,r]}class Q{constructor(e){if(this.size=0|e,this.size<=1||(this.size&this.size-1)!=0)throw Error("FFT size must be a power of two and bigger than 1");this._csize=e<<1,this.table=new Float32Array(2*this.size);for(let e=0;e<this.table.length;e+=2){let t=Math.PI*e/this.size;this.table[e]=Math.cos(t),this.table[e+1]=-Math.sin(t)}let t=0;for(let e=1;this.size>e;e<<=1)++t;this._width=t%2==0?t-1:t,this._bitrev=new Int32Array(1<<this._width);for(let e=0;e<this._bitrev.length;++e){this._bitrev[e]=0;for(let t=0;t<this._width;t+=2){let r=this._width-t-2;this._bitrev[e]|=(e>>>t&3)<<r}}}createComplexArray(){return new Float32Array(this._csize)}fromComplexArray(e,t){let r=t||Array(e.length>>>1);for(let t=0;t<e.length;t+=2)r[t>>>1]=e[t];return r}toComplexArray(e,t){let r=t||this.createComplexArray();for(let t=0;t<r.length;t+=2)r[t]=e[t>>>1],r[t+1]=0;return r}completeSpectrum(e){let t=this._csize,r=t>>>1;for(let n=2;n<r;n+=2)e[t-n]=e[n],e[t-n+1]=-e[n+1]}transform(e,t){if(e===t)throw Error("Input and output buffers must be different");this._transform4(e,t,1)}realTransform(e,t){if(e===t)throw Error("Input and output buffers must be different");this._realTransform4(e,t,1)}inverseTransform(e,t){if(e===t)throw Error("Input and output buffers must be different");this._transform4(e,t,-1);for(let t=0;t<e.length;++t)e[t]/=this.size}_transform4(e,t,r){let n,s;let i=this._csize,o=this._width,a=1<<o,l=i/a<<1,h=this._bitrev;if(4===l)for(n=0,s=0;n<i;n+=l,++s){let r=h[s];this._singleTransform2(t,e,n,r,a)}else for(n=0,s=0;n<i;n+=l,++s){let i=h[s];this._singleTransform4(t,e,n,i,a,r)}for(a>>=2;a>=2;a>>=2){let t=(l=i/a<<1)>>>2;for(n=0;n<i;n+=l){let s=n+t;for(let i=n,o=0;i<s;i+=2,o+=a){let n=i,s=n+t,a=s+t,l=a+t,h=e[n],c=e[n+1],u=e[s],d=e[s+1],f=e[a],p=e[a+1],_=e[l],m=e[l+1],g=this.table[o],y=r*this.table[o+1],w=u*g-d*y,b=u*y+d*g,k=this.table[2*o],v=r*this.table[2*o+1],x=f*k-p*v,A=f*v+p*k,E=this.table[3*o],z=r*this.table[3*o+1],T=_*E-m*z,M=_*z+m*E,I=h+x,B=c+A,S=h-x,C=c-A,P=w+T,U=b+M,L=r*(w-T),O=r*(b-M);e[n]=I+P,e[n+1]=B+U,e[s]=S+O,e[s+1]=C-L,e[a]=I-P,e[a+1]=B-U,e[l]=S-O,e[l+1]=C+L}}}}_singleTransform2(e,t,r,n,s){let i=e[n],o=e[n+1],a=e[n+s],l=e[n+s+1];t[r]=i+a,t[r+1]=o+l,t[r+2]=i-a,t[r+3]=o-l}_singleTransform4(e,t,r,n,s,i){let o=2*s,a=3*s,l=e[n],h=e[n+1],c=e[n+s],u=e[n+s+1],d=e[n+o],f=e[n+o+1],p=e[n+a],_=e[n+a+1],m=l+d,g=h+f,y=l-d,w=h-f,b=c+p,k=u+_,v=i*(c-p),x=i*(u-_);t[r]=m+b,t[r+1]=g+k,t[r+2]=y+x,t[r+3]=w-v,t[r+4]=m-b,t[r+5]=g-k,t[r+6]=y-x,t[r+7]=w+v}_realTransform4(e,t,r){let n=this._csize,s=this._width,i=1<<s,o=n/i<<1;var a,l,h=this._bitrev;if(4===o)for(a=0,l=0;a<n;a+=o,++l){let r=h[l];this._singleRealTransform2(t,e,a,r>>>1,i>>>1)}else for(a=0,l=0;a<n;a+=o,++l){let n=h[l];this._singleRealTransform4(t,e,a,n>>>1,i>>>1,r)}for(i>>=2;i>=2;i>>=2){o=n/i<<1;let t=o>>>1,s=t>>>1,l=s>>>1;for(a=0;a<n;a+=o)for(let n=0,o=0;n<=l;n+=2,o+=i){let i=a+n,h=i+s,c=h+s,u=c+s,d=e[i],f=e[i+1],p=e[h],_=e[h+1],m=e[c],g=e[c+1],y=e[u],w=e[u+1],b=this.table[o],k=r*this.table[o+1],v=p*b-_*k,x=p*k+_*b,A=this.table[2*o],E=r*this.table[2*o+1],z=m*A-g*E,T=m*E+g*A,M=this.table[3*o],I=r*this.table[3*o+1],B=y*M-w*I,S=y*I+w*M,C=d+z,P=f+T,U=d-z,L=f-T,O=v+B,R=x+S,j=r*(v-B),N=r*(x-S);if(e[i]=C+O,e[i+1]=P+R,e[h]=U+N,e[h+1]=L-j,0===n){e[c]=C-O,e[c+1]=P-R;continue}if(n===l)continue;let $=a+s-n,F=a+t-n;e[$]=U+-r*N,e[$+1]=-L-r*j,e[F]=C+-r*O,e[F+1]=-P+r*R}}}_singleRealTransform2(e,t,r,n,s){let i=e[n],o=e[n+s];t[r]=i+o,t[r+1]=0,t[r+2]=i-o,t[r+3]=0}_singleRealTransform4(e,t,r,n,s,i){let o=e[n],a=e[n+s],l=e[n+2*s],h=e[n+3*s],c=o+l,u=o-l,d=a+h,f=i*(a-h);t[r]=c+d,t[r+1]=0,t[r+2]=u,t[r+3]=-f,t[r+4]=c-d,t[r+5]=0,t[r+6]=u,t[r+7]=f}}function ee(e,t){if(t%2==0||t<=0)throw Error("Window size must be a positive odd number");let r=new e.constructor(e.length),n=new e.constructor(t),s=Math.floor(t/2);for(let t=0;t<e.length;++t){let i=0;for(let r=-s;r<=s;++r){let s=t+r;s<0?s=Math.abs(s):s>=e.length&&(s=2*(e.length-1)-s),n[i++]=e[s]}n.sort(),r[t]=n[s]}return r}function et(e,t){let r=Math.pow(10,t);return Math.round(e*r)/r}let er=n.Tensor;class en extends er{constructor(...e){return e[0]instanceof n.Tensor?super(e[0].type,e[0].data,e[0].dims):super(...e),new Proxy(this,{get:(e,t)=>{if("string"==typeof t){let r=Number(t);if(Number.isInteger(r))return e._getitem(r)}return e[t]},set:(e,t,r)=>e[t]=r})}*[Symbol.iterator](){let[e,...t]=this.dims;if(t.length>0){let r=t.reduce((e,t)=>e*t);for(let n=0;n<e;++n)yield this._subarray(n,r,t)}else yield*this.data}_getitem(e){let[t,...r]=this.dims;if(e=el(e,t),!(r.length>0))return new en(this.type,[this.data[e]],r);{let t=r.reduce((e,t)=>e*t);return this._subarray(e,t,r)}}indexOf(e){for(let t=0;t<this.data.length;++t)if(this.data[t]==e)return t;return -1}_subarray(e,t,r){let n=this.data.subarray(e*t,(e+1)*t);return new en(this.type,n,r)}item(){if(1!==this.data.length)throw Error(`a Tensor with ${this.data.length} elements cannot be converted to Scalar`);return this.data[0]}tolist(){return function(e,t){let r=e.length,n=t.reduce((e,t)=>e*t);if(r!==n)throw Error(`cannot reshape array of size ${r} into shape (${t})`);let s=e;for(let e=t.length-1;e>=0;e--)s=s.reduce((r,n)=>{let s=r[r.length-1];return s.length<t[e]?s.push(n):r.push([n]),r},[[]]);return s[0]}(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){for(let e=0;e<this.data.length;++e)this.data[e]=1/(1+Math.exp(-this.data[e]));return this}clone(){return new en(this.type,this.data.slice(),this.dims.slice())}slice(...e){let t=[],r=[];for(let n=0;n<this.dims.length;++n){let s=e[n];if(null==s)r.push([0,this.dims[n]]),t.push(this.dims[n]);else if("number"==typeof s)s=el(s,this.dims[n],n),r.push([s,s+1]);else if(Array.isArray(s)&&2===s.length){if(s[0]>s[1])throw Error(`Invalid slice: ${s}`);let e=[Math.max(s[0],0),Math.min(s[1],this.dims[n])];r.push(e),t.push(e[1]-e[0])}else throw Error(`Invalid slice: ${s}`)}let n=r.map(([e,t])=>t-e),s=n.reduce((e,t)=>e*t),i=new this.data.constructor(s),o=this.stride();for(let e=0;e<s;++e){let t=0;for(let s=n.length-1,i=e;s>=0;--s){let e=n[s];t+=(i%e+r[s][0])*o[s],i=Math.floor(i/e)}i[e]=this.data[t]}return new en(this.type,i,t)}transpose(...e){return es(this,e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,r=!1){if("fro"===e)e=2;else if("string"==typeof e)throw Error(`Unsupported norm: ${e}`);if(null===t){let t=this.data.reduce((t,r)=>t+r**e,0)**(1/e);return new en(this.type,[t],[])}t=el(t,this.dims.length);let n=this.dims.slice();n[t]=1;let s=new this.data.constructor(this.data.length/this.dims[t]);for(let r=0;r<this.data.length;++r){let i=0;for(let e=this.dims.length-1,s=r,o=1;e>=0;--e){let r=this.dims[e];if(e!==t){let t=s%r;i+=t*o,o*=n[e]}s=Math.floor(s/r)}s[i]+=this.data[r]**e}if(1!==e)for(let t=0;t<s.length;++t)s[t]=s[t]**(1/e);return r||n.splice(t,1),new en(this.type,s,n)}normalize_(e=2,t=1){t=el(t,this.dims.length);let r=this.norm(e,t,!0);for(let e=0;e<this.data.length;++e){let n=0;for(let r=this.dims.length-1,s=e,i=1;r>=0;--r){let e=this.dims[r];if(r!==t){let t=s%e;n+=t*i,i*=this.dims[r]}s=Math.floor(s/e)}this.data[e]/=r.data[n]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return function(e){let t=Array(e.length);for(let r=e.length-1,n=1;r>=0;--r)t[r]=n,n*=e[r];return t}(this.dims)}squeeze(e=null){return new en(this.type,this.data,eo(this.dims,e))}squeeze_(e=null){return this.dims=eo(this.dims,e),this}unsqueeze(e=null){return new en(this.type,this.data,ea(this.dims,e))}unsqueeze_(e=null){return this.dims=ea(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let r=this.dims.slice(0,e),n=this.dims.slice(e,t+1),s=this.dims.slice(t+1);return this.dims=[...r,n.reduce((e,t)=>e*t,1),...s],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let r=0;r<e.length;++r)if(-1===e[r]){if(-1!==t)throw Error("Only one dimension can be inferred");t=r}if(-1!==t){let r=e.reduce((e,r,n)=>n!==t?e*r:e,1);e[t]=this.data.length/r}return new en(this.type,this.data,e)}neg_(){for(let e=0;e<this.data.length;++e)this.data[e]=-this.data[e];return this}neg(){return this.clone().neg_()}}function es(e,t){let[r,n]=function(e,t,r){let n=Array(r.length),s=Array(r.length);for(let e=r.length-1,i=1;e>=0;--e)s[e]=i,n[e]=t[r[e]],i*=n[e];let i=r.map((e,t)=>s[r.indexOf(t)]),o=new e.constructor(e.length);for(let r=0;r<e.length;++r){let n=0;for(let e=t.length-1,s=r;e>=0;--e)n+=s%t[e]*i[e],s=Math.floor(s/t[e]);o[n]=e[r]}return[o,n]}(e.data,e.dims,t);return new en(e.type,r,n)}function ei(e,[t,r],n="bilinear",s=!1){let i=e.dims.at(-3)??1,o=e.dims.at(-2),a=e.dims.at(-1),l=function(e,[t,r,n],[s,i],o="bilinear",a=!1){let l=i/n,h=s/r,c=new e.constructor(s*i*t),u=r*n,d=s*i;for(let o=0;o<s;++o)for(let s=0;s<i;++s){let a=o*i+s,f=(s+.5)/l-.5,p=(o+.5)/h-.5,_=Math.floor(f),m=Math.floor(p),g=Math.min(_+1,n-1),y=Math.min(m+1,r-1);_=Math.max(_,0),m=Math.max(m,0);let w=f-_,b=p-m,k=(1-w)*(1-b),v=w*(1-b),x=(1-w)*b,A=w*b,E=m*n,z=y*n,T=E+_,M=E+g,I=z+_,B=z+g;for(let r=0;r<t;++r){let t=r*u;c[r*d+a]=k*e[t+T]+v*e[t+M]+x*e[t+I]+A*e[t+B]}}return c}(e.data,[i,o,a],[t,r],n,s);return new en(e.type,l,[i,t,r])}function eo(e,t){return e=e.slice(),null===t?e=e.filter(e=>1!==e):"number"==typeof t?1===e[t]&&e.splice(t,1):Array.isArray(t)&&(e=e.filter((e,r)=>1!==e||!t.includes(r))),e}function ea(e,t){return t=el(t,e.length+1),(e=e.slice()).splice(t,0,1),e}function el(e,t,r=null){if(e<-t||e>=t)throw Error(`IndexError: index ${e} is out of bounds for dimension${null===r?"":" "+r} with size ${t}`);return e<0&&(e=(e%t+t)%t),e}function eh(e,t=0){t=el(t,e[0].dims.length);let r=e[0].dims.slice();r[t]=e.reduce((e,r)=>e+r.dims[t],0);let n=r.reduce((e,t)=>e*t,1),s=new e[0].data.constructor(n),i=e[0].type;if(0===t){let t=0;for(let r of e)s.set(r.data,t),t+=r.data.length}else{let n=0;for(let i=0;i<e.length;++i){let o=e[i];for(let e=0;e<o.data.length;++e){let i=0;for(let s=o.dims.length-1,a=e,l=1;s>=0;--s){let e=o.dims[s],h=a%e;s===t&&(h+=n),i+=h*l,l*=r[s],a=Math.floor(a/e)}s[i]=o.data[e]}n+=o.dims[t]}}return new en(i,s,r)}function ec(e,t=null,r=!1){if(null===t){let t=e.data.reduce((e,t)=>e+t,0);return new en(e.type,[t/e.data.length],[])}t=el(t,e.dims.length);let n=e.dims.slice();n[t]=1;let s=new e.data.constructor(e.data.length/e.dims[t]);for(let r=0;r<e.data.length;++r){let i=0;for(let s=e.dims.length-1,o=r,a=1;s>=0;--s){let r=e.dims[s];if(s!==t){let e=o%r;i+=e*a,a*=n[s]}o=Math.floor(o/r)}s[i]+=e.data[r]}if(1!==e.dims[t])for(let r=0;r<s.length;++r)s[r]=s[r]/e.dims[t];return r||n.splice(t,1),new en(e.type,s,n)}async function eu(e,t){return await Promise.all([H(e,"tokenizer.json",!0,t),H(e,"tokenizer_config.json",!0,t)])}function ed(e,t=!0){return e.Regex?RegExp(t?e.Regex:`(${e.Regex})`,"gu"):e.String?e.String:(console.warn("Unknown pattern type:",e),null)}function ef(e){return e.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n\'t/g,"n't").replace(/ \'m/g,"'m").replace(/ \'s/g,"'s").replace(/ \'ve/g,"'ve").replace(/ \'re/g,"'re")}let ep="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E";class e_ extends h{constructor(e){super(),this.config=e,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=!1}static fromConfig(e,...t){switch(e.type){case"WordPiece":return new em(e);case"Unigram":return new eg(e,...t);case"BPE":return new eb(e,...t);default:throw Error(`Unknown TokenizerModel type: ${e.type}`)}}_call(e){return this.encode(e)}encode(e){throw Error("encode should be implemented in subclass.")}convert_tokens_to_ids(e){let t=e.map(e=>this.tokens_to_ids.get(e)??this.unk_token_id);return this.fuse_unk&&(t=function(e,t){let r=[],n=0;for(;n<e.length;){if(r.push(e[n]),e[n]!==t){++n;continue}for(;n<e.length&&e[n]===t;)++n}return r}(t,this.unk_token_id)),t}convert_ids_to_tokens(e){return e.map(e=>this.vocab[e]??this.unk_token)}}class em extends e_{constructor(e){for(let[t,r]of(super(e),this.tokens_to_ids=e.vocab,this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=Array(this.tokens_to_ids.size),this.tokens_to_ids))this.vocab[r]=t}encode(e){let t=[];for(let r of e){let e=[...r],n=!1,s=0,i=[];for(;s<e.length;){let t=e.length,r=null;for(;s<t;){let n=e.slice(s,t).join("");if(s>0&&(n=this.config.continuing_subword_prefix+n),this.tokens_to_ids.has(n)){r=n;break}--t}if(null===r){n=!0;break}i.push(r),s=t}n?t.push(this.unk_token):t.push(...i)}return t}}class eg extends e_{constructor(e,t){super(e),this.vocab=Array(e.vocab.size),this.scores=Array(e.vocab.size);let r=0;e.vocab.forEach((e,t)=>{this.vocab[r]=t,this.scores[r]=e,++r}),this.unk_token_id=e.unk_id,this.unk_token=this.vocab[e.unk_id],this.tokens_to_ids=new Map(this.vocab.map((e,t)=>[e,t])),this.bosToken=" ",this.bosTokenId=this.tokens_to_ids.get(this.bosToken),this.eosToken=t.eos_token,this.eosTokenId=this.tokens_to_ids.get(this.eosToken),this.unkToken=this.vocab[this.unk_token_id],this.minScore=function(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],r=0;for(let n=1;n<e.length;++n)e[n]<t&&(t=e[n],r=n);return[t,r]}(this.scores)[0],this.unkScore=this.minScore-10,this.scores[this.unk_token_id]=this.unkScore,this.trie=new tp,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes(e){let t=e.sentence,r=t.length,n=0;for(;n<r;){let r=!1,s=[];for(let i of this.trie.commonPrefixSearch(t.slice(n))){s.push(i);let t=this.tokens_to_ids.get(i),o=this.scores[t],a=i.length;e.insert(n,a,o,t),r||1!==a||(r=!0)}r||e.insert(n,1,this.unkScore,this.unk_token_id),n+=1}}tokenize(e){let t=new tm(e,this.bosTokenId,this.eosTokenId);return this.populateNodes(t),t.tokens()}encode(e){let t=[];for(let r of e){let e=this.tokenize(r);t.push(...e)}return t}}let ey=(()=>{let e=[...Array.from({length:94},(e,t)=>t+33),...Array.from({length:12},(e,t)=>t+161),...Array.from({length:82},(e,t)=>t+174)],t=e.slice(),r=0;for(let n=0;n<256;++n)e.includes(n)||(e.push(n),t.push(256+r),r+=1);let n=t.map(e=>String.fromCharCode(e));return Object.fromEntries(e.map((e,t)=>[e,n[t]]))})(),ew=Object.fromEntries(Object.entries(ey).map(([e,t])=>[t,e]));class eb extends e_{constructor(e){for(let[t,r]of(super(e),this.BPE_SPLIT_TOKEN=" ",this.tokens_to_ids=e.vocab,this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=Array(this.tokens_to_ids.size),this.tokens_to_ids))this.vocab[r]=t;this.bpe_ranks=Object.fromEntries(e.merges.map((e,t)=>[e,t])),this.merges=e.merges.map(e=>e.split(this.BPE_SPLIT_TOKEN)),this.end_of_word_suffix=e.end_of_word_suffix,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.cache=Object.create(null),this.fuse_unk??=this.config.fuse_unk}get_pairs(e){let t=new Set,r=e[0];for(let n=1;n<e.length;++n){let s=e[n];t.add(r+this.BPE_SPLIT_TOKEN+s),r=s}return Array.from(t)}bpe(e){if(e in this.cache)return this.cache[e];let t=Array.from(e);this.end_of_word_suffix&&(t[t.length-1]+=this.end_of_word_suffix);let r=this.get_pairs(t);if(!r.length)return this.end_of_word_suffix&&(e+=this.end_of_word_suffix),e;for(;;){let e=r.reduce((e,t)=>(this.bpe_ranks[e]??1/0)<=(this.bpe_ranks[t]??1/0)?e:t);if(!(e in this.bpe_ranks))break;let[n,s]=e.split(this.BPE_SPLIT_TOKEN),i=[],o=0,a=-1;for(;o<t.length;){try{if(a=t.indexOf(n,o),-1===a)throw"Error"}catch(e){i.push(...t.slice(o));break}i.push(...t.slice(o,a)),t[o=a]===n&&o<t.length-1&&t[o+1]===s?(i.push(n+s),o+=2):(i.push(t[o]),o+=1)}if(1===(t=i).length)break;r=this.get_pairs(t)}let n=t.join(this.BPE_SPLIT_TOKEN);return this.cache[e]=n,n}encode(e){let t=[];for(let r of e)for(let e of this.bpe(r).split(this.BPE_SPLIT_TOKEN))this.tokens_to_ids.has(e)?t.push(e):this.byte_fallback?t.push(...Array.from(this.text_encoder.encode(e)).map(e=>`<0x${e.toString(16).toUpperCase().padStart(2,"0")}>`)):t.push(this.unk_token);return t}}class ek extends h{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"BertNormalizer":return new eI(e);case"Precompiled":return new eJ(e);case"Sequence":return new eM(e);case"Replace":return new ev(e);case"NFC":return new ex(e);case"NFKD":return new eA(e);case"StripAccents":return new eE(e);case"Lowercase":return new ez(e);case"Prepend":return new eT(e);default:throw Error(`Unknown Normalizer type: ${e.type}`)}}normalize(e){throw Error("normalize should be implemented in subclass.")}_call(e){return this.normalize(e)}}class ev extends ek{normalize(e){let t=ed(this.config.pattern);return null===t?e:e=e.replaceAll(t,this.config.content)}}class ex extends ek{normalize(e){return e=e.normalize("NFC")}}class eA extends ek{normalize(e){return e=e.normalize("NFKD")}}class eE extends ek{normalize(e){return e=e.replace(/[\u0300-\u036f]/g,"")}}class ez extends ek{normalize(e){return e=e.toLowerCase()}}class eT extends ek{normalize(e){return e=this.config.prepend+e}}class eM extends ek{constructor(e){super(e),this.normalizers=e.normalizers.map(e=>ek.fromConfig(e))}normalize(e){return this.normalizers.reduce((e,t)=>t.normalize(e),e)}}class eI extends ek{_tokenize_chinese_chars(e){let t=[];for(let r=0;r<e.length;++r){let n=e[r],s=n.charCodeAt(0);this._is_chinese_char(s)?(t.push(" "),t.push(n),t.push(" ")):t.push(n)}return t.join("")}_is_chinese_char(e){return e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=194560&&e<=195103}stripAccents(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}normalize(e){return this.config.handle_chinese_chars&&(e=this._tokenize_chinese_chars(e)),this.config.lowercase?(e=e.toLowerCase(),!1!==this.config.strip_accents&&(e=this.stripAccents(e))):this.config.strip_accents&&(e=this.stripAccents(e)),e}}class eB extends h{static fromConfig(e){if(null===e)return null;switch(e.type){case"BertPreTokenizer":return new eS(e);case"Sequence":return new eY(e);case"WhitespaceSplit":return new eZ(e);case"Metaspace":return new eX(e);case"ByteLevel":return new eC(e);case"Split":return new eP(e);case"Punctuation":return new eU(e);case"Digits":return new eL(e);default:throw Error(`Unknown PreTokenizer type: ${e.type}`)}}pre_tokenize_text(e){throw Error("pre_tokenize_text should be implemented in subclass.")}pre_tokenize(e){return(Array.isArray(e)?e.map(e=>this.pre_tokenize_text(e)):this.pre_tokenize_text(e)).flat()}_call(e){return this.pre_tokenize(e)}}class eS extends eB{constructor(e){super(),this.pattern=RegExp(`[^\\s${ep}]+|[${ep}]`,"gu")}pre_tokenize_text(e){return e.trim().match(this.pattern)||[]}}class eC extends eB{constructor(e){super(),this.config=e,this.add_prefix_space=this.config.add_prefix_space,this.trim_offsets=this.config.trim_offsets,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=ey,this.text_encoder=new TextEncoder}pre_tokenize_text(e){return(this.use_regex?e.match(this.pattern)||[]:[e]).map(e=>(this.add_prefix_space&&!e.startsWith(" ")&&(e=" "+e),e=Array.from(this.text_encoder.encode(e),e=>this.byte_encoder[e]).join("")))}}class eP extends eB{constructor(e){super(),this.config=e,this.pattern=ed(this.config.pattern,this.config.invert)}pre_tokenize_text(e){return null===this.pattern?[]:this.config.invert?e.match(this.pattern)||[]:e.split(this.pattern).filter(e=>e)}}class eU extends eB{constructor(e){super(),this.config=e,this.pattern=RegExp(`[^${ep}]+|[${ep}]+`,"gu")}pre_tokenize_text(e){return e.match(this.pattern)||[]}}class eL extends eB{constructor(e){super(),this.config=e;let t=`[^\\d]+|\\d${this.config.individual_digits?"":"+"}`;this.pattern=RegExp(t,"gu")}pre_tokenize_text(e){return e.match(this.pattern)||[]}}class eO extends h{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"TemplateProcessing":return new ej(e);case"ByteLevel":return new eN(e);case"RobertaProcessing":return new eR(e);default:throw Error(`Unknown PostProcessor type: ${e.type}`)}}post_process(e,...t){throw Error("post_process should be implemented in subclass.")}_call(e,...t){return this.post_process(e,...t)}}class eR extends eO{constructor(e){super(e),this.cls=e.cls[0],this.sep=e.sep[0]}post_process(e,t=null){return e=f([this.cls],e,[this.sep]),null!==t&&(e=f(e,[this.sep],t,[this.sep])),e}}class ej extends eO{constructor(e){super(e),this.single=e.single,this.pair=e.pair}post_process(e,t=null){let r=null===t?this.single:this.pair,n=[];for(let s of r)"SpecialToken"in s?n.push(s.SpecialToken.id):"Sequence"in s&&("A"===s.Sequence.id?n=f(n,e):"B"===s.Sequence.id&&(n=f(n,t)));return n}}class eN extends eO{post_process(e){return e}}class e$ extends h{constructor(e){super(),this.config=e,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets=e.trim_offsets}static fromConfig(e){switch(e.type){case"WordPiece":return new eW(e);case"Metaspace":return new eV(e);case"ByteLevel":return new eK(e);case"Replace":return new eF(e);case"ByteFallback":return new eG(e);case"Fuse":return new eq(e);case"Strip":return new eD(e);case"Sequence":return new eH(e);default:throw Error(`Unknown Decoder type: ${e.type}`)}}_call(e){return this.decode(e)}decode(e){return this.decode_chain(e).join("")}decode_chain(e){throw Error("`decode_chain` should be implemented in subclass.")}}class eF extends e${constructor(e){super(e)}decode_chain(e){let t=ed(this.config.pattern);return null===t?e:e.map(e=>e.replaceAll(t,this.config.content))}}class eG extends e${constructor(e){super(e),this.text_decoder=new TextDecoder}decode_chain(e){let t=[],r=[];for(let n of e){let e=null;if(6===n.length&&n.startsWith("<0x")&&n.endsWith(">")){let t=parseInt(n.slice(3,5),16);isNaN(t)||(e=t)}if(null!==e)r.push(e);else{if(r.length>0){let e=this.text_decoder.decode(Uint8Array.from(r));t.push(e),r=[]}t.push(n)}}if(r.length>0){let e=this.text_decoder.decode(Uint8Array.from(r));t.push(e),r=[]}return t}}class eq extends e${constructor(e){super(e)}decode_chain(e){return[e.join("")]}}class eD extends e${constructor(e){super(e),this.content=this.config.content,this.start=this.config.start,this.stop=this.config.stop}decode_chain(e){return e.map(e=>{let t=0;for(let r=0;r<this.start;++r){if(e[r]===this.content){t=r+1;continue}break}let r=e.length;for(let t=0;t<this.stop;++t){let n=e.length-t-1;if(e[n]===this.content){r=n;continue}break}return e.slice(t,r)})}}class eW extends e${constructor(e){super(e),this.cleanup=e.cleanup}decode_chain(e){return e.map((e,t)=>(0!==t&&(e=e.startsWith(this.config.prefix)?e.replace(this.config.prefix,""):" "+e),this.cleanup&&(e=ef(e)),e))}}class eK extends e${constructor(e){super(e),this.byte_decoder=ew,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(e){let t=e.join(""),r=new Uint8Array([...t].map(e=>this.byte_decoder[e]));return this.text_decoder.decode(r)}decode_chain(e){let t=[],r=[];for(let n of e)this.added_tokens.includes(n)?(r.length>0&&(t.push(this.convert_tokens_to_string(r)),r=[]),t.push(n)):r.push(n);return r.length>0&&t.push(this.convert_tokens_to_string(r)),t}}class eH extends e${constructor(e){super(e),this.decoders=e.decoders.map(e=>e$.fromConfig(e))}decode_chain(e){return this.decoders.reduce((e,t)=>t.decode_chain(e),e)}}class eX extends eB{constructor(e){super(),this.addPrefixSpace=e.add_prefix_space,this.replacement=e.replacement,this.strRep=e.str_rep||this.replacement}pre_tokenize(e){"string"==typeof e&&(e=e.trimStart().split(/\s+/));let t=[];for(let r of e){let e=r.replaceAll(" ",this.strRep);this.addPrefixSpace&&!e.startsWith(this.replacement)&&(e=this.strRep+e),t.push(e)}return t}}class eV extends e${constructor(e){super(e),this.addPrefixSpace=e.add_prefix_space,this.replacement=e.replacement}decode_chain(e){let t=[];for(let r=0;r<e.length;++r){let n=e[r].replaceAll(this.replacement," ");this.addPrefixSpace&&0==r&&n.startsWith(" ")&&(n=n.substring(1)),t.push(n)}return t}}class eJ extends ek{constructor(e){super(e),this.charsmap=e.precompiled_charsmap}normalize(e){return e=e.normalize("NFKC")}}class eY extends eB{constructor(e){super(),this.tokenizers=e.pretokenizers.map(e=>eB.fromConfig(e))}pre_tokenize_text(e){return"string"==typeof e&&(e=[e]),this.tokenizers.reduce((e,t)=>t.pre_tokenize(e),e)}}class eZ extends eB{constructor(e){super()}pre_tokenize_text(e){return e.match(/\S+/g)||[]}}class eQ extends h{constructor(e,t){for(let r of(super(),this.normalizer=ek.fromConfig(e.normalizer),this.pre_tokenizer=eB.fromConfig(e.pre_tokenizer),e.model.vocab&&(Array.isArray(e.model.vocab)||(e.model.vocab=Object.entries(e.model.vocab)),e.model.vocab=new Map(e.model.vocab)),this.model=e_.fromConfig(e.model,t),this.post_processor=eO.fromConfig(e.post_processor),this.decoder=e$.fromConfig(e.decoder),this.decoder.end_of_word_suffix=this.model.end_of_word_suffix,this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[],e.added_tokens)){let e=r.id,t=r.content;this.added_tokens.push(t),this.model.tokens_to_ids.set(t,e),this.model.vocab[e]=t,r.special&&(this.special_tokens.push(t),this.all_special_ids.push(e))}this.decoder.added_tokens=this.added_tokens,this.added_tokens_regex=RegExp("("+this.added_tokens.map(l).join("|")+")"),this.mask_token=this.getToken(t,"mask_token"),this.mask_token_id=this.model.tokens_to_ids.get(this.mask_token),this.pad_token=this.getToken(t,"pad_token","eos_token"),this.pad_token_id=this.model.tokens_to_ids.get(this.pad_token),this.sep_token=this.getToken(t,"sep_token"),this.sep_token_id=this.model.tokens_to_ids.get(this.sep_token),this.model_max_length=t.model_max_length,this.remove_space=t.remove_space,this.clean_up_tokenization_spaces=t.clean_up_tokenization_spaces??!0,this.padding_side="right"}getToken(e,...t){for(let r of t){let t=e[r];if(t){if("object"!=typeof t)return t;if("AddedToken"===t.__type)return t.content;throw Error(`Unknown token: ${t}`)}}return null}static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:n=null,local_files_only:s=!1,revision:i="main"}={}){let o=await eu(e,{progress_callback:t,config:r,cache_dir:n,local_files_only:s,revision:i});return new this(...o)}prepare_model_inputs(e){return e}_call(e,{text_pair:t=null,padding:r=!1,truncation:n=null,max_length:s=null,return_tensor:i=!0}={}){let o;if(Array.isArray(e)){if(0===e.length)throw Error("text array must be non-empty");if(null!==t){if(Array.isArray(t)){if(e.length!==t.length)throw Error("text and text_pair must have the same length")}else throw Error("text_pair must also be an array");o=e.map((e,r)=>this.encode(e,t[r]))}else o=e.map(e=>this.encode(e))}else{if(null===e)throw Error("text may not be null");if(Array.isArray(t))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");o=[this.encode(e,t)]}let a=Z(o.map(e=>e.length))[0];null===s&&(s=a),s=Math.min(s,this.model_max_length);let l=[];if(r||n)for(let e=0;e<o.length;++e){if(o[e].length===s){l.push(Array(o[e].length).fill(1));continue}if(o[e].length>s)n&&(o[e]=o[e].slice(0,s)),l.push(Array(o[e].length).fill(1));else if(r){let t=s-o[e].length;"right"===this.padding_side?(l.push(Array(o[e].length).fill(1).concat(Array(t).fill(0))),o[e].push(...Array(t).fill(this.pad_token_id))):(l.push(Array(t).fill(0).concat(Array(o[e].length).fill(1))),o[e].unshift(...Array(t).fill(this.pad_token_id)))}else l.push(Array(o[e].length).fill(1))}else l=o.map(e=>Array(e.length).fill(1));if(i){if(!(r&&n)&&o.some(e=>e.length!==o[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");let e=[o.length,o[0].length];o=new en("int64",BigInt64Array.from(o.flat().map(BigInt)),e),l=new en("int64",BigInt64Array.from(l.flat().map(BigInt)),e)}else Array.isArray(e)||(o=o[0],l=l[0]);let h={input_ids:o,attention_mask:l};return this.prepare_model_inputs(h)}_encode_text(e){if(null===e)return null;let t=e.split(this.added_tokens_regex).filter(e=>e);return t.map(e=>{if(this.added_tokens.includes(e))return e;{!0===this.remove_space&&(e=e.trim().split(/\s+/).join(" ")),null!==this.normalizer&&(e=this.normalizer(e));let t=null!==this.pre_tokenizer?this.pre_tokenizer(e):[e];return this.model(t)}}).flat()}encode(e,t=null){let r=this._encode_text(e),n=this._encode_text(t),s=null!==this.post_processor?this.post_processor(r,n):f(r??[],n??[]);return this.model.convert_tokens_to_ids(s)}batch_decode(e,t={}){return e.map(e=>this.decode(e,t))}decode(e,t={}){if(!Array.isArray(e)||0===e.length||!u(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,t)}decode_single(e,{skip_special_tokens:t=!1,clean_up_tokenization_spaces:r=null}){let n=this.model.convert_ids_to_tokens(e);t&&(n=n.filter(e=>!this.special_tokens.includes(e)));let s=this.decoder(n);return this.decoder.end_of_word_suffix&&(s=s.replaceAll(this.decoder.end_of_word_suffix," "),t&&(s=s.trim())),(r??this.clean_up_tokenization_spaces)&&(s=ef(s)),s}}function e0(e){if(e.input_ids instanceof en)e.token_type_ids=new en("int64",new BigInt64Array(e.input_ids.data.length),e.input_ids.dims);else if(Array.isArray(e.input_ids))Array.isArray(e.input_ids[0])?e.token_type_ids=e.input_ids.map(e=>Array(e.length).fill(0)):e.token_type_ids=Array(e.input_ids.length).fill(0);else throw Error("Input ids must be a Tensor or an Array");return e}class e1 extends eQ{prepare_model_inputs(e){return e0(e)}}class e2 extends eQ{prepare_model_inputs(e){return e0(e)}}class e3 extends eQ{prepare_model_inputs(e){return e0(e)}}class e6 extends eQ{prepare_model_inputs(e){return e0(e)}}class e4 extends eQ{}class e5 extends eQ{}class e8 extends eQ{}class e7 extends eQ{}class e9 extends eQ{}class te extends eQ{}class tt extends eQ{}class tr extends eQ{}class tn extends eQ{}class ts extends eQ{prepare_model_inputs(e){return e0(e)}}class ti extends eQ{}class to extends eQ{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.special_tokens.filter(e=>this.languageRegex.test(e))}_build_translation_inputs(e,t,r){if(!this.language_codes.includes(r.tgt_lang))throw Error(`Target language code "${r.tgt_lang}" is not valid. Must be one of: {${this.language_codes.join(", ")}}`);if(void 0!==r.src_lang){if(!this.language_codes.includes(r.src_lang))throw Error(`Source language code "${r.src_lang}" is not valid. Must be one of: {${this.language_codes.join(", ")}}`);for(let e of this.post_processor.config.single)if("SpecialToken"in e&&this.languageRegex.test(e.SpecialToken.id)){e.SpecialToken.id=r.src_lang;break}}return r.forced_bos_token_id=this.model.convert_tokens_to_ids([r.tgt_lang])[0],this._call(e,t)}}let ta=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],tl=new Map(ta),th=new Map([...ta.map(([e,t])=>[t,e]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);class tc extends eQ{_decode_asr(e,{return_timestamps:t=!1,return_language:r=!1,time_precision:n=null,force_full_sequences:s=!0}={}){if(null===n)throw Error("Must specify time_precision");let i=null,o="word"===t;function a(){return{language:i,timestamp:[null,null],text:""}}let l=[],h=a(),c=0,u=this.model.convert_tokens_to_ids(["<|notimestamps|>"])[0]+1,d=[],f=[],p=!1,_=null,m=new Set(this.all_special_ids);for(let r of e){let e=r.tokens,s=o?r.token_timestamps:null,g=null,y=u;if("stride"in r){let[t,s,i]=r.stride;if(c-=s,_=t-i,s&&(y=s/n+u),i)for(let t=e.length-1;t>=0;--t){let r=e[t];if(r>=u){if(null!==g&&(r-u)*n<_)break;g=r}}}let w=[],b=[];for(let r=0;r<e.length;++r){let _=e[r];if(m.has(_)){let e=this.decode([_]);if("["===e[0]&&"]"===e[e.length-1]){let r=tl.get(e.slice(1,-1));if(void 0!==r){if(null!==i&&r!==i&&!t){d.push(w);let e=this.findLongestCommonSequence(d)[0],t=this.decode(e);h.text=t,l.push(h),d=[],w=[],h=a()}i=h.language=r}}}else if(_>=u){let e=(_-u)*n+c,t=et(e,2);if(null!==g&&_>=g)p=!0;else if(p||d.length>0&&_<y)p=!1;else if(null===h.timestamp[0])h.timestamp[0]=t;else if(t===h.timestamp[0]);else{h.timestamp[1]=t,d.push(w),o&&f.push(b);let[e,r]=this.findLongestCommonSequence(d,f),n=this.decode(e);h.text=n,o&&(h.words=this.collateWordTimestamps(e,r,i)),l.push(h),d=[],w=[],f=[],b=[],h=a()}}else if(w.push(_),o){let e,t=et(s[r]+c,2);e=r+1<s.length?et(s[r+1]+c,2):null,b.push([t,e])}}if("stride"in r){let[e,t,n]=r.stride;c+=e-n}w.length>0?(d.push(w),o&&f.push(b)):d.every(e=>0===e.length)&&(h=a(),d=[],w=[],f=[],b=[])}if(d.length>0){if(s&&t)throw Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");let[e,r]=this.findLongestCommonSequence(d,f),n=this.decode(e);h.text=n,o&&(h.words=this.collateWordTimestamps(e,r,i)),l.push(h)}let g=Object.create(null),y=l.map(e=>e.text).join("");if(t||r){for(let e=0;e<l.length;++e){let n=l[e];t||delete n.timestamp,r||delete n.language}if(o){let e=[];for(let t of l)for(let r of t.words)e.push(r);g={chunks:e}}else g={chunks:l}}return[y,g]}findLongestCommonSequence(e,t=null){let r=e[0],n=r.length,s=[],i=Array.isArray(t)&&t.length>0,o=i?[]:null,a=i?t[0]:null;for(let l=1;l<e.length;++l){let h=e[l],c=0,u=[n,n,0,0],d=h.length;for(let e=1;e<n+d;++e){let t=e/1e4,s=Math.max(0,n-e),i=Math.min(n,n+d-e),o=r.slice(s,i),a=Math.max(0,e-n),l=Math.min(d,e),f=h.slice(a,l);if(o.length!==f.length)throw Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let p=o.filter((e,t)=>e===f[t]).length,_=p/e+t;p>1&&_>c&&(c=_,u=[s,i,a,l])}let[f,p,_,m]=u,g=Math.floor((p+f)/2),y=Math.floor((m+_)/2);s.push(...r.slice(0,g)),n=(r=h.slice(y)).length,i&&(o.push(...a.slice(0,g)),a=t[l].slice(y))}return(s.push(...r),i)?(o.push(...a),[s,o]):[s,[]]}collateWordTimestamps(e,t,r){let[n,s,i]=this.combineTokensIntoWords(e,r),o=[];for(let e=0;e<n.length;++e){let r=i[e];o.push({text:n[e],timestamp:[t[r.at(0)][0],t[r.at(-1)][1]]})}return o}combineTokensIntoWords(e,t,r="\"'“\xa1\xbf([{-",n="\"'.。,,!!??::”)]}、"){let s,i,o;return["chinese","japanese","thai","lao","myanmar"].includes(t=t??"english")?[s,i,o]=this.splitTokensOnUnicode(e):[s,i,o]=this.splitTokensOnSpaces(e),this.mergePunctuations(s,i,o,r,n)}decode(e,t){return t&&t.decode_with_timestamps?this.decodeWithTimestamps(e,t):super.decode(e,t)}decodeWithTimestamps(e,t){let r=t?.time_precision??.02,n=Array.from(this.all_special_ids).at(-1)+1,s=[[]];for(let t of e)if(t>=n){let e=(t-n)*r;e=et(e,2),s.push(`<|${e}|>`),s.push([])}else s[s.length-1].push(t);return(s=s.map(e=>"string"==typeof e?e:super.decode(e,t))).join("")}splitTokensOnUnicode(e){let t=this.decode(e,{decode_with_timestamps:!0}),r=[],n=[],s=[],i=[],o=[],a=0;for(let l=0;l<e.length;++l){let h=e[l];i.push(h),o.push(l);let c=this.decode(i,{decode_with_timestamps:!0});c.includes("�")&&"�"!==t[a+c.indexOf("�")]||(r.push(c),n.push(i),s.push(o),i=[],o=[],a+=c.length)}return[r,n,s]}splitTokensOnSpaces(e){let[t,r,n]=this.splitTokensOnUnicode(e),s=[],i=[],o=[],a=RegExp(`[${ep}]`);for(let e=0;e<t.length;++e){let l=t[e],h=r[e],c=n[e],u=h[0]>=this.model.tokens_to_ids.get("<|endoftext|>"),d=l.startsWith(" "),f=l.trim(),p=a.test(f);if(u||d||p||0===s.length)s.push(l),i.push(h),o.push(c);else{let e=s.length-1;s[e]+=l,i[e].push(...h),o[e].push(...c)}}return[s,i,o]}mergePunctuations(e,t,r,n,s){let i=structuredClone(e),o=structuredClone(t),a=structuredClone(r),l=i.length-2,h=i.length-1;for(;l>=0;)i[l].startsWith(" ")&&n.includes(i[l].trim())?(i[h]=i[l]+i[h],o[h]=f(o[l],o[h]),a[h]=f(a[l],a[h]),i[l]="",o[l]=[],a[l]=[]):h=l,--l;for(l=0,h=1;h<i.length;)!i[l].endsWith(" ")&&s.includes(i[h])?(i[l]+=i[h],o[l]=f(o[l],o[h]),a[l]=f(a[l],a[h]),i[h]="",o[h]=[],a[h]=[]):l=h,++h;return[i.filter(e=>e),o.filter(e=>e.length>0),a.filter(e=>e.length>0)]}get_decoder_prompt_ids({language:e=null,task:t=null,no_timestamps:r=!0}={}){let n=[];if(e){e=e.toLowerCase();let t=th.get(e);if(void 0===t){if(tl.has(e))t=e;else{let t=2===e.length,r=t?tl.keys():tl.values();throw Error(`Language "${e}" is not supported. Must be one of: ${JSON.stringify(r)}`)}}let r=this.model.tokens_to_ids.get(`<|${t}|>`);if(void 0===r)throw Error(`Unable to find language "${t}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`);n.push(r)}else n.push(null);if(t){if("transcribe"!==(t=t.toLowerCase())&&"translate"!==t)throw Error(`Task "${t}" is not supported. Must be one of: ["transcribe", "translate"]`);let e=this.model.tokens_to_ids.get(`<|${t}|>`);if(void 0===e)throw Error(`Unable to find task "${t}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`);n.push(e)}else n.push(null);if(r){let e=this.model.tokens_to_ids.get("<|notimestamps|>");if(void 0===e)throw Error('Unable to find "<|notimestamps|>" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.');n.push(e)}return n.map((e,t)=>[t+1,e]).filter(e=>null!==e[1])}}class tu extends eQ{}class td extends eQ{}class tf extends eQ{constructor(e,t){super(e,t),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=this.model.vocab.filter(e=>this.languageRegex.test(e)),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(null===e)return null;let[t,...r]=e.trim().split(this.languageRegex);if(0===r.length)return super._encode_text(t);if(2===r.length){let[e,t]=r;return this.supported_language_codes.includes(e)||console.warn(`Unsupported language code "${e}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),f([e],super._encode_text(t))}}}class tp{constructor(){this.root=t_.default()}extend(e){for(let t of e)this.push(t)}push(e){let t=this.root;for(let r of e){let e=t.children.get(r);void 0===e&&(e=t_.default(),t.children.set(r,e)),t=e}t.isLeaf=!0}*commonPrefixSearch(e){let t=this.root,r="";for(let n=0;n<e.length&&void 0!==t;++n){let s=e[n];r+=s,void 0!==(t=t.children.get(s))&&t.isLeaf&&(yield r)}}}class t_{constructor(e,t){this.isLeaf=e,this.children=t}static default(){return new t_(!1,new Map)}}class tm{constructor(e,t,r){this.sentence=e,this.len=e.length,this.bosTokenId=t,this.eosTokenId=r,this.nodes=[],this.beginNodes=Array(this.len+1),this.endNodes=Array(this.len+1);for(let e=0;e<this.len+1;++e)this.beginNodes[e]=[],this.endNodes[e]=[];let n=new tg(this.bosTokenId,0,0,0,0),s=new tg(this.eosTokenId,1,this.len,0,0);this.nodes.push(n.clone()),this.nodes.push(s.clone()),this.beginNodes[this.len].push(s),this.endNodes[0].push(n)}insert(e,t,r,n){let s=this.nodes.length,i=new tg(n,s,e,t,r);this.beginNodes[e].push(i),this.endNodes[e+t].push(i),this.nodes.push(i)}viterbi(){let e=this.len,t=0;for(;t<=e;){if(0==this.beginNodes[t].length)return[];for(let e of this.beginNodes[t]){e.prev=null;let r=0,n=null;for(let s of this.endNodes[t]){let t=s.backtraceScore+e.score;(null===n||t>r)&&(n=s.clone(),r=t)}if(null===n)return[];e.prev=n,e.backtraceScore=r}++t}let r=[],n=this.beginNodes[e][0],s=n.prev;if(null===s)return[];let i=s.clone();for(;null!==i.prev;){r.push(i.clone());let e=i.clone();i=e.prev.clone()}return r.reverse(),r}piece(e){return this.sentence.slice(e.pos,e.pos+e.length)}tokens(){let e=this.viterbi();return e.map(e=>this.piece(e))}tokenIds(){let e=this.viterbi();return e.map(e=>e.tokenId)}}class tg{constructor(e,t,r,n,s){this.tokenId=e,this.nodeId=t,this.pos=r,this.length=n,this.score=s,this.prev=null,this.backtraceScore=0}clone(){let e=new tg(this.tokenId,this.nodeId,this.pos,this.length,this.score);return e.prev=this.prev,e.backtraceScore=this.backtraceScore,e}}class ty{static TOKENIZER_CLASS_MAPPING={T5Tokenizer:e5,DistilBertTokenizer:e4,BertTokenizer:e1,MobileBertTokenizer:e3,SqueezeBertTokenizer:e6,AlbertTokenizer:e2,GPT2Tokenizer:e8,BartTokenizer:e7,RobertaTokenizer:e9,WhisperTokenizer:tc,CodeGenTokenizer:tu,CLIPTokenizer:td,MarianTokenizer:tf,BloomTokenizer:te,NllbTokenizer:to,LlamaTokenizer:tt,XLMRobertaTokenizer:tr,MPNetTokenizer:tn,FalconTokenizer:ts,GPTNeoXTokenizer:ti,PreTrainedTokenizer:eQ};static async from_pretrained(e,{quantized:t=!0,progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:i=!1,revision:o="main"}={}){let[a,l]=await eu(e,{quantized:t,progress_callback:r,config:n,cache_dir:s,local_files_only:i,revision:o}),h=l.tokenizer_class.replace(/Fast$/,""),c=this.TOKENIZER_CLASS_MAPPING[h];return c||(console.warn(`Unknown tokenizer class "${h}", attempting to construct from base class.`),c=eQ),new c(a,l)}}async function tw(e,t){return await H(e,"config.json",!0,t)}class tb{constructor(e){this.model_type=null,this.is_encoder_decoder=!1,Object.assign(this,e)}static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:n=null,local_files_only:s=!1,revision:i="main"}={}){let o=r??await tw(e,{progress_callback:t,config:r,cache_dir:n,local_files_only:s,revision:i});return new this(o)}}class tk{static async from_pretrained(...e){return tb.from_pretrained(...e)}}class tv extends h{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,t){for(let r of t)this.processors.forEach(t=>t(e,r))}[Symbol.iterator](){return this.processors.values()}}class tx extends h{_call(e,t){throw Error("`_call` should be implemented in a subclass")}}class tA extends tx{constructor(e){super(),this.force_token_map=Object.fromEntries(e??[])}_call(e,t){let r=this.force_token_map[e.length];return null!=r&&(t.data.fill(-1/0),t.data[r]=0),t}}class tE extends tx{constructor(e){super(),this.bos_token_id=e}_call(e,t){return 1===e.length&&(t.data.fill(-1/0),t.data[this.bos_token_id]=0),t}}class tz extends tx{constructor(e,t){super(),this.max_length=e,this.forced_eos_token_id=t}_call(e,t){}}class tT extends tx{constructor(e,t){super(),this.begin_suppress_tokens=e,this.begin_index=t}_call(e,t){if(e.length===this.begin_index)for(let e of this.begin_suppress_tokens)t.data[e]=-1/0;return t}}class tM extends tx{constructor(e){super(),this.eos_token_id=e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=(e.forced_decoder_ids||[]).length+2,e.forced_decoder_ids.slice(-1)[0][1]===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,t){if(t.data[this.no_timestamps_token_id]=-1/0,e.length===this.begin_index-1)return t.data.fill(-1/0),t.data[this.timestamp_begin]=0,t;let r=e.slice(this.begin_index),n=r.length>=1&&r[r.length-1]>=this.timestamp_begin,s=r.length<2||r[r.length-2]>=this.timestamp_begin;if(n&&(s?t.data.subarray(this.timestamp_begin).fill(-1/0):t.data.subarray(0,this.eos_token_id).fill(-1/0)),e.length===this.begin_index&&null!==this.max_initial_timestamp_index){let e=this.timestamp_begin+this.max_initial_timestamp_index;t.data.subarray(e+1).fill(-1/0)}let i=function(e){let t=J(e),r=t.map(e=>Math.log(e));return r}(t.data),o=Math.log(i.subarray(this.timestamp_begin).map(Math.exp).reduce((e,t)=>e+t)),a=Z(i.subarray(0,this.timestamp_begin))[0];return o>a&&t.data.subarray(0,this.timestamp_begin).fill(-1/0),t}}class tI extends tx{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){let t=e.length,r=[];for(let n=0;n<t+1-this.no_repeat_ngram_size;++n){let t=[];for(let r=0;r<this.no_repeat_ngram_size;++r)t.push(e[n+r]);r.push(t)}let n=new Map;for(let e of r){let t=e.slice(0,e.length-1),r=JSON.stringify(t),s=n.get(r)??[];s.push(e[e.length-1]),n.set(r,s)}return n}getGeneratedNgrams(e,t){let r=t.slice(t.length+1-this.no_repeat_ngram_size,t.length),n=e.get(JSON.stringify(r))??[];return n}calcBannedNgramTokens(e){if(e.length+1<this.no_repeat_ngram_size)return[];{let t=this.getNgrams(e),r=this.getGeneratedNgrams(t,e);return r}}_call(e,t){let r=this.calcBannedNgramTokens(e);for(let e of r)t.data[e]=-1/0;return t}}class tB extends tx{constructor(e){super(),this.penalty=e}_call(e,t){for(let r of e)t.data[r]<0?t.data[r]*=this.penalty:t.data[r]/=this.penalty;return t}}class tS{constructor(e={}){this.max_length=e.max_length??20,this.max_new_tokens=e.max_new_tokens??null,this.min_length=e.min_length??0,this.min_new_tokens=e.min_new_tokens??null,this.early_stopping=e.early_stopping??!1,this.max_time=e.max_time??null,this.do_sample=e.do_sample??!1,this.num_beams=e.num_beams??1,this.num_beam_groups=e.num_beam_groups??1,this.penalty_alpha=e.penalty_alpha??null,this.use_cache=e.use_cache??!0,this.temperature=e.temperature??1,this.top_k=e.top_k??50,this.top_p=e.top_p??1,this.typical_p=e.typical_p??1,this.epsilon_cutoff=e.epsilon_cutoff??0,this.eta_cutoff=e.eta_cutoff??0,this.diversity_penalty=e.diversity_penalty??0,this.repetition_penalty=e.repetition_penalty??1,this.encoder_repetition_penalty=e.encoder_repetition_penalty??1,this.length_penalty=e.length_penalty??1,this.no_repeat_ngram_size=e.no_repeat_ngram_size??0,this.bad_words_ids=e.bad_words_ids??null,this.force_words_ids=e.force_words_ids??null,this.renormalize_logits=e.renormalize_logits??!1,this.constraints=e.constraints??null,this.forced_bos_token_id=e.forced_bos_token_id??null,this.forced_eos_token_id=e.forced_eos_token_id??null,this.remove_invalid_values=e.remove_invalid_values??!1,this.exponential_decay_length_penalty=e.exponential_decay_length_penalty??null,this.suppress_tokens=e.suppress_tokens??null,this.begin_suppress_tokens=e.begin_suppress_tokens??null,this.forced_decoder_ids=e.forced_decoder_ids??null,this.num_return_sequences=e.num_return_sequences??1,this.output_attentions=e.output_attentions??!1,this.output_hidden_states=e.output_hidden_states??!1,this.output_scores=e.output_scores??!1,this.return_dict_in_generate=e.return_dict_in_generate??!1,this.pad_token_id=e.pad_token_id??null,this.bos_token_id=e.bos_token_id??null,this.eos_token_id=e.eos_token_id??null,this.encoder_no_repeat_ngram_size=e.encoder_no_repeat_ngram_size??0,this.decoder_start_token_id=e.decoder_start_token_id??null,this.generation_kwargs=e.generation_kwargs??{}}}class tC extends h{constructor(e){super(),this.generation_config=e}_call(e,t=-1){return this.sample(e,t)}sample(e,t){throw Error("sample should be implemented in subclasses.")}getLogits(e,t){let r=e.dims.at(-1),n=e.data;if(-1===t)n=n.slice(-r);else{let e=t*r;n=n.slice(e,e+r)}return this.generation_config.temperature>0&&(n=n.map(e=>e/this.generation_config.temperature)),n}randomSelect(e){let t=Math.random()*e.reduce((e,t)=>e+t,0);for(let r=0;r<e.length;++r)if((t-=e[r])<=0)return r;return 0}static getSampler(e){if(e.do_sample)return new tU(e);if(e.num_beams>1)return new tL(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new tP(e)}}class tP extends tC{sample(e,t=-1){return[[Z(this.getLogits(e,t))[1],0]]}}class tU extends tC{sample(e,t=-1){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));let n=this.getLogits(e,t),s=Y(n,r),i=J(s.map(e=>e[1]));return Array.from({length:this.generation_config.num_beams},()=>{let e=this.randomSelect(i);return[s[e][0],Math.log(i[e])]})}}class tL extends tC{sample(e,t=-1){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));let n=this.getLogits(e,t),s=Y(n,r),i=J(s.map(e=>e[1]));return Array.from({length:this.generation_config.num_beams},(e,t)=>[s[t][0],Math.log(i[t])])}}let{InferenceSession:tO,Tensor:tR}=n;class tj{}class tN extends tj{}class t$ extends tj{}class tF extends t${}class tG extends tj{}let tq=new Map,tD=new Map;async function tW(e,t){return tq.get(e.constructor.name)===tG?await t1(e,t):await t0(e,t)}async function tK(e,t,r){let n=`onnx/${t}${r.quantized?"_quantized":""}.onnx`,s=await K(e,n,!0,r);try{return await tO.create(s,{executionProviders:E})}catch(e){if(1===E.length&&"wasm"===E[0])throw e;return console.warn(e),console.warn("Something went wrong during model construction (most likely a missing operation). Using `wasm` as a fallback. "),await tO.create(s,{executionProviders:["wasm"]})}}async function tH(e,t){let r={},n=[];for(let s of e.inputNames)void 0===t[s]?n.push(s):r[s]=t[s];if(n.length>0)throw Error(`An error occurred during model execution: "Missing the following inputs: ${n.join(", ")}.`);let s=Object.keys(t).length,i=e.inputNames.length;return s>i&&console.warn(`WARNING: Too many inputs were provided (${s} > ${i}). The following inputs will be ignored: "${Object.keys(t).filter(t=>!e.inputNames.includes(t)).join(", ")}".`),r}async function tX(e,t){let r=await tH(e,t);try{let t=await e.run(r);return t=function e(t){for(let r in t)t[r]instanceof tR?t[r]=new en(t[r]):"object"==typeof t[r]&&e(t[r]);return t}(t)}catch(e){throw console.error(`An error occurred during model execution: "${e}".`),console.error("Inputs given to model:",r),e}}function tV(e,t){let r=e.config.pad_token_id??null,n=e.config.eos_token_id??null;u(n)&&(n=[n]);let s=-1!==t.indexOf(r),i=null===n||!n.includes(r);if(!s||!i)return new en("int64",new BigInt64Array(t.data.length).fill(1n),t.dims);{let e=BigInt64Array.from(t.data.map(e=>e!=r));return new en("int64",e,t.dims)}}function tJ(e){return new en("bool",[e],[1])}async function tY(e,t,{add_decoder_pkv:r=!0}={}){let{encoder_outputs:n,past_key_values:s}=t;n||(n=(await t0(e,t)).last_hidden_state);let i={input_ids:t.decoder_input_ids,encoder_hidden_states:n,use_cache_branch:tJ(!!s)};e.decoder_merged_session.inputNames.includes("encoder_attention_mask")&&(i.encoder_attention_mask=t.attention_mask),e.addPastKeyValues(i,s,r);let o=await tX(e.decoder_merged_session,i),a=o.logits;s=e.getPastKeyValues(o,s);let l=e.getAttentions(o);return new r$({logits:a,past_key_values:s,encoder_outputs:n,...l})}function tZ(e,t,r,n=!0){let s=[],i=0,o=e.config.decoder_start_token_id;for(let r of(Array.isArray(o)||(o=[o]),t)){r.dims=[1,...r.dims];let t={inputs:r,encoder_outputs:null,prev_model_outputs:null,output_token_ids:o,done:!1,score:0,id:i++};n&&(t.attention_mask=tV(e,r)),s.push(t)}return s}async function tQ(e,t,{input_name:r="input_ids"}={}){let n={[r]:t.inputs,decoder_input_ids:function(e){if(e instanceof en)return e;if(0===e.length)throw Error("items must be non-empty");if(!Array.isArray(e[0]))return new en("int64",BigInt64Array.from(e.map(e=>BigInt(e))),[1,e.length]);if(e.some(t=>t.length!==e[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new en("int64",BigInt64Array.from(e.flat().map(e=>BigInt(e))),[e.length,e[0].length])}(t.output_token_ids.slice(-1)),encoder_outputs:t.encoder_outputs,past_key_values:t.prev_model_outputs?.past_key_values};t.attention_mask&&(n.attention_mask=t.attention_mask);let s=await e.forward(n);return t.prev_model_outputs=s,t.encoder_outputs=s.encoder_outputs,s}async function t0(e,t){let r={};for(let n of e.session.inputNames)r[n]=t[n];return await tX(e.session,r)}async function t1(e,t){let{input_ids:r,past_key_values:n,attention_mask:s}=t,i={input_ids:r,attention_mask:s??tV(e,r),use_cache_branch:tJ(null!==n)};e.addPastKeyValues(i,n);let o=await tX(e.session,i);return{logits:o.logits,past_key_values:n=e.getPastKeyValues(o,n)}}function t2(e,t,r,n){let s=[],i=0;for(let o of t){let t,a=o.tolist().map(Number);o.dims=[1,...o.dims],n?(t=n[i]).dims=[1,...t.dims]:t=tV(e,o);let l={input:o,model_input_ids:o,attention_mask:t,prev_model_outputs:null,output_token_ids:a,num_output_tokens:r,done:!1,score:0,id:i++};s.push(l)}return s}async function t3(e,t){let r=new BigInt64Array(t.output_token_ids.length).fill(1n),n={input_ids:t.model_input_ids,attention_mask:new en("int64",r,[1,r.length]),past_key_values:t.prev_model_outputs?.past_key_values},s=await e.forward(n);return t.prev_model_outputs=s,s}function t6(e,t){e.output_token_ids=[...e.output_token_ids,t],e.model_input_ids=new en("int64",[BigInt(t)],[1,1])}class t4 extends h{constructor(e,t){super(),this.config=e,this.session=t}async dispose(){let e=[];for(let t of Object.keys(this)){let r=this[t];r instanceof tO&&e.push(r.handler.dispose())}return await Promise.all(e)}static async from_pretrained(e,{quantized:t=!0,progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:i=!1,revision:o="main"}={}){let a,l={quantized:t,progress_callback:r,config:n,cache_dir:s,local_files_only:i,revision:o},h=tq.get(this.name);if(h===tG)a=await Promise.all([tk.from_pretrained(e,l),tK(e,"decoder_model_merged",l)]);else if(h===tF)a=await Promise.all([tk.from_pretrained(e,l),tK(e,"encoder_model",l),tK(e,"decoder_model_merged",l),H(e,"generation_config.json",!1,l)]);else if(h===t$)a=await Promise.all([tk.from_pretrained(e,l),tK(e,"encoder_model",l),tK(e,"decoder_model_merged",l)]);else if(h===tN)a=await Promise.all([tk.from_pretrained(e,l),tK(e,"model",l)]);else throw console.warn("Malformed class definition.",this),Error(`Unable to load model: ${e}. Please report this bug at https://github.com/xenova/transformers.js/issues/new/choose.`);return new this(...a)}async _call(e){return await this.forward(e)}async forward(e){return await tW(this,e)}_get_logits_processor(e,t,r=null){let n=new tv;if(null!==e.repetition_penalty&&1!==e.repetition_penalty&&n.push(new tB(e.repetition_penalty)),null!==e.no_repeat_ngram_size&&e.no_repeat_ngram_size>0&&n.push(new tI(e.no_repeat_ngram_size)),null!==e.forced_bos_token_id&&n.push(new tE(e.forced_bos_token_id)),null!==e.forced_eos_token_id&&n.push(new tz(e.max_length,e.forced_eos_token_id)),null!==e.begin_suppress_tokens){let r=t>1||null===e.forced_bos_token_id?t:t+1;null!==e.forced_decoder_ids&&(r+=e.forced_decoder_ids[e.forced_decoder_ids.length-1][0]),n.push(new tT(e.begin_suppress_tokens,r))}return null!==e.forced_decoder_ids&&n.push(new tA(e.forced_decoder_ids)),null!==r&&n.extend(r),n}_get_generation_config(e){let t=new tS;return"generation_config"in this&&Object.assign(t,this.generation_config),null!==e&&Object.assign(t,e),t}async generate(e,t=null,r=null,{inputs_attention_mask:n=null}={}){let s;if(!(e instanceof en)&&e?.prototype?.__proto__?.constructor?.name!=="TypedArray"&&!Array.isArray(e))throw Error(`\`inputs\` must be a Tensor, TypedArray, or Array, but is "${e.constructor.name}".`);if(this.config.is_encoder_decoder)s=0;else if(0===(s=e instanceof en?e.dims[0]:e.length))throw Error("Must supply a non-empty array of input token ids.");t=this._get_generation_config(t),r=r??new tv,r=this._get_logits_processor(t,s,r);let i=1,o=i+(t.max_new_tokens??1/0),a=Number.isInteger(t.max_length)&&(t.max_new_tokens??null)===null,l=tC.getSampler(t),h=this.getStartBeams(e,i,n);for(;h.some(e=>!e.done)&&i<o;){let e=[];for(let n of h){if(n.done){e.push(n);continue}if(a&&n.output_token_ids.length>=t.max_length){n.done=!0,e.push(n);continue}let s=await this.runBeam(n);t.output_attentions&&this.addAttentionsToBeam(n,s),t.output_scores;let i=s.logits.slice(null,-1,null);for(let[t,s]of(r(n.output_token_ids,i),l(i))){let r={...n};this.updateBeam(r,t),r.score+=s,t===this.config.eos_token_id&&(r.done=!0),e.push(r)}}++i,h=(e=this.groupBeams(e).map(e=>e.sort((e,t)=>t.score-e.score).slice(0,t.num_beams))).flat(),t.callback_function&&t.callback_function(h)}let c=this.groupBeams(h),u=e=>c.map(r=>t.num_return_sequences>1?r.slice(0,t.num_return_sequences).map(t=>t[e]):[r[0][e]]).flat(),d=u("output_token_ids");if(!t.return_dict_in_generate)return d;{let e=u("decoder_attentions"),t=u("cross_attentions");return{sequences:d,decoder_attentions:e,cross_attentions:t}}}addAttentionsToBeam(e,t){if(this.config.is_encoder_decoder){if(!t.cross_attentions||0===t.cross_attentions.length)throw Error("`output_attentions` is true, but the model did not produce cross-attentions. This is most likely because the model was not exported with `output_attentions=True`.");e.cross_attentions||(e.cross_attentions=[]),e.cross_attentions.push(t.cross_attentions)}if(!t.decoder_attentions||0===t.decoder_attentions.length)throw Error("`output_attentions` is true, but the model did not produce decoder-attentions. This is most likely because the model was not exported with `output_attentions=True`.");e.decoder_attentions||(e.decoder_attentions=[]),e.decoder_attentions.push(t.decoder_attentions)}groupBeams(e){let t=Object.create(null);for(let r of e)void 0===t[r.id]?t[r.id]=[r]:t[r.id].push(r);return Object.values(t)}getPastKeyValues(e,t){let r=Object.create(null);for(let n in e)if(n.startsWith("present")){let s=n.replace("present","past_key_values");t&&n.includes("encoder")?r[s]=t[s]:r[s]=e[n]}return r}getAttentions(e){let t=Object.create(null);for(let r of["cross_attentions","decoder_attentions"]){let n=[];for(let t in e)if(t.startsWith(r)){let r=t.split(".").pop();n[r]=e[t]}t[r]=n}return t}addPastKeyValues(e,t,r=!1){if(t)Object.assign(e,t);else if(r){let t=[1,this.num_encoder_heads,0,this.encoder_dim_kv];for(let r=0;r<this.num_encoder_layers;++r)e[`past_key_values.${r}.encoder.key`]=new en("float32",[],t),e[`past_key_values.${r}.encoder.value`]=new en("float32",[],t);let r=[1,this.num_decoder_heads,0,this.decoder_dim_kv];for(let t=0;t<this.num_decoder_layers;++t)e[`past_key_values.${t}.decoder.key`]=new en("float32",[],r),e[`past_key_values.${t}.decoder.value`]=new en("float32",[],r)}else{let t=[1,this.num_heads,0,this.dim_kv];for(let r=0;r<this.num_layers;++r)e[`past_key_values.${r}.key`]=new en("float32",[],t),e[`past_key_values.${r}.value`]=new en("float32",[],t)}}}class t5{}class t8 extends t4{}class t7 extends t4{}class t9 extends t4{}class re extends t4{}class rt extends t4{}class rr extends t4{}class rn extends t4{}class rs extends t4{}class ri extends t4{}class ro extends t4{}class ra extends t4{}class rl extends t4{}class rh extends t4{constructor(e,t){super(e,t),this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.n_head,this.num_layers=this.config.n_layer,this.dim_kv=this.config.n_embd/this.num_heads}}class rc extends t4{constructor(e,t){super(e,t),this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_heads,this.num_layers=this.config.num_layers,this.dim_kv=this.config.hidden_size/this.num_heads}}class ru extends t4{constructor(e,t){super(e,t),this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.n_head,this.num_layers=this.config.n_layer,this.dim_kv=this.config.n_embd/this.num_heads}}class rd extends t4{}class rf extends t4{}class rp extends t4{}class r_ extends t5{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class rm extends t5{constructor({logits:e,pred_boxes:t,pred_masks:r}){super(),this.logits=e,this.pred_boxes=t,this.pred_masks=r}}class rg extends t4{}class ry extends rg{async _call(e){return new rw(await super._call(e))}}class rw extends t5{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}}class rb extends t4{}class rk extends t4{}class rv{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{quantized:t=!0,progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:i=!1,revision:o="main"}={}){let a,l={quantized:t,progress_callback:r,config:n,cache_dir:s,local_files_only:i,revision:o};if(n=await tk.from_pretrained(e,l),!this.MODEL_CLASS_MAPPINGS)throw Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);for(let t of this.MODEL_CLASS_MAPPINGS)if(a=t.get(n.model_type))return await a.from_pretrained(e,l);if(this.BASE_IF_FAIL)return console.warn(`Unknown model class "${n.model_type}", attempting to construct from base class.`),await t4.from_pretrained(e,l);throw Error(`Unsupported model type: ${n.model_type}`)}}let rx=new Map([["bert",class extends t8{}],["albert",class extends rt{}],["distilbert",class extends t7{}],["roberta",class extends ri{}],["xlm-roberta",class extends ro{}],["clip",class extends rl{}],["mobilebert",class extends t9{}],["squeezebert",class extends re{}],["sam",ry]]),rA=new Map([["t5",class extends rr{async generate(...e){throw Error("The current model class (T5Model) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'T5ForConditionalGeneration'}")}}],["mt5",class extends rn{async generate(...e){throw Error("The current model class (MT5Model) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'MT5ForConditionalGeneration'}")}}],["bart",class extends rs{async generate(...e){throw Error("The current model class (BartModel) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'BartForConditionalGeneration'}")}}],["marian",class extends rb{async generate(...e){throw Error("The current model class (MarianModel) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'MarianMTModel'}")}}],["whisper",class extends ra{async generate(...e){throw Error("The current model class (WhisperModel) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'WhisperForConditionalGeneration'}")}}],["m2m_100",class extends rk{async generate(...e){throw Error("The current model class (M2M100Model) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'M2M100ForConditionalGeneration'}")}}]]),rE=new Map([["gpt2",class extends rh{async generate(...e){throw Error("The current model class (GPT2Model) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'GPT2LMHeadModel'}")}}],["gpt_neo",class extends rc{async generate(...e){throw Error("The current model class (GPTNeoModel) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'GPTNeoForCausalLM'}")}}],["codegen",class extends ru{async generate(...e){throw Error("The current model class (CodeGenModel) is not compatible with `.generate()`, as it doesn't have a language model head. Please use one of the following classes instead: {'CodeGenForCausalLM'}")}}]]),rz=new Map([["bert",class extends t8{async _call(e){return new rF(await super._call(e))}}],["albert",class extends rt{async _call(e){return new rF(await super._call(e))}}],["distilbert",class extends t7{async _call(e){return new rF(await super._call(e))}}],["roberta",class extends ri{async _call(e){return new rF(await super._call(e))}}],["xlm-roberta",class extends ro{async _call(e){return new rF(await super._call(e))}}],["bart",class extends rs{async _call(e){return new rF(await super._call(e))}}],["mobilebert",class extends t9{async _call(e){return new rF(await super._call(e))}}],["squeezebert",class extends re{async _call(e){return new rF(await super._call(e))}}]]),rT=new Map([["bert",class extends t8{async _call(e){return new rG(await super._call(e))}}],["distilbert",class extends t7{async _call(e){return new rG(await super._call(e))}}],["roberta",class extends ri{async _call(e){return new rG(await super._call(e))}}],["xlm-roberta",class extends ro{async _call(e){return new rG(await super._call(e))}}]]),rM=new Map([["t5",class extends rr{constructor(e,t,r,n){super(e,t),this.decoder_merged_session=r,this.generation_config=n,this.num_decoder_layers=this.config.num_decoder_layers,this.num_decoder_heads=this.config.num_heads,this.decoder_dim_kv=this.config.d_kv,this.num_encoder_layers=this.config.num_layers,this.num_encoder_heads=this.config.num_heads,this.encoder_dim_kv=this.config.d_kv}getStartBeams(e,t,...r){return tZ(this,e,t)}async runBeam(e){return await tQ(this,e)}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e)}}],["mt5",class extends rn{constructor(e,t,r,n){super(e,t),this.decoder_merged_session=r,this.generation_config=n,this.num_decoder_layers=this.config.num_decoder_layers,this.num_decoder_heads=this.config.num_heads,this.decoder_dim_kv=this.config.d_kv,this.num_encoder_layers=this.config.num_layers,this.num_encoder_heads=this.config.num_heads,this.encoder_dim_kv=this.config.d_kv}getStartBeams(e,t,...r){return tZ(this,e,t)}async runBeam(e){return await tQ(this,e)}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e)}}],["bart",class extends rs{constructor(e,t,r,n){super(e,t),this.decoder_merged_session=r,this.generation_config=n,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}getStartBeams(e,t,...r){return tZ(this,e,t)}async runBeam(e){return await tQ(this,e)}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e)}}],["whisper",class extends ra{constructor(e,t,r,n){super(e,t),this.decoder_merged_session=r,this.generation_config=n,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}async generate(e,t=null,r=null){if(t=this._get_generation_config(t),t.return_timestamps??=!1,t.return_timestamps&&(r=[new tM(t)]),t.return_token_timestamps&&(t.output_attentions=!0,t.return_dict_in_generate=!0,"translate"===t.task&&console.warn("Token-level timestamps may not be reliable for task 'translate'."),!t.alignment_heads))throw Error("Model generation config has no `alignment_heads`, token-level timestamps not available. See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config.");let n=await super.generate(e,t,r);return t.return_token_timestamps&&t.alignment_heads&&(n.token_timestamps=this._extract_token_timestamps(n,t.alignment_heads)),n}getStartBeams(e,t,...r){return tZ(this,e,t,!1)}async runBeam(e){return await tQ(this,e,{input_name:"input_features"})}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e)}_extract_token_timestamps(e,t,r=.02){if(!e.cross_attentions)throw Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");let n=this.config.median_filter_width;void 0===n&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),n=7);let s=e.cross_attentions.map(e=>{let r=Array.from({length:this.config.decoder_layers},(t,r)=>eh(e.map(e=>e[r]),2)),s=function(e,t=0){return eh(e.map(e=>e.unsqueeze(t)),t)}(t.map(([e,t])=>r[e].slice(null,t))),[i,o]=function(e,t=null,r=1,n=!1){if(null===t){let t=e.data.reduce((e,t)=>e+t,0),n=t/e.data.length,s=Math.sqrt(e.data.reduce((e,t)=>e+(t-n)**2,0)/(e.data.length-r)),i=new en(e.type,[n],[]),o=new en(e.type,[s],[]);return[o,i]}t=el(t,e.dims.length);let s=ec(e,t,n),i=e.dims.slice();i[t]=1;let o=new e.data.constructor(e.data.length/e.dims[t]);for(let r=0;r<e.data.length;++r){let n=0;for(let s=e.dims.length-1,o=r,a=1;s>=0;--s){let r=e.dims[s];if(s!==t){let e=o%r;n+=e*a,a*=i[s]}o=Math.floor(o/r)}o[n]+=(e.data[r]-s.data[n])**2}for(let n=0;n<o.length;++n)o[n]=Math.sqrt(o[n]/(e.dims[t]-r));n||i.splice(t,1);let a=new en(e.type,o,i);return[a,s]}(s=s.transpose(1,0,2,3),-2,0,!0),a=s.clone();for(let e=0;e<a.dims[0];++e){let t=a[e];for(let r=0;r<t.dims[0];++r){let s=t[r],a=i[e][r][0],l=o[e][r][0];for(let e=0;e<s.dims[0];++e){let t=s[e];for(let e=0;e<t.data.length;++e)t.data[e]=(t.data[e]-l.data[e])/a.data[e];t.data.set(ee(t.data,n))}}}let l=ec(a,1);return l}),i=[e.sequences.length,e.sequences[0].length],o=new en("float32",new Float32Array(i[0]*i[1]),i);for(let e=0;e<i[0];++e){let t=s[e].neg().squeeze_(0),[n,i]=function(e){let[t,r]=e.dims,n=[t+1,r+1],s=new en("float32",new Float32Array(n[0]*n[1]).fill(1/0),n),i=new en("float32",new Float32Array(n[0]*n[1]).fill(-1),n);s[0].data[0]=0;for(let n=1;n<r+1;++n)for(let r=1;r<t+1;++r){let t,o;let a=s[r-1][n-1].item(),l=s[r-1][n].item(),h=s[r][n-1].item();a<l&&a<h?(t=a,o=0):l<a&&l<h?(t=l,o=1):(t=h,o=2),s[r].data[n]=e[r-1][n-1].item()+t,i[r].data[n]=o}let o=t,a=r;i.data.fill(2,0,n[1]);for(let e=0;e<n[0];++e)i[e].data[0]=1;let l=[],h=[];for(;o>0||a>0;){l.push(o-1),h.push(a-1);let e=i[o][a].item();switch(e){case 0:--o,--a;break;case 1:--o;break;case 2:--a;break;default:throw Error(`Internal error in dynamic time warping. Unexpected trace[${o}, ${a}]. Please file a bug report.`)}}return l.reverse(),h.reverse(),[l,h]}(t),a=f([1],Array.from({length:n.length-1},(e,t)=>n[t+1]-n[t])).map(e=>!!e),l=[];for(let e=0;e<a.length;++e)a[e]&&l.push(i[e]*r);o[e].data.set(l,1)}return o}}],["marian",class extends rb{constructor(e,t,r,n){super(e,t),this.decoder_merged_session=r,this.generation_config=n,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}getStartBeams(e,t,...r){return tZ(this,e,t)}async runBeam(e){return await tQ(this,e)}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e)}}],["m2m_100",class extends rk{constructor(e,t,r,n){super(e,t),this.decoder_merged_session=r,this.generation_config=n,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}getStartBeams(e,t,...r){return tZ(this,e,t)}async runBeam(e){return await tQ(this,e)}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e)}}]]),rI=new Map([["gpt2",class extends rh{getStartBeams(e,t,r){return t2(this,e,t,r)}async runBeam(e){return await t3(this,e)}updateBeam(e,t){return t6(e,t)}async forward(e){return await t1(this,e)}}],["gpt_neo",class extends rc{getStartBeams(e,t,r){return t2(this,e,t,r)}async runBeam(e){return await t3(this,e)}updateBeam(e,t){return t6(e,t)}async forward(e){return await t1(this,e)}}],["codegen",class extends ru{getStartBeams(e,t,r){return t2(this,e,t,r)}async runBeam(e){return await t3(this,e)}updateBeam(e,t){return t6(e,t)}async forward(e){return await t1(this,e)}}]]),rB=new Map([["bert",class extends t8{async _call(e){return new rq(await super._call(e))}}],["albert",class extends rt{async _call(e){return new rq(await super._call(e))}}],["distilbert",class extends t7{async _call(e){return new rq(await super._call(e))}}],["roberta",class extends ri{async _call(e){return new rq(await super._call(e))}}],["xlm-roberta",class extends ro{async _call(e){return new rq(await super._call(e))}}],["mobilebert",class extends t9{async _call(e){return new rq(await super._call(e))}}],["squeezebert",class extends re{async _call(e){return new rq(await super._call(e))}}]]),rS=new Map([["bert",class extends t8{async _call(e){return new rD(await super._call(e))}}],["albert",class extends rt{async _call(e){return new rD(await super._call(e))}}],["distilbert",class extends t7{async _call(e){return new rD(await super._call(e))}}],["roberta",class extends ri{async _call(e){return new rD(await super._call(e))}}],["xlm-roberta",class extends ro{async _call(e){return new rD(await super._call(e))}}],["mobilebert",class extends t9{async _call(e){return new rD(await super._call(e))}}],["squeezebert",class extends re{async _call(e){return new rD(await super._call(e))}}]]),rC=new Map([["vision-encoder-decoder",class extends t4{constructor(e,t,r){super(e,t),this.decoder_merged_session=r,this.num_layers=this.config.decoder.n_layer,this.num_heads=this.config.decoder.n_head,this.dim_kv=this.config.decoder.n_embd/this.num_heads}getStartBeams(e,t,...r){return tZ(this,e,t)}async runBeam(e){return tQ(this,e,{input_name:"pixel_values"})}updateBeam(e,t){e.output_token_ids=[...e.output_token_ids,t]}async forward(e){return await tY(this,e,{add_decoder_pkv:!1})}}]]),rP=new Map([["vit",class extends rd{async _call(e){return new rF(await super._call(e))}}],["mobilevit",class extends rf{async _call(e){return new rF(await super._call(e))}}]]),rU=new Map([["detr",class extends rp{async _call(e){return new r_(await super._call(e))}}]]),rL=new Map([["detr",class extends rp{async _call(e){return new rm(await super._call(e))}}]]),rO=new Map([["sam",ry]]);for(let[e,t]of[[rx,tN],[rA,t$],[rE,tG],[rz,tN],[rT,tN],[rM,tF],[rI,tG],[rB,tN],[rS,tN],[rC,t$],[rP,tN],[rL,tN],[rU,tN],[rO,tN]])for(let[r,n]of e.entries())tq.set(n.name,t),tD.set(n.name,r);class rR extends rv{static MODEL_CLASS_MAPPINGS=[rx,rA,rE];static BASE_IF_FAIL=!0}class rj extends rv{static MODEL_CLASS_MAPPINGS=[rz]}class rN extends rv{static MODEL_CLASS_MAPPINGS=[rM]}class r$ extends t5{constructor({logits:e,past_key_values:t,encoder_outputs:r,decoder_attentions:n=null,cross_attentions:s=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=r,this.decoder_attentions=n,this.cross_attentions=s}}class rF extends t5{constructor({logits:e}){super(),this.logits=e}}class rG extends t5{constructor({logits:e}){super(),this.logits=e}}class rq extends t5{constructor({logits:e}){super(),this.logits=e}}class rD extends t5{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}}var rW=r(3380);let rK="undefined"!=typeof self;if(rK)s=(e,t)=>{if(!self.OffscreenCanvas)throw Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(e,t)},o=self.createImageBitmap,i=self.ImageData;else if(rW)o=async e=>{let t=await e.metadata(),r=t.channels,{data:n,info:s}=await e.raw().toBuffer({resolveWithObject:!0}),i=new rX(new Uint8ClampedArray(n),s.width,s.height,s.channels);return void 0!==r&&r!==s.channels&&i.convert(r),i};else throw Error("Unable to load image processing library.");let rH={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"};class rX{constructor(e,t,r,n){this._update(e,t,r,n)}static async read(e){if(e instanceof rX)return e;if(c(e)||e instanceof URL)return await this.fromURL(e);throw Error(`Unsupported input type: ${typeof e}`)}static async fromURL(e){let t=await G(e),r=await t.blob();return this.fromBlob(r)}static async fromBlob(e){if(rK){let t=await o(e),r=s(t.width,t.height).getContext("2d");return r.drawImage(t,0,0),new this(r.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}{let t=rW(await e.arrayBuffer());return await o(t)}}grayscale(){if(1===this.channels)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,r=0;t<this.data.length;t+=this.channels){let n=this.data[t],s=this.data[t+1],i=this.data[t+2];e[r++]=Math.round(.2989*n+.587*s+.114*i)}break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(3===this.channels)return this;let e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let t=0,r=0;t<this.data.length;++t)e[r++]=this.data[t],e[r++]=this.data[t],e[r++]=this.data[t];break;case 4:for(let t=0,r=0;t<this.data.length;t+=4)e[r++]=this.data[t],e[r++]=this.data[t+1],e[r++]=this.data[t+2];break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(4===this.channels)return this;let e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let t=0,r=0;t<this.data.length;++t)e[r++]=this.data[t],e[r++]=this.data[t],e[r++]=this.data[t],e[r++]=255;break;case 3:for(let t=0,r=0;t<this.data.length;t+=3)e[r++]=this.data[t],e[r++]=this.data[t+1],e[r++]=this.data[t+2],e[r++]=255;break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}async resize(e,t,{resample:r=2}={}){let n=rH[r]??r;if(rK){let r=this.channels,n=this.toCanvas(),i=s(e,t).getContext("2d");return i.drawImage(n,0,0,e,t),new rX(i.getImageData(0,0,e,t).data,e,t,4).convert(r)}{let r=rW(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}});switch(n){case"box":case"hamming":("box"===n||"hamming"===n)&&(console.warn(`Resampling method ${n} is not yet supported. Using bilinear instead.`),n="bilinear");case"nearest":case"bilinear":case"bicubic":r=r.affine([e/this.width,0,0,t/this.height],{interpolator:n});break;case"lanczos":r=r.resize({width:e,height:t,fit:"fill",kernel:"lanczos3"});break;default:throw Error(`Resampling method ${n} is not supported.`)}return await o(r)}}async pad([e,t,r,n]){if(e=Math.max(e,0),t=Math.max(t,0),r=Math.max(r,0),n=Math.max(n,0),0===e&&0===t&&0===r&&0===n)return this;if(rK){let i=this.channels,o=this.toCanvas(),a=this.width+e+t,l=this.height+r+n,h=s(a,l).getContext("2d");return h.drawImage(o,0,0,this.width,this.height,e,r,a,l),new rX(h.getImageData(0,0,a,l).data,a,l,4).convert(i)}{let s=rW(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}}).extend({left:e,right:t,top:r,bottom:n});return await o(s)}}async center_crop(e,t){if(this.width===e&&this.height===t)return this;let r=(this.width-e)/2,n=(this.height-t)/2;if(rK){let i=this.channels,o=this.toCanvas(),a=s(e,t).getContext("2d"),l=0,h=0,c=0,u=0;return r>=0?l=r:c=-r,n>=0?h=n:u=-n,a.drawImage(o,l,h,e,t,c,u,e,t),new rX(a.getImageData(0,0,e,t).data,e,t,4).convert(i)}{let s=rW(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}});if(r>=0&&n>=0)s=s.extract({left:Math.floor(r),top:Math.floor(n),width:e,height:t});else if(r<=0&&n<=0){let i=Math.floor(-n),o=Math.floor(-r);s=s.extend({top:i,left:o,right:e-this.width-o,bottom:t-this.height-i})}else{let i=[0,0],o=0;n<0?(i[0]=Math.floor(-n),i[1]=t-this.height-i[0]):o=Math.floor(n);let a=[0,0],l=0;r<0?(a[0]=Math.floor(-r),a[1]=e-this.width-a[0]):l=Math.floor(r),s=s.extend({top:i[0],bottom:i[1],left:a[0],right:a[1]}).extract({left:l,top:o,width:e,height:t})}return await o(s)}}toCanvas(){let e=this.clone().rgba(),t=s(e.width,e.height),r=new i(e.data,e.width,e.height);return t.getContext("2d").putImageData(r,0,0),t}_update(e,t,r,n=null){return this.data=e,this.width=t,this.height=r,null!==n&&(this.channels=n),this}clone(){return new rX(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}save(e,t="image/png"){if(!O.useFS)throw Error("Unable to save the image because filesystem is disabled in this environment.");let r=this.toCanvas(),n=r.toBuffer(t);p.writeFileSync(e,n)}}async function rV(e,t){let r;if("undefined"==typeof AudioContext)throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/tutorials/node-audio-processing.");let n=await (await G(e)).arrayBuffer(),s=new AudioContext({sampleRate:t});void 0===t&&console.warn(`No sampling rate provided, using default of ${s.sampleRate}Hz.`);let i=await s.decodeAudioData(n);if(2===i.numberOfChannels){let e=Math.sqrt(2),t=i.getChannelData(0),n=i.getChannelData(1);r=new Float32Array(t.length);for(let s=0;s<i.length;++s)r[s]=e*(t[s]+n[s])/2}else r=i.getChannelData(0);return r}class rJ extends h{constructor(e){super(),this.config=e}}class rY extends rJ{constructor(e){super(e),this.image_mean=this.config.image_mean,this.image_std=this.config.image_std,this.resample=this.config.resample??2,this.do_rescale=this.config.do_rescale??!0,this.rescale_factor=this.config.rescale_factor??1/255,this.do_normalize=this.config.do_normalize,this.do_resize=this.config.do_resize,this.size=this.config.size,this.do_center_crop=this.config.do_center_crop,this.crop_size=this.config.crop_size,this.do_convert_rgb=this.config.do_convert_rgb??!0,this.pad_size=this.config.pad_size,this.do_pad=(this.config.do_pad??!1)&&this.pad_size}async preprocess(e){this.do_convert_rgb&&(e=e.rgb());let t=e.width,r=e.height;if(this.do_resize){let n,s;if(Number.isInteger(this.size)?(n=this.size,s=this.config.max_size??n):(n=this.size.shortest_edge,s=this.size.longest_edge),void 0!==n||void 0!==s){let i=void 0===n?1:Math.max(n/t,n/r),o=t*i,a=r*i,l=void 0===s?1:Math.min(s/o,s/a);e=await e.resize(Math.floor(o*l),Math.floor(a*l),{resample:this.resample})}else if(void 0!==this.size.width&&void 0!==this.size.height)e=await e.resize(this.size.width,this.size.height,{resample:this.resample});else throw Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(this.size)}`)}if(this.do_center_crop){let t,r;Number.isInteger(this.crop_size)?(t=this.crop_size,r=this.crop_size):(t=this.crop_size.width,r=this.crop_size.height),e=await e.center_crop(t,r)}let n=[e.height,e.width];if(this.do_pad){let t=this.pad_size.width-e.width,r=this.pad_size.height-e.height;e=await e.pad([0,t,0,r])}let s=Float32Array.from(e.data);if(this.do_rescale)for(let e=0;e<s.length;++e)s[e]=this.rescale_factor*s[e];if(this.do_normalize){let t=this.image_mean;Array.isArray(this.image_mean)||(t=Array(e.channels).fill(t));let r=this.image_std;if(Array.isArray(this.image_std)||(r=Array(e.channels).fill(t)),t.length!==e.channels||r.length!==e.channels)throw Error(`When set to arrays, the length of \`image_mean\` (${t.length}) and \`image_std\` (${r.length}) must match the number of channels in the image (${e.channels}).`);for(let t=0;t<s.length;t+=e.channels)for(let r=0;r<e.channels;++r)s[t+r]=(s[t+r]-this.image_mean[r])/this.image_std[r]}let i=[e.height,e.width,e.channels];return{original_size:[r,t],reshaped_input_size:n,pixel_values:es(new en("float32",s,i),[2,0,1])}}async _call(e){Array.isArray(e)||(e=[e]);let t=await Promise.all(e.map(e=>this.preprocess(e)));return t.forEach(e=>e.pixel_values.dims=[1,...e.pixel_values.dims]),{pixel_values:eh(t.map(e=>e.pixel_values)),original_sizes:t.map(e=>e.original_size),reshaped_input_sizes:t.map(e=>e.reshaped_input_size)}}}class rZ extends rY{}class rQ extends rY{}class r0 extends rY{async _call(e){let t=await super._call(e),r=[t.pixel_values.dims[0],64,64];return t.pixel_mask=new en("int64",new BigInt64Array(r.reduce((e,t)=>e*t)).fill(1n),r),t}center_to_corners_format([e,t,r,n]){return[e-r/2,t-n/2,e+r/2,t+n/2]}post_process_object_detection(e,t=.5,r=null){let n=e.logits,s=e.pred_boxes,[i,o,a]=n.dims;if(null!==r&&r.length!==i)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let l=[];for(let e=0;e<i;++e){let i=null!==r?r[e]:null,h={boxes:[],classes:[],scores:[]},c=n[e],u=s[e];for(let e=0;e<o;++e){let r=c[e],n=Z(r.data)[1];if(n===a-1)continue;let s=J(r.data)[n];if(s>t){let t=u[e].data;t=this.center_to_corners_format(t),null!==i&&(t=t.map((e,t)=>e*i[(t+1)%2])),h.boxes.push(t),h.classes.push(n),h.scores.push(s)}}l.push(h)}return l}remove_low_and_no_objects(e,t,r,n){let s=[],i=[],o=[];for(let a=0;a<e.dims[0];++a){let l=e[a],h=t[a],c=Z(l.data)[1];if(c===n)continue;let u=J(l.data)[c];u>r&&(s.push(h),i.push(u),o.push(c))}return[s,i,o]}check_segment_validity(e,t,r,n=.5,s=.8){let i=[],o=0,a=0;for(let s=0;s<e.length;++s)e[s]===r&&(i.push(s),++o),t[r].data[s]>=n&&++a;let l=o>0&&a>0;return l&&(l=o/a>s),[l,i]}compute_segments(e,t,r,n,s,i=null,o=null){let[a,l]=o??e[0].dims,h=new en("int32",new Int32Array(a*l),[a,l]),c=[];if(null!==o)for(let t=0;t<e.length;++t)e[t]=ei(e[t],o,"bilinear",!1);let u=new Int32Array(e[0].data.length),d=new Float32Array(e[0].data.length);for(let r=0;r<e.length;++r){let n=t[r];for(let t=0;t<e[r].data.length;++t)e[r].data[t]*=n,e[r].data[t]>d[t]&&(u[t]=r,d[t]=e[r].data[t])}let f=0;for(let i=0;i<r.length;++i){let o=r[i],[a,l]=this.check_segment_validity(u,e,i,n,s);if(a){for(let e of(++f,l))h.data[e]=f;c.push({id:f,label_id:o,score:t[i]})}}return[h,c]}post_process_panoptic_segmentation(e,t=.5,r=.5,n=.8,s=null,i=null){null===s&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),s=new Set);let o=e.logits,a=e.pred_masks,l=a.sigmoid(),[h,c,u]=o.dims;if(u-=1,null!==i&&i.length!==h)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let d=[];for(let e=0;e<h;++e){let a=null!==i?i[e]:null,h=o[e],c=l[e],[f,p,_]=this.remove_low_and_no_objects(h,c,t,u);if(0===_.length){let[e,t]=a??c.dims.slice(-2),r=new en("int32",new Int32Array(e*t).fill(-1),[e,t]);d.push({segmentation:r,segments_info:[]});continue}let[m,g]=this.compute_segments(f,p,_,r,n,s,a);d.push({segmentation:m,segments_info:g})}return d}post_process_instance_segmentation(){throw Error("Not implemented yet")}}class r1 extends rY{async _call(e,t){let{pixel_values:r,original_sizes:n,reshaped_input_sizes:s}=await super._call(e),i=function(e){let t=[],r=e;for(;Array.isArray(r);)t.push(r.length),r=r[0];return t}(t);if(3===i.length)i=[1,...i],t=[t];else if(4!==i.length)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let e=0;e<t.length;++e){let r=n[e],i=s[e],o=[i[0]/r[0],i[1]/r[1]];for(let r=0;r<t[e].length;++r)for(let n=0;n<t[e][r].length;++n)for(let s=0;s<t[e][r][n].length;++s)t[e][r][n][s]*=o[s]}return{pixel_values:r,original_sizes:n,reshaped_input_sizes:s,input_points:new en("int64",BigInt64Array.from(t.flat(1/0).map(e=>BigInt(Math.round(e)))),i)}}post_process_masks(e,t,r,{mask_threshold:n=0,binarize:s=!0,pad_size:i=null}={}){let o=[],a=[(i=i??this.pad_size).height,i.width];for(let i=0;i<t.length;++i){let l=t[i],h=r[i],c=e[i],u=[];for(let e=0;e<c.dims[0];++e){let t=ei(c[e],a,"bilinear",!1);t=t.slice(null,[0,h[0]],[0,h[1]]),t=ei(c,l,"bilinear",!1),s&&(t=new en("bool",Array.from(t.data).map(e=>e>n),t.dims)),t.dims=[1,...t.dims],u.push(t)}let d=eh(u);o.push(d)}return o}}class r2 extends rJ{constructor(e){super(e),this.config.mel_filters??=function(e,t,r=128){r=Math.floor(r);let n=Math.floor(1+t/2),s=Array(r),i=function(e,t=1){if(!Number.isInteger(e))throw TypeError(`n should be an integer, but ${e} given.`);let r=1/(e*t),n=Math.floor(e/2)+1,s=Array(n);for(let e=0;e<n;++e)s[e]=e*r;return s}(t,1/e),o=45.245640471924965/(r+1),a=200/3,l=Array(r+2),h=1e3/a,c=Math.log(6.4)/27,u=Array(l.length);for(let e=0;e<l.length;++e){let t=e*o+0;t>=h?l[e]=1e3*Math.exp(c*(t-h)):l[e]=0+a*t,u[e]=i.map(t=>l[e]-t)}let d=l.slice(1).map((e,t)=>1/(e-l[t]));for(let e=0;e<s.length;++e){s[e]=Array(n);let t=d[e],r=d[e+1],i=u[e],o=u[e+2],a=2/(l[e+2]-l[e]);for(let n=0;n<s[e].length;++n){let l=-i[n]*t,h=o[n]*r;s[e][n]=Math.max(0,Math.min(l,h))*a}}return s}(this.config.sampling_rate,this.config.n_fft,this.config.feature_size)}calcOffset(e,t){return Math.abs((e+t)%(2*t)-t)}padReflect(e,t,r){let n=new Float32Array(e.length+t+r),s=e.length-1;for(let r=0;r<e.length;++r)n[t+r]=e[r];for(let r=1;r<=t;++r)n[t-r]=e[this.calcOffset(r,s)];for(let i=1;i<=r;++i)n[s+t+i]=e[this.calcOffset(s-i,s)];return n}stft(e,t){let r=this.config.n_fft,n=2*(r-1),s=2*(2*r-1),i=2**Math.ceil(Math.log2(s)),o=r+2,a=new Float32Array(o*e.length),l=new Float32Array(s),h=new Float32Array(i),c=new Float32Array(i),u=new Float32Array(i),d=new Float32Array(i),f=new Float32Array(i),p=new Float32Array(i),_=-2*Math.PI/r,m=Math.cos(_),g=Math.sin(_);for(let e=0;e<s>>1;++e){let t=(e+1-r)**2/2,n=Math.sqrt(m**2+g**2)**t,s=t*Math.atan2(g,m),i=2*e;l[i]=n*Math.cos(s),l[i+1]=n*Math.sin(s),h[i]=l[i],h[i+1]=-l[i+1]}let y=l.subarray(n,s),w=new Q(i>>1);w.transform(d,h);for(let r=0;r<e.length;++r){let s=e[r];for(let e=0;e<y.length;e+=2){let r=e+1,n=e>>1,i=s[n]*t[n];c[e]=i*y[e],c[r]=i*y[r]}w.transform(f,c);for(let e=0;e<d.length;e+=2){let t=e+1;u[e]=f[e]*d[e]-f[t]*d[t],u[t]=f[e]*d[t]+f[t]*d[e]}w.inverseTransform(p,u);let i=r*o;for(let e=0;e<o;e+=2){let t=p[e+n],r=p[e+n+1],s=y[e],o=y[e+1],l=i+e;a[l]=t*s-r*o,a[l+1]=t*o+r*s}}return{data:a,dims:[e.length,o]}}fram_wave(e,t=!0){let r=[],n=Math.floor((this.config.n_fft-1)/2)+1,s=e.length;for(let i=0;i<s+1;i+=this.config.hop_length){let o;if(t){let t=i>n?i-n:0,r=i<s-n?i+n:s;o=e.subarray(t,r),0===t?o=this.padReflect(o,-i+n,0):r===s&&(o=this.padReflect(o,0,i-s+n))}else{o=new Float32Array(this.config.n_fft);let t=e.subarray(i,i+this.config.n_fft);t.length<this.config.n_fft?(o.set(t),o.fill(0,t.length,this.config.n_fft)):o=t}r.push(o)}return r}hanning(e){if(e<1)return[];if(1===e)return[1];let t=e-1,r=new Float32Array(t);for(let n=0;n<t;++n){let s=2*n-e+1;r[n]=.5+.5*Math.cos(Math.PI*s/t)}return r}_extract_fbank_features(e){let t=new Float32Array(this.config.n_samples);t.set(e);let r=this.hanning(this.config.n_fft+1),n=this.fram_wave(t),s=this.stft(n,r),i=s.data,o=s.dims[0]-1,a=s.dims[1]>>1,l=new Float32Array(o*a);for(let e=0;e<o;++e)for(let t=0;t<a;++t){let r=e*a+t,n=r<<1,s=i[n]**2+i[n+1]**2;l[r]=s}let h=this.config.mel_filters,c=h.length,u=new Float32Array(c*o),d=0;for(let e=0;e<c;++e){let t=h[e];for(let e=0;e<o;++e){let r=0;for(let n=0;n<a;++n)r+=t[n]*l[e*a+n];u[d++]=r}}let f=new Float32Array(u.length),p=0;for(let e=0;e<u.length;++e){let t=Math.max(1e-10,u[e]),r=Math.log10(t);f[e]=r,p=Math.max(r,p)}for(let e=0;e<f.length;++e)f[e]=Math.max(f[e],p-8),f[e]=(f[e]+4)/4;return{data:f,dims:[c,o]}}async _call(e){if(!(e instanceof Float32Array||e instanceof Float64Array))throw Error(`WhisperFeatureExtractor expects input to be a Float32Array or a Float64Array, but got ${e?.constructor?.name??typeof e} instead.If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`);e.length>this.config.n_samples&&console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`.");let t=e.slice(0,this.config.n_samples),r=this._extract_fbank_features(t);return{input_features:new en("float32",r.data,[1,...r.dims])}}}class r3 extends h{constructor(e){super(),this.feature_extractor=e}async _call(e){return await this.feature_extractor(e)}}class r6 extends r3{async _call(e,t){return await this.feature_extractor(e,t)}post_process_masks(...e){return this.feature_extractor.post_process_masks(...e)}}class r4 extends r3{async _call(e){return await this.feature_extractor(e)}}class r5{static FEATURE_EXTRACTOR_CLASS_MAPPING={WhisperFeatureExtractor:r2,ViTFeatureExtractor:rZ,MobileViTFeatureExtractor:rQ,DetrFeatureExtractor:r0,SamImageProcessor:r1};static PROCESSOR_CLASS_MAPPING={WhisperProcessor:r4,SamProcessor:r6};static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:n=null,local_files_only:s=!1,revision:i="main"}={}){let o=r??await H(e,"preprocessor_config.json",!0,{progress_callback:t,config:r,cache_dir:n,local_files_only:s,revision:i}),a=o.feature_extractor_type??o.image_processor_type,l=this.FEATURE_EXTRACTOR_CLASS_MAPPING[a];if(!l){if(void 0!==o.size)console.warn("Feature extractor type not specified, assuming ImageFeatureExtractor due to size parameter in config."),l=rY;else throw Error(`Unknown Feature Extractor type: ${o.feature_extractor_type}`)}let h=this.PROCESSOR_CLASS_MAPPING[o.processor_class]??r3,c=new l(o);return new h(c)}}async function r8(e){return Array.isArray(e)||(e=[e]),e=await Promise.all(e.map(e=>rX.read(e)))}class r7 extends h{constructor(e,t,r){super(),this.task=e,this.tokenizer=t,this.model=r}async dispose(){await this.model.dispose()}async _call(e){let t=this.tokenizer(e,{padding:!0,truncation:!0}),r=await this.model(t);return[t,r]}}class r9 extends r7{_key=null;async _call(e,t={}){let r;Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(e=>this.model.config.prefix+e));let n=this.model.config.task_specific_params;n&&n[this.task]&&n[this.task].prefix&&(e=e.map(e=>n[this.task].prefix+e));let s={padding:!0,truncation:!0};r=this instanceof ne&&"_build_translation_inputs"in this.tokenizer?this.tokenizer._build_translation_inputs(e,s,t).input_ids:this.tokenizer(e,s).input_ids;let i=await this.model.generate(r,t),o=this.tokenizer.batch_decode(i,{skip_special_tokens:!0});return null!==this._key&&(o=o.map(e=>null===this._key?e:{[this._key]:e})),o}}class ne extends r9{_key="translation_text"}let nt={"text-classification":{tokenizer:ty,pipeline:class extends r7{async _call(e,{topk:t=1}={}){let[r,n]=await super._call(e),s=this.model.config.id2label,i=[];for(let e of n.logits){let r=Y(J(e.data),t).map(function(e){return{label:s[e[0]],score:e[1]}});1===t?i.push(...r):i.push(r)}return Array.isArray(e)||1===t?i:i[0]}},model:rj,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:ty,pipeline:class extends r7{async _call(e,{ignore_labels:t=["O"]}={}){let r=Array.isArray(e);r||(e=[e]);let n=this.tokenizer,[s,i]=await super._call(e),o=i.logits,a=this.model.config.id2label,l=[];for(let e=0;e<o.dims[0];++e){let r=s.input_ids[e],i=o[e],h=[];for(let e=0;e<i.dims[0];++e){let s=i[e],o=Z(s.data)[1],l=a[o];if(t.includes(l))continue;let c=n.decode([r[e].item()],{skip_special_tokens:!0});if(""===c)continue;let u=J(s.data);h.push({entity:l,score:u[o],index:e,word:c,start:null,end:null})}l.push(h)}return r?l:l[0]}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rT]},default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:ty,pipeline:class extends r7{async _call(e,t,{topk:r=1}={}){let n=this.tokenizer(e,{text_pair:t,padding:!0,truncation:!0}),s=await this.model(n),i=[];for(let e=0;e<s.start_logits.dims[0];++e){let t=n.input_ids[e],o=t.indexOf(this.tokenizer.sep_token_id),a=(function(...e){return e.reduce((e,t)=>e.flatMap(e=>t.map(t=>[e,t])))})(Array.from(J(s.start_logits[e].data)).map((e,t)=>[e,t]).filter(e=>e[1]>o),Array.from(J(s.end_logits[e].data)).map((e,t)=>[e,t]).filter(e=>e[1]>o)).filter(e=>e[0][1]<=e[1][1]).map(e=>[e[0][1],e[1][1],e[0][0]*e[1][0]]).sort((e,t)=>t[2]-e[2]);for(let e=0;e<Math.min(a.length,r);++e){let[r,n,s]=a[e],o=[...t].slice(r,n+1),l=this.tokenizer.decode(o,{skip_special_tokens:!0});i.push({answer:l,score:s})}}return 1===r?i[0]:i}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rS]},default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:ty,pipeline:class extends r7{async _call(e,{topk:t=5}={}){let[r,n]=await super._call(e),s=this.tokenizer,i=[];for(let e=0;e<r.input_ids.dims[0];++e){let o=r.input_ids[e],a=o.indexOf(this.tokenizer.mask_token_id);if(-1===a)throw Error(`Mask token (${s.mask_token}) not found in text.`);let l=Y(J(n.logits[e][a].data),t);i.push(l.map(e=>{let t=[...o];return t[a]=e[0],{score:e[1],token:e[0],token_str:s.model.vocab[e[0]],sequence:s.decode(t,{skip_special_tokens:!0})}}))}return Array.isArray(e)?i:i[0]}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rB]},default:{model:"Xenova/bert-base-uncased"},type:"text"},summarization:{tokenizer:ty,pipeline:class extends r9{_key="summary_text"},model:rN,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:ty,pipeline:ne,model:rN,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:ty,pipeline:r9,model:rN,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:ty,pipeline:class extends r7{async _call(e,t={}){let r="string"==typeof e||e instanceof String;r&&(e=[e]),this.tokenizer.padding_side="left";let n=this.tokenizer(e,{padding:!0,truncation:!0}),s=n.input_ids,i=n.attention_mask,o=await this.model.generate(s,t,null,{inputs_attention_mask:i}),a=this.tokenizer.batch_decode(o,{skip_special_tokens:!0}),l=Array.from({length:e.length},e=>[]);for(let t=0;t<a.length;++t){let r=Math.floor(t/o.length*e.length);l[r].push({generated_text:a[t]})}return r&&1===l.length?l[0]:l}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rI]},default:{model:"Xenova/gpt2"},type:"text"},"zero-shot-classification":{tokenizer:ty,pipeline:class extends r7{constructor(e,t,r){super(e,t,r),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([e,t])=>[e.toLowerCase(),t])),this.entailment_id=this.label2id.entailment,void 0===this.entailment_id&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction,void 0===this.contradiction_id&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:r="This example is {}.",multi_label:n=!1}={}){let s=Array.isArray(e);s||(e=[e]),Array.isArray(t)||(t=[t]);let i=t.map(e=>r.replace("{}",e)),o=n||1===t.length,a=[];for(let r of e){let e=[];for(let t of i){let n=this.tokenizer(r,{text_pair:t,padding:!0,truncation:!0}),s=await this.model(n);o?e.push([s.logits.data[this.contradiction_id],s.logits.data[this.entailment_id]]):e.push(s.logits.data[this.entailment_id])}let n=(o?e.map(e=>J(e)[1]):J(e)).map((e,t)=>[e,t]).sort((e,t)=>t[0]-e[0]);a.push({sequence:r,labels:n.map(e=>t[e[1]]),scores:n.map(e=>e[0])})}return s?a:a[0]}},model:rj,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"automatic-speech-recognition":{tokenizer:ty,pipeline:class extends r7{constructor(e,t,r,n){super(e,t,r),this.processor=n}async _preprocess(e,t){return c(e)&&(e=await rV(e,t)),e}async _call(e,t={}){let r=t.return_timestamps??!1,n=t.chunk_length_s??0,s=t.stride_length_s??null,i=t.chunk_callback??null,o=t.force_full_sequences??!1;"word"===r&&(t.return_token_timestamps=!0);let a=d(t,"language",null),l=d(t,"task",null);if(a||l||r){if(t.forced_decoder_ids)throw Error("Cannot specify `language`/`task`/`return_timestamps` and `forced_decoder_ids` at the same time.");let e=this.tokenizer.get_decoder_prompt_ids({language:a,task:l,no_timestamps:!r});e.length>0&&(t.forced_decoder_ids=e)}let h=!Array.isArray(e);h&&(e=[e]);let c=this.processor.feature_extractor.config.sampling_rate,u=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,f=[];for(let a of e){a=await this._preprocess(a,c);let e=[];if(n>0){if(null===s)s=n/6;else if(n<=s)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");let t=c*n,r=c*s,i=t-2*r,o=0;for(;o<a.length;){let n=a.subarray(o,o+t),s=await this.processor(n),l=0===o,h=o+i>=a.length;e.push({stride:[n.length,l?0:r,h?0:r],input_features:s.input_features,is_last:h}),o+=i}}else e=[{stride:[a.length,0,0],input_features:(await this.processor(a)).input_features,is_last:!0}];for(let n of e){let e=await this.model.generate(n.input_features,t);"word"===r?(n.tokens=e.sequences[0],n.token_timestamps=e.token_timestamps.tolist()[0].map(e=>et(e,2))):n.tokens=e[0],n.stride=n.stride.map(e=>e/c),null!==i&&i(n)}let[l,h]=this.tokenizer._decode_asr(e,{time_precision:u,return_timestamps:r,force_full_sequences:o});f.push({text:l,...h})}return h?f[0]:f}},model:rN,processor:r5,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"image-to-text":{tokenizer:ty,pipeline:class extends r7{constructor(e,t,r,n){super(e,t,r),this.processor=n}async _call(e,t={}){let r=Array.isArray(e);e=await r8(e);let{pixel_values:n}=await this.processor(e),s=[];for(let e of n){e.dims=[1,...e.dims];let r=await this.model.generate(e,t),n=this.tokenizer.batch_decode(r,{skip_special_tokens:!0}).map(e=>({generated_text:e.trim()}));s.push(n)}return r?s:s[0]}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rC]},processor:r5,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:class extends r7{constructor(e,t,r){super(e,null,t),this.processor=r}async _call(e,{topk:t=1}={}){let r=Array.isArray(e);e=await r8(e);let{pixel_values:n}=await this.processor(e),s=await this.model({pixel_values:n}),i=this.model.config.id2label,o=[];for(let e of s.logits){let r=Y(J(e.data),t).map(function(e){return{label:i[e[0]],score:e[1]}});1===t?o.push(...r):o.push(r)}return r||1===t?o:o[0]}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rP]},processor:r5,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:class extends r7{constructor(e,t,r){super(e,null,t),this.processor=r,this.subtasks_mapping={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"}}async _call(e,{threshold:t=.5,mask_threshold:r=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:s=null,target_sizes:i=null,subtask:o=null}={}){if(Array.isArray(e)&&1!==e.length)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");let a=(e=await r8(e)).map(e=>[e.height,e.width]),{pixel_values:l,pixel_mask:h}=await this.processor(e),c=await this.model({pixel_values:l,pixel_mask:h}),u=null;if(null!==o)u=this.subtasks_mapping[o];else for(let[e,t]of Object.entries(this.subtasks_mapping))if(t in this.processor.feature_extractor){u=this.processor.feature_extractor[t].bind(this.processor.feature_extractor),o=e;break}let d=[];if("panoptic"===o||"instance"===o){let e=u(c,t,r,n,s,i??a)[0],o=e.segmentation,l=this.model.config.id2label;for(let t of e.segments_info){let e=new Uint8ClampedArray(o.data.length);for(let r=0;r<o.data.length;++r)o.data[r]===t.id&&(e[r]=255);let r=new rX(e,o.dims[1],o.dims[0],1);d.push({score:t.score,label:l[t.label_id],mask:r})}}else if("semantic"===o)throw Error("semantic segmentation not yet supported.");else throw Error(`Subtask ${o} not supported.`);return d}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rL]},processor:r5,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"zero-shot-image-classification":{tokenizer:ty,pipeline:class extends r7{constructor(e,t,r,n){super(e,t,r),this.processor=n}async _call(e,t,{hypothesis_template:r="This is a photo of {}"}={}){let n=Array.isArray(e);e=await r8(e);let s=t.map(e=>r.replace("{}",e)),i=this.tokenizer(s,{padding:!0,truncation:!0}),{pixel_values:o}=await this.processor(e),a=await this.model({...i,pixel_values:o}),l=[];for(let e of a.logits_per_image){let r=J(e.data);l.push([...r].map((e,r)=>({score:e,label:t[r]})))}return n?l:l[0]}},model:rR,processor:r5,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:class extends r7{constructor(e,t,r){super(e,null,t),this.processor=r}async _call(e,{threshold:t=.9,percentage:r=!1}={}){let n=Array.isArray(e);if(n&&1!==e.length)throw Error("Object detection pipeline currently only supports a batch size of 1.");e=await r8(e);let s=r?null:e.map(e=>[e.height,e.width]),{pixel_values:i,pixel_mask:o}=await this.processor(e),a=await this.model({pixel_values:i,pixel_mask:o}),l=this.processor.feature_extractor.post_process_object_detection(a,t,s),h=this.model.config.id2label,c=l.map(e=>e.boxes.map((t,n)=>({score:e.scores[n],label:h[e.classes[n]],box:this._get_bounding_box(t,!r)})));return n?c:c[0]}_get_bounding_box(e,t){t&&(e=e.map(e=>0|e));let[r,n,s,i]=e;return{xmin:r,ymin:n,xmax:s,ymax:i}}},model:class extends rv{static MODEL_CLASS_MAPPINGS=[rU]},processor:r5,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"feature-extraction":{tokenizer:ty,pipeline:class extends r7{async _call(e,{pooling:t="none",normalize:r=!1}={}){let[n,s]=await super._call(e),i=s.last_hidden_state??s.logits;if("none"===t);else if("mean"===t)i=function(e,t){let r=[e.dims[0],e.dims[2]],n=new e.data.constructor(r[0]*r[1]),[s,i,o]=e.dims,a=0;for(let r=0;r<s;++r){let s=r*o*i;for(let l=0;l<o;++l){let h=0,c=0,u=r*i,d=s+l;for(let r=0;r<i;++r){let n=Number(t.data[u+r]);c+=n,h+=e.data[d+r*o]*n}let f=h/c;n[a++]=f}}return new en(e.type,n,r)}(i,n.attention_mask);else throw Error(`Pooling method '${t}' not supported.`);return r&&(i=i.normalize(2,-1)),i}},model:rR,default:{model:"Xenova/all-MiniLM-L6-v2"},type:"text"}},nr={"sentiment-analysis":"text-classification",ner:"token-classification",vqa:"visual-question-answering",asr:"automatic-speech-recognition",embeddings:"feature-extraction"};async function nn(e,t=null,{quantized:r=!0,progress_callback:n=null,config:s=null,cache_dir:i=null,local_files_only:o=!1,revision:l="main"}={}){let h=nt[(e=nr[e]??e).split("_",1)[0]];if(!h)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(nt)}]`);t||console.log(`No model specified. Using default model: "${t=h.default.model}".`);let c=h.tokenizer,u=h.model,d=h.pipeline,f=h.processor,p=[],_={quantized:r,progress_callback:n,config:s,cache_dir:i,local_files_only:o,revision:l};c&&p.push(c.from_pretrained(t,_)),u&&p.push(u.from_pretrained(t,_)),f&&p.push(f.from_pretrained(t,_));let m=await Promise.all(p);return a(n,{status:"ready",task:e,model:t}),new d(e,...m)}}}]); |