File size: 4,548 Bytes
03c1b64
1
!function(){var t,e,n,r,o,i,a,s,c={495:function(){},7147:function(){},1418:function(){},3380:function(){},319:function(){},8386:function(){},3342:function(){},4549:function(t,e,n){"use strict";var r=n(552);async function o(t){let e;try{e=await caches.open("image-database");let n=await e.match(t);if(n)return await n.arrayBuffer()}catch(t){console.warn("Unable to open cache",t)}let n=await fetch(t),r=await n.arrayBuffer();if(e)try{await e.put(t,new Response(r,{headers:n.headers}))}catch(t){console.warn("Unable to cache file",t)}return r}async function i(t){let e=await o(t);return JSON.parse(new TextDecoder("utf-8").decode(e))}r.OBj.allowLocalModels=!1;class a{static async getInstance(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return null===this.tokenizer&&(this.tokenizer=r.t25.from_pretrained(this.model_id,{progress_callback:t})),null===this.text_model&&(this.text_model=r.v3$.from_pretrained(this.model_id,{progress_callback:t})),null===this.metadata&&(this.metadata=i(this.BASE_URL+"image-embeddings.json")),null===this.embeddings&&(this.embeddings=new Promise((t,e)=>{o(this.BASE_URL+"image-embeddings_25k-512-32bit.bin").then(e=>{t(new Float32Array(e))}).catch(e)})),Promise.all([this.tokenizer,this.text_model,this.metadata,this.embeddings])}}a.model_id="Xenova/clip-vit-base-patch16",a.BASE_URL="https://huggingface.co/datasets/Xenova/semantic-image-search-assets/resolve/main/",a.tokenizer=null,a.text_model=null,a.metadata=null,a.embeddings=null,self.addEventListener("message",async t=>{let[e,n,r,o]=await a.getInstance(self.postMessage);self.postMessage({status:"ready"});let i=e(t.data.text,{padding:!0,truncation:!0}),{text_embeds:s}=await n(i),c=function(t,e){let n=e.length/512,r=Array(n);for(let o=0;o<n;++o){let n=512*o,i=e.slice(n,n+512),a=0,s=0,c=0;for(let e=0;e<512;++e){let n=t[e],r=i[e];a+=n*r,s+=n*n,c+=r*r}r[o]=a/(Math.sqrt(s)*Math.sqrt(c))}return r}(s.data,o),u=r.slice(0);for(let t=0;t<r.length;++t)u[t].score=c[t];u.sort((t,e)=>e.score-t.score),u=u.slice(0,100),self.postMessage({status:"complete",output:u})})}},u={};function l(t){var e=u[t];if(void 0!==e)return e.exports;var n=u[t]={exports:{}},r=!0;try{c[t](n,n.exports,l),r=!1}finally{r&&delete u[t]}return n.exports}l.m=c,l.x=function(){var t=l.O(void 0,[15,990],function(){return l(4549)});return l.O(t)},t=[],l.O=function(e,n,r,o){if(n){o=o||0;for(var i=t.length;i>0&&t[i-1][2]>o;i--)t[i]=t[i-1];t[i]=[n,r,o];return}for(var a=1/0,i=0;i<t.length;i++){for(var n=t[i][0],r=t[i][1],o=t[i][2],s=!0,c=0;c<n.length;c++)a>=o&&Object.keys(l.O).every(function(t){return l.O[t](n[c])})?n.splice(c--,1):(s=!1,o<a&&(a=o));if(s){t.splice(i--,1);var u=r();void 0!==u&&(e=u)}}return e},n=Object.getPrototypeOf?function(t){return Object.getPrototypeOf(t)}:function(t){return t.__proto__},l.t=function(t,r){if(1&r&&(t=this(t)),8&r||"object"==typeof t&&t&&(4&r&&t.__esModule||16&r&&"function"==typeof t.then))return t;var o=Object.create(null);l.r(o);var i={};e=e||[null,n({}),n([]),n(n)];for(var a=2&r&&t;"object"==typeof a&&!~e.indexOf(a);a=n(a))Object.getOwnPropertyNames(a).forEach(function(e){i[e]=function(){return t[e]}});return i.default=function(){return t},l.d(o,i),o},l.d=function(t,e){for(var n in e)l.o(e,n)&&!l.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},l.f={},l.e=function(t){return Promise.all(Object.keys(l.f).reduce(function(e,n){return l.f[n](t,e),e},[]))},l.u=function(t){return"static/chunks/"+(15===t?"b2db8554":t)+"."+({15:"501a8fbaf2ca19ba",990:"a6bf775ee164baff"})[t]+".js"},l.miniCssF=function(t){},l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),l.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},l.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},l.tt=function(){return void 0===r&&(r={createScriptURL:function(t){return t}},"undefined"!=typeof trustedTypes&&trustedTypes.createPolicy&&(r=trustedTypes.createPolicy("nextjs#bundler",r))),r},l.tu=function(t){return l.tt().createScriptURL(t)},l.p="/_next/",o={200:1},l.f.i=function(t,e){o[t]||importScripts(l.tu(l.p+l.u(t)))},a=(i=self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push.bind(i),i.push=function(t){var e=t[0],n=t[1],r=t[2];for(var i in n)l.o(n,i)&&(l.m[i]=n[i]);for(r&&r(l);e.length;)o[e.pop()]=1;a(t)},s=l.x,l.x=function(){return Promise.all([l.e(15),l.e(990)]).then(s)},_N_E=l.x()}();