@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 • 425 kB
JavaScript
import*as e from"fs";import*as t from"onnxruntime-common";import*as s from"onnxruntime-node";import*as o from"path";import*as r from"sharp";import*as n from"url";var a,i,l={fs:t=>{t.exports=e},"onnxruntime-common":e=>{e.exports=t},"onnxruntime-node":e=>{e.exports=s},path:e=>{e.exports=o},sharp:e=>{e.exports=r},url:e=>{e.exports=n},"?8b6b":()=>{},"./node_modules/@huggingface/jinja/dist/index.js":(e,t,s)=>{s.r(t),s.d(t,{Environment:()=>Y,Interpreter:()=>K,Template:()=>te,parse:()=>V,tokenize:()=>d});var o=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"}),r=Object.freeze({set:o.Set,for:o.For,in:o.In,is:o.Is,if:o.If,else:o.Else,endset:o.EndSet,endif:o.EndIf,elif:o.ElseIf,endfor:o.EndFor,and:o.And,or:o.Or,not:o.Not,"not in":o.NotIn,macro:o.Macro,endmacro:o.EndMacro,true:o.BooleanLiteral,false:o.BooleanLiteral,none:o.NullLiteral,True:o.BooleanLiteral,False:o.BooleanLiteral,None:o.NullLiteral}),n=class{constructor(e,t){this.value=e,this.type=t}};function a(e){return/\w/.test(e)}function i(e){return/[0-9]/.test(e)}var l=[["{%",o.OpenStatement],["%}",o.CloseStatement],["{{",o.OpenExpression],["}}",o.CloseExpression],["(",o.OpenParen],[")",o.CloseParen],["{",o.OpenCurlyBracket],["}",o.CloseCurlyBracket],["[",o.OpenSquareBracket],["]",o.CloseSquareBracket],[",",o.Comma],[".",o.Dot],[":",o.Colon],["|",o.Pipe],["<=",o.ComparisonBinaryOperator],[">=",o.ComparisonBinaryOperator],["==",o.ComparisonBinaryOperator],["!=",o.ComparisonBinaryOperator],["<",o.ComparisonBinaryOperator],[">",o.ComparisonBinaryOperator],["+",o.AdditiveBinaryOperator],["-",o.AdditiveBinaryOperator],["*",o.MultiplicativeBinaryOperator],["/",o.MultiplicativeBinaryOperator],["%",o.MultiplicativeBinaryOperator],["=",o.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===o.CloseStatement||e===o.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,o.Text));continue}}_((e=>/\s/.test(e)));const t=d[u];if("-"===t||"+"===t){const e=s.at(-1)?.type;if(e===o.Text||void 0===e)throw new SyntaxError(`Unexpected character: ${t}`);switch(e){case o.Identifier:case o.NumericLiteral:case o.BooleanLiteral:case o.NullLiteral:case o.StringLiteral:case o.CloseParen:case o.CloseSquareBracket:break;default:{++u;const e=_(i);s.push(new n(`${t}${e}`,e.length>0?o.NumericLiteral:o.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(i(t)){const e=_(i);s.push(new n(e,o.NumericLiteral))}else{if(!a(t))throw new SyntaxError(`Unexpected character: ${t}`);{const e=_(a),t=Object.hasOwn(r,e)?r[e]:o.Identifier;t===o.In&&s.at(-1)?.type===o.Not?(s.pop(),s.push(new n("not in",o.NotIn))):s.push(new n(e,t))}}else{++u;const e=_((e=>e!==t));s.push(new n(e,o.StringLiteral)),++u}}return s}var u=class{type="Statement"},_=class extends u{constructor(e){super(),this.body=e}type="Program"},m=class extends u{constructor(e,t,s){super(),this.test=e,this.body=t,this.alternate=s}type="If"},p=class extends u{constructor(e,t,s,o){super(),this.loopvar=e,this.iterable=t,this.body=s,this.defaultBlock=o}type="For"},h=class extends u{constructor(e,t,s){super(),this.assignee=e,this.value=t,this.body=s}type="Set"},g=class extends u{constructor(e,t,s){super(),this.name=e,this.args=t,this.body=s}type="Macro"},f=class extends u{type="Expression"},M=class extends f{constructor(e,t,s){super(),this.object=e,this.property=t,this.computed=s}type="MemberExpression"},w=class extends f{constructor(e,t){super(),this.callee=e,this.args=t}type="CallExpression"},T=class extends f{constructor(e){super(),this.value=e}type="Identifier"},b=class extends f{constructor(e){super(),this.value=e}type="Literal"},x=class extends b{type="NumericLiteral"},P=class extends b{type="StringLiteral"},k=class extends b{type="BooleanLiteral"},F=class extends b{type="NullLiteral"},y=class extends b{type="ArrayLiteral"},v=class extends b{type="TupleLiteral"},C=class extends b{type="ObjectLiteral"},S=class extends f{constructor(e,t,s){super(),this.operator=e,this.left=t,this.right=s}type="BinaryExpression"},A=class extends f{constructor(e,t){super(),this.operand=e,this.filter=t}type="FilterExpression"},E=class extends f{constructor(e,t){super(),this.iterable=e,this.test=t}type="SelectExpression"},L=class extends f{constructor(e,t,s){super(),this.operand=e,this.negate=t,this.test=s}type="TestExpression"},I=class extends f{constructor(e,t){super(),this.operator=e,this.argument=t}type="UnaryExpression"},z=class extends f{constructor(e=void 0,t=void 0,s=void 0){super(),this.start=e,this.stop=t,this.step=s}type="SliceExpression"},D=class extends f{constructor(e,t){super(),this.key=e,this.value=t}type="KeywordArgumentExpression"};function V(e){const t=new _([]);let s=0;function r(t,o){const r=e[s++];if(!r||r.type!==t)throw new Error(`Parser Error: ${o}. ${r.type} !== ${t}.`);return r}function n(){switch(e[s].type){case o.Text:return new P(r(o.Text,"Expected text token").value);case o.OpenStatement:return function(){let t;switch(r(o.OpenStatement,"Expected opening statement token"),e[s].type){case o.Set:++s,t=function(){const t=d();if(i(o.Equals)){++s;const e=d();return new h(t,e,[])}{const a=[];for(r(o.CloseStatement,"Expected %} token");e[s]?.type!==o.OpenStatement||e[s+1]?.type!==o.EndSet;){const e=n();a.push(e)}return r(o.OpenStatement,"Expected {% token"),r(o.EndSet,"Expected endset token"),new h(t,null,a)}}(),r(o.CloseStatement,"Expected closing statement token");break;case o.If:++s,t=l(),r(o.OpenStatement,"Expected {% token"),r(o.EndIf,"Expected endif token"),r(o.CloseStatement,"Expected %} token");break;case o.Macro:++s,t=function(){const e=q();if("Identifier"!==e.type)throw new SyntaxError("Expected identifier following macro statement");const t=O();r(o.CloseStatement,"Expected closing statement token");const s=[];for(;a(o.OpenStatement,o.EndMacro);)s.push(n());return new g(e,t,s)}(),r(o.OpenStatement,"Expected {% token"),r(o.EndMacro,"Expected endmacro token"),r(o.CloseStatement,"Expected %} token");break;case o.For:++s,t=function(){const e=c(!0);if(!(e instanceof T||e instanceof v))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);r(o.In,"Expected `in` keyword following loop variable");const t=d();r(o.CloseStatement,"Expected closing statement token");const l=[];for(;a(o.OpenStatement,o.EndFor)&&a(o.OpenStatement,o.Else);)l.push(n());const u=[];if(i(o.OpenStatement,o.Else))for(++s,++s,r(o.CloseStatement,"Expected closing statement token");a(o.OpenStatement,o.EndFor);)u.push(n());return new p(e,t,l,u)}(),r(o.OpenStatement,"Expected {% token"),r(o.EndFor,"Expected endfor token"),r(o.CloseStatement,"Expected %} token");break;default:throw new SyntaxError(`Unknown statement type: ${e[s].type}`)}return t}();case o.OpenExpression:return function(){r(o.OpenExpression,"Expected opening expression token");const e=d();return r(o.CloseExpression,"Expected closing expression token"),e}();default:throw new SyntaxError(`Unexpected token type: ${e[s].type}`)}}function a(...t){return s+t.length<=e.length&&t.some(((t,o)=>t!==e[s+o].type))}function i(...t){return s+t.length<=e.length&&t.every(((t,o)=>t===e[s+o].type))}function l(){const t=d();r(o.CloseStatement,"Expected closing statement token");const a=[],c=[];for(;e[s]?.type!==o.OpenStatement||e[s+1]?.type!==o.ElseIf&&e[s+1]?.type!==o.Else&&e[s+1]?.type!==o.EndIf;)a.push(n());if(e[s]?.type===o.OpenStatement&&e[s+1]?.type!==o.EndIf)if(++s,i(o.ElseIf))r(o.ElseIf,"Expected elseif token"),c.push(l());else for(r(o.Else,"Expected else token"),r(o.CloseStatement,"Expected closing statement token");e[s]?.type!==o.OpenStatement||e[s+1]?.type!==o.EndIf;)c.push(n());return new m(t,a,c)}function c(e=!1){const t=e?q:d,r=[t()],n=i(o.Comma);for(;n&&(++s,r.push(t()),i(o.Comma)););return n?new v(r):r[0]}function d(){return function(){const e=u();if(i(o.If)){++s;const t=u();if(i(o.Else)){++s;const o=u();return new m(t,[e],[o])}return new E(e,t)}return e}()}function u(){let t=f();for(;i(o.Or);){const o=e[s];++s;const r=f();t=new S(o,t,r)}return t}function f(){let t=b();for(;i(o.And);){const o=e[s];++s;const r=b();t=new S(o,t,r)}return t}function b(){let t;for(;i(o.Not);){const o=e[s];++s;const r=b();t=new I(o,r)}return t??function(){let t=V();for(;i(o.ComparisonBinaryOperator)||i(o.In)||i(o.NotIn);){const o=e[s];++s;const r=V();t=new S(o,t,r)}return t}()}function V(){let t=G();for(;i(o.AdditiveBinaryOperator);){const o=e[s];++s;const r=G();t=new S(o,t,r)}return t}function j(e){let t=new w(e,O());return t=B(t),i(o.OpenParen)&&(t=j(t)),t}function O(){r(o.OpenParen,"Expected opening parenthesis for arguments list");const e=function(){const e=[];for(;!i(o.CloseParen);){let t=d();if(i(o.Equals)){if(++s,!(t instanceof T))throw new SyntaxError("Expected identifier for keyword argument");const e=d();t=new D(t,e)}e.push(t),i(o.Comma)&&++s}return e}();return r(o.CloseParen,"Expected closing parenthesis for arguments list"),e}function N(){const e=[];let t=!1;for(;!i(o.CloseSquareBracket);)i(o.Colon)?(e.push(void 0),++s,t=!0):(e.push(d()),i(o.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 z(...e)}return e[0]}function B(t){for(;i(o.Dot)||i(o.OpenSquareBracket);){const n=e[s];let a;++s;const i=n.type!==o.Dot;if(i)a=N(),r(o.CloseSquareBracket,"Expected closing square bracket");else if(a=q(),"Identifier"!==a.type)throw new SyntaxError("Expected identifier following dot operator");t=new M(t,a,i)}return t}function G(){let t=R();for(;i(o.MultiplicativeBinaryOperator);){const o=e[s];++s;const r=R();t=new S(o,t,r)}return t}function R(){let e=function(){let e=function(){const e=B(q());return i(o.OpenParen)?j(e):e}();for(;i(o.Pipe);){++s;let t=q();if(!(t instanceof T))throw new SyntaxError("Expected identifier for the filter");i(o.OpenParen)&&(t=j(t)),e=new A(e,t)}return e}();for(;i(o.Is);){++s;const t=i(o.Not);t&&++s;let r=q();if(r instanceof k?r=new T(r.value.toString()):r instanceof F&&(r=new T("none")),!(r instanceof T))throw new SyntaxError("Expected identifier for the test");e=new L(e,t,r)}return e}function q(){const t=e[s];switch(t.type){case o.NumericLiteral:return++s,new x(Number(t.value));case o.StringLiteral:return++s,new P(t.value);case o.BooleanLiteral:return++s,new k("true"===t.value.toLowerCase());case o.NullLiteral:return++s,new F(null);case o.Identifier:return++s,new T(t.value);case o.OpenParen:{++s;const t=c();if(e[s].type!==o.CloseParen)throw new SyntaxError(`Expected closing parenthesis, got ${e[s].type} instead`);return++s,t}case o.OpenSquareBracket:{++s;const e=[];for(;!i(o.CloseSquareBracket);)e.push(d()),i(o.Comma)&&++s;return++s,new y(e)}case o.OpenCurlyBracket:{++s;const e=new Map;for(;!i(o.CloseCurlyBracket);){const t=d();r(o.Colon,"Expected colon between key and value in object literal");const n=d();e.set(t,n),i(o.Comma)&&++s}return++s,new C(e)}default:throw new SyntaxError(`Unexpected token: ${t.type}`)}}for(;s<e.length;)t.body.push(n());return t}function j(e,t,s=1){void 0===t&&(t=e,e=0);const o=[];for(let r=e;r<t;r+=s)o.push(r);return o}function O(e,t,s,o=1){const r=Math.sign(o);r>=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 a=t;r*a<r*s;a+=o)n.push(e[a]);return n}function N(e){return e.replace(/\b\w/g,(e=>e.toUpperCase()))}var B=class{type="RuntimeValue";value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new q(!!this.value)}},G=class extends B{type="NumericValue"},R=class extends B{type="StringValue";builtins=new Map([["upper",new Q((()=>new R(this.value.toUpperCase())))],["lower",new Q((()=>new R(this.value.toLowerCase())))],["strip",new Q((()=>new R(this.value.trim())))],["title",new Q((()=>new R(N(this.value))))],["length",new G(this.value.length)],["rstrip",new Q((()=>new R(this.value.trimEnd())))],["lstrip",new Q((()=>new R(this.value.trimStart())))],["split",new Q((e=>{const t=e[0]??new H;if(!(t instanceof R||t instanceof H))throw new Error("sep argument must be a string or null");const s=e[1]??new G(-1);if(!(s instanceof G))throw new Error("maxsplit argument must be a number");let o=[];if(t instanceof H){const e=this.value.trimStart();for(const{0:t,index:r}of e.matchAll(/\S+/g)){if(-1!==s.value&&o.length>=s.value&&void 0!==r){o.push(t+e.slice(r+t.length));break}o.push(t)}}else{if(""===t.value)throw new Error("empty separator");o=this.value.split(t.value),-1!==s.value&&o.length>s.value&&o.push(o.splice(s.value).join(t.value))}return new U(o.map((e=>new R(e))))}))]])},q=class extends B{type="BooleanValue"},W=class extends B{type="ObjectValue";__bool__(){return new q(this.value.size>0)}builtins=new Map([["get",new Q((([e,t])=>{if(!(e instanceof R))throw new Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new H}))],["items",new Q((()=>new U(Array.from(this.value.entries()).map((([e,t])=>new U([new R(e),t]))))))]])},$=class extends W{type="KeywordArgumentsValue"},U=class extends B{type="ArrayValue";builtins=new Map([["length",new G(this.value.length)]]);__bool__(){return new q(this.value.length>0)}},X=class extends U{type="TupleValue"},Q=class extends B{type="FunctionValue"},H=class extends B{type="NullValue"},J=class extends B{type="UndefinedValue"},Y=class{constructor(e){this.parent=e}variables=new Map([["namespace",new Q((e=>{if(0===e.length)return new W(new Map);if(1!==e.length||!(e[0]instanceof W))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 Q],["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,Z(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 J}catch{return new J}}},K=class{global;constructor(e){this.global=e??new Y}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 o=this.evaluate(e.right,t);switch(e.operator.value){case"==":return new q(s.value==o.value);case"!=":return new q(s.value!=o.value)}if(s instanceof J||o instanceof J)throw new Error("Cannot perform operation on undefined values");if(s instanceof H||o instanceof H)throw new Error("Cannot perform operation on null values");if(s instanceof G&&o instanceof G)switch(e.operator.value){case"+":return new G(s.value+o.value);case"-":return new G(s.value-o.value);case"*":return new G(s.value*o.value);case"/":return new G(s.value/o.value);case"%":return new G(s.value%o.value);case"<":return new q(s.value<o.value);case">":return new q(s.value>o.value);case">=":return new q(s.value>=o.value);case"<=":return new q(s.value<=o.value)}else if(s instanceof U&&o instanceof U){if("+"===e.operator.value)return new U(s.value.concat(o.value))}else if(o instanceof U){const t=void 0!==o.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 R||o instanceof R)&&"+"===e.operator.value)return new R(s.value.toString()+o.value.toString());if(s instanceof R&&o instanceof R)switch(e.operator.value){case"in":return new q(o.value.includes(s.value));case"not in":return new q(!o.value.includes(s.value))}if(s instanceof R&&o instanceof W)switch(e.operator.value){case"in":return new q(o.value.has(s.value));case"not in":return new q(!o.value.has(s.value))}throw new SyntaxError(`Unknown operator "${e.operator.value}" between ${s.type} and ${o.type}`)}evaluateArguments(e,t){const s=[],o=new Map;for(const r of e)if("KeywordArgumentExpression"===r.type){const e=r;o.set(e.key.value,this.evaluate(e.value,t))}else{if(o.size>0)throw new Error("Positional arguments must come before keyword arguments");s.push(this.evaluate(r,t))}return[s,o]}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 R(ee(s));if(s instanceof U)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 G(s.value.length);case"reverse":return new U(s.value.reverse());case"sort":return new U(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 R(s.value.map((e=>e.value)).join(""));case"string":return new R(ee(s));default:throw new Error(`Unknown ArrayValue filter: ${t.value}`)}else if(s instanceof R)switch(t.value){case"length":return new G(s.value.length);case"upper":return new R(s.value.toUpperCase());case"lower":return new R(s.value.toLowerCase());case"title":return new R(N(s.value));case"capitalize":return new R(s.value.charAt(0).toUpperCase()+s.value.slice(1));case"trim":return new R(s.value.trim());case"indent":return new R(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 G){if("abs"===t.value)return new G(Math.abs(s.value));throw new Error(`Unknown NumericValue filter: ${t.value}`)}if(s instanceof W)switch(t.value){case"items":return new U(Array.from(s.value.entries()).map((([e,t])=>new U([new R(e),t]))));case"length":return new G(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 o=e.filter;if("Identifier"!==o.callee.type)throw new Error(`Unknown filter: ${o.callee.type}`);const r=o.callee.value;if("tojson"===r){const[,e]=this.evaluateArguments(o.args,t),r=e.get("indent")??new H;if(!(r instanceof G||r instanceof H))throw new Error("If set, indent must be a number");return new R(ee(s,r.value))}if("join"===r){let e;if(s instanceof R)e=Array.from(s.value);else{if(!(s instanceof U))throw new Error(`Cannot apply filter "${r}" to type: ${s.type}`);e=s.value.map((e=>e.value))}const[n,a]=this.evaluateArguments(o.args,t),i=n.at(0)??a.get("separator")??new R("");if(!(i instanceof R))throw new Error("separator must be a string");return new R(e.join(i.value))}if(s instanceof U){switch(r){case"selectattr":case"rejectattr":{const e="selectattr"===r;if(s.value.some((e=>!(e instanceof W))))throw new Error(`\`${r}\` can only be applied to array of objects`);if(o.args.some((e=>"StringLiteral"!==e.type)))throw new Error(`arguments of \`${r}\` must be strings`);const[n,a,i]=o.args.map((e=>this.evaluate(e,t)));let l;if(a){const e=t.tests.get(a.value);if(!e)throw new Error(`Unknown test: ${a.value}`);l=e}else l=(...e)=>e[0].__bool__().value;const c=s.value.filter((t=>{const s=t.value.get(n.value),o=!!s&&l(s,i);return e?o:!o}));return new U(c)}case"map":{const[,e]=this.evaluateArguments(o.args,t);if(e.has("attribute")){const t=e.get("attribute");if(!(t instanceof R))throw new Error("attribute must be a string");const o=e.get("default"),r=s.value.map((e=>{if(!(e instanceof W))throw new Error("items in map must be an object");return e.value.get(t.value)??o??new J}));return new U(r)}throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${r}`)}if(s instanceof R){if("indent"===r){const[e,r]=this.evaluateArguments(o.args,t),n=e.at(0)??r.get("width")??new G(4);if(!(n instanceof G))throw new Error("width must be a number");const a=e.at(1)??r.get("first")??new q(!1),i=e.at(2)??r.get("blank")??new q(!1),l=s.value.split("\n"),c=" ".repeat(n.value),d=l.map(((e,t)=>!a.value&&0===t||!i.value&&0===e.length?e:c+e));return new R(d.join("\n"))}throw new Error(`Unknown StringValue filter: ${r}`)}throw new Error(`Cannot apply filter "${r}" to type: ${s.type}`)}throw new Error(`Unknown filter: ${e.filter.type}`)}evaluateTestExpression(e,t){const s=this.evaluate(e.operand,t),o=t.tests.get(e.test.value);if(!o)throw new Error(`Unknown test: ${e.test.value}`);const r=o(s);return new q(e.negate?!r:r)}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 o of e){const e=this.evaluate(o,t);"NullValue"!==e.type&&"UndefinedValue"!==e.type&&(s+=e.value)}return new R(s)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){const[s,o]=this.evaluateArguments(e.args,t);o.size>0&&s.push(new $(o));const r=this.evaluate(e.callee,t);if("FunctionValue"!==r.type)throw new Error(`Cannot call something that is not a function: got ${r.type}`);return r.value(s,t)}evaluateSliceExpression(e,t,s){if(!(e instanceof U||e instanceof R))throw new Error("Slice object must be an array or string");const o=this.evaluate(t.start,s),r=this.evaluate(t.stop,s),n=this.evaluate(t.step,s);if(!(o instanceof G||o instanceof J))throw new Error("Slice start must be numeric or undefined");if(!(r instanceof G||r instanceof J))throw new Error("Slice stop must be numeric or undefined");if(!(n instanceof G||n instanceof J))throw new Error("Slice step must be numeric or undefined");return e instanceof U?new U(O(e.value,o.value,r.value,n.value)):new R(O(Array.from(e.value),o.value,r.value,n.value).join(""))}evaluateMemberExpression(e,t){const s=this.evaluate(e.object,t);let o,r;if(e.computed){if("SliceExpression"===e.property.type)return this.evaluateSliceExpression(s,e.property,t);o=this.evaluate(e.property,t)}else o=new R(e.property.value);if(s instanceof W){if(!(o instanceof R))throw new Error(`Cannot access property with non-string: got ${o.type}`);r=s.value.get(o.value)??s.builtins.get(o.value)}else if(s instanceof U||s instanceof R)if(o instanceof G)r=s.value.at(o.value),s instanceof R&&(r=new R(s.value.at(o.value)));else{if(!(o instanceof R))throw new Error(`Cannot access property with non-string/non-number: got ${o.type}`);r=s.builtins.get(o.value)}else{if(!(o instanceof R))throw new Error(`Cannot access property with non-string: got ${o.type}`);r=s.builtins.get(o.value)}return r instanceof B?r:new J}evaluateSet(e,t){const s=e.value?this.evaluate(e.value,t):this.evaluateBlock(e.body,t);if("Identifier"===e.assignee.type){const o=e.assignee.value;t.setVariable(o,s)}else{if("MemberExpression"!==e.assignee.type)throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);{const o=e.assignee,r=this.evaluate(o.object,t);if(!(r instanceof W))throw new Error("Cannot assign to member of non-object");if("Identifier"!==o.property.type)throw new Error("Cannot assign to member with non-identifier property");r.value.set(o.property.value,s)}}return new H}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 Y(t);let o,r;if("SelectExpression"===e.iterable.type){const t=e.iterable;r=this.evaluate(t.iterable,s),o=t.test}else r=this.evaluate(e.iterable,s);if(!(r instanceof U))throw new Error(`Expected iterable type in for loop: got ${r.type}`);const n=[],a=[];for(let t=0;t<r.value.length;++t){const i=new Y(s),l=r.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 o=0;o<t.value.length;++o){if("Identifier"!==t.value[o].type)throw new Error(`Cannot unpack non-identifier type: ${t.value[o].type}`);e.setVariable(t.value[o].value,s.value[o])}}}}if(o){c(i);if(!this.evaluate(o,i).__bool__().value)continue}n.push(l),a.push(c)}let i="",l=!0;for(let t=0;t<n.length;++t){const o=new Map([["index",new G(t+1)],["index0",new G(t)],["revindex",new G(n.length-t)],["revindex0",new G(n.length-t-1)],["first",new q(0===t)],["last",new q(t===n.length-1)],["length",new G(n.length)],["previtem",t>0?n[t-1]:new J],["nextitem",t<n.length-1?n[t+1]:new J]]);s.setVariable("loop",new W(o)),a[t](s);i+=this.evaluateBlock(e.body,s).value,l=!1}if(l){i+=this.evaluateBlock(e.defaultBlock,s).value}return new R(i)}evaluateMacro(e,t){return t.setVariable(e.name.value,new Q(((t,s)=>{const o=new Y(s);let r;t=t.slice(),"KeywordArgumentsValue"===t.at(-1)?.type&&(r=t.pop());for(let s=0;s<e.args.length;++s){const n=e.args[s],a=t[s];if("Identifier"===n.type){const e=n;if(!a)throw new Error(`Missing positional argument: ${e.value}`);o.setVariable(e.value,a)}else{if("KeywordArgumentExpression"!==n.type)throw new Error(`Unknown argument type: ${n.type}`);{const e=n,t=a??r?.value.get(e.key.value)??this.evaluate(e.value,o);o.setVariable(e.key.value,t)}}}return this.evaluateBlock(e.body,o)}))),new H}evaluate(e,t){if(void 0===e)return new J;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"NumericLiteral":return new G(Number(e.value));case"StringLiteral":return new R(e.value);case"BooleanLiteral":return new q(e.value);case"NullLiteral":return new H(e.value);case"ArrayLiteral":return new U(e.value.map((e=>this.evaluate(e,t))));case"TupleLiteral":return new X(e.value.map((e=>this.evaluate(e,t))));case"ObjectLiteral":{const s=new Map;for(const[o,r]of e.value){const e=this.evaluate(o,t);if(!(e instanceof R))throw new Error(`Object keys must be strings: got ${e.type}`);s.set(e.value,this.evaluate(r,t))}return new W(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 Z(e){switch(typeof e){case"number":return new G(e);case"string":return new R(e);case"boolean":return new q(e);case"undefined":return new J;case"object":return null===e?new H:Array.isArray(e)?new U(e.map(Z)):new W(new Map(Object.entries(e).map((([e,t])=>[e,Z(t)]))));case"function":return new Q(((t,s)=>Z(e(...t.map((e=>e.value)))??null)));default:throw new Error(`Cannot convert to runtime value: ${e}`)}}function ee(e,t,s){const o=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):"",r="\n"+s.repeat(o),n=r+s;if("ArrayValue"===e.type){const s=e.value.map((e=>ee(e,t,o+1)));return t?`[${n}${s.join(`,${n}`)}${r}]`:`[${s.join(", ")}]`}{const s=Array.from(e.value.entries()).map((([e,s])=>{const r=`"${e}": ${ee(s,t,o+1)}`;return t?`${n}${r}`:r}));return t?`{${s.join(",")}${r}}`:`{${s.join(", ")}}`}}default:throw new Error(`Cannot convert to JSON: ${e.type}`)}}var te=class{parsed;constructor(e){const t=d(e,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=V(t)}render(e){const t=new Y;if(t.set("false",!1),t.set("true",!0),t.set("raise_exception",(e=>{throw new Error(e)})),t.set("range",j),e)for(const[s,o]of Object.entries(e))t.set(s,o);return new K(t).run(this.parsed).value}}},"./src/backends/onnx.js":(e,t,s)=>{var o;s.r(t),s.d(t,{Tensor:()=>i.Tensor,createInferenceSession:()=>g,deviceToExecutionProviders:()=>p,isONNXProxy:()=>w,isONNXTensor:()=>f});var r=s("./src/env.js"),n=s("onnxruntime-node"),a=s("?8b6b"),i=s("onnxruntime-common");const l=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"}}),c=[];let d,u;const _=Symbol.for("onnxruntime");if(_ in globalThis)u=globalThis[_];else if(r.apis.IS_NODE_ENV){switch(u=n.default??n,process.platform){case"win32":c.push("dml");break;case"linux":"x64"===process.arch&&c.push("cuda")}c.push("cpu"),d=["cpu"]}else u=o||(o=s.t(a,2)),r.apis.IS_WEBNN_AVAILABLE&&c.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),r.apis.IS_WEBGPU_AVAILABLE&&c.push("webgpu"),c.push("wasm"),d=["wasm"];const m=u.InferenceSession;function p(e=null){if(!e)return d;switch(e){case"auto":return c;case"gpu":return c.filter((e=>["webgpu","cuda","dml","webnn-gpu"].includes(e)))}if(c.includes(e))return[l[e]??e];throw new Error(`Unsupported device: "${e}". Should be one of: ${c.join(", ")}.`)}let h=null;async function g(e,t,s){h&&await h;const o=m.create(e,t);h??=o;const r=await o;return r.config=s,r}function f(e){return e instanceof u.Tensor}const M=u?.env;function w(){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@${r.env.version}/dist/`),M.wasm.proxy=!1),M?.webgpu&&(M.webgpu.powerPreference="high-performance"),r.env.backends.onnx=M},"./src/base/feature_extraction_utils.js":(e,t,s)=>{s.r(t),s.d(t,{FeatureExtractor:()=>a,validate_audio_inputs:()=>i});var o=s("./src/utils/constants.js"),r=s("./src/utils/generic.js"),n=s("./src/utils/hub.js");class a extends r.Callable{constructor(e){super(),this.config=e}static async from_pretrained(e,t){return new this(await(0,n.getModelJSON)(e,o.FEATURE_EXTRACTOR_NAME,!0,t))}}function i(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)=>{s.r(t),s.d(t,{ImageProcessor:()=>w,center_to_corners_format:()=>u,post_process_instance_segmentation:()=>M,post_process_object_detection:()=>_,post_process_panoptic_segmentation:()=>f,post_process_semantic_segmentation:()=>m});var o=s("./src/utils/generic.js"),r=s("./src/utils/tensor.js"),n=s("./src/utils/maths.js"),a=(s("./src/utils/image.js"),s("./src/utils/core.js")),i=s("./src/utils/hub.js"),l=s("./src/utils/constants.js");function c(e,t,s=0,o=null){const r=e/t;let a=(0,n.bankers_round)(r)*t;return null!==o&&a>o&&(a=Math.floor(r)*t),a<s&&(a=Math.ceil(r)*t),a}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,o]){return[e-s/2,t-o/2,e+s/2,t+o/2]}function _(e,t=.5,s=null,o=!1){const r=e.logits,a=e.pred_boxes,[i,l,c]=r.dims;if(null!==s&&s.length!==i)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<i;++e){let i=null!==s?s[e]:null,_={boxes:[],classes:[],scores:[]},m=r[e],p=a[e];for(let e=0;e<l;++e){let s,r=m[e],a=[];if(o){s=r.sigmoid().data;for(let e=0;e<s.length;++e)s[e]>t&&a.push(e)}else{let e=(0,n.max)(r.data)[1];if(e===c-1)continue;if(s=(0,n.softmax)(r.data),s[e]<t)continue;a.push(e)}for(const t of a){let o=p[e].data;o=u(o),null!==i&&(o=o.map(((e,t)=>e*i[(t+1)%2]))),_.boxes.push(o),_.classes.push(t),_.scores.push(s[t])}}d.push(_)}return d}function m(e,t=null){const s=e.logits,o=s.dims[0];if(null!==t&&t.length!==o)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<o;++e){const o=null!==t?t[e]:null;let a=s[e];null!==o&&(a=(0,r.interpolate)(a,o,"bilinear",!1));const[i,l]=o??a.dims.slice(-2),c=new r.Tensor("int32",new Int32Array(i*l),[i,l]),d=a[0].data,u=c.data;for(let e=1;e<a.dims[0];++e){const t=a[e].data;for(let s=0;s<t.length;++s)t[s]>d[s]&&(d[s]=t[s],u[s]=e)}const _=new Array(a.dims[0]);for(let e=0;e<u.length;++e){const t=u[e];_[t]=t}const m=_.filter((e=>void 0!==e));n.push({segmentation:c,labels:m})}return n}function p(e,t,s,o){const r=[],a=[],i=[];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===o)continue;const _=(0,n.softmax)(c.data)[u];_>s&&(r.push(d),a.push(_),i.push(u))}return[r,a,i]}function h(e,t,s,o=.5,r=.8){const n=[];let a=0,i=0;const l=t[s].data;for(let t=0;t<e.length;++t)e[t]===s&&(n.push(t),++a),l[t]>=o&&++i;let c=a>0&&i>0;if(c){c=a/i>r}return[c,n]}function g(e,t,s,o,n,a=null,i=null){const[l,c]=i??e[0].dims,d=new r.Tensor("int32",new Int32Array(l*c),[l,c]),u=[];if(null!==i)for(let t=0;t<e.length;++t)e[t]=(0,r.interpolate)(e[t],i,"bilinear",!1);const _=new Int32Array(e[0].data.length),m=new Float32Array(e[0].data.length);for(let s=0;s<e.length;++s){let o=t[s];const r=e[s].data;for(let e=0;e<r.length;++e)r[e]*=o,r[e]>m[e]&&(_[e]=s,m[e]=r[e])}let p=0;const g=d.data;for(let r=0;r<s.length;++r){const a=s[r],[i,l]=h(_,e,r,o,n);if(i){++p;for(const e of l)g[e]=p;u.push({id:p,label_id:a,score:t[r]})}}return[d,u]}function f(e,t=.5,s=.5,o=.8,n=null,a=null){null===n&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),n=new Set);const i=e.class_queries_logits??e.logits,l=(e.masks_queries_logits??e.pred_masks).sigmoid();let[c,d,u]=i.dims;if(u-=1,null!==a&&a.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!==a?a[e]:null,d=i[e],m=l[e],[h,f,M]=p(d,m,t,u);if(0===M.length){let[e,t]=c??m.dims.slice(-2),s=new r.Tensor("int32",new Int32Array(e*t).fill(-1),[e,t]);_.push({segmentation:s,segments_info:[]});continue}let[w,T]=g(h,f,M,s,o,n,c);_.push({segmentation:w,segments_info:T})}return _}function M(e,t=.5,s=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}class w extends o.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.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 o=e.height,r=e.width,n=t.height,a=t.width;let i=Math.min(o,n),l=Math.min(r,a);return i===o&&l===r?e:(o>r?l=Math.floor(r*i/o):r>o&&(i=Math.floor(o*l/r)),await e.resize(l,i,{resample:s}))}async crop_margin(e,t=200){const s=e.clone().grayscale(),o=(0,n.min)(s.data)[0],r=(0,n.max)(s.data)[0]-o;if(0===r)return e;const a=t/255;let i=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]-o)/r<a&&(i=Math.min(i,n),l=Math.min(l,e),c=Math.max(c,n),d=Math.max(d,e))}return e=await e.crop([i,l,c,d])}pad_image(e,t,s,{mode:o="constant",center:r=!1,constant_values:n=0}={}){const[i,l,c]=t;let d,u;if("number"==typeof s?(d=s,u=s):"square"===s?d=u=Math.max(i,l):(d=s.width,u=s.height),d!==l||u!==i){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[_,m]=r?[Math.floor((d-l)/2),Math.floor((u-i)/2)]:[0,0];for(let t=0;t<i;++t){const o=(t+m)*d,r=t*l;for(let t=0;t<l;++t){const n=(o+t+_)*c,a=(r+t)*c;for(let t=0;t<c;++t)s[n+t]=e[a+t]}}if("symmetric"===o){if(r)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");const t=i-1,o=l-1;for(let r=0;r<u;++r){const n=r*d,u=(0,a.calculateReflectOffset)(r,t)*l;for(let t=0;t<d;++t){if(r<i&&t<l)continue;const d=(n+t)*c,_=(u+(0,a.calculateReflectOffset)(t,o))*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,o]=e.size;let r,n;if(this.do_thumbnail){const{height:e,width:s}=t;r=Math.min(e,s)}else Number.isInteger(t)?(r=t,n=this.config.max_size??r):void 0!==t&&(r=t.shortest_edge,n=t.longest_edge);if(void 0!==r||void 0!==n){const e=void 0===r?1:Math.max(r/s,r/o),t=s*e,a=o*e,i=void 0===n?1:Math.min(n/t,n/a);let l=Math.floor(Number((t*i).toFixed(2))),c=Math.floor(Number((a*i).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,r=t.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let t=r/o,n=e/s;Math.abs(1-n)<Math.abs(1-t)?t=n:n=t,r=c(t*o,this.config.ensure_multiple_of),e=c(n*s,this.config.ensure_multiple_of)}return[e,r]}if(void 0!==this.size_divisibility)return d([s,o],this.size_divisibility);if(void 0!==t.min_pixels&&void 0!==t.max_pixels){const{min_pixels:e,max_pixels:r}=t;return function(e,t,s=28,o=3136,r=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,a=Math.round(t/s)*s;if(n*a>r){const o=Math.sqrt(e*t/r);n=Math.floor(e/o/s)*s,a=Math.floor(t/o/s)*s}else if(n*a<o){const r=Math.sqrt(o/(e*t));n=Math.ceil(e*r/s)*s,a=Math.ceil(t*r/s)*s}return[n,a]}(o,s,this.config.patch_size*this.config.merge_size,e,r)}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:o=null,do_convert_grayscale:n=null,do_flip_channel_order:a=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));const[i,l]=e.size;if(o??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 o=0;o<u.length;o+=e.channels)for(let r=0;r<e.channels;++r)u[o+r]=(u[o+r]-t[r])/s[r]}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(a??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,i],reshaped_input_size:c,pixel_values:new r.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,r.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,i.getModelJSON)(e,l.IMAGE_PROCESSOR_NAME,!0,t))}}},"./src/base/processing_utils.js":(e,t,s)=>{s.r(t),s.d(t,{Processor:()=>a});var o=s("./src/utils/constants.js"),r=s("./src/utils/generic.js"),n=s("./src/utils/hub.js");class a extends r.Callable{static classes=["image_processor_class","tokenizer_class","feature_extractor_class"];static uses_processor_config=!1;constructor(e,t){super(),this.config=e,this.components=t}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,...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,r]=await Promise.all([this.uses_processor_config?(0,n.getModelJSON)(e,o.PROCESSOR_NAME,!0,t):{},Promise.all(this.classes.filter((e=>e in this)).map((async s=>{const o=await this[s].from_pretrained(e,t);return[s.replace(/_class$/,""),o]}))).then(Object.fromEntries)]);return new this(s,r)}}},"./src/configs.js":(e,t,s)=>{s.r(t),s.d(t,{AutoConfig:()=>l,PretrainedConfig:()=>i,getKeyValueShapes:()=>a});var o=s("./src/utils/core.js"),r=s("./src/utils/hub.js");function n(e){const t={};let s={};switch(e.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"ultravox":case"smolvlm":s=n(e.text_config);break;case"moondream1":s=n(e.phi_config);break;case"musicgen":s=n(e.decoder);break;case"multi_modality":s=n(e.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":t.num_heads="num_attention_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size";break;case"llama":case"olmo":case"olmo2":case"mobilellm":case"granite":case"cohere":case"mistral":case"starcoder2":case"qwen2":case"qwen2_vl":case"phi":case"phi3":case"phi3_v":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.num_attention_heads="num_attention_heads";break;case"gemma":case"gemma2":case"gemma3_text":case"glm":case"helium":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.dim_kv="head_dim";break;case"openelm":t.num_heads="num_kv_heads",t.num_layers="num_transformer_layers",t.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":t.num_heads="num_heads",t.num_layers="num_layers",t.hidden_size="hidden_size";break;case"bloom":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="hidden_size";break;case"mpt":t.num_heads="n_heads",t.num_layers="n_layers",t.hidden_size="d_model";break;case"exaone":t.num_heads="num_key_value_heads",t.num_layers="num_layers",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":t.num_decoder_layers="num_decoder_layers",t.num_decoder_heads="num_heads",t.decoder_dim_kv="d_kv",t.num_encoder_layers="num_layers",t.num_encoder_heads="num_heads",t.encoder_dim_kv="d_kv";break;case"bart":case"mbart":case"marian":case"whisper":case"lite-whisper":case"m2m_100":case"blenderbot":case"blenderbot-small":case"florence2_language":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="d_model",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="d_model";break;case"speecht5":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="hidden_size",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="hidden_size";break;case"trocr":t.num_encoder_layers=t.num_decoder_layers="decoder_layers",t.num_encoder_heads=t.num_decoder_heads="decoder_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="d_model";break;case"musicgen_decoder":t.num_encoder_layers=t.num_decoder_layers="num_hidden_layers",t.num_encoder_heads=t.num_decoder_heads="num_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"moonshine":t.num_decoder_layers="decoder_num_hidden_layers",t.num_decoder_heads="decoder_num_key_value_heads",t.num_encoder_layers="encoder_num_hidden_layers",t.num_encoder_heads="encoder_num_key_value_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"vision-encoder-decoder":const r=n(e.decoder),a="num_decoder_layers"in r,i=(0,o.pick)(e,["model_type","is_encoder_decoder"]);return a?(i.num_decoder_layers=r.num_decoder_layers,i.num_decoder_heads=r.num_decoder_heads,i.decoder_hidden_size=r.decoder_hidden_size,i.num_encoder_layers=r.num_encoder_layers,i.num_encoder_heads=r.num_encoder_heads,i.encoder_hidden_size=r.encoder_hidden_size):(i.num_layers=r.num_layers,i.num_heads=r.num_heads,i.hidden_size=r.hidden_size),i}const r={...s,...(0,o.pick)(e,["model_type","multi_query","is_encoder_decoder"])};for(const s in t)r[s]=e[t[s]];return r}function a(e,{prefix:t="past_key_values",batch_size:s=1}={}){const o={},r=e.normalized_config;if(r.is_encoder_decoder&&"num_encoder_heads"in r&&"num_decoder_heads"in r){const e=r.encoder_dim_kv??r.encoder_hidden_size/r.num_encoder_heads,n=r.decoder_dim_kv??r.decoder_hidden_size/r.num_decoder_heads,a=[s,r.num_encoder_heads,0,e],i=[s,r.num_decoder_heads,0,n];for(let e=0;e<r.num_decoder_layers;++e)o[`${t}.${e}.encoder.key`]=a,o[`${t}.${e}.encoder.value`]=a,o[`${t}.${e}.decoder.key`]=i,o[`${t}.${e}.decoder.value`]=i}else{const e=r.num_heads,n=r.num_layers,a=r.dim_kv??r.hidden_size/(r.num_attention_heads??e);if("falcon"===r.model_type){const r=[s*e,0,a];for(let e=0;e<n;++e)o[`${t}.${e}.key`]=r,o[`${t}.${e}.value`]=r}else if(r.multi_query){const r=[s*e,0,2*a];for(let e=0;e<n;++e)o[`${t}.${e}.key_value`]=r}else if("bloom"===r.model_type){const r=[s*e,a,0],i=[s*e,0,a];for(let e=0;e<n;++e)o[`${t}.${e}.key`]=r,o[`