Skip to content

Whisper Transcriber: run on phones, and stop the bundle phoning home#132

Merged
YurMil merged 1 commit into
mainfrom
feat/whisper-transcriber-mobile
Jul 21, 2026
Merged

Whisper Transcriber: run on phones, and stop the bundle phoning home#132
YurMil merged 1 commit into
mainfrom
feat/whisper-transcriber-mobile

Conversation

@YurMil

@YurMil YurMil commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Republishes the embedded transcriber so it works on a phone, and corrects the documentation that no longer matched it. Source changes: YurMil/ws-speech-text#3 (merged).

Reported symptom: on an iPhone the page reloaded itself right after the model finished downloading — the browser killing the tab for memory, not an error the app could catch.

What changed for users

Before After
Model on a phone 151 MB of fp32 weights 41 MB, WASM + q8
Model on desktop 151 MB of fp32 weights 77 MB, WebGPU + fp16
Conveyor windows on a phone 30 s / 5 s overlap 15 s / 3 s — halves peak memory
Quoted download size 77 MB, wrong on both paths the figure for this device, shown before you start
Transcript field read-only, absent with timestamps on editable again — exports read from it
Third-party requests a web font from Google none

The interface is now mobile-first: one column on a phone, tap targets at least 44 px, 16 px form fields so iOS does not zoom on focus, and the screen is kept awake while work is in flight.

The leak worth reviewing

The mobile branch arrived with a new stylesheet that opened with @import url('https://fonts.googleapis.com/…').

Our CSP (style-src 'self', font-src 'self' data:) blocks it, so the typeface never arrived and the design silently fell back to a system font — while every page load still announced the visitor's IP to Google. The privacy section of this utility's documentation, in all six locales, says the only outbound request is the pinned model. That would have been false.

It is the same class of bug as the jsDelivr one in #131, one layer down, and my artifact audit did not catch it because it only inspected the entry HTML. That gap is now closed upstream: pnpm verify fails on any absolute URL in CSS and ratchets JS origins against a reviewed allowlist. Regression-tested by re-adding the import — the build fails with stylesheet reaches a third party.

Documentation

Rewritten in all six locales to match the shipped utility:

  • download size is per device (41 MB WASM / 77 MB WebGPU) instead of one number that was wrong for both paths;
  • control names match the interface again — Start Transcription, Record Audio, Clear File;
  • conveyor windows documented as 30/5 on desktop and 15/3 on mobile;
  • new "On a phone" section: what is adjusted automatically, plus the two things that still need the user — keeping the tab in the foreground, and expecting a phone to be slower than a laptop;
  • privacy section now also states that the build is checked for third-party references before it can be published.

src/data/utilityShellPages.tsx carries the same corrected download figure and a mobile line in the feature list.

Verification

The artifact was served with the exact headers from this repository's vercel.json — same script-src, connect-src and Permissions-Policy — and a real transcription was run on both engines:

Engine Result Model preparation
auto → WebGPU / fp16 complete, no console errors 9.9 s
WASM / q8 complete, no console errors 4.3 s

Zero external requests recorded. Layout holds at 375 px with no horizontal overflow and no tap target under 44 px. npm run typecheck, npm run lint (0 errors) and the six-locale npm run build pass; the artifact manifest checksums verify and its build id resolves to a commit on the source repository's main.

Not verified: a real iPhone. The tab-kill that prompted this is device behaviour I cannot reproduce locally. Worth a live check after deploy — the utility should select WASM and quote ~41 MB on its own, and the badge above the drop zone shows which path it picked before anything downloads.

🤖 Generated with Claude Code

Picks up the mobile work from the source repository: fp16 instead of fp32, a
WASM default and a 41 MB model on mobile, tighter conveyor windows, one
mobile-first interface, and no third-party requests at all — the new stylesheet
had been pulling a web font from Google, which this site's CSP blocks and which
would have leaked every visitor's IP.

Documentation follows what the utility now does, in all six locales:
- download size is per device (41 MB WASM / 77 MB WebGPU) instead of one wrong
  number quoted for both paths;
- control names match the interface again (Start Transcription, Record Audio,
  Clear File);
- conveyor windows are documented as 30/5 on desktop and 15/3 on mobile;
- a new "on a phone" section covers what is adjusted automatically and the two
  things that still need the user's attention;
- privacy section states that nothing but the pinned model is fetched, and that
  the build is checked for it before publishing.

Typecheck, lint and the six-locale build pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cadautoscript-com Ready Ready Preview, Comment Jul 21, 2026 6:34pm

@supabase

supabase Bot commented Jul 21, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project bkcimygtsnckzexbfqxh because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@YurMil
YurMil merged commit 615d239 into main Jul 21, 2026
8 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

