@huggingface/transformers
Version:
State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
1 lines • 399 kB
JavaScript
(()=>{var e,t,s={"node:fs":e=>{"use strict";e.exports=require("node:fs")},"node:path":e=>{"use strict";e.exports=require("node:path")},"node:url":e=>{"use strict";e.exports=require("node:url")},"onnxruntime-common":e=>{"use strict";e.exports=require("onnxruntime-common")},"onnxruntime-node":e=>{"use strict";e.exports=require("onnxruntime-node")},sharp:e=>{"use strict";e.exports=require("sharp")},"?8b6b":()=>{},"./node_modules/@huggingface/jinja/dist/index.js":(e,t,s)=>{"use strict";s.r(t),s.d(t,{Environment:()=>te,Interpreter:()=>se,Template:()=>_e,parse:()=>N,tokenize:()=>d});var r=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",BooleanLiteral:"BooleanLiteral",NullLiteral:"NullLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Set:"Set",If:"If",For:"For",In:"In",Is:"Is",NotIn:"NotIn",Else:"Else",EndSet:"EndSet",EndIf:"EndIf",ElseIf:"ElseIf",EndFor:"EndFor",And:"And",Or:"Or",Not:"UnaryOperator",Macro:"Macro",EndMacro:"EndMacro",Break:"Break",Continue:"Continue"}),o=Object.freeze({set:r.Set,for:r.For,in:r.In,is:r.Is,if:r.If,else:r.Else,endset:r.EndSet,endif:r.EndIf,elif:r.ElseIf,endfor:r.EndFor,and:r.And,or:r.Or,not:r.Not,"not in":r.NotIn,macro:r.Macro,endmacro:r.EndMacro,break:r.Break,continue:r.Continue,true:r.BooleanLiteral,false:r.BooleanLiteral,none:r.NullLiteral,True:r.BooleanLiteral,False:r.BooleanLiteral,None:r.NullLiteral}),n=class{constructor(e,t){this.value=e,this.type=t}};function i(e){return/\w/.test(e)}function a(e){return/[0-9]/.test(e)}var l=[["{%",r.OpenStatement],["%}",r.CloseStatement],["{{",r.OpenExpression],["}}",r.CloseExpression],["(",r.OpenParen],[")",r.CloseParen],["{",r.OpenCurlyBracket],["}",r.CloseCurlyBracket],["[",r.OpenSquareBracket],["]",r.CloseSquareBracket],[",",r.Comma],[".",r.Dot],[":",r.Colon],["|",r.Pipe],["<=",r.ComparisonBinaryOperator],[">=",r.ComparisonBinaryOperator],["==",r.ComparisonBinaryOperator],["!=",r.ComparisonBinaryOperator],["<",r.ComparisonBinaryOperator],[">",r.ComparisonBinaryOperator],["+",r.AdditiveBinaryOperator],["-",r.AdditiveBinaryOperator],["*",r.MultiplicativeBinaryOperator],["/",r.MultiplicativeBinaryOperator],["%",r.MultiplicativeBinaryOperator],["=",r.Equals]],c=new Map([["n","\n"],["t","\t"],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function d(e,t={}){const s=[],d=function(e,t={}){return e.endsWith("\n")&&(e=e.slice(0,-1)),e=e.replace(/{#.*?#}/gs,"{##}"),t.lstrip_blocks&&(e=e.replace(/^[ \t]*({[#%])/gm,"$1")),t.trim_blocks&&(e=e.replace(/([#%]})\n/g,"$1")),e.replace(/{##}/g,"").replace(/-%}\s*/g,"%}").replace(/\s*{%-/g,"{%").replace(/-}}\s*/g,"}}").replace(/\s*{{-/g,"{{")}(e,t);let u=0;const _=e=>{let t="";for(;e(d[u]);)if("\\"!==d[u]){if(t+=d[u++],u>=d.length)throw new SyntaxError("Unexpected end of input")}else{if(++u,u>=d.length)throw new SyntaxError("Unexpected end of input");const e=d[u++],s=c.get(e);if(void 0===s)throw new SyntaxError(`Unexpected escaped character: ${e}`);t+=s}return t};e:for(;u<d.length;){const e=s.at(-1)?.type;if(void 0===e||e===r.CloseStatement||e===r.CloseExpression){let e="";for(;u<d.length&&("{"!==d[u]||"%"!==d[u+1]&&"{"!==d[u+1]);)e+=d[u++];if(e.length>0){s.push(new n(e,r.Text));continue}}_((e=>/\s/.test(e)));const t=d[u];if("-"===t||"+"===t){const e=s.at(-1)?.type;if(e===r.Text||void 0===e)throw new SyntaxError(`Unexpected character: ${t}`);switch(e){case r.Identifier:case r.NumericLiteral:case r.BooleanLiteral:case r.NullLiteral:case r.StringLiteral:case r.CloseParen:case r.CloseSquareBracket:break;default:{++u;const e=_(a);s.push(new n(`${t}${e}`,e.length>0?r.NumericLiteral:r.UnaryOperator));continue}}}for(const[e,t]of l){if(d.slice(u,u+e.length)===e){s.push(new n(e,t)),u+=e.length;continue e}}if("'"!==t&&'"'!==t)if(a(t)){const e=_(a);s.push(new n(e,r.NumericLiteral))}else{if(!i(t))throw new SyntaxError(`Unexpected character: ${t}`);{const e=_(i),t=Object.hasOwn(o,e)?o[e]:r.Identifier;t===r.In&&s.at(-1)?.type===r.Not?(s.pop(),s.push(new n("not in",r.NotIn))):s.push(new n(e,t))}}else{++u;const e=_((e=>e!==t));s.push(new n(e,r.StringLiteral)),++u}}return s}var u=class{type="Statement"},_=class extends u{constructor(e){super(),this.body=e}type="Program"},p=class extends u{constructor(e,t,s){super(),this.test=e,this.body=t,this.alternate=s}type="If"},m=class extends u{constructor(e,t,s,r){super(),this.loopvar=e,this.iterable=t,this.body=s,this.defaultBlock=r}type="For"},h=class extends u{type="Break"},g=class extends u{type="Continue"},f=class extends u{constructor(e,t,s){super(),this.assignee=e,this.value=t,this.body=s}type="Set"},w=class extends u{constructor(e,t,s){super(),this.name=e,this.args=t,this.body=s}type="Macro"},M=class extends u{type="Expression"},x=class extends M{constructor(e,t,s){super(),this.object=e,this.property=t,this.computed=s}type="MemberExpression"},b=class extends M{constructor(e,t){super(),this.callee=e,this.args=t}type="CallExpression"},k=class extends M{constructor(e){super(),this.value=e}type="Identifier"},y=class extends M{constructor(e){super(),this.value=e}type="Literal"},v=class extends y{type="NumericLiteral"},T=class extends y{type="StringLiteral"},P=class extends y{type="BooleanLiteral"},F=class extends y{type="NullLiteral"},C=class extends y{type="ArrayLiteral"},S=class extends y{type="TupleLiteral"},A=class extends y{type="ObjectLiteral"},E=class extends M{constructor(e,t,s){super(),this.operator=e,this.left=t,this.right=s}type="BinaryExpression"},L=class extends M{constructor(e,t){super(),this.operand=e,this.filter=t}type="FilterExpression"},I=class extends M{constructor(e,t){super(),this.iterable=e,this.test=t}type="SelectExpression"},z=class extends M{constructor(e,t,s){super(),this.operand=e,this.negate=t,this.test=s}type="TestExpression"},j=class extends M{constructor(e,t){super(),this.operator=e,this.argument=t}type="UnaryExpression"},D=class extends M{constructor(e=void 0,t=void 0,s=void 0){super(),this.start=e,this.stop=t,this.step=s}type="SliceExpression"},O=class extends M{constructor(e,t){super(),this.key=e,this.value=t}type="KeywordArgumentExpression"};function N(e){const t=new _([]);let s=0;function o(t,r){const o=e[s++];if(!o||o.type!==t)throw new Error(`Parser Error: ${r}. ${o.type} !== ${t}.`);return o}function n(){switch(e[s].type){case r.Text:return new T(o(r.Text,"Expected text token").value);case r.OpenStatement:return function(){let t;switch(o(r.OpenStatement,"Expected opening statement token"),e[s].type){case r.Set:++s,t=function(){const t=d();if(a(r.Equals)){++s;const e=d();return new f(t,e,[])}{const i=[];for(o(r.CloseStatement,"Expected %} token");e[s]?.type!==r.OpenStatement||e[s+1]?.type!==r.EndSet;){const e=n();i.push(e)}return o(r.OpenStatement,"Expected {% token"),o(r.EndSet,"Expected endset token"),new f(t,null,i)}}(),o(r.CloseStatement,"Expected closing statement token");break;case r.If:++s,t=l(),o(r.OpenStatement,"Expected {% token"),o(r.EndIf,"Expected endif token"),o(r.CloseStatement,"Expected %} token");break;case r.Macro:++s,t=function(){const e=W();if("Identifier"!==e.type)throw new SyntaxError("Expected identifier following macro statement");const t=B();o(r.CloseStatement,"Expected closing statement token");const s=[];for(;i(r.OpenStatement,r.EndMacro);)s.push(n());return new w(e,t,s)}(),o(r.OpenStatement,"Expected {% token"),o(r.EndMacro,"Expected endmacro token"),o(r.CloseStatement,"Expected %} token");break;case r.For:++s,t=function(){const e=c(!0);if(!(e instanceof k||e instanceof S))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);o(r.In,"Expected `in` keyword following loop variable");const t=d();o(r.CloseStatement,"Expected closing statement token");const l=[];for(;i(r.OpenStatement,r.EndFor)&&i(r.OpenStatement,r.Else);)l.push(n());const u=[];if(a(r.OpenStatement,r.Else))for(++s,++s,o(r.CloseStatement,"Expected closing statement token");i(r.OpenStatement,r.EndFor);)u.push(n());return new m(e,t,l,u)}(),o(r.OpenStatement,"Expected {% token"),o(r.EndFor,"Expected endfor token"),o(r.CloseStatement,"Expected %} token");break;case r.Break:++s,o(r.CloseStatement,"Expected closing statement token"),t=new h;break;case r.Continue:++s,o(r.CloseStatement,"Expected closing statement token"),t=new g;break;default:throw new SyntaxError(`Unknown statement type: ${e[s].type}`)}return t}();case r.OpenExpression:return function(){o(r.OpenExpression,"Expected opening expression token");const e=d();return o(r.CloseExpression,"Expected closing expression token"),e}();default:throw new SyntaxError(`Unexpected token type: ${e[s].type}`)}}function i(...t){return s+t.length<=e.length&&t.some(((t,r)=>t!==e[s+r].type))}function a(...t){return s+t.length<=e.length&&t.every(((t,r)=>t===e[s+r].type))}function l(){const t=d();o(r.CloseStatement,"Expected closing statement token");const i=[],c=[];for(;e[s]?.type!==r.OpenStatement||e[s+1]?.type!==r.ElseIf&&e[s+1]?.type!==r.Else&&e[s+1]?.type!==r.EndIf;)i.push(n());if(e[s]?.type===r.OpenStatement&&e[s+1]?.type!==r.EndIf)if(++s,a(r.ElseIf))o(r.ElseIf,"Expected elseif token"),c.push(l());else for(o(r.Else,"Expected else token"),o(r.CloseStatement,"Expected closing statement token");e[s]?.type!==r.OpenStatement||e[s+1]?.type!==r.EndIf;)c.push(n());return new p(t,i,c)}function c(e=!1){const t=e?W:d,o=[t()],n=a(r.Comma);for(;n&&(++s,o.push(t()),a(r.Comma)););return n?new S(o):o[0]}function d(){return function(){const e=u();if(a(r.If)){++s;const t=u();if(a(r.Else)){++s;const r=u();return new p(t,[e],[r])}return new I(e,t)}return e}()}function u(){let t=M();for(;a(r.Or);){const r=e[s];++s;const o=M();t=new E(r,t,o)}return t}function M(){let t=y();for(;a(r.And);){const r=e[s];++s;const o=y();t=new E(r,t,o)}return t}function y(){let t;for(;a(r.Not);){const r=e[s];++s;const o=y();t=new j(r,o)}return t??function(){let t=N();for(;a(r.ComparisonBinaryOperator)||a(r.In)||a(r.NotIn);){const r=e[s];++s;const o=N();t=new E(r,t,o)}return t}()}function N(){let t=$();for(;a(r.AdditiveBinaryOperator);){const r=e[s];++s;const o=$();t=new E(r,t,o)}return t}function V(e){let t=new b(e,B());return t=R(t),a(r.OpenParen)&&(t=V(t)),t}function B(){o(r.OpenParen,"Expected opening parenthesis for arguments list");const e=function(){const e=[];for(;!a(r.CloseParen);){let t=d();if(a(r.Equals)){if(++s,!(t instanceof k))throw new SyntaxError("Expected identifier for keyword argument");const e=d();t=new O(t,e)}e.push(t),a(r.Comma)&&++s}return e}();return o(r.CloseParen,"Expected closing parenthesis for arguments list"),e}function G(){const e=[];let t=!1;for(;!a(r.CloseSquareBracket);)a(r.Colon)?(e.push(void 0),++s,t=!0):(e.push(d()),a(r.Colon)&&(++s,t=!0));if(0===e.length)throw new SyntaxError("Expected at least one argument for member/slice expression");if(t){if(e.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new D(...e)}return e[0]}function R(t){for(;a(r.Dot)||a(r.OpenSquareBracket);){const n=e[s];let i;++s;const a=n.type!==r.Dot;if(a)i=G(),o(r.CloseSquareBracket,"Expected closing square bracket");else if(i=W(),"Identifier"!==i.type)throw new SyntaxError("Expected identifier following dot operator");t=new x(t,i,a)}return t}function $(){let t=q();for(;a(r.MultiplicativeBinaryOperator);){const r=e[s];++s;const o=q();t=new E(r,t,o)}return t}function q(){let e=function(){let e=function(){const e=R(W());return a(r.OpenParen)?V(e):e}();for(;a(r.Pipe);){++s;let t=W();if(!(t instanceof k))throw new SyntaxError("Expected identifier for the filter");a(r.OpenParen)&&(t=V(t)),e=new L(e,t)}return e}();for(;a(r.Is);){++s;const t=a(r.Not);t&&++s;let o=W();if(o instanceof P?o=new k(o.value.toString()):o instanceof F&&(o=new k("none")),!(o instanceof k))throw new SyntaxError("Expected identifier for the test");e=new z(e,t,o)}return e}function W(){const t=e[s];switch(t.type){case r.NumericLiteral:return++s,new v(Number(t.value));case r.StringLiteral:return++s,new T(t.value);case r.BooleanLiteral:return++s,new P("true"===t.value.toLowerCase());case r.NullLiteral:return++s,new F(null);case r.Identifier:return++s,new k(t.value);case r.OpenParen:{++s;const t=c();if(e[s].type!==r.CloseParen)throw new SyntaxError(`Expected closing parenthesis, got ${e[s].type} instead`);return++s,t}case r.OpenSquareBracket:{++s;const e=[];for(;!a(r.CloseSquareBracket);)e.push(d()),a(r.Comma)&&++s;return++s,new C(e)}case r.OpenCurlyBracket:{++s;const e=new Map;for(;!a(r.CloseCurlyBracket);){const t=d();o(r.Colon,"Expected colon between key and value in object literal");const n=d();e.set(t,n),a(r.Comma)&&++s}return++s,new A(e)}default:throw new SyntaxError(`Unexpected token: ${t.type}`)}}for(;s<e.length;)t.body.push(n());return t}function V(e,t,s=1){void 0===t&&(t=e,e=0);const r=[];for(let o=e;o<t;o+=s)r.push(o);return r}function B(e,t,s,r=1){const o=Math.sign(r);o>=0?(t=(t??=0)<0?Math.max(e.length+t,0):Math.min(t,e.length),s=(s??=e.length)<0?Math.max(e.length+s,0):Math.min(s,e.length)):(t=(t??=e.length-1)<0?Math.max(e.length+t,-1):Math.min(t,e.length-1),s=(s??=-1)<-1?Math.max(e.length+s,-1):Math.min(s,e.length-1));const n=[];for(let i=t;o*i<o*s;i+=r)n.push(e[i]);return n}function G(e){return e.replace(/\b\w/g,(e=>e.toUpperCase()))}var R=class extends Error{},$=class extends Error{},q=class{type="RuntimeValue";value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new Q(!!this.value)}},W=class extends q{type="NumericValue"},U=class extends q{type="StringValue";builtins=new Map([["upper",new K((()=>new U(this.value.toUpperCase())))],["lower",new K((()=>new U(this.value.toLowerCase())))],["strip",new K((()=>new U(this.value.trim())))],["title",new K((()=>new U(G(this.value))))],["length",new W(this.value.length)],["rstrip",new K((()=>new U(this.value.trimEnd())))],["lstrip",new K((()=>new U(this.value.trimStart())))],["startswith",new K((e=>{if(0===e.length)throw new Error("startswith() requires at least one argument");const t=e[0];if(!(t instanceof U))throw new Error("startswith() argument must be a string");return new Q(this.value.startsWith(t.value))}))],["endswith",new K((e=>{if(0===e.length)throw new Error("endswith() requires at least one argument");const t=e[0];if(!(t instanceof U))throw new Error("endswith() argument must be a string");return new Q(this.value.endsWith(t.value))}))],["split",new K((e=>{const t=e[0]??new Z;if(!(t instanceof U||t instanceof Z))throw new Error("sep argument must be a string or null");const s=e[1]??new W(-1);if(!(s instanceof W))throw new Error("maxsplit argument must be a number");let r=[];if(t instanceof Z){const e=this.value.trimStart();for(const{0:t,index:o}of e.matchAll(/\S+/g)){if(-1!==s.value&&r.length>=s.value&&void 0!==o){r.push(t+e.slice(o+t.length));break}r.push(t)}}else{if(""===t.value)throw new Error("empty separator");r=this.value.split(t.value),-1!==s.value&&r.length>s.value&&r.push(r.splice(s.value).join(t.value))}return new J(r.map((e=>new U(e))))}))]])},Q=class extends q{type="BooleanValue"},X=class extends q{type="ObjectValue";__bool__(){return new Q(this.value.size>0)}builtins=new Map([["get",new K((([e,t])=>{if(!(e instanceof U))throw new Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new Z}))],["items",new K((()=>new J(Array.from(this.value.entries()).map((([e,t])=>new J([new U(e),t]))))))]])},H=class extends X{type="KeywordArgumentsValue"},J=class extends q{type="ArrayValue";builtins=new Map([["length",new W(this.value.length)]]);__bool__(){return new Q(this.value.length>0)}},Y=class extends J{type="TupleValue"},K=class extends q{type="FunctionValue"},Z=class extends q{type="NullValue"},ee=class extends q{type="UndefinedValue"},te=class{constructor(e){this.parent=e}variables=new Map([["namespace",new K((e=>{if(0===e.length)return new X(new Map);if(1!==e.length||!(e[0]instanceof X))throw new Error("`namespace` expects either zero arguments or a single object argument");return e[0]}))]]);tests=new Map([["boolean",e=>"BooleanValue"===e.type],["callable",e=>e instanceof K],["odd",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "odd" to type: ${e.type}`);return e.value%2!=0}],["even",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "even" to type: ${e.type}`);return e.value%2==0}],["false",e=>"BooleanValue"===e.type&&!e.value],["true",e=>"BooleanValue"===e.type&&e.value],["none",e=>"NullValue"===e.type],["string",e=>"StringValue"===e.type],["number",e=>"NumericValue"===e.type],["integer",e=>"NumericValue"===e.type&&Number.isInteger(e.value)],["iterable",e=>"ArrayValue"===e.type||"StringValue"===e.type],["mapping",e=>"ObjectValue"===e.type],["lower",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toLowerCase()}],["upper",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toUpperCase()}],["none",e=>"NullValue"===e.type],["defined",e=>"UndefinedValue"!==e.type],["undefined",e=>"UndefinedValue"===e.type],["equalto",(e,t)=>e.value===t.value],["eq",(e,t)=>e.value===t.value]]);set(e,t){return this.declareVariable(e,re(t))}declareVariable(e,t){if(this.variables.has(e))throw new SyntaxError(`Variable already declared: ${e}`);return this.variables.set(e,t),t}setVariable(e,t){return this.variables.set(e,t),t}resolve(e){if(this.variables.has(e))return this;if(this.parent)return this.parent.resolve(e);throw new Error(`Unknown variable: ${e}`)}lookupVariable(e){try{return this.resolve(e).variables.get(e)??new ee}catch{return new ee}}},se=class{global;constructor(e){this.global=e??new te}run(e){return this.evaluate(e,this.global)}evaluateBinaryExpression(e,t){const s=this.evaluate(e.left,t);switch(e.operator.value){case"and":return s.__bool__().value?this.evaluate(e.right,t):s;case"or":return s.__bool__().value?s:this.evaluate(e.right,t)}const r=this.evaluate(e.right,t);switch(e.operator.value){case"==":return new Q(s.value==r.value);case"!=":return new Q(s.value!=r.value)}if(s instanceof ee||r instanceof ee)throw new Error("Cannot perform operation on undefined values");if(s instanceof Z||r instanceof Z)throw new Error("Cannot perform operation on null values");if(s instanceof W&&r instanceof W)switch(e.operator.value){case"+":return new W(s.value+r.value);case"-":return new W(s.value-r.value);case"*":return new W(s.value*r.value);case"/":return new W(s.value/r.value);case"%":return new W(s.value%r.value);case"<":return new Q(s.value<r.value);case">":return new Q(s.value>r.value);case">=":return new Q(s.value>=r.value);case"<=":return new Q(s.value<=r.value)}else if(s instanceof J&&r instanceof J){if("+"===e.operator.value)return new J(s.value.concat(r.value))}else if(r instanceof J){const t=void 0!==r.value.find((e=>e.value===s.value));switch(e.operator.value){case"in":return new Q(t);case"not in":return new Q(!t)}}if((s instanceof U||r instanceof U)&&"+"===e.operator.value)return new U(s.value.toString()+r.value.toString());if(s instanceof U&&r instanceof U)switch(e.operator.value){case"in":return new Q(r.value.includes(s.value));case"not in":return new Q(!r.value.includes(s.value))}if(s instanceof U&&r instanceof X)switch(e.operator.value){case"in":return new Q(r.value.has(s.value));case"not in":return new Q(!r.value.has(s.value))}throw new SyntaxError(`Unknown operator "${e.operator.value}" between ${s.type} and ${r.type}`)}evaluateArguments(e,t){const s=[],r=new Map;for(const o of e)if("KeywordArgumentExpression"===o.type){const e=o;r.set(e.key.value,this.evaluate(e.value,t))}else{if(r.size>0)throw new Error("Positional arguments must come before keyword arguments");s.push(this.evaluate(o,t))}return[s,r]}evaluateFilterExpression(e,t){const s=this.evaluate(e.operand,t);if("Identifier"===e.filter.type){const t=e.filter;if("tojson"===t.value)return new U(oe(s));if(s instanceof J)switch(t.value){case"list":return s;case"first":return s.value[0];case"last":return s.value[s.value.length-1];case"length":return new W(s.value.length);case"reverse":return new J(s.value.reverse());case"sort":return new J(s.value.sort(((e,t)=>{if(e.type!==t.type)throw new Error(`Cannot compare different types: ${e.type} and ${t.type}`);switch(e.type){case"NumericValue":return e.value-t.value;case"StringValue":return e.value.localeCompare(t.value);default:throw new Error(`Cannot compare type: ${e.type}`)}})));case"join":return new U(s.value.map((e=>e.value)).join(""));case"string":return new U(oe(s));default:throw new Error(`Unknown ArrayValue filter: ${t.value}`)}else if(s instanceof U)switch(t.value){case"length":return new W(s.value.length);case"upper":return new U(s.value.toUpperCase());case"lower":return new U(s.value.toLowerCase());case"title":return new U(G(s.value));case"capitalize":return new U(s.value.charAt(0).toUpperCase()+s.value.slice(1));case"trim":return new U(s.value.trim());case"indent":return new U(s.value.split("\n").map(((e,t)=>0===t||0===e.length?e:" "+e)).join("\n"));case"join":case"string":return s;default:throw new Error(`Unknown StringValue filter: ${t.value}`)}else{if(s instanceof W){if("abs"===t.value)return new W(Math.abs(s.value));throw new Error(`Unknown NumericValue filter: ${t.value}`)}if(s instanceof X)switch(t.value){case"items":return new J(Array.from(s.value.entries()).map((([e,t])=>new J([new U(e),t]))));case"length":return new W(s.value.size);default:throw new Error(`Unknown ObjectValue filter: ${t.value}`)}}throw new Error(`Cannot apply filter "${t.value}" to type: ${s.type}`)}if("CallExpression"===e.filter.type){const r=e.filter;if("Identifier"!==r.callee.type)throw new Error(`Unknown filter: ${r.callee.type}`);const o=r.callee.value;if("tojson"===o){const[,e]=this.evaluateArguments(r.args,t),o=e.get("indent")??new Z;if(!(o instanceof W||o instanceof Z))throw new Error("If set, indent must be a number");return new U(oe(s,o.value))}if("join"===o){let e;if(s instanceof U)e=Array.from(s.value);else{if(!(s instanceof J))throw new Error(`Cannot apply filter "${o}" to type: ${s.type}`);e=s.value.map((e=>e.value))}const[n,i]=this.evaluateArguments(r.args,t),a=n.at(0)??i.get("separator")??new U("");if(!(a instanceof U))throw new Error("separator must be a string");return new U(e.join(a.value))}if(s instanceof J){switch(o){case"selectattr":case"rejectattr":{const e="selectattr"===o;if(s.value.some((e=>!(e instanceof X))))throw new Error(`\`${o}\` can only be applied to array of objects`);if(r.args.some((e=>"StringLiteral"!==e.type)))throw new Error(`arguments of \`${o}\` must be strings`);const[n,i,a]=r.args.map((e=>this.evaluate(e,t)));let l;if(i){const e=t.tests.get(i.value);if(!e)throw new Error(`Unknown test: ${i.value}`);l=e}else l=(...e)=>e[0].__bool__().value;const c=s.value.filter((t=>{const s=t.value.get(n.value),r=!!s&&l(s,a);return e?r:!r}));return new J(c)}case"map":{const[,e]=this.evaluateArguments(r.args,t);if(e.has("attribute")){const t=e.get("attribute");if(!(t instanceof U))throw new Error("attribute must be a string");const r=e.get("default"),o=s.value.map((e=>{if(!(e instanceof X))throw new Error("items in map must be an object");return e.value.get(t.value)??r??new ee}));return new J(o)}throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${o}`)}if(s instanceof U){if("indent"===o){const[e,o]=this.evaluateArguments(r.args,t),n=e.at(0)??o.get("width")??new W(4);if(!(n instanceof W))throw new Error("width must be a number");const i=e.at(1)??o.get("first")??new Q(!1),a=e.at(2)??o.get("blank")??new Q(!1),l=s.value.split("\n"),c=" ".repeat(n.value),d=l.map(((e,t)=>!i.value&&0===t||!a.value&&0===e.length?e:c+e));return new U(d.join("\n"))}throw new Error(`Unknown StringValue filter: ${o}`)}throw new Error(`Cannot apply filter "${o}" to type: ${s.type}`)}throw new Error(`Unknown filter: ${e.filter.type}`)}evaluateTestExpression(e,t){const s=this.evaluate(e.operand,t),r=t.tests.get(e.test.value);if(!r)throw new Error(`Unknown test: ${e.test.value}`);const o=r(s);return new Q(e.negate?!o:o)}evaluateUnaryExpression(e,t){const s=this.evaluate(e.argument,t);if("not"===e.operator.value)return new Q(!s.value);throw new SyntaxError(`Unknown operator: ${e.operator.value}`)}evalProgram(e,t){return this.evaluateBlock(e.body,t)}evaluateBlock(e,t){let s="";for(const r of e){const e=this.evaluate(r,t);"NullValue"!==e.type&&"UndefinedValue"!==e.type&&(s+=e.value)}return new U(s)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){const[s,r]=this.evaluateArguments(e.args,t);r.size>0&&s.push(new H(r));const o=this.evaluate(e.callee,t);if("FunctionValue"!==o.type)throw new Error(`Cannot call something that is not a function: got ${o.type}`);return o.value(s,t)}evaluateSliceExpression(e,t,s){if(!(e instanceof J||e instanceof U))throw new Error("Slice object must be an array or string");const r=this.evaluate(t.start,s),o=this.evaluate(t.stop,s),n=this.evaluate(t.step,s);if(!(r instanceof W||r instanceof ee))throw new Error("Slice start must be numeric or undefined");if(!(o instanceof W||o instanceof ee))throw new Error("Slice stop must be numeric or undefined");if(!(n instanceof W||n instanceof ee))throw new Error("Slice step must be numeric or undefined");return e instanceof J?new J(B(e.value,r.value,o.value,n.value)):new U(B(Array.from(e.value),r.value,o.value,n.value).join(""))}evaluateMemberExpression(e,t){const s=this.evaluate(e.object,t);let r,o;if(e.computed){if("SliceExpression"===e.property.type)return this.evaluateSliceExpression(s,e.property,t);r=this.evaluate(e.property,t)}else r=new U(e.property.value);if(s instanceof X){if(!(r instanceof U))throw new Error(`Cannot access property with non-string: got ${r.type}`);o=s.value.get(r.value)??s.builtins.get(r.value)}else if(s instanceof J||s instanceof U)if(r instanceof W)o=s.value.at(r.value),s instanceof U&&(o=new U(s.value.at(r.value)));else{if(!(r instanceof U))throw new Error(`Cannot access property with non-string/non-number: got ${r.type}`);o=s.builtins.get(r.value)}else{if(!(r instanceof U))throw new Error(`Cannot access property with non-string: got ${r.type}`);o=s.builtins.get(r.value)}return o instanceof q?o:new ee}evaluateSet(e,t){const s=e.value?this.evaluate(e.value,t):this.evaluateBlock(e.body,t);if("Identifier"===e.assignee.type){const r=e.assignee.value;t.setVariable(r,s)}else{if("MemberExpression"!==e.assignee.type)throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);{const r=e.assignee,o=this.evaluate(r.object,t);if(!(o instanceof X))throw new Error("Cannot assign to member of non-object");if("Identifier"!==r.property.type)throw new Error("Cannot assign to member with non-identifier property");o.value.set(r.property.value,s)}}return new Z}evaluateIf(e,t){const s=this.evaluate(e.test,t);return this.evaluateBlock(s.__bool__().value?e.body:e.alternate,t)}evaluateFor(e,t){const s=new te(t);let r,o;if("SelectExpression"===e.iterable.type){const t=e.iterable;o=this.evaluate(t.iterable,s),r=t.test}else o=this.evaluate(e.iterable,s);if(!(o instanceof J))throw new Error(`Expected iterable type in for loop: got ${o.type}`);const n=[],i=[];for(let t=0;t<o.value.length;++t){const a=new te(s),l=o.value[t];let c;if("Identifier"===e.loopvar.type)c=t=>t.setVariable(e.loopvar.value,l);else{if("TupleLiteral"!==e.loopvar.type)throw new Error(`Invalid loop variable(s): ${e.loopvar.type}`);{const t=e.loopvar;if("ArrayValue"!==l.type)throw new Error(`Cannot unpack non-iterable type: ${l.type}`);const s=l;if(t.value.length!==s.value.length)throw new Error(`Too ${t.value.length>s.value.length?"few":"many"} items to unpack`);c=e=>{for(let r=0;r<t.value.length;++r){if("Identifier"!==t.value[r].type)throw new Error(`Cannot unpack non-identifier type: ${t.value[r].type}`);e.setVariable(t.value[r].value,s.value[r])}}}}if(r){c(a);if(!this.evaluate(r,a).__bool__().value)continue}n.push(l),i.push(c)}let a="",l=!0;for(let t=0;t<n.length;++t){const r=new Map([["index",new W(t+1)],["index0",new W(t)],["revindex",new W(n.length-t)],["revindex0",new W(n.length-t-1)],["first",new Q(0===t)],["last",new Q(t===n.length-1)],["length",new W(n.length)],["previtem",t>0?n[t-1]:new ee],["nextitem",t<n.length-1?n[t+1]:new ee]]);s.setVariable("loop",new X(r)),i[t](s);try{a+=this.evaluateBlock(e.body,s).value}catch(e){if(e instanceof $)continue;if(e instanceof R)break;throw e}l=!1}if(l){a+=this.evaluateBlock(e.defaultBlock,s).value}return new U(a)}evaluateMacro(e,t){return t.setVariable(e.name.value,new K(((t,s)=>{const r=new te(s);let o;t=t.slice(),"KeywordArgumentsValue"===t.at(-1)?.type&&(o=t.pop());for(let s=0;s<e.args.length;++s){const n=e.args[s],i=t[s];if("Identifier"===n.type){const e=n;if(!i)throw new Error(`Missing positional argument: ${e.value}`);r.setVariable(e.value,i)}else{if("KeywordArgumentExpression"!==n.type)throw new Error(`Unknown argument type: ${n.type}`);{const e=n,t=i??o?.value.get(e.key.value)??this.evaluate(e.value,r);r.setVariable(e.key.value,t)}}}return this.evaluateBlock(e.body,r)}))),new Z}evaluate(e,t){if(void 0===e)return new ee;switch(e.type){case"Program":return this.evalProgram(e,t);case"Set":return this.evaluateSet(e,t);case"If":return this.evaluateIf(e,t);case"For":return this.evaluateFor(e,t);case"Macro":return this.evaluateMacro(e,t);case"Break":throw new R;case"Continue":throw new $;case"NumericLiteral":return new W(Number(e.value));case"StringLiteral":return new U(e.value);case"BooleanLiteral":return new Q(e.value);case"NullLiteral":return new Z(e.value);case"ArrayLiteral":return new J(e.value.map((e=>this.evaluate(e,t))));case"TupleLiteral":return new Y(e.value.map((e=>this.evaluate(e,t))));case"ObjectLiteral":{const s=new Map;for(const[r,o]of e.value){const e=this.evaluate(r,t);if(!(e instanceof U))throw new Error(`Object keys must be strings: got ${e.type}`);s.set(e.value,this.evaluate(o,t))}return new X(s)}case"Identifier":return this.evaluateIdentifier(e,t);case"CallExpression":return this.evaluateCallExpression(e,t);case"MemberExpression":return this.evaluateMemberExpression(e,t);case"UnaryExpression":return this.evaluateUnaryExpression(e,t);case"BinaryExpression":return this.evaluateBinaryExpression(e,t);case"FilterExpression":return this.evaluateFilterExpression(e,t);case"TestExpression":return this.evaluateTestExpression(e,t);default:throw new SyntaxError(`Unknown node type: ${e.type}`)}}};function re(e){switch(typeof e){case"number":return new W(e);case"string":return new U(e);case"boolean":return new Q(e);case"undefined":return new ee;case"object":return null===e?new Z:Array.isArray(e)?new J(e.map(re)):new X(new Map(Object.entries(e).map((([e,t])=>[e,re(t)]))));case"function":return new K(((t,s)=>re(e(...t.map((e=>e.value)))??null)));default:throw new Error(`Cannot convert to runtime value: ${e}`)}}function oe(e,t,s){const r=s??0;switch(e.type){case"NullValue":case"UndefinedValue":return"null";case"NumericValue":case"StringValue":case"BooleanValue":return JSON.stringify(e.value);case"ArrayValue":case"ObjectValue":{const s=t?" ".repeat(t):"",o="\n"+s.repeat(r),n=o+s;if("ArrayValue"===e.type){const s=e.value.map((e=>oe(e,t,r+1)));return t?`[${n}${s.join(`,${n}`)}${o}]`:`[${s.join(", ")}]`}{const s=Array.from(e.value.entries()).map((([e,s])=>{const o=`"${e}": ${oe(s,t,r+1)}`;return t?`${n}${o}`:o}));return t?`{${s.join(",")}${o}}`:`{${s.join(", ")}}`}}default:throw new Error(`Cannot convert to JSON: ${e.type}`)}}var ne="\n",ie="{%- ",ae=" -%}",le={MultiplicativeBinaryOperator:2,AdditiveBinaryOperator:1,ComparisonBinaryOperator:0};function ce(...e){return ie+e.join(" ")+ae}function de(e,t,s){return e.map((e=>function(e,t,s){const r=s.repeat(t);switch(e.type){case"Program":return de(e.body,t,s);case"If":return function(e,t,s){const r=s.repeat(t),o=[];let n=e;for(;n&&(o.push({test:n.test,body:n.body}),1===n.alternate.length&&"If"===n.alternate[0].type);)n=n.alternate[0];let i=r+ce("if",ue(o[0].test))+ne+de(o[0].body,t+1,s);for(let e=1;e<o.length;e++)i+=ne+r+ce("elif",ue(o[e].test))+ne+de(o[e].body,t+1,s);n&&n.alternate.length>0&&(i+=ne+r+ce("else")+ne+de(n.alternate,t+1,s));return i+=ne+r+ce("endif"),i}(e,t,s);case"For":return function(e,t,s){const r=s.repeat(t);let o="";if("SelectExpression"===e.iterable.type){const t=e.iterable;o=`${ue(t.iterable)} if ${ue(t.test)}`}else o=ue(e.iterable);let n=r+ce("for",ue(e.loopvar),"in",o)+ne+de(e.body,t+1,s);e.defaultBlock.length>0&&(n+=ne+r+ce("else")+ne+de(e.defaultBlock,t+1,s));return n+=ne+r+ce("endfor"),n}(e,t,s);case"Set":return function(e,t,s){const r=s.repeat(t),o=ue(e.assignee),n=e.value?ue(e.value):"",i=r+ce("set",`${o}${e.value?" = "+n:""}`);if(0===e.body.length)return i;return i+ne+de(e.body,t+1,s)+ne+r+ce("endset")}(e,t,s);case"Macro":return function(e,t,s){const r=s.repeat(t),o=e.args.map(ue).join(", ");return r+ce("macro",`${e.name.value}(${o})`)+ne+de(e.body,t+1,s)+ne+r+ce("endmacro")}(e,t,s);case"Break":return r+ce("break");case"Continue":return r+ce("continue");default:return r+"{{- "+ue(e)+" -}}"}}(e,t,s))).join(ne)}function ue(e,t=-1){switch(e.type){case"Identifier":return e.value;case"NullLiteral":return"none";case"NumericLiteral":case"BooleanLiteral":return`${e.value}`;case"StringLiteral":return JSON.stringify(e.value);case"BinaryExpression":{const s=e,r=le[s.operator.type]??0,o=ue(s.left,r),n=ue(s.right,r+1),i=`${o} ${s.operator.value} ${n}`;return r<t?`(${i})`:i}case"UnaryExpression":{const t=e;return t.operator.value+("not"===t.operator.value?" ":"")+ue(t.argument,1/0)}case"LogicalNegationExpression":return`not ${ue(e.argument,1/0)}`;case"CallExpression":{const t=e,s=t.args.map((e=>ue(e,-1))).join(", ");return`${ue(t.callee,-1)}(${s})`}case"MemberExpression":{const t=e;let s=ue(t.object,-1);"Identifier"!==t.object.type&&(s=`(${s})`);let r=ue(t.property,-1);return t.computed||"Identifier"===t.property.type||(r=`(${r})`),t.computed?`${s}[${r}]`:`${s}.${r}`}case"FilterExpression":{const t=e,s=ue(t.operand,1/0);return"CallExpression"===t.filter.type?`${s} | ${ue(t.filter,-1)}`:`${s} | ${t.filter.value}`}case"SelectExpression":{const t=e;return`${ue(t.iterable,-1)} | select(${ue(t.test,-1)})`}case"TestExpression":{const t=e;return`${ue(t.operand,-1)} is${t.negate?" not":""} ${t.test.value}`}case"ArrayLiteral":case"TupleLiteral":{const t=e.value.map((e=>ue(e,-1))),s="ArrayLiteral"===e.type?"[]":"()";return`${s[0]}${t.join(", ")}${s[1]}`}case"ObjectLiteral":return`{ ${Array.from(e.value.entries()).map((([e,t])=>`${ue(e,-1)}: ${ue(t,-1)}`)).join(", ")} }`;case"SliceExpression":{const t=e;return`${t.start?ue(t.start,-1):""}:${t.stop?ue(t.stop,-1):""}${t.step?`:${ue(t.step,-1)}`:""}`}case"KeywordArgumentExpression":{const t=e;return`${t.key.value}=${ue(t.value,-1)}`}case"If":{const t=e,s=ue(t.test,-1);return`${ue(t.body[0],0)} if ${s} else ${ue(t.alternate[0],-1)}`}default:throw new Error(`Unknown expression type: ${e.type}`)}}var _e=class{parsed;constructor(e){const t=d(e,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=N(t)}render(e){const t=new te;if(t.set("false",!1),t.set("true",!0),t.set("raise_exception",(e=>{throw new Error(e)})),t.set("range",V),e)for(const[s,r]of Object.entries(e))t.set(s,r);return new se(t).run(this.parsed).value}format(e){return function(e,t="\t"){const s="number"==typeof t?" ".repeat(t):t;return de(e.body,0,s).replace(/\n$/,"")}(this.parsed,e?.indent||"\t")}}},"./src/backends/onnx.js":(e,t,s)=>{"use strict";var r,o;s.r(t),s.d(t,{Tensor:()=>l.Tensor,createInferenceSession:()=>f,deviceToExecutionProviders:()=>h,isONNXProxy:()=>x,isONNXTensor:()=>w});var n=s("./src/env.js"),i=s("onnxruntime-node"),a=s("?8b6b"),l=s("onnxruntime-common");const c=Object.freeze({auto:null,gpu:null,cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",webnn:{name:"webnn",deviceType:"cpu"},"webnn-npu":{name:"webnn",deviceType:"npu"},"webnn-gpu":{name:"webnn",deviceType:"gpu"},"webnn-cpu":{name:"webnn",deviceType:"cpu"}}),d=[];let u,_;const p=Symbol.for("onnxruntime");if(p in globalThis)_=globalThis[p];else if(n.apis.IS_NODE_ENV){switch(_=i??(r||(r=s.t(i,2))),process.platform){case"win32":d.push("dml");break;case"linux":"x64"===process.arch&&d.push("cuda")}d.push("cpu"),u=["cpu"]}else _=o||(o=s.t(a,2)),n.apis.IS_WEBNN_AVAILABLE&&d.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),n.apis.IS_WEBGPU_AVAILABLE&&d.push("webgpu"),d.push("wasm"),u=["wasm"];const m=_.InferenceSession;function h(e=null){if(!e)return u;switch(e){case"auto":return d;case"gpu":return d.filter((e=>["webgpu","cuda","dml","webnn-gpu"].includes(e)))}if(d.includes(e))return[c[e]??e];throw new Error(`Unsupported device: "${e}". Should be one of: ${d.join(", ")}.`)}let g=null;async function f(e,t,s){g&&await g;const r=m.create(e,t);g??=r;const o=await r;return o.config=s,o}function w(e){return e instanceof _.Tensor}const M=_?.env;function x(){return M?.wasm?.proxy}M?.wasm&&("undefined"!=typeof ServiceWorkerGlobalScope&&self instanceof ServiceWorkerGlobalScope||M.wasm.wasmPaths||(M.wasm.wasmPaths=`https://cdn.jsdelivr.net/npm/@huggingface/transformers@${n.env.version}/dist/`),M.wasm.proxy=!1),M?.webgpu&&(M.webgpu.powerPreference="high-performance"),n.env.backends.onnx=M},"./src/base/feature_extraction_utils.js":(e,t,s)=>{"use strict";s.r(t),s.d(t,{FeatureExtractor:()=>i,validate_audio_inputs:()=>a});var r=s("./src/utils/constants.js"),o=s("./src/utils/generic.js"),n=s("./src/utils/hub.js");class i extends o.Callable{constructor(e){super(),this.config=e}static async from_pretrained(e,t={}){return new this(await(0,n.getModelJSON)(e,r.FEATURE_EXTRACTOR_NAME,!0,t))}}function a(e,t){if(!(e instanceof Float32Array||e instanceof Float64Array))throw new Error(`${t} 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.`)}},"./src/base/image_processors_utils.js":(e,t,s)=>{"use strict";s.r(t),s.d(t,{ImageProcessor:()=>M,center_to_corners_format:()=>u,post_process_instance_segmentation:()=>w,post_process_object_detection:()=>_,post_process_panoptic_segmentation:()=>f,post_process_semantic_segmentation:()=>p});var r=s("./src/utils/generic.js"),o=s("./src/utils/tensor.js"),n=s("./src/utils/maths.js"),i=(s("./src/utils/image.js"),s("./src/utils/core.js")),a=s("./src/utils/hub.js"),l=s("./src/utils/constants.js");function c(e,t,s=0,r=null){const o=e/t;let i=(0,n.bankers_round)(o)*t;return null!==r&&i>r&&(i=Math.floor(o)*t),i<s&&(i=Math.ceil(o)*t),i}function d([e,t],s){return[Math.max(Math.floor(e/s),1)*s,Math.max(Math.floor(t/s),1)*s]}function u([e,t,s,r]){return[e-s/2,t-r/2,e+s/2,t+r/2]}function _(e,t=.5,s=null,r=!1){const o=e.logits,i=e.pred_boxes,[a,l,c]=o.dims;if(null!==s&&s.length!==a)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<a;++e){let a=null!==s?s[e]:null,_={boxes:[],classes:[],scores:[]},p=o[e],m=i[e];for(let e=0;e<l;++e){let s,o=p[e],i=[];if(r){s=o.sigmoid().data;for(let e=0;e<s.length;++e)s[e]>t&&i.push(e)}else{let e=(0,n.max)(o.data)[1];if(e===c-1)continue;if(s=(0,n.softmax)(o.data),s[e]<t)continue;i.push(e)}for(const t of i){let r=m[e].data;r=u(r),null!==a&&(r=r.map(((e,t)=>e*a[(t+1)%2]))),_.boxes.push(r),_.classes.push(t),_.scores.push(s[t])}}d.push(_)}return d}function p(e,t=null){const s=e.logits,r=s.dims[0];if(null!==t&&t.length!==r)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");const n=[];for(let e=0;e<r;++e){const r=null!==t?t[e]:null;let i=s[e];null!==r&&(i=(0,o.interpolate)(i,r,"bilinear",!1));const[a,l]=r??i.dims.slice(-2),c=new o.Tensor("int32",new Int32Array(a*l),[a,l]),d=i[0].data,u=c.data;for(let e=1;e<i.dims[0];++e){const t=i[e].data;for(let s=0;s<t.length;++s)t[s]>d[s]&&(d[s]=t[s],u[s]=e)}const _=new Array(i.dims[0]);for(let e=0;e<u.length;++e){const t=u[e];_[t]=t}const p=_.filter((e=>void 0!==e));n.push({segmentation:c,labels:p})}return n}function m(e,t,s,r){const o=[],i=[],a=[];for(let l=0;l<e.dims[0];++l){const c=e[l],d=t[l],u=(0,n.max)(c.data)[1];if(u===r)continue;const _=(0,n.softmax)(c.data)[u];_>s&&(o.push(d),i.push(_),a.push(u))}return[o,i,a]}function h(e,t,s,r=.5,o=.8){const n=[];let i=0,a=0;const l=t[s].data;for(let t=0;t<e.length;++t)e[t]===s&&(n.push(t),++i),l[t]>=r&&++a;let c=i>0&&a>0;if(c){c=i/a>o}return[c,n]}function g(e,t,s,r,n,i=null,a=null){const[l,c]=a??e[0].dims,d=new o.Tensor("int32",new Int32Array(l*c),[l,c]),u=[];if(null!==a)for(let t=0;t<e.length;++t)e[t]=(0,o.interpolate)(e[t],a,"bilinear",!1);const _=new Int32Array(e[0].data.length),p=new Float32Array(e[0].data.length);for(let s=0;s<e.length;++s){let r=t[s];const o=e[s].data;for(let e=0;e<o.length;++e)o[e]*=r,o[e]>p[e]&&(_[e]=s,p[e]=o[e])}let m=0;const g=d.data;for(let o=0;o<s.length;++o){const i=s[o],[a,l]=h(_,e,o,r,n);if(a){++m;for(const e of l)g[e]=m;u.push({id:m,label_id:i,score:t[o]})}}return[d,u]}function f(e,t=.5,s=.5,r=.8,n=null,i=null){null===n&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),n=new Set);const a=e.class_queries_logits??e.logits,l=(e.masks_queries_logits??e.pred_masks).sigmoid();let[c,d,u]=a.dims;if(u-=1,null!==i&&i.length!==c)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let _=[];for(let e=0;e<c;++e){let c=null!==i?i[e]:null,d=a[e],p=l[e],[h,f,w]=m(d,p,t,u);if(0===w.length){let[e,t]=c??p.dims.slice(-2),s=new o.Tensor("int32",new Int32Array(e*t).fill(-1),[e,t]);_.push({segmentation:s,segments_info:[]});continue}let[M,x]=g(h,f,w,s,r,n,c);_.push({segmentation:M,segments_info:x})}return _}function w(e,t=.5,s=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}class M extends r.Callable{constructor(e){super(),this.image_mean=e.image_mean??e.mean,this.image_std=e.image_std??e.std,this.resample=e.resample??2,this.do_rescale=e.do_rescale??!0,this.rescale_factor=e.rescale_factor??1/255,this.do_normalize=e.do_normalize,this.do_thumbnail=e.do_thumbnail,this.size=e.size??e.image_size,this.do_resize=e.do_resize??void 0!==this.size,this.size_divisibility=e.size_divisibility??e.size_divisor,this.do_center_crop=e.do_center_crop,this.crop_size=e.crop_size,this.do_convert_rgb=e.do_convert_rgb??!0,this.do_crop_margin=e.do_crop_margin,this.pad_size=e.pad_size,this.do_pad=e.do_pad,this.min_pixels=e.min_pixels,this.max_pixels=e.max_pixels,this.do_pad&&!this.pad_size&&this.size&&void 0!==this.size.width&&void 0!==this.size.height&&(this.pad_size=this.size),this.do_flip_channel_order=e.do_flip_channel_order??!1,this.config=e}async thumbnail(e,t,s=2){const r=e.height,o=e.width,n=t.height,i=t.width;let a=Math.min(r,n),l=Math.min(o,i);return a===r&&l===o?e:(r>o?l=Math.floor(o*a/r):o>r&&(a=Math.floor(r*l/o)),await e.resize(l,a,{resample:s}))}async crop_margin(e,t=200){const s=e.clone().grayscale(),r=(0,n.min)(s.data)[0],o=(0,n.max)(s.data)[0]-r;if(0===o)return e;const i=t/255;let a=s.width,l=s.height,c=0,d=0;const u=s.data;for(let e=0;e<s.height;++e){const t=e*s.width;for(let n=0;n<s.width;++n)(u[t+n]-r)/o<i&&(a=Math.min(a,n),l=Math.min(l,e),c=Math.max(c,n),d=Math.max(d,e))}return e=await e.crop([a,l,c,d])}pad_image(e,t,s,{mode:r="constant",center:o=!1,constant_values:n=0}={}){const[a,l,c]=t;let d,u;if("number"==typeof s?(d=s,u=s):"square"===s?d=u=Math.max(a,l):(d=s.width,u=s.height),d!==l||u!==a){const s=new Float32Array(d*u*c);if(Array.isArray(n))for(let e=0;e<s.length;++e)s[e]=n[e%c];else 0!==n&&s.fill(n);const[_,p]=o?[Math.floor((d-l)/2),Math.floor((u-a)/2)]:[0,0];for(let t=0;t<a;++t){const r=(t+p)*d,o=t*l;for(let t=0;t<l;++t){const n=(r+t+_)*c,i=(o+t)*c;for(let t=0;t<c;++t)s[n+t]=e[i+t]}}if("symmetric"===r){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");const t=a-1,r=l-1;for(let o=0;o<u;++o){const n=o*d,u=(0,i.calculateReflectOffset)(o,t)*l;for(let t=0;t<d;++t){if(o<a&&t<l)continue;const d=(n+t)*c,_=(u+(0,i.calculateReflectOffset)(t,r))*c;for(let t=0;t<c;++t)s[d+t]=e[_+t]}}}e=s,t=[u,d,c]}return[e,t]}rescale(e){for(let t=0;t<e.length;++t)e[t]=this.rescale_factor*e[t]}get_resize_output_image_size(e,t){const[s,r]=e.size;let o,n;if(this.do_thumbnail){const{height:e,width:s}=t;o=Math.min(e,s)}else Number.isInteger(t)?(o=t,n=this.config.max_size??o):void 0!==t&&(o=t.shortest_edge,n=t.longest_edge);if(void 0!==o||void 0!==n){const e=void 0===o?1:Math.max(o/s,o/r),t=s*e,i=r*e,a=void 0===n?1:Math.min(n/t,n/i);let l=Math.floor(Number((t*a).toFixed(2))),c=Math.floor(Number((i*a).toFixed(2)));return void 0!==this.size_divisibility&&([l,c]=d([l,c],this.size_divisibility)),[l,c]}if(void 0!==t&&void 0!==t.width&&void 0!==t.height){let e=t.width,o=t.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let t=o/r,n=e/s;Math.abs(1-n)<Math.abs(1-t)?t=n:n=t,o=c(t*r,this.config.ensure_multiple_of),e=c(n*s,this.config.ensure_multiple_of)}return[e,o]}if(void 0!==this.size_divisibility)return d([s,r],this.size_divisibility);if(void 0!==this.min_pixels&&void 0!==this.max_pixels){return function(e,t,s=28,r=3136,o=1003520){if(e<s||t<s)throw new Error(`height:${e} or width:${t} must be larger than factor:${s}`);if(Math.max(e,t)/Math.min(e,t)>200)throw new Error("absolute aspect ratio must be smaller than 200, got "+Math.max(e,t)/Math.min(e,t));let n=Math.round(e/s)*s,i=Math.round(t/s)*s;if(n*i>o){const r=Math.sqrt(e*t/o);n=Math.floor(e/r/s)*s,i=Math.floor(t/r/s)*s}else if(n*i<r){const o=Math.sqrt(r/(e*t));n=Math.ceil(e*o/s)*s,i=Math.ceil(t*o/s)*s}return[n,i]}(r,s,this.config.patch_size*this.config.merge_size,this.min_pixels,this.max_pixels)}throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(t)}`)}async resize(e){const[t,s]=this.get_resize_output_image_size(e,this.size);return await e.resize(t,s,{resample:this.resample})}async preprocess(e,{do_normalize:t=null,do_pad:s=null,do_convert_rgb:r=null,do_convert_grayscale:n=null,do_flip_channel_order:i=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));const[a,l]=e.size;if(r??this.do_convert_rgb?e=e.rgb():n&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let t,s;Number.isInteger(this.crop_size)?(t=this.crop_size,s=this.crop_size):(t=this.crop_size.width,s=this.crop_size.height),e=await e.center_crop(t,s)}const c=[e.height,e.width];let u=Float32Array.from(e.data),_=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(u),t??this.do_normalize){let t=this.image_mean;Array.isArray(this.image_mean)||(t=new Array(e.channels).fill(t));let s=this.image_std;if(Array.isArray(this.image_std)||(s=new Array(e.channels).fill(t)),t.length!==e.channels||s.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${t.length}) and \`image_std\` (${s.length}) must match the number of channels in the image (${e.channels}).`);for(let r=0;r<u.length;r+=e.channels)for(let o=0;o<e.channels;++o)u[r+o]=(u[r+o]-t[o])/s[o]}if(s??this.do_pad)if(this.pad_size){const t=this.pad_image(u,[e.height,e.width,e.channels],this.pad_size);[u,_]=t}else if(this.size_divisibility){const[e,t]=d([_[1],_[0]],this.size_divisibility);[u,_]=this.pad_image(u,_,{width:e,height:t})}if(i??this.do_flip_channel_order){if(3!==_[2])throw new Error("Flipping channel order is only supported for RGB images.");for(let e=0;e<u.length;e+=3){const t=u[e];u[e]=u[e+2],u[e+2]=t}}return{original_size:[l,a],reshaped_input_size:c,pixel_values:new o.Tensor("float32",u,_).permute(2,0,1)}}async _call(e,...t){Array.isArray(e)||(e=[e]);const s=await Promise.all(e.map((e=>this.preprocess(e))));return{pixel_values:(0,o.stack)(s.map((e=>e.pixel_values)),0),original_sizes:s.map((e=>e.original_size)),reshaped_input_sizes:s.map((e=>e.reshaped_input_size))}}static async from_pretrained(e,t={}){return new this(await(0,a.getModelJSON)(e,l.IMAGE_PROCESSOR_NAME,!0,t))}}},"./src/base/processing_utils.js":(e,t,s)=>{"use strict";s.r(t),s.d(t,{Processor:()=>i});var r=s("./src/utils/constants.js"),o=s("./src/utils/generic.js"),n=s("./src/utils/hub.js");class i extends o.Callable{static classes=["image_processor_class","tokenizer_class","feature_extractor_class"];static uses_processor_config=!1;static uses_chat_template_file=!1;constructor(e,t,s){super(),this.config=e,this.components=t,this.chat_template=s}get image_processor(){return this.components.image_processor}get tokenizer(){return this.components.tokenizer}get feature_extractor(){return this.components.feature_extractor}apply_chat_template(e,t={}){if(!this.tokenizer)throw new Error("Unable to apply chat template without a tokenizer.");return this.tokenizer.apply_chat_template(e,{tokenize:!1,chat_template:this.chat_template??void 0,...t})}batch_decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.batch_decode(...e)}decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.decode(...e)}async _call(e,...t){for(const s of[this.image_processor,this.feature_extractor,this.tokenizer])if(s)return s(e,...t);throw new Error("No image processor, feature extractor, or tokenizer found.")}static async from_pretrained(e,t={}){const[s,o,i]=await Promise.all([this.uses_processor_config?(0,n.getModelJSON)(e,r.PROCESSOR_NAME,!0,t):{},Promise.all(this.classes.filter((e=>e in this)).map((async s=>{const r=await this[s].from_pretrained(e,t);return[s.replace(/_class$/,""),r]}))).then(Object.fromEntries),this.uses_chat_te