`}):(console.warn("You are passing both `text` and `images` to `PaliGemmaProcessor`. The processor expects special image tokens in the text, as many tokens as there are images per each text. It is recommended to add `<image>` tokens in the very beginning of your text. For this call, we will infer how many images each text has and add special tokens."),y=d.map(v=>i(v,f,_,a,p.length)));const k=this.tokenizer(y,u);return{...await this.image_processor(p,u),...k}}}}),"./src/models/parakeet/feature_extraction_parakeet.js":((e,r,t)=>{t.r(r),t.d(r,{ParakeetFeatureExtractor:()=>i});var s=t("./src/base/feature_extraction_utils.js"),n=t("./src/utils/tensor.js"),o=t("./src/utils/audio.js");const a=1e-5;class i extends s.FeatureExtractor{constructor(c){super(c),this.config.mel_filters??=(0,o.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,this.config.sampling_rate/2,this.config.sampling_rate,"slaney","slaney");const p=(0,o.window_function)(this.config.win_length,"hann",{periodic:!1});this.window=new Float64Array(this.config.n_fft);const d=Math.floor((this.config.n_fft-this.config.win_length)/2);this.window.set(p,d)}async _extract_fbank_features(c){const p=this.config.preemphasis;c=new Float64Array(c);for(let u=c.length-1;u>=1;--u)c[u]-=p*c[u-1];return await(0,o.spectrogram)(c,this.window,this.window.length,this.config.hop_length,{fft_length:this.config.n_fft,power:2,mel_filters:this.config.mel_filters,log_mel:"log",mel_floor:-1/0,pad_mode:"constant",center:!0,transpose:!0,mel_offset:2**-24})}async _call(c){(0,s.validate_audio_inputs)(c,"ParakeetFeatureExtractor");const p=await this._extract_fbank_features(c),d=Math.floor((c.length+Math.floor(this.config.n_fft/2)*2-this.config.n_fft)/this.config.hop_length),u=p.data;u.fill(0,d*p.dims[1]);const[f,_]=p.dims,y=new Float64Array(_),k=new Float64Array(_);for(let I=0;I<d;++I){const T=I*_;for(let b=0;b<_;++b){const E=u[T+b];y[b]+=E,k[b]+=E*E}}const w=d>1?d-1:1;for(let I=0;I<_;++I){const T=y[I]/d,b=(k[I]-d*T*T)/w,x=1/(Math.sqrt(b)+a);for(let S=0;S<d;++S){const O=S*_+I;u[O]=(u[O]-T)*x}}const v=new BigInt64Array(f);return v.fill(1n,0,d),{input_features:p.unsqueeze_(0),attention_mask:new n.Tensor("int64",v,[1,f])}}}}),"./src/models/phi3_v/image_processing_phi3_v.js":((e,r,t)=>{t.r(r),t.d(r,{Phi3VImageProcessor:()=>p});var s=t("./src/base/image_processors_utils.js"),n=t("./src/utils/tensor.js");const o=336,a=[2,3],{ceil:i,floor:l,sqrt:c}=Math;class p extends s.ImageProcessor{constructor(u){super({...u,do_normalize:!0,do_pad:!0,pad_size:"custom",do_convert_rgb:!0,do_resize:!0}),this._num_crops=u.num_crops}calc_num_image_tokens_from_image_size(u,f){const{num_img_tokens:_}=this.config;return l((l(f/o)*l(u/o)+1)*_+1+(l(f/o)+1)*c(_))}get_resize_output_image_size(u,f){const _=this._num_crops,[y,k]=u.size;let w=y/k,v=1;for(;v*Math.ceil(v/w)<=_;)v+=1;v-=1;const I=Math.floor(v*336),T=Math.floor(I/w);return[I,T]}pad_image(u,f,_,y={}){const[k,w]=f,v=o*i(k/o),I=o*i(w/o),T=[1,1,1].map((b,E)=>(b-this.image_mean[E])/this.image_std[E]);return super.pad_image(u,f,{width:I,height:v},{center:!0,constant_values:T,...y})}async _call(u,{num_crops:f=null}={}){if(this._num_crops=f??=this.config.num_crops,f<4||c(f)%1!==0)throw new Error("num_crops must be a square number >= 4");Array.isArray(u)||(u=[u]);const _=u.length,y=await Promise.all(u.map(x=>this.preprocess(x))),k=y.map(x=>x.original_size),w=y.map(x=>x.reshaped_input_size),v=[];for(const{pixel_values:x}of y){x.unsqueeze_(0);const[S,O]=x.dims.slice(-2),F=await(0,n.interpolate_4d)(x,{size:[o,o],mode:"bicubic"});if(f>0){const H=[],W=c(f),B=l(O/W),Y=l(S/W);for(let J=0;J<W;++J)for(let re=0;re<W;++re){let ne,le,pe,oe;J===W-1?(le=S-Y,oe=S):(le=J*Y,oe=(J+1)*Y),re===W-1?(ne=O-B,pe=O):(ne=re*B,pe=(re+1)*B);const K=[le,ne],N=[oe,pe],D=await(0,n.slice)(x,K,N,a);H.push(D)}const X=await(0,n.interpolate_4d)((0,n.cat)(H,0),{size:[o,o],mode:"bicubic"});v.push((0,n.cat)([F,X],0))}else v.push(F)}const I=(0,n.stack)(v,0),T=w.map(x=>x.map(S=>o*i(S/o))),b=new n.Tensor("int64",T.flat(),[_,2]),E=T.map(([x,S])=>this.calc_num_image_tokens_from_image_size(S,x));return{pixel_values:I,original_sizes:k,reshaped_input_sizes:w,image_sizes:b,num_img_tokens:E}}}}),"./src/models/phi3_v/processing_phi3_v.js":((e,r,t)=>{t.r(r),t.d(r,{Phi3VProcessor:()=>l});var s=t("./src/base/processing_utils.js"),n=t("./src/models/auto/image_processing_auto.js"),o=t("./src/tokenizers.js");t("./src/utils/image.js");const a="<|image|>",i=/<\|image_\d+\|>/g;class l extends s.Processor{static image_processor_class=n.AutoImageProcessor;static tokenizer_class=o.AutoTokenizer;async _call(p,d=null,{padding:u=!0,truncation:f=!0,num_crops:_=null}={}){Array.isArray(p)||(p=[p]);let y,k;if(d){k=await this.image_processor(d,{num_crops:_});const{num_img_tokens:w}=k,v=p.map((T,b)=>T.split(i).join(a.repeat(w[b])));y=this.tokenizer(v,{padding:u,truncation:f});const I=this.tokenizer.model.convert_tokens_to_ids([a])[0];y.input_ids.map_(T=>T==I?-T:T)}else y=this.tokenizer(p);return{...y,...k}}}}),"./src/models/pixtral/image_processing_pixtral.js":((e,r,t)=>{t.r(r),t.d(r,{PixtralImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{get_resize_output_image_size(a,i){const{longest_edge:l}=i;if(l===void 0)throw new Error("size must contain 'longest_edge'");const[c,p]=a.size,d=Math.max(c,p)/l;let u=c,f=p;d>1&&(u=Math.floor(c/d),f=Math.floor(p/d));const{patch_size:_,spatial_merge_size:y}=this.config;if(!y)throw new Error("config must contain 'spatial_merge_size'");const k=_*y,w=Math.floor((u-1)/k)+1,v=Math.floor((f-1)/k)+1;return[w*k,v*k]}}}),"./src/models/pixtral/processing_pixtral.js":((e,r,t)=>{t.r(r),t.d(r,{PixtralProcessor:()=>a});var s=t("./src/base/processing_utils.js"),n=t("./src/models/auto/image_processing_auto.js"),o=t("./src/tokenizers.js");class a extends s.Processor{static tokenizer_class=o.AutoTokenizer;static image_processor_class=n.AutoImageProcessor;static uses_processor_config=!0;async _call(l,c=null,p={}){const d=await this.image_processor(l,p);if(c){const[f,_]=d.pixel_values.dims.slice(-2),{image_token:y,image_break_token:k,image_end_token:w,patch_size:v,spatial_merge_size:I}=this.config,T=v*I,b=Math.floor(f/T),E=Math.floor(_/T);c=structuredClone(c),Array.isArray(c)||(c=[c]);for(let x=0;x<c.length;++x){const S=y.repeat(E),O=S+k,F=S+w,H=O.repeat(b-1)+F;c[x]=c[x].replace(y,H)}}const u=c?this.tokenizer(c,p):{};return{...d,...u}}}}),"./src/models/processors.js":((e,r,t)=>{t.r(r),t.d(r,{Florence2Processor:()=>s.Florence2Processor,Gemma3nProcessor:()=>n.Gemma3nProcessor,GroundingDinoProcessor:()=>o.GroundingDinoProcessor,Idefics3Processor:()=>a.Idefics3Processor,JinaCLIPProcessor:()=>l.JinaCLIPProcessor,LlavaProcessor:()=>c.LlavaProcessor,MgpstrProcessor:()=>p.MgpstrProcessor,MoonshineProcessor:()=>d.MoonshineProcessor,OwlViTProcessor:()=>u.OwlViTProcessor,PaliGemmaProcessor:()=>f.PaliGemmaProcessor,Phi3VProcessor:()=>_.Phi3VProcessor,PixtralProcessor:()=>y.PixtralProcessor,PyAnnoteProcessor:()=>k.PyAnnoteProcessor,Qwen2VLProcessor:()=>w.Qwen2VLProcessor,Sam2Processor:()=>I.Sam2Processor,Sam2VideoProcessor:()=>I.Sam2VideoProcessor,SamProcessor:()=>v.SamProcessor,SmolVLMProcessor:()=>T.SmolVLMProcessor,SpeechT5Processor:()=>b.SpeechT5Processor,UltravoxProcessor:()=>E.UltravoxProcessor,VLChatProcessor:()=>i.VLChatProcessor,VoxtralProcessor:()=>x.VoxtralProcessor,Wav2Vec2Processor:()=>S.Wav2Vec2Processor,Wav2Vec2ProcessorWithLM:()=>O.Wav2Vec2ProcessorWithLM,WhisperProcessor:()=>F.WhisperProcessor});var s=t("./src/models/florence2/processing_florence2.js"),n=t("./src/models/gemma3n/processing_gemma3n.js"),o=t("./src/models/grounding_dino/processing_grounding_dino.js"),a=t("./src/models/idefics3/processing_idefics3.js"),i=t("./src/models/janus/processing_janus.js"),l=t("./src/models/jina_clip/processing_jina_clip.js"),c=t("./src/models/llava/processing_llava.js"),p=t("./src/models/mgp_str/processing_mgp_str.js"),d=t("./src/models/moonshine/processing_moonshine.js"),u=t("./src/models/owlvit/processing_owlvit.js"),f=t("./src/models/paligemma/processing_paligemma.js"),_=t("./src/models/phi3_v/processing_phi3_v.js"),y=t("./src/models/pixtral/processing_pixtral.js"),k=t("./src/models/pyannote/processing_pyannote.js"),w=t("./src/models/qwen2_vl/processing_qwen2_vl.js"),v=t("./src/models/sam/processing_sam.js"),I=t("./src/models/sam2/processing_sam2.js"),T=t("./src/models/smolvlm/processing_smolvlm.js"),b=t("./src/models/speecht5/processing_speecht5.js"),E=t("./src/models/ultravox/processing_ultravox.js"),x=t("./src/models/voxtral/processing_voxtral.js"),S=t("./src/models/wav2vec2/processing_wav2vec2.js"),O=t("./src/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.js"),F=t("./src/models/whisper/processing_whisper.js")}),"./src/models/pvt/image_processing_pvt.js":((e,r,t)=>{t.r(r),t.d(r,{PvtImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{}}),"./src/models/pyannote/feature_extraction_pyannote.js":((e,r,t)=>{t.r(r),t.d(r,{PyAnnoteFeatureExtractor:()=>a});var s=t("./src/base/feature_extraction_utils.js"),n=t("./src/utils/tensor.js"),o=t("./src/utils/maths.js");class a extends s.FeatureExtractor{async _call(l){(0,s.validate_audio_inputs)(l,"PyAnnoteFeatureExtractor"),l instanceof Float64Array&&(l=new Float32Array(l));const c=[1,1,l.length];return{input_values:new n.Tensor("float32",l,c)}}samples_to_frames(l){return(l-this.config.offset)/this.config.step}post_process_speaker_diarization(l,c){const p=c/this.samples_to_frames(c)/this.config.sampling_rate,d=[];for(const u of l.tolist()){const f=[];let _=-1;for(let y=0;y<u.length;++y){const k=(0,o.softmax)(u[y]),[w,v]=(0,o.max)(k),[I,T]=[y,y+1];v!==_?(_=v,f.push({id:v,start:I,end:T,score:w})):(f.at(-1).end=T,f.at(-1).score+=w)}d.push(f.map(({id:y,start:k,end:w,score:v})=>({id:y,start:k*p,end:w*p,confidence:v/(w-k)})))}return d}}}),"./src/models/pyannote/processing_pyannote.js":((e,r,t)=>{t.r(r),t.d(r,{PyAnnoteProcessor:()=>o});var s=t("./src/base/processing_utils.js"),n=t("./src/models/pyannote/feature_extraction_pyannote.js");class o extends s.Processor{static feature_extractor_class=n.PyAnnoteFeatureExtractor;async _call(i){return await this.feature_extractor(i)}post_process_speaker_diarization(...i){return this.feature_extractor.post_process_speaker_diarization(...i)}get sampling_rate(){return this.feature_extractor.config.sampling_rate}}}),"./src/models/qwen2_vl/image_processing_qwen2_vl.js":((e,r,t)=>{t.r(r),t.d(r,{Qwen2VLImageProcessor:()=>o});var s=t("./src/base/image_processors_utils.js"),n=t("./src/utils/tensor.js");class o extends s.ImageProcessor{async _call(i,...l){const{pixel_values:c,original_sizes:p,reshaped_input_sizes:d}=await super._call(i,...l);let u=c;const{temporal_patch_size:f,merge_size:_,patch_size:y}=this.config;u.dims[0]===1&&(u=(0,n.cat)(Array.from({length:f},()=>u),0));const k=u.dims[0]/f,w=u.dims[1],v=Math.floor(u.dims[2]/y),I=Math.floor(u.dims[3]/y),T=u.view(k,f,w,Math.floor(v/_),_,y,Math.floor(I/_),_,y).permute(0,3,6,4,7,2,1,5,8).view(k*v*I,w*f*y*y),b=new n.Tensor("int64",[k,v,I],[1,3]);return{pixel_values:T,image_grid_thw:b,original_sizes:p,reshaped_input_sizes:d}}}}),"./src/models/qwen2_vl/processing_qwen2_vl.js":((e,r,t)=>{t.r(r),t.d(r,{Qwen2VLProcessor:()=>a});var s=t("./src/base/processing_utils.js"),n=t("./src/models/auto/image_processing_auto.js"),o=t("./src/tokenizers.js");t("./src/utils/image.js");class a extends s.Processor{static image_processor_class=n.AutoImageProcessor;static tokenizer_class=o.AutoTokenizer;async _call(l,c=null,...p){Array.isArray(l)||(l=[l]);let d,u;if(c&&(d=await this.image_processor(c),u=d.image_grid_thw),u){let _=this.image_processor.config.merge_size**2,y=0;const k=u.tolist();l=l.map(w=>{for(;w.includes("<|image_pad|>");){const v=Number(k[y++].reduce((I,T)=>I*T,1n));w=w.replace("<|image_pad|>","<|placeholder|>".repeat(Math.floor(v/_)))}return w.replaceAll("<|placeholder|>","<|image_pad|>")})}return{...this.tokenizer(l),...d}}}}),"./src/models/rt_detr/image_processing_rt_detr.js":((e,r,t)=>{t.r(r),t.d(r,{RTDetrImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{post_process_object_detection(...a){return(0,s.post_process_object_detection)(...a)}}}),"./src/models/sam/image_processing_sam.js":((e,r,t)=>{t.r(r),t.d(r,{SamImageProcessor:()=>a});var s=t("./src/base/image_processors_utils.js"),n=t("./src/utils/core.js"),o=t("./src/utils/tensor.js");class a extends s.ImageProcessor{reshape_input_points(l,c,p,d=!1){l=structuredClone(l);let u=(0,n.calculateDimensions)(l);if(u.length===3)d||(u=[1,...u]),l=[l];else if(u.length!==4)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let f=0;f<l.length;++f){const[_,y]=c[f],[k,w]=p[f],v=[w/y,k/_];for(let I=0;I<l[f].length;++I)for(let T=0;T<l[f][I].length;++T)for(let b=0;b<l[f][I][T].length;++b)l[f][I][T][b]*=v[b%2]}return new o.Tensor("float32",Float32Array.from(l.flat(1/0)),u)}add_input_labels(l,c){let p=(0,n.calculateDimensions)(l);if(p.length===2)p=[1,...p],l=[l];else if(p.length!==3)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(p.some((d,u)=>d!==c.dims[u]))throw Error(`The first ${p.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new o.Tensor("int64",l.flat(1/0).map(BigInt),p)}async _call(l,{input_points:c=null,input_labels:p=null,input_boxes:d=null}={}){const u=await super._call(l);if(c&&(u.input_points=this.reshape_input_points(c,u.original_sizes,u.reshaped_input_sizes)),p){if(!u.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");u.input_labels=this.add_input_labels(p,u.input_points)}return d&&(u.input_boxes=this.reshape_input_points(d,u.original_sizes,u.reshaped_input_sizes,!0)),u}async post_process_masks(l,c,p,{mask_threshold:d=0,binarize:u=!0,pad_size:f=null}={}){const _=[];f=f??this.pad_size??this.size;const y=[f.height,f.width];for(let k=0;k<c.length;++k){const w=c[k],v=p[k];let I=await(0,o.interpolate_4d)(l[k],{mode:"bilinear",size:y});if(I=I.slice(null,null,[0,v[0]],[0,v[1]]),I=await(0,o.interpolate_4d)(I,{mode:"bilinear",size:w}),u){const T=I.data,b=new Uint8Array(T.length);for(let E=0;E<T.length;++E)T[E]>d&&(b[E]=1);I=new o.Tensor("bool",b,I.dims)}_.push(I)}return _}generate_crop_boxes(l,c,{crop_n_layers:p=0,overlap_ratio:d=512/1500,points_per_crop:u=32,crop_n_points_downscale_factor:f=1}={}){}}}),"./src/models/sam/processing_sam.js":((e,r,t)=>{t.r(r),t.d(r,{SamProcessor:()=>o});var s=t("./src/base/processing_utils.js"),n=t("./src/models/auto/image_processing_auto.js");class o extends s.Processor{static image_processor_class=n.AutoImageProcessor;async _call(...i){return await this.image_processor(...i)}post_process_masks(...i){return this.image_processor.post_process_masks(...i)}reshape_input_points(...i){return this.image_processor.reshape_input_points(...i)}}}),"./src/models/sam2/image_processing_sam2.js":((e,r,t)=>{t.r(r),t.d(r,{Sam2ImageProcessor:()=>s.SamImageProcessor});var s=t("./src/models/sam/image_processing_sam.js")}),"./src/models/sam2/processing_sam2.js":((e,r,t)=>{t.r(r),t.d(r,{Sam2Processor:()=>n,Sam2VideoProcessor:()=>o});var s=t("./src/models/sam/processing_sam.js");class n extends s.SamProcessor{}class o extends n{}}),"./src/models/sam3/image_processing_sam3.js":((e,r,t)=>{t.r(r),t.d(r,{Sam3ImageProcessor:()=>s.Sam2ImageProcessor});var s=t("./src/models/sam2/image_processing_sam2.js")}),"./src/models/seamless_m4t/feature_extraction_seamless_m4t.js":((e,r,t)=>{t.r(r),t.d(r,{SeamlessM4TFeatureExtractor:()=>a});var s=t("./src/base/feature_extraction_utils.js"),n=t("./src/utils/tensor.js"),o=t("./src/utils/audio.js");class a extends s.FeatureExtractor{constructor(l){super(l);const c=this.config.sampling_rate,p=(0,o.mel_filter_bank)(257,this.config.num_mel_bins,20,Math.floor(c/2),c,null,"kaldi",!0);this.mel_filters=p,this.window=(0,o.window_function)(400,"povey",{periodic:!1})}async _extract_fbank_features(l,c){return l=l.map(p=>p*32768),(0,o.spectrogram)(l,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:c,transpose:!0})}async _call(l,{padding:c=!0,pad_to_multiple_of:p=2,do_normalize_per_mel_bins:d=!0,return_attention_mask:u=!0}={}){(0,s.validate_audio_inputs)(l,"SeamlessM4TFeatureExtractor");let f=await this._extract_fbank_features(l,this.config.max_length);if(d){const[b,E]=f.dims,x=f.data;for(let S=0;S<E;++S){let O=0;for(let B=0;B<b;++B)O+=x[B*E+S];const F=O/b;let H=0;for(let B=0;B<b;++B)H+=(x[B*E+S]-F)**2;H/=b-1;const W=Math.sqrt(H+1e-7);for(let B=0;B<b;++B){const Y=B*E+S;x[Y]=(x[Y]-F)/W}}}let _;if(c){const[b,E]=f.dims,x=f.data,S=b%p;if(S>0){const O=new Float32Array(E*(b+S));O.set(x),O.fill(this.config.padding_value,x.length);const F=b+S;f=new n.Tensor(f.type,O,[F,E]),u&&(_=new n.Tensor("int64",new BigInt64Array(F),[1,F]),_.data.fill(1n,0,b))}}const[y,k]=f.dims,w=this.config.stride;if(y%w!==0)throw new Error(`The number of frames (${y}) must be a multiple of the stride (${w}).`);const I=f.view(1,Math.floor(y/w),k*w),T={input_features:I};if(u){const b=I.dims[1],E=new BigInt64Array(b);if(_){const x=_.data;for(let S=1,O=0;S<y;S+=w,++O)E[O]=x[S]}else E.fill(1n);T.attention_mask=new n.Tensor("int64",E,[1,b])}return T}}}),"./src/models/segformer/image_processing_segformer.js":((e,r,t)=>{t.r(r),t.d(r,{SegformerFeatureExtractor:()=>o,SegformerImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{post_process_semantic_segmentation(...i){return(0,s.post_process_semantic_segmentation)(...i)}}class o extends n{}}),"./src/models/siglip/image_processing_siglip.js":((e,r,t)=>{t.r(r),t.d(r,{SiglipImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{}}),"./src/models/smolvlm/image_processing_smolvlm.js":((e,r,t)=>{t.r(r),t.d(r,{SmolVLMImageProcessor:()=>s.Idefics3ImageProcessor});var s=t("./src/models/idefics3/image_processing_idefics3.js")}),"./src/models/smolvlm/processing_smolvlm.js":((e,r,t)=>{t.r(r),t.d(r,{SmolVLMProcessor:()=>s.Idefics3Processor});var s=t("./src/models/idefics3/processing_idefics3.js")}),"./src/models/snac/feature_extraction_snac.js":((e,r,t)=>{t.r(r),t.d(r,{SnacFeatureExtractor:()=>n});var s=t("./src/models/dac/feature_extraction_dac.js");class n extends s.DacFeatureExtractor{}}),"./src/models/speecht5/feature_extraction_speecht5.js":((e,r,t)=>{t.r(r),t.d(r,{SpeechT5FeatureExtractor:()=>n});var s=t("./src/base/feature_extraction_utils.js");class n extends s.FeatureExtractor{}}),"./src/models/speecht5/processing_speecht5.js":((e,r,t)=>{t.r(r),t.d(r,{SpeechT5Processor:()=>a});var s=t("./src/base/processing_utils.js"),n=t("./src/tokenizers.js"),o=t("./src/models/auto/feature_extraction_auto.js");class a extends s.Processor{static tokenizer_class=n.AutoTokenizer;static feature_extractor_class=o.AutoFeatureExtractor;async _call(l){return await this.feature_extractor(l)}}}),"./src/models/swin2sr/image_processing_swin2sr.js":((e,r,t)=>{t.r(r),t.d(r,{Swin2SRImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{pad_image(a,i,l,c={}){const[p,d,u]=i;return super.pad_image(a,i,{width:d+(l-d%l)%l,height:p+(l-p%l)%l},{mode:"symmetric",center:!1,constant_values:-1,...c})}}}),"./src/models/ultravox/processing_ultravox.js":((e,r,t)=>{t.r(r),t.d(r,{UltravoxProcessor:()=>a});var s=t("./src/models/auto/feature_extraction_auto.js"),n=t("./src/tokenizers.js"),o=t("./src/base/processing_utils.js");class a extends o.Processor{static tokenizer_class=n.AutoTokenizer;static feature_extractor_class=s.AutoFeatureExtractor;static uses_processor_config=!0;async _call(l,c=null,p={}){if(Array.isArray(l))throw new Error("Batched inputs are not supported yet.");let d={};if(c){const f=c.length,{input_features:_}=await this.feature_extractor(c,{...p,max_length:f}),y=Math.round(f/this.config.encoder_ds_factor+1e-4),k=1+Math.ceil(y/this.config.stack_factor);d.audio_token_len=[k],d.audio_values=_;const w=this.config.audio_placeholder;if(!l.includes(w))throw new Error(`The input text does not contain the image token ${w}.`);l=l.replaceAll(w,w.repeat(k))}return{...this.tokenizer(l,{add_special_tokens:!1,...p}),...d}}}}),"./src/models/vit/image_processing_vit.js":((e,r,t)=>{t.r(r),t.d(r,{ViTFeatureExtractor:()=>o,ViTImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{}class o extends n{}}),"./src/models/vitmatte/image_processing_vitmatte.js":((e,r,t)=>{t.r(r),t.d(r,{VitMatteImageProcessor:()=>o});var s=t("./src/base/image_processors_utils.js"),n=t("./src/utils/tensor.js");class o extends s.ImageProcessor{async _call(i,l){Array.isArray(i)||(i=[i]),Array.isArray(l)||(l=[l]);const c=await Promise.all(i.map(u=>this.preprocess(u))),p=await Promise.all(l.map(u=>this.preprocess(u,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:(0,n.stack)(c.map((u,f)=>(0,n.cat)([u.pixel_values,p[f].pixel_values],0)),0),original_sizes:c.map(u=>u.original_size),reshaped_input_sizes:c.map(u=>u.reshaped_input_size)}}}}),"./src/models/vitpose/image_processing_vitpose.js":((e,r,t)=>{t.r(r),t.d(r,{VitPoseImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{post_process_pose_estimation(a,i,{threshold:l=null}={}){const c=a.tolist(),[p,d,u,f]=a.dims,_=[];for(let y=0;y<p;++y){const k=c[y],w=i[y],v=[];for(let I=0;I<w.length;++I){const T=w[I],b=[],E=[],x=[],S=T.at(-2)/f,O=T.at(-1)/u;for(let F=0;F<k.length;++F){let[H,W]=[0,0],B=0,Y=-1/0;const X=k[F];for(let re=0;re<X.length;++re){const ne=X[re];for(let le=0;le<ne.length;++le){const pe=ne[le];B+=pe,Y=Math.max(Y,pe),H+=(le+.5)*pe,W+=re*pe}}if(l!=null&&Y<l)continue;const J=[S*H/B,O*W/B];b.push(J),x.push(F),E.push(Y)}v.push({bbox:T,scores:E,labels:x,keypoints:b})}_.push(v)}return _}}}),"./src/models/voxtral/processing_voxtral.js":((e,r,t)=>{t.r(r),t.d(r,{VoxtralProcessor:()=>d});var s=t("./src/models/auto/feature_extraction_auto.js"),n=t("./src/tokenizers.js"),o=t("./src/base/processing_utils.js"),a=t("./src/utils/tensor.js");const i="[AUDIO]",l="[BEGIN_AUDIO]",c=375;function p(u,f){const _=[];for(let y=0;y<u.length;y+=f)_.push(u.subarray(y,Math.min(y+f,u.length)));return _}class d extends o.Processor{static tokenizer_class=n.AutoTokenizer;static feature_extractor_class=s.AutoFeatureExtractor;static uses_processor_config=!1;async _call(f,_=null,y={}){if(Array.isArray(f))throw new Error("Batched inputs are not supported yet.");const k={};if(_){if(!f.includes(i))throw new Error(`The input text does not contain the audio token ${i}.`);Array.isArray(_)||(_=[_]);const v=f.split(i),I=v.length-1;if(I!==_.length)throw new Error(`The number of audio inputs (${_.length}) does not match the number of audio tokens in the text (${I}).`);const T=this.feature_extractor.config.n_samples,b=_.map(F=>p(F,T)),E=b.map(F=>F.length),x=b.flat(),S=(await Promise.all(x.map(F=>this.feature_extractor(F,y)))).map(F=>F.input_features);k.audio_values=S.length>1?(0,a.cat)(S,0):S[0];let O=v[0];for(let F=0;F<E.length;++F){O+=l;for(let H=0;H<E[F];++H)O+=i.repeat(c);O+=v[F+1]}f=O}return{...this.tokenizer(f,{add_special_tokens:!1,...y}),...k}}}}),"./src/models/wav2vec2/feature_extraction_wav2vec2.js":((e,r,t)=>{t.r(r),t.d(r,{Wav2Vec2FeatureExtractor:()=>o});var s=t("./src/base/feature_extraction_utils.js"),n=t("./src/utils/tensor.js");class o extends s.FeatureExtractor{_zero_mean_unit_var_norm(i){const c=i.reduce((d,u)=>d+u,0)/i.length,p=i.reduce((d,u)=>d+(u-c)**2,0)/i.length;return i.map(d=>(d-c)/Math.sqrt(p+1e-7))}async _call(i){(0,s.validate_audio_inputs)(i,"Wav2Vec2FeatureExtractor"),i instanceof Float64Array&&(i=new Float32Array(i));let l=i;this.config.do_normalize&&(l=this._zero_mean_unit_var_norm(l));const c=[1,l.length];return{input_values:new n.Tensor("float32",l,c),attention_mask:new n.Tensor("int64",new BigInt64Array(l.length).fill(1n),c)}}}}),"./src/models/wav2vec2/processing_wav2vec2.js":((e,r,t)=>{t.r(r),t.d(r,{Wav2Vec2Processor:()=>a});var s=t("./src/tokenizers.js"),n=t("./src/models/auto/feature_extraction_auto.js"),o=t("./src/base/processing_utils.js");class a extends o.Processor{static tokenizer_class=s.AutoTokenizer;static feature_extractor_class=n.AutoFeatureExtractor;async _call(l){return await this.feature_extractor(l)}}}),"./src/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.js":((e,r,t)=>{t.r(r),t.d(r,{Wav2Vec2ProcessorWithLM:()=>a});var s=t("./src/tokenizers.js"),n=t("./src/models/auto/feature_extraction_auto.js"),o=t("./src/base/processing_utils.js");class a extends o.Processor{static tokenizer_class=s.AutoTokenizer;static feature_extractor_class=n.AutoFeatureExtractor;async _call(l){return await this.feature_extractor(l)}}}),"./src/models/wespeaker/feature_extraction_wespeaker.js":((e,r,t)=>{t.r(r),t.d(r,{WeSpeakerFeatureExtractor:()=>o});var s=t("./src/base/feature_extraction_utils.js");t("./src/utils/tensor.js");var n=t("./src/utils/audio.js");class o extends s.FeatureExtractor{constructor(i){super(i);const l=this.config.sampling_rate,c=(0,n.mel_filter_bank)(257,this.config.num_mel_bins,20,Math.floor(l/2),l,null,"kaldi",!0);this.mel_filters=c,this.window=(0,n.window_function)(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(i){return i=i.map(l=>l*32768),(0,n.spectrogram)(i,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(i){(0,s.validate_audio_inputs)(i,"WeSpeakerFeatureExtractor");const l=(await this._extract_fbank_features(i)).unsqueeze_(0);if(this.config.fbank_centering_span===null){const c=l.mean(1).data,p=l.data,[d,u,f]=l.dims;for(let _=0;_<d;++_){const y=_*u*f,k=_*f;for(let w=0;w<u;++w){const v=y+w*f;for(let I=0;I<f;++I)p[v+I]-=c[k+I]}}}return{input_features:l}}}}),"./src/models/whisper/common_whisper.js":((e,r,t)=>{t.r(r),t.d(r,{WHISPER_LANGUAGE_MAPPING:()=>n,WHISPER_TO_LANGUAGE_CODE_MAPPING:()=>o,whisper_language_to_code:()=>a});const s=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],n=new Map(s),o=new Map([...s.map(([i,l])=>[l,i]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);function a(i){i=i.toLowerCase();let l=o.get(i);if(l===void 0){const c=i.match(/^<\|([a-z]{2})\|>$/);if(c&&(i=c[1]),n.has(i))l=i;else{const d=i.length===2?n.keys():n.values();throw new Error(`Language "${i}" is not supported. Must be one of: ${JSON.stringify(Array.from(d))}`)}}return l}}),"./src/models/whisper/feature_extraction_whisper.js":((e,r,t)=>{t.r(r),t.d(r,{WhisperFeatureExtractor:()=>a});var s=t("./src/base/feature_extraction_utils.js");t("./src/utils/tensor.js");var n=t("./src/utils/audio.js"),o=t("./src/utils/maths.js");class a extends s.FeatureExtractor{constructor(l){super(l),this.config.mel_filters??=(0,n.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=(0,n.window_function)(this.config.n_fft,"hann")}async _extract_fbank_features(l){const c=await(0,n.spectrogram)(l,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:Math.min(Math.floor(l.length/this.config.hop_length),this.config.nb_max_frames)}),p=c.data,d=(0,o.max)(p)[0];for(let u=0;u<p.length;++u)p[u]=(Math.max(p[u],d-8)+4)/4;return c}async _call(l,{max_length:c=null}={}){(0,s.validate_audio_inputs)(l,"WhisperFeatureExtractor");let p;const d=c??this.config.n_samples;return l.length>d?(l.length>this.config.n_samples&&console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),p=l.slice(0,d)):(p=new Float32Array(d),p.set(l)),{input_features:(await this._extract_fbank_features(p)).unsqueeze_(0)}}}}),"./src/models/whisper/generation_whisper.js":((e,r,t)=>{t.r(r),t.d(r,{WhisperGenerationConfig:()=>n});var s=t("./src/generation/configuration_utils.js");class n extends s.GenerationConfig{return_timestamps=null;return_token_timestamps=null;num_frames=null;alignment_heads=null;task=null;language=null;no_timestamps_token_id=null;prompt_ids=null;is_multilingual=null;lang_to_id=null;task_to_id=null;max_initial_timestamp_index=1}}),"./src/models/whisper/processing_whisper.js":((e,r,t)=>{t.r(r),t.d(r,{WhisperProcessor:()=>a});var s=t("./src/models/auto/feature_extraction_auto.js"),n=t("./src/tokenizers.js"),o=t("./src/base/processing_utils.js");class a extends o.Processor{static tokenizer_class=n.AutoTokenizer;static feature_extractor_class=s.AutoFeatureExtractor;async _call(l){return await this.feature_extractor(l)}}}),"./src/models/yolos/image_processing_yolos.js":((e,r,t)=>{t.r(r),t.d(r,{YolosFeatureExtractor:()=>o,YolosImageProcessor:()=>n});var s=t("./src/base/image_processors_utils.js");class n extends s.ImageProcessor{post_process_object_detection(...i){return(0,s.post_process_object_detection)(...i)}}class o extends n{}}),"./src/ops/registry.js":((e,r,t)=>{t.r(r),t.d(r,{TensorOpRegistry:()=>a});var s=t("./src/backends/onnx.js"),n=t("./src/utils/tensor.js");const o=async(i,l,c)=>{const p=await(0,s.createInferenceSession)(new Uint8Array(i),l);return(async d=>{const u=(0,s.isONNXProxy)(),f=Object.fromEntries(Object.entries(d).map(([y,k])=>[y,(u?k.clone():k).ort_tensor])),_=await(0,s.runInferenceSession)(p,f);return Array.isArray(c)?c.map(y=>new n.Tensor(_[y])):new n.Tensor(_[c])})};class a{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=o([8,10,18,0,58,129,1,10,41,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,18,10,4,109,111,100,101,34,7,110,101,97,114,101,115,116,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,21],this.session_options,"y")),this._nearest_interpolate_4d}static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||(this._bilinear_interpolate_4d=o([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||(this._bicubic_interpolate_4d=o([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||(this._matmul=o([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,"c")),this._matmul}static get stft(){return this._stft||(this._stft=o([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,"o")),this._stft}static get rfft(){return this._rfft||(this._rfft=o([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,"y")),this._rfft}static get top_k(){return this._top_k||(this._top_k=o([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,["v","i"])),this._top_k}static get slice(){return this._slice||(this._slice=o([8,7,18,0,58,96,10,25,10,1,120,10,1,115,10,1,101,10,1,97,10,1,116,18,1,121,34,5,83,108,105,99,101,18,1,114,90,9,10,1,120,18,4,10,2,8,1,90,9,10,1,115,18,4,10,2,8,7,90,9,10,1,101,18,4,10,2,8,7,90,9,10,1,97,18,4,10,2,8,7,90,9,10,1,116,18,4,10,2,8,7,98,9,10,1,121,18,4,10,2,8,1,66,2,16,13],this.session_options,"y")),this._slice}}}),"./src/pipelines.js":((e,r,t)=>{t.r(r),t.d(r,{AudioClassificationPipeline:()=>W,AutomaticSpeechRecognitionPipeline:()=>Y,BackgroundRemovalPipeline:()=>ne,DepthEstimationPipeline:()=>te,DocumentQuestionAnsweringPipeline:()=>K,FeatureExtractionPipeline:()=>F,FillMaskPipeline:()=>I,ImageClassificationPipeline:()=>J,ImageFeatureExtractionPipeline:()=>H,ImageSegmentationPipeline:()=>re,ImageToImagePipeline:()=>D,ImageToTextPipeline:()=>X,ObjectDetectionPipeline:()=>pe,Pipeline:()=>y,QuestionAnsweringPipeline:()=>v,SummarizationPipeline:()=>b,Text2TextGenerationPipeline:()=>T,TextClassificationPipeline:()=>k,TextGenerationPipeline:()=>S,TextToAudioPipeline:()=>N,TokenClassificationPipeline:()=>w,TranslationPipeline:()=>E,ZeroShotAudioClassificationPipeline:()=>B,ZeroShotClassificationPipeline:()=>O,ZeroShotImageClassificationPipeline:()=>le,ZeroShotObjectDetectionPipeline:()=>oe,pipeline:()=>Ie});var s=t("./src/tokenizers.js"),n=t("./src/models.js"),o=t("./src/models/auto/processing_auto.js");t("./src/base/processing_utils.js");var a=t("./src/utils/generic.js"),i=t("./src/utils/core.js"),l=t("./src/utils/maths.js"),c=t("./src/utils/audio.js"),p=t("./src/utils/tensor.js"),d=t("./src/utils/image.js");async function u(Te){return Array.isArray(Te)||(Te=[Te]),await Promise.all(Te.map(Q=>d.RawImage.read(Q)))}async function f(Te,Q){return Array.isArray(Te)||(Te=[Te]),await Promise.all(Te.map(z=>typeof z=="string"||z instanceof URL?(0,c.read_audio)(z,Q):z instanceof Float64Array?new Float32Array(z):z))}function _(Te,Q){Q&&(Te=Te.map(xe=>xe|0));const[z,de,be,ve]=Te;return{xmin:z,ymin:de,xmax:be,ymax:ve}}class y extends a.Callable{constructor({task:Q,model:z,tokenizer:de=null,processor:be=null}){super(),this.task=Q,this.model=z,this.tokenizer=de,this.processor=be}async dispose(){await this.model.dispose()}}class k extends y{constructor(Q){super(Q)}async _call(Q,{top_k:z=1}={}){const de=this.tokenizer(Q,{padding:!0,truncation:!0}),be=await this.model(de),ve=this.model.config.problem_type==="multi_label_classification"?ge=>ge.sigmoid():ge=>new p.Tensor("float32",(0,l.softmax)(ge.data),ge.dims),xe=this.model.config.id2label,Ce=[];for(const ge of be.logits){const De=ve(ge),fe=await(0,p.topk)(De,z),Ee=fe[0].tolist(),Fe=fe[1].tolist().map((tt,Re)=>({label:xe?xe[tt]:`LABEL_${tt}`,score:Ee[Re]}));z===1?Ce.push(...Fe):Ce.push(Fe)}return Array.isArray(Q)||z===1?Ce:Ce[0]}}class w extends y{constructor(Q){super(Q)}async _call(Q,{ignore_labels:z=["O"]}={}){const de=Array.isArray(Q),be=this.tokenizer(de?Q:[Q],{padding:!0,truncation:!0}),xe=(await this.model(be)).logits,Ce=this.model.config.id2label,ge=[];for(let De=0;De<xe.dims[0];++De){const fe=be.input_ids[De],Ee=xe[De],We=[];for(let Fe=0;Fe<Ee.dims[0];++Fe){const tt=Ee[Fe],Re=(0,l.max)(tt.data)[1],rt=Ce?Ce[Re]:`LABEL_${Re}`;if(z.includes(rt))continue;const Ze=this.tokenizer.decode([fe[Fe].item()],{skip_special_tokens:!0});if(Ze==="")continue;const Ne=(0,l.softmax)(tt.data);We.push({entity:rt,score:Ne[Re],index:Fe,word:Ze})}ge.push(We)}return de?ge:ge[0]}}class v extends y{constructor(Q){super(Q)}async _call(Q,z,{top_k:de=1}={}){const be=this.tokenizer(Q,{text_pair:z,padding:!0,truncation:!0}),{start_logits:ve,end_logits:xe}=await this.model(be),Ce=be.input_ids.tolist(),ge=be.attention_mask.tolist(),De=this.tokenizer.all_special_ids,fe=[];for(let Ee=0;Ee<ve.dims[0];++Ee){const We=Ce[Ee],Fe=We.findIndex(Oe=>Oe==this.tokenizer.sep_token_id);ge[Ee].map((Oe,ot)=>Oe==1&&(ot===0||ot>Fe&&De.findIndex(ht=>ht==We[ot])===-1));const tt=ve[Ee].tolist(),Re=xe[Ee].tolist();for(let Oe=1;Oe<tt.length;++Oe)(ge[Ee]==0||Oe<=Fe||De.findIndex(ot=>ot==We[Oe])!==-1)&&(tt[Oe]=-1/0,Re[Oe]=-1/0);const rt=(0,l.softmax)(tt).map((Oe,ot)=>[Oe,ot]),Ze=(0,l.softmax)(Re).map((Oe,ot)=>[Oe,ot]);rt[0][0]=0,Ze[0][0]=0;const Ne=(0,i.product)(rt,Ze).filter(Oe=>Oe[0][1]<=Oe[1][1]).map(Oe=>[Oe[0][1],Oe[1][1],Oe[0][0]*Oe[1][0]]).sort((Oe,ot)=>ot[2]-Oe[2]);for(let Oe=0;Oe<Math.min(Ne.length,de);++Oe){const[ot,ht,Rt]=Ne[Oe],It=We.slice(ot,ht+1),gr=this.tokenizer.decode(It,{skip_special_tokens:!0});fe.push({answer:gr,score:Rt})}}return de===1?fe[0]:fe}}class I extends y{constructor(Q){super(Q)}async _call(Q,{top_k:z=5}={}){const de=this.tokenizer(Q,{padding:!0,truncation:!0}),{logits:be}=await this.model(de),ve=[],xe=de.input_ids.tolist();for(let Ce=0;Ce<xe.length;++Ce){const ge=xe[Ce],De=ge.findIndex(tt=>tt==this.tokenizer.mask_token_id);if(De===-1)throw Error(`Mask token (${this.tokenizer.mask_token}) not found in text.`);const fe=be[Ce][De],Ee=await(0,p.topk)(new p.Tensor("float32",(0,l.softmax)(fe.data),fe.dims),z),We=Ee[0].tolist(),Fe=Ee[1].tolist();ve.push(Fe.map((tt,Re)=>{const rt=ge.slice();return rt[De]=tt,{score:We[Re],token:Number(tt),token_str:this.tokenizer.decode([tt]),sequence:this.tokenizer.decode(rt,{skip_special_tokens:!0})}}))}return Array.isArray(Q)?ve:ve[0]}}class T extends y{_key="generated_text";constructor(Q){super(Q)}async _call(Q,z={}){Array.isArray(Q)||(Q=[Q]),this.model.config.prefix&&(Q=Q.map(ge=>this.model.config.prefix+ge));const de=this.model.config.task_specific_params;de&&de[this.task]&&de[this.task].prefix&&(Q=Q.map(ge=>de[this.task].prefix+ge));const be=this.tokenizer,ve={padding:!0,truncation:!0};let xe;this instanceof E&&"_build_translation_inputs"in be?xe=be._build_translation_inputs(Q,ve,z):xe=be(Q,ve);const Ce=await this.model.generate({...xe,...z});return be.batch_decode(Ce,{skip_special_tokens:!0}).map(ge=>({[this._key]:ge}))}}class b extends T{_key="summary_text";constructor(Q){super(Q)}}class E extends T{_key="translation_text";constructor(Q){super(Q)}}function x(Te){return Array.isArray(Te)&&Te.every(Q=>"role"in Q&&"content"in Q)}class S extends y{constructor(Q){super(Q)}async _call(Q,z={}){let de=!1,be=!1,ve=z.add_special_tokens??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,xe;if(typeof Q=="string")xe=Q=[Q];else if(Array.isArray(Q)&&Q.every(Fe=>typeof Fe=="string"))de=!0,xe=Q;else{if(x(Q))Q=[Q];else if(Array.isArray(Q)&&Q.every(x))de=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");be=!0,xe=Q.map(Fe=>this.tokenizer.apply_chat_template(Fe,{tokenize:!1,add_generation_prompt:!0})),ve=!1}const Ce=be?!1:z.return_full_text??!0;this.tokenizer.padding_side="left";const ge=this.tokenizer(xe,{add_special_tokens:ve,padding:!0,truncation:!0}),De=await this.model.generate({...ge,...z}),fe=this.tokenizer.batch_decode(De,{skip_special_tokens:!0});let Ee;!Ce&&ge.input_ids.dims.at(-1)>0&&(Ee=this.tokenizer.batch_decode(ge.input_ids,{skip_special_tokens:!0}).map(Fe=>Fe.length));const We=Array.from({length:Q.length},Fe=>[]);for(let Fe=0;Fe<fe.length;++Fe){const tt=Math.floor(Fe/De.dims[0]*Q.length);Ee&&(fe[Fe]=fe[Fe].slice(Ee[tt])),We[tt].push({generated_text:be?[...Q[tt],{role:"assistant",content:fe[Fe]}]:fe[Fe]})}return!de&&We.length===1?We[0]:We}}class O extends y{constructor(Q){super(Q),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([z,de])=>[z.toLowerCase(),de])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(Q,z,{hypothesis_template:de="This example is {}.",multi_label:be=!1}={}){const ve=Array.isArray(Q);ve||(Q=[Q]),Array.isArray(z)||(z=[z]);const xe=z.map(De=>de.replace("{}",De)),Ce=be||z.length===1,ge=[];for(const De of Q){const fe=[];for(const Fe of xe){const tt=this.tokenizer(De,{text_pair:Fe,padding:!0,truncation:!0}),Re=await this.model(tt);Ce?fe.push([Re.logits.data[this.contradiction_id],Re.logits.data[this.entailment_id]]):fe.push(Re.logits.data[this.entailment_id])}const We=(Ce?fe.map(Fe=>(0,l.softmax)(Fe)[1]):(0,l.softmax)(fe)).map((Fe,tt)=>[Fe,tt]).sort((Fe,tt)=>tt[0]-Fe[0]);ge.push({sequence:De,labels:We.map(Fe=>z[Fe[1]]),scores:We.map(Fe=>Fe[0])})}return ve?ge:ge[0]}}class F extends y{constructor(Q){super(Q)}async _call(Q,{pooling:z="none",normalize:de=!1,quantize:be=!1,precision:ve="binary"}={}){const xe=this.tokenizer(Q,{padding:!0,truncation:!0}),Ce=await this.model(xe);let ge=Ce.last_hidden_state??Ce.logits??Ce.token_embeddings;switch(z){case"none":break;case"mean":ge=(0,p.mean_pooling)(ge,xe.attention_mask);break;case"first_token":case"cls":ge=ge.slice(null,0);break;case"last_token":case"eos":ge=ge.slice(null,-1);break;default:throw Error(`Pooling method '${z}' not supported.`)}return de&&(ge=ge.normalize(2,-1)),be&&(ge=(0,p.quantize_embeddings)(ge,ve)),ge}}class H extends y{constructor(Q){super(Q)}async _call(Q,{pool:z=null}={}){const de=await u(Q),{pixel_values:be}=await this.processor(de),ve=await this.model({pixel_values:be});let xe;if(z){if(!("pooler_output"in ve))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");xe=ve.pooler_output}else xe=ve.last_hidden_state??ve.logits??ve.image_embeds;return xe}}class W extends y{constructor(Q){super(Q)}async _call(Q,{top_k:z=5}={}){const de=this.processor.feature_extractor.config.sampling_rate,be=await f(Q,de),ve=this.model.config.id2label,xe=[];for(const Ce of be){const ge=await this.processor(Ce),fe=(await this.model(ge)).logits[0],Ee=await(0,p.topk)(new p.Tensor("float32",(0,l.softmax)(fe.data),fe.dims),z),We=Ee[0].tolist(),tt=Ee[1].tolist().map((Re,rt)=>({label:ve?ve[Re]:`LABEL_${Re}`,score:We[rt]}));xe.push(tt)}return Array.isArray(Q)?xe:xe[0]}}class B extends y{constructor(Q){super(Q)}async _call(Q,z,{hypothesis_template:de="This is a sound of {}."}={}){const be=!Array.isArray(Q);be&&(Q=[Q]);const ve=z.map(fe=>de.replace("{}",fe)),xe=this.tokenizer(ve,{padding:!0,truncation:!0}),Ce=this.processor.feature_extractor.config.sampling_rate,ge=await f(Q,Ce),De=[];for(const fe of ge){const Ee=await this.processor(fe),We=await this.model({...xe,...Ee}),Fe=(0,l.softmax)(We.logits_per_audio.data);De.push([...Fe].map((tt,Re)=>({score:tt,label:z[Re]})))}return be?De[0]:De}}class Y extends y{constructor(Q){super(Q)}async _call(Q,z={}){switch(this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(Q,z);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(Q,z);case"moonshine":return this._call_moonshine(Q,z);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(Q,z){z.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),z.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const de=!Array.isArray(Q);de&&(Q=[Q]);const be=this.processor.feature_extractor.config.sampling_rate,ve=await f(Q,be),xe=[];for(const Ce of ve){const ge=await this.processor(Ce),fe=(await this.model(ge)).logits[0],Ee=[];for(const Fe of fe)Ee.push((0,l.max)(Fe.data)[1]);const We=this.tokenizer.decode(Ee,{skip_special_tokens:!0}).trim();xe.push({text:We})}return de?xe[0]:xe}async _call_whisper(Q,z){const de=z.return_timestamps??!1,be=z.chunk_length_s??0,ve=z.force_full_sequences??!1;let xe=z.stride_length_s??null;const Ce={...z};de==="word"&&(Ce.return_token_timestamps=!0,Ce.return_timestamps=!1);const ge=!Array.isArray(Q);ge&&(Q=[Q]);const De=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,fe=this.processor.feature_extractor.config.hop_length,Ee=this.processor.feature_extractor.config.sampling_rate,We=await f(Q,Ee),Fe=[];for(const tt of We){let Re=[];if(be>0){if(xe===null)xe=be/6;else if(be<=xe)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const Ne=Ee*be,Oe=Ee*xe,ot=Ne-2*Oe;let ht=0;for(;;){const Rt=ht+Ne,It=tt.subarray(ht,Rt),gr=await this.processor(It),Or=ht===0,zt=Rt>=tt.length;if(Re.push({stride:[It.length,Or?0:Oe,zt?0:Oe],input_features:gr.input_features,is_last:zt}),zt)break;ht+=ot}}else Re=[{stride:[tt.length,0,0],input_features:(await this.processor(tt)).input_features,is_last:!0}];for(const Ne of Re){Ce.num_frames=Math.floor(Ne.stride[0]/fe);const Oe=await this.model.generate({inputs:Ne.input_features,...Ce});de==="word"?(Ne.tokens=Oe.sequences.tolist()[0],Ne.token_timestamps=Oe.token_timestamps.tolist()[0].map(ot=>(0,l.round)(ot,2))):Ne.tokens=Oe[0].tolist(),Ne.stride=Ne.stride.map(ot=>ot/Ee)}const[rt,Ze]=this.tokenizer._decode_asr(Re,{time_precision:De,return_timestamps:de,force_full_sequences:ve});Fe.push({text:rt,...Ze})}return ge?Fe[0]:Fe}async _call_moonshine(Q,z){const de=!Array.isArray(Q);de&&(Q=[Q]);const be=this.processor.feature_extractor.config.sampling_rate,ve=await f(Q,be),xe=[];for(const Ce of ve){const ge=await this.processor(Ce),De=Math.floor(Ce.length/be)*6,fe=await this.model.generate({max_new_tokens:De,...z,...ge}),Ee=this.processor.batch_decode(fe,{skip_special_tokens:!0})[0];xe.push({text:Ee})}return de?xe[0]:xe}}class X extends y{constructor(Q){super(Q)}async _call(Q,z={}){const de=Array.isArray(Q),be=await u(Q),{pixel_values:ve}=await this.processor(be),xe=[];for(const Ce of ve){Ce.dims=[1,...Ce.dims];const ge=await this.model.generate({inputs:Ce,...z}),De=this.tokenizer.batch_decode(ge,{skip_special_tokens:!0}).map(fe=>({generated_text:fe.trim()}));xe.push(De)}return de?xe:xe[0]}}class J extends y{constructor(Q){super(Q)}async _call(Q,{top_k:z=5}={}){const de=await u(Q),{pixel_values:be}=await this.processor(de),ve=await this.model({pixel_values:be}),xe=this.model.config.id2label,Ce=[];for(const ge of ve.logits){const De=await(0,p.topk)(new p.Tensor("float32",(0,l.softmax)(ge.data),ge.dims),z),fe=De[0].tolist(),We=De[1].tolist().map((Fe,tt)=>({label:xe?xe[Fe]:`LABEL_${Fe}`,score:fe[tt]}));Ce.push(We)}return Array.isArray(Q)?Ce:Ce[0]}}class re extends y{constructor(Q){super(Q),this.subtasks_mapping={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"}}async _call(Q,{threshold:z=.5,mask_threshold:de=.5,overlap_mask_area_threshold:be=.8,label_ids_to_fuse:ve=null,target_sizes:xe=null,subtask:Ce=null}={}){if(Array.isArray(Q)&&Q.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const De=await u(Q),fe=De.map(Ne=>[Ne.height,Ne.width]),Ee=await this.processor(De),{inputNames:We,outputNames:Fe}=this.model.sessions.model;if(!We.includes("pixel_values")){if(We.length!==1)throw Error(`Expected a single input name, but got ${We.length} inputs: ${We}.`);const Ne=We[0];if(Ne in Ee)throw Error(`Input name ${Ne} already exists in the inputs.`);Ee[Ne]=Ee.pixel_values}const tt=await this.model(Ee);let Re=null;if(Ce!==null)Re=this.subtasks_mapping[Ce];else if(this.processor.image_processor){for(const[Ne,Oe]of Object.entries(this.subtasks_mapping))if(Oe in this.processor.image_processor){Re=this.processor.image_processor[Oe].bind(this.processor.image_processor),Ce=Ne;break}}const rt=this.model.config.id2label,Ze=[];if(Ce)if(Ce==="panoptic"||Ce==="instance"){const Ne=Re(tt,z,de,be,ve,xe??fe)[0],Oe=Ne.segmentation;for(const ot of Ne.segments_info){const ht=new Uint8ClampedArray(Oe.data.length);for(let It=0;It<Oe.data.length;++It)Oe.data[It]===ot.id&&(ht[It]=255);const Rt=new d.RawImage(ht,Oe.dims[1],Oe.dims[0],1);Ze.push({score:ot.score,label:rt[ot.label_id],mask:Rt})}}else if(Ce==="semantic"){const{segmentation:Ne,labels:Oe}=Re(tt,xe??fe)[0];for(const ot of Oe){const ht=new Uint8ClampedArray(Ne.data.length);for(let It=0;It<Ne.data.length;++It)Ne.data[It]===ot&&(ht[It]=255);const Rt=new d.RawImage(ht,Ne.dims[1],Ne.dims[0],1);Ze.push({score:null,label:rt[ot],mask:Rt})}}else throw Error(`Subtask ${Ce} not supported.`);else{const Oe=tt[Fe[0]];for(let ot=0;ot<fe.length;++ot){const ht=fe[ot],Rt=Oe[ot];Rt.data.some(gr=>gr<-1e-5||gr>1+1e-5)&&Rt.sigmoid_();const It=await d.RawImage.fromTensor(Rt.mul_(255).to("uint8")).resize(ht[1],ht[0]);Ze.push({label:null,score:null,mask:It})}}return Ze}}class ne extends re{constructor(Q){super(Q)}async _call(Q,z={}){if(Array.isArray(Q)&&Q.length!==1)throw Error("Background removal pipeline currently only supports a batch size of 1.");const be=await u(Q),ve=await super._call(Q,z);return be.map((Ce,ge)=>{const De=Ce.clone();return De.putAlpha(ve[ge].mask),De})}}class le extends y{constructor(Q){super(Q)}async _call(Q,z,{hypothesis_template:de="This is a photo of {}"}={}){const be=Array.isArray(Q),ve=await u(Q),xe=z.map(We=>de.replace("{}",We)),Ce=this.tokenizer(xe,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:ge}=await this.processor(ve),De=await this.model({...Ce,pixel_values:ge}),fe=this.model.config.model_type==="siglip"?We=>We.sigmoid().data:We=>(0,l.softmax)(We.data),Ee=[];for(const We of De.logits_per_image){const tt=[...fe(We)].map((Re,rt)=>({score:Re,label:z[rt]}));tt.sort((Re,rt)=>rt.score-Re.score),Ee.push(tt)}return be?Ee:Ee[0]}}class pe extends y{constructor(Q){super(Q)}async _call(Q,{threshold:z=.9,percentage:de=!1}={}){const be=Array.isArray(Q);if(be&&Q.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");const ve=await u(Q),xe=de?null:ve.map(Fe=>[Fe.height,Fe.width]),{pixel_values:Ce,pixel_mask:ge}=await this.processor(ve),De=await this.model({pixel_values:Ce,pixel_mask:ge}),fe=this.processor.image_processor.post_process_object_detection(De,z,xe),Ee=this.model.config.id2label,We=fe.map(Fe=>Fe.boxes.map((tt,Re)=>({score:Fe.scores[Re],label:Ee[Fe.classes[Re]],box:_(tt,!de)})));return be?We:We[0]}}class oe extends y{constructor(Q){super(Q)}async _call(Q,z,{threshold:de=.1,top_k:be=null,percentage:ve=!1}={}){const xe=Array.isArray(Q),Ce=await u(Q),ge=this.tokenizer(z,{padding:!0,truncation:!0}),De=await this.processor(Ce),fe=[];for(let Ee=0;Ee<Ce.length;++Ee){const We=Ce[Ee],Fe=ve?null:[[We.height,We.width]],tt=De.pixel_values[Ee].unsqueeze_(0),Re=await this.model({...ge,pixel_values:tt});let rt;if("post_process_grounded_object_detection"in this.processor){const Ze=this.processor.post_process_grounded_object_detection(Re,ge.input_ids,{box_threshold:de,text_threshold:de,target_sizes:Fe})[0];rt=Ze.boxes.map((Ne,Oe)=>({score:Ze.scores[Oe],label:Ze.labels[Oe],box:_(Ne,!ve)}))}else{const Ze=this.processor.image_processor.post_process_object_detection(Re,de,Fe,!0)[0];rt=Ze.boxes.map((Ne,Oe)=>({score:Ze.scores[Oe],label:z[Ze.classes[Oe]],box:_(Ne,!ve)}))}rt.sort((Ze,Ne)=>Ne.score-Ze.score),be!==null&&(rt=rt.slice(0,be)),fe.push(rt)}return xe?fe:fe[0]}}class K extends y{constructor(Q){super(Q)}async _call(Q,z,de={}){const be=(await u(Q))[0],{pixel_values:ve}=await this.processor(be),xe=`<s_docvqa><s_question>${z}</s_question><s_answer>`,Ce=this.tokenizer(xe,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,ge=await this.model.generate({inputs:ve,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:Ce,...de}),fe=this.tokenizer.batch_decode(ge)[0].match(/<s_answer>(.*?)<\/s_answer>/);let Ee=null;return fe&&fe.length>=2&&(Ee=fe[1].trim()),[{answer:Ee}]}}class N extends y{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(Q){super(Q),this.vocoder=Q.vocoder??null}async _prepare_speaker_embeddings(Q){if((typeof Q=="string"||Q instanceof URL)&&(Q=new Float32Array(await(await fetch(Q)).arrayBuffer())),Q instanceof Float32Array)Q=new p.Tensor("float32",Q,[Q.length]);else if(!(Q instanceof p.Tensor))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");return Q}async _call(Q,{speaker_embeddings:z=null,num_inference_steps:de,speed:be}={}){return this.processor?this._call_text_to_spectrogram(Q,{speaker_embeddings:z}):this.model.config.model_type==="supertonic"?this._call_supertonic(Q,{speaker_embeddings:z,num_inference_steps:de,speed:be}):this._call_text_to_waveform(Q)}async _call_supertonic(Q,{speaker_embeddings:z,num_inference_steps:de,speed:be}){if(!z)throw new Error("Speaker embeddings must be provided for Supertonic models.");z=await this._prepare_speaker_embeddings(z);const{sampling_rate:ve,style_dim:xe}=this.model.config;z=z.view(1,-1,xe);const Ce=this.tokenizer(Q,{padding:!0,truncation:!0}),{waveform:ge}=await this.model.generate_speech({...Ce,style:z,num_inference_steps:de,speed:be});return new c.RawAudio(ge.data,ve)}async _call_text_to_waveform(Q){const z=this.tokenizer(Q,{padding:!0,truncation:!0}),{waveform:de}=await this.model(z),be=this.model.config.sampling_rate;return new c.RawAudio(de.data,be)}async _call_text_to_spectrogram(Q,{speaker_embeddings:z}){this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await n.AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));const{input_ids:de}=this.tokenizer(Q,{padding:!0,truncation:!0});z=await this._prepare_speaker_embeddings(z),z=z.view(1,-1);const{waveform:be}=await this.model.generate_speech(de,z,{vocoder:this.vocoder}),ve=this.processor.feature_extractor.config.sampling_rate;return new c.RawAudio(be.data,ve)}}class D extends y{constructor(Q){super(Q)}async _call(Q){const z=await u(Q),de=await this.processor(z),be=await this.model(de),ve=[];for(const xe of be.reconstruction){const Ce=xe.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");ve.push(d.RawImage.fromTensor(Ce))}return ve.length>1?ve:ve[0]}}class te extends y{constructor(Q){super(Q)}async _call(Q){const z=await u(Q),de=await this.processor(z),{predicted_depth:be}=await this.model(de),ve=[];for(let xe=0;xe<z.length;++xe){const Ce=be[xe],[ge,De]=Ce.dims.slice(-2),[fe,Ee]=z[xe].size,We=(await(0,p.interpolate_4d)(Ce.view(1,1,ge,De),{size:[Ee,fe],mode:"bilinear"})).view(Ee,fe),Fe=We.min().item(),tt=We.max().item(),Re=We.sub(Fe).div_(tt-Fe).mul_(255).to("uint8").unsqueeze(0),rt=d.RawImage.fromTensor(Re);ve.push({predicted_depth:We,depth:rt})}return ve.length>1?ve:ve[0]}}const he=Object.freeze({"text-classification":{tokenizer:s.AutoTokenizer,pipeline:k,model:n.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:s.AutoTokenizer,pipeline:w,model:n.AutoModelForTokenClassification,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:s.AutoTokenizer,pipeline:v,model:n.AutoModelForQuestionAnswering,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:s.AutoTokenizer,pipeline:I,model:n.AutoModelForMaskedLM,default:{model:"Xenova/bert-base-uncased"},type:"text"},summarization:{tokenizer:s.AutoTokenizer,pipeline:b,model:n.AutoModelForSeq2SeqLM,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:s.AutoTokenizer,pipeline:E,model:n.AutoModelForSeq2SeqLM,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:s.AutoTokenizer,pipeline:T,model:n.AutoModelForSeq2SeqLM,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:s.AutoTokenizer,pipeline:S,model:n.AutoModelForCausalLM,default:{model:"Xenova/gpt2"},type:"text"},"zero-shot-classification":{tokenizer:s.AutoTokenizer,pipeline:O,model:n.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:W,model:n.AutoModelForAudioClassification,processor:o.AutoProcessor,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:s.AutoTokenizer,pipeline:B,model:n.AutoModel,processor:o.AutoProcessor,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:s.AutoTokenizer,pipeline:Y,model:[n.AutoModelForSpeechSeq2Seq,n.AutoModelForCTC],processor:o.AutoProcessor,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:s.AutoTokenizer,pipeline:N,model:[n.AutoModelForTextToWaveform,n.AutoModelForTextToSpectrogram],processor:[o.AutoProcessor,null],default:{model:"Xenova/speecht5_tts"},type:"text"},"image-to-text":{tokenizer:s.AutoTokenizer,pipeline:X,model:n.AutoModelForVision2Seq,processor:o.AutoProcessor,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:J,model:n.AutoModelForImageClassification,processor:o.AutoProcessor,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:re,model:[n.AutoModelForImageSegmentation,n.AutoModelForSemanticSegmentation,n.AutoModelForUniversalSegmentation],processor:o.AutoProcessor,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:ne,model:[n.AutoModelForImageSegmentation,n.AutoModelForSemanticSegmentation,n.AutoModelForUniversalSegmentation],processor:o.AutoProcessor,default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{tokenizer:s.AutoTokenizer,pipeline:le,model:n.AutoModel,processor:o.AutoProcessor,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:pe,model:n.AutoModelForObjectDetection,processor:o.AutoProcessor,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:s.AutoTokenizer,pipeline:oe,model:n.AutoModelForZeroShotObjectDetection,processor:o.AutoProcessor,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:s.AutoTokenizer,pipeline:K,model:n.AutoModelForDocumentQuestionAnswering,processor:o.AutoProcessor,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:D,model:n.AutoModelForImageToImage,processor:o.AutoProcessor,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:te,model:n.AutoModelForDepthEstimation,processor:o.AutoProcessor,default:{model:"Xenova/dpt-large"},type:"image"},"feature-extraction":{tokenizer:s.AutoTokenizer,pipeline:F,model:n.AutoModel,default:{model:"Xenova/all-MiniLM-L6-v2"},type:"text"},"image-feature-extraction":{processor:o.AutoProcessor,pipeline:H,model:[n.AutoModelForImageFeatureExtraction,n.AutoModel],default:{model:"Xenova/vit-base-patch16-224-in21k"},type:"image"}}),Ae=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function Ie(Te,Q=null,{progress_callback:z=null,config:de=null,cache_dir:be=null,local_files_only:ve=!1,revision:xe="main",device:Ce=null,dtype:ge=null,subfolder:De="onnx",use_external_data_format:fe=null,model_file_name:Ee=null,session_options:We={}}={}){Te=Ae[Te]??Te;const Fe=he[Te.split("_",1)[0]];if(!Fe)throw Error(`Unsupported pipeline: ${Te}. Must be one of [${Object.keys(he)}]`);Q||(Q=Fe.default.model,console.log(`No model specified. Using default model: "${Q}".`));const tt={progress_callback:z,config:de,cache_dir:be,local_files_only:ve,revision:xe,device:Ce,dtype:ge,subfolder:De,use_external_data_format:fe,model_file_name:Ee,session_options:We},Re=new Map([["tokenizer",Fe.tokenizer],["model",Fe.model],["processor",Fe.processor]]),rt=await je(Re,Q,tt);rt.task=Te,(0,i.dispatchCallback)(z,{status:"ready",task:Te,model:Q});const Ze=Fe.pipeline;return new Ze(rt)}async function je(Te,Q,z){const de=Object.create(null),be=[];for(const[ve,xe]of Te.entries()){if(!xe)continue;let Ce;Array.isArray(xe)?Ce=new Promise(async(ge,De)=>{let fe;for(const Ee of xe){if(Ee===null){ge(null);return}try{ge(await Ee.from_pretrained(Q,z));return}catch(We){if(We.message?.includes("Unsupported model type"))fe=We;else if(We.message?.includes("Could not locate file"))fe=We;else{De(We);return}}}De(fe)}):Ce=xe.from_pretrained(Q,z),de[ve]=Ce,be.push(Ce)}await Promise.all(be);for(const[ve,xe]of Object.entries(de))de[ve]=await xe;return de}}),"./src/tokenizers.js":((e,r,t)=>{t.r(r),t.d(r,{AlbertTokenizer:()=>Es,AutoTokenizer:()=>Dn,BartTokenizer:()=>He,BertTokenizer:()=>qt,BlenderbotSmallTokenizer:()=>Ue,BlenderbotTokenizer:()=>ze,BloomTokenizer:()=>kt,CLIPTokenizer:()=>ks,CamembertTokenizer:()=>Z,CodeGenTokenizer:()=>$s,CodeLlamaTokenizer:()=>ar,CohereTokenizer:()=>Fs,ConvBertTokenizer:()=>q,DebertaTokenizer:()=>yt,DebertaV2Tokenizer:()=>Cs,DistilBertTokenizer:()=>G,ElectraTokenizer:()=>ye,EsmTokenizer:()=>Lr,FalconTokenizer:()=>Dr,GPT2Tokenizer:()=>ut,GPTNeoXTokenizer:()=>Is,GemmaTokenizer:()=>ts,Grok1Tokenizer:()=>wr,HerbertTokenizer:()=>C,LlamaTokenizer:()=>dr,M2M100Tokenizer:()=>rs,MBart50Tokenizer:()=>qe,MBartTokenizer:()=>Mt,MPNetTokenizer:()=>Ss,MarianTokenizer:()=>ss,MgpstrTokenizer:()=>js,MobileBertTokenizer:()=>Ps,NllbTokenizer:()=>Hr,NougatTokenizer:()=>Kt,PreTrainedTokenizer:()=>ft,Qwen2Tokenizer:()=>zr,RoFormerTokenizer:()=>R,RobertaTokenizer:()=>Tt,SiglipTokenizer:()=>As,SpeechT5Tokenizer:()=>nt,SqueezeBertTokenizer:()=>Kr,T5Tokenizer:()=>et,TokenizerModel:()=>H,VitsTokenizer:()=>Ns,Wav2Vec2CTCTokenizer:()=>Nr,WhisperTokenizer:()=>Rs,XLMRobertaTokenizer:()=>Tr,XLMTokenizer:()=>ce,is_chinese_char:()=>I});var s=t("./src/utils/generic.js"),n=t("./src/utils/core.js"),o=t("./src/utils/hub.js"),a=t("./src/utils/maths.js"),i=t("./src/utils/tensor.js"),l=t("./src/utils/data-structures.js"),c=t("./node_modules/@huggingface/jinja/dist/index.js"),p=t("./src/models/whisper/common_whisper.js");async function d(ue,$){const U=await Promise.all([(0,o.getModelJSON)(ue,"tokenizer.json",!0,$),(0,o.getModelJSON)(ue,"tokenizer_config.json",!0,$)]);return $.legacy!==null&&(U[1].legacy=$.legacy),U}function u(ue,$){const U=[];let ee=0;for(const se of ue.matchAll($)){const Me=se[0];ee<se.index&&U.push(ue.slice(ee,se.index)),Me.length>0&&U.push(Me),ee=se.index+Me.length}return ee<ue.length&&U.push(ue.slice(ee)),U}function f(ue,$=!0){if(ue.Regex!==void 0){let U=ue.Regex.replace(/\\([#&~])/g,"$1");for(const[ee,se]of O)U=U.replaceAll(ee,se);return new RegExp(U,"gu")}else if(ue.String!==void 0){const U=(0,n.escapeRegExp)(ue.String);return new RegExp($?U:`(${U})`,"gu")}else return console.warn("Unknown pattern type:",ue),null}function _(ue){return new Map(Object.entries(ue))}function y(ue){const $=ue.dims;switch($.length){case 1:return ue.tolist();case 2:if($[0]!==1)throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return ue.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${$.length}.`)}}function k(ue){return ue.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n\'t/g,"n't").replace(/ \'m/g,"'m").replace(/ \'s/g,"'s").replace(/ \'ve/g,"'ve").replace(/ \'re/g,"'re")}function w(ue){return ue.replace(new RegExp("\\p{M}","gu"),"")}function v(ue){return w(ue.toLowerCase())}function I(ue){return ue>=19968&&ue<=40959||ue>=13312&&ue<=19903||ue>=131072&&ue<=173791||ue>=173824&&ue<=177983||ue>=177984&&ue<=178207||ue>=178208&&ue<=183983||ue>=63744&&ue<=64255||ue>=194560&&ue<=195103}function T(ue,$,U){const ee=[];let se=0;for(;se<ue.length;){if(ee.push(ue[se]),($.get(ue[se])??U)!==U){++se;continue}for(;++se<ue.length&&($.get(ue[se])??U)===U;)$.get(ee.at(-1))!==U&&(ee[ee.length-1]+=ue[se])}return ee}function b(ue){return ue.match(/\S+/g)||[]}const E="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",x=new RegExp(`^[${E}]+$`,"gu"),S=".,!?…。,、।۔،",O=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],["(?i:[sdmt]|ll|ve|re)","(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])"],["[^\\r\\n\\p{L}\\p{N}]?+","[^\\r\\n\\p{L}\\p{N}]?"],["[^\\s\\p{L}\\p{N}]++","[^\\s\\p{L}\\p{N}]+"],[` ?[^(\\s|[${S}])]+`,` ?[^\\s${S}]+`]]);class F{constructor($){this.content=$.content,this.id=$.id,this.single_word=$.single_word??!1,this.lstrip=$.lstrip??!1,this.rstrip=$.rstrip??!1,this.special=$.special??!1,this.normalized=$.normalized??null}}class H extends s.Callable{constructor($){super(),this.config=$,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}static fromConfig($,...U){switch($.type){case"WordPiece":return new W($);case"Unigram":return new B($,...U);case"BPE":return new J($);default:if($.vocab)return Array.isArray($.vocab)?new B($,...U):Object.hasOwn($,"continuing_subword_prefix")&&Object.hasOwn($,"unk_token")?Object.hasOwn($,"merges")?new J($):new W($):new re($,...U);throw new Error(`Unknown TokenizerModel type: ${$.type}`)}}_call($){return $=this.encode($),this.fuse_unk&&($=T($,this.tokens_to_ids,this.unk_token_id)),$}encode($){throw Error("encode should be implemented in subclass.")}convert_tokens_to_ids($){return $.map(U=>this.tokens_to_ids.get(U)??this.unk_token_id)}convert_ids_to_tokens($){return $.map(U=>this.vocab[U]??this.unk_token)}}class W extends H{constructor($){super($),this.tokens_to_ids=_($.vocab),this.unk_token_id=this.tokens_to_ids.get($.unk_token),this.unk_token=$.unk_token,this.max_input_chars_per_word=$.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(const[U,ee]of this.tokens_to_ids)this.vocab[ee]=U}encode($){const U=[];for(const ee of $){const se=[...ee];if(se.length>this.max_input_chars_per_word){U.push(this.unk_token);continue}let Me=!1,$e=0;const Xe=[];for(;$e<se.length;){let Je=se.length,Ye=null;for(;$e<Je;){let Ke=se.slice($e,Je).join("");if($e>0&&(Ke=this.config.continuing_subword_prefix+Ke),this.tokens_to_ids.has(Ke)){Ye=Ke;break}--Je}if(Ye===null){Me=!0;break}Xe.push(Ye),$e=Je}Me?U.push(this.unk_token):U.push(...Xe)}return U}}class B extends H{constructor($,U){super($);const ee=$.vocab.length;this.vocab=new Array(ee),this.scores=new Array(ee);for(let se=0;se<ee;++se)[this.vocab[se],this.scores[se]]=$.vocab[se];this.unk_token_id=$.unk_id,this.unk_token=this.vocab[$.unk_id],this.tokens_to_ids=new Map(this.vocab.map((se,Me)=>[se,Me])),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=U.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.minScore=(0,a.min)(this.scores)[0],this.unk_score=this.minScore-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new l.CharTrie,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes($){const U=$.chars,ee=1;let se=0;for(;se<U.length;){let Me=!1;const $e=U.slice(se).join(""),Xe=this.trie.commonPrefixSearch($e);for(const Je of Xe){const Ye=this.tokens_to_ids.get(Je),Ke=this.scores[Ye],$t=(0,n.len)(Je);$.insert(se,$t,Ke,Ye),!Me&&$t===ee&&(Me=!0)}Me||$.insert(se,ee,this.unk_score,this.unk_token_id),se+=ee}}tokenize($){const U=new l.TokenLattice($,this.bos_token_id,this.eos_token_id);return this.populateNodes(U),U.tokens()}encode($){const U=[];for(const ee of $){const se=this.tokenize(ee);U.push(...se)}return U}}const Y=(()=>{const ue=[...Array.from({length:94},(se,Me)=>Me+33),...Array.from({length:12},(se,Me)=>Me+161),...Array.from({length:82},(se,Me)=>Me+174)],$=ue.slice();let U=0;for(let se=0;se<256;++se)ue.includes(se)||(ue.push(se),$.push(256+U),U+=1);const ee=$.map(se=>String.fromCharCode(se));return Object.fromEntries(ue.map((se,Me)=>[se,ee[Me]]))})(),X=(0,n.reverseDictionary)(Y);class J extends H{constructor($){super($),this.tokens_to_ids=_($.vocab),this.unk_token_id=this.tokens_to_ids.get($.unk_token),this.unk_token=$.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(const[ee,se]of this.tokens_to_ids)this.vocab[se]=ee;const U=Array.isArray($.merges[0]);this.merges=U?$.merges:$.merges.map(ee=>ee.split(" ",2)),this.bpe_ranks=new Map(this.merges.map((ee,se)=>[JSON.stringify(ee),se])),this.end_of_word_suffix=$.end_of_word_suffix,this.continuing_subword_suffix=$.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.max_length_to_cache=256,this.cache_capacity=1e4,this.cache=new l.LRUCache(this.cache_capacity)}clear_cache(){this.cache.clear()}bpe($){if($.length===0)return[];const U=this.cache.get($);if(U!==void 0)return U;const ee=Array.from($);this.end_of_word_suffix&&(ee[ee.length-1]+=this.end_of_word_suffix);let se=[];if(ee.length>1){const Me=new l.PriorityQueue((Je,Ye)=>Je.score<Ye.score);let $e={token:ee[0],bias:0,prev:null,next:null},Xe=$e;for(let Je=1;Je<ee.length;++Je){const Ye={bias:Je/ee.length,token:ee[Je],prev:Xe,next:null};Xe.next=Ye,this._add_node(Me,Xe),Xe=Ye}for(;!Me.isEmpty();){const Je=Me.pop();if(Je.deleted||!Je.next||Je.next.deleted)continue;if(Je.deleted=!0,Je.next.deleted=!0,Je.prev){const Ke={...Je.prev};Je.prev.deleted=!0,Je.prev=Ke,Ke.prev?Ke.prev.next=Ke:$e=Ke}const Ye={token:Je.token+Je.next.token,bias:Je.bias,prev:Je.prev,next:Je.next.next};Ye.prev?(Ye.prev.next=Ye,this._add_node(Me,Ye.prev)):$e=Ye,Ye.next&&(Ye.next.prev=Ye,this._add_node(Me,Ye))}for(let Je=$e;Je!==null;Je=Je.next)se.push(Je.token)}else se=ee;if(this.continuing_subword_suffix)for(let Me=0;Me<se.length-1;++Me)se[Me]+=this.continuing_subword_suffix;return $.length<this.max_length_to_cache&&this.cache.put($,se),se}_add_node($,U){const ee=this.bpe_ranks.get(JSON.stringify([U.token,U.next.token]));ee!==void 0&&(U.score=ee+U.bias,$.push(U))}encode($){const U=[];for(const ee of $){if(this.ignore_merges&&this.tokens_to_ids.has(ee)){U.push(ee);continue}const se=this.bpe(ee);for(const Me of se)if(this.tokens_to_ids.has(Me))U.push(Me);else if(this.byte_fallback){const $e=Array.from(this.text_encoder.encode(Me)).map(Xe=>`<0x${Xe.toString(16).toUpperCase().padStart(2,"0")}>`);$e.every(Xe=>this.tokens_to_ids.has(Xe))?U.push(...$e):U.push(this.unk_token)}else U.push(this.unk_token)}return U}}class re extends H{constructor($,U){super($),this.tokens_to_ids=_(U.target_lang?$.vocab[U.target_lang]:$.vocab),this.bos_token=U.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=U.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=U.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=U.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(const[ee,se]of this.tokens_to_ids)this.vocab[se]=ee}encode($){return $}}class ne extends s.Callable{constructor($){super(),this.config=$}static fromConfig($){if($===null)return null;switch($.type){case"BertNormalizer":return new Te($);case"Precompiled":return new zt($);case"Sequence":return new je($);case"Replace":return new le($);case"NFC":return new oe($);case"NFD":return new K($);case"NFKC":return new N($);case"NFKD":return new D($);case"Strip":return new te($);case"StripAccents":return new he($);case"Lowercase":return new Ae($);case"Prepend":return new Ie($);default:throw new Error(`Unknown Normalizer type: ${$.type}`)}}normalize($){throw Error("normalize should be implemented in subclass.")}_call($){return this.normalize($)}}class le extends ne{normalize($){const U=f(this.config.pattern);return U===null?$:$.replaceAll(U,this.config.content)}}class pe extends ne{form=void 0;normalize($){return $=$.normalize(this.form),$}}class oe extends pe{form="NFC"}class K extends pe{form="NFD"}class N extends pe{form="NFKC"}class D extends pe{form="NFKD"}class te extends ne{normalize($){return this.config.strip_left&&this.config.strip_right?$=$.trim():(this.config.strip_left&&($=$.trimStart()),this.config.strip_right&&($=$.trimEnd())),$}}class he extends ne{normalize($){return $=w($),$}}class Ae extends ne{normalize($){return $=$.toLowerCase(),$}}class Ie extends ne{normalize($){return $=this.config.prepend+$,$}}class je extends ne{constructor($){super($),this.normalizers=$.normalizers.map(U=>ne.fromConfig(U))}normalize($){return this.normalizers.reduce((U,ee)=>ee.normalize(U),$)}}class Te extends ne{_tokenize_chinese_chars($){const U=[];for(let ee=0;ee<$.length;++ee){const se=$[ee],Me=se.charCodeAt(0);I(Me)?(U.push(" "),U.push(se),U.push(" ")):U.push(se)}return U.join("")}stripAccents($){return $.normalize("NFD").replace(new RegExp("\\p{Mn}","gu"),"")}_is_control($){switch($){case" ":case`

P2 Badge Re-prepare when switching to WebGPU preferred

If a model was prepared under Auto and fell back to WASM with a fallback reason (notably WEBGPU_MOBILE_POLICY, where WebGPU was never attempted), changing Engine Runtime to WebGPU Preferred still returns the cached WASM pipeline because this cache predicate treats any fallback reason as acceptable for an explicit WebGPU request. In that sequence the user cannot actually force WebGPU without clearing/reloading, and the app keeps using the smaller/slower WASM model despite the selected runtime.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant