1const __vite__fileDeps=["./eventsource-CfQQVHjX.js","./_commonjsHelpers-BosuxZz1.js","./url-BybKzMWq.js","./__vite-browser-external-DFe-p4yY.js","./wrapper-CviSselG-DCvi549i.js","./Index-DT6VPx-K.js","./Index-Btj90uky.css"],__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[i]); 2import*as Z from"./svelte/svelte.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))r(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function t(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(n){if(n.ep)return;n.ep=!0;const o=t(n);fetch(n.href,o)}})();const Oe="modulepreload",Ae=function(e,s){return new URL(e,s).href},le={},J=function(s,t,r){let n=Promise.resolve();if(t&&t.length>0){const o=document.getElementsByTagName("link"),i=document.querySelector("meta[property=csp-nonce]"),c=i?.nonce||i?.getAttribute("nonce");n=Promise.all(t.map(u=>{if(u=Ae(u,r),u in le)return;le[u]=!0;const l=u.endsWith(".css"),f=l?'[rel="stylesheet"]':"";if(!!r)for(let g=o.length-1;g>=0;g--){const v=o[g];if(v.href===u&&(!l||v.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=l?"stylesheet":Oe,l||(p.as="script",p.crossOrigin=""),p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),l)return new Promise((g,v)=>{p.addEventListener("load",g),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}return n.then(()=>s()).catch(o=>{const i=new Event("vite:preloadError",{cancelable:!0});if(i.payload=o,window.dispatchEvent(i),!i.defaultPrevented)throw o})};var Ce=Object.defineProperty,ke=(e,s,t)=>s in e?Ce(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,_=(e,s,t)=>(ke(e,typeof s!="symbol"?s+"":s,t),t),ee=new Intl.Collator(0,{numeric:1}).compare;function de(e,s,t){return e=e.split("."),s=s.split("."),ee(e[0],s[0])||ee(e[1],s[1])||(s[2]=s.slice(2).join("."),t=/[.-]/.test(e[2]=e.slice(2).join(".")),t==/[.-]/.test(s[2])?ee(e[2],s[2]):t?-1:1)}const Pe="upload",Te="config",Re="info",Ne="runtime",De="sleeptime",je="https://gradio-space-api-fetcher-v2.hf.space/api",_e="This application is currently busy. Please try again. ",I="Connection errored out. ",B="Could not resolve app config. ",qe="Could not get space status. ",xe="Could not get API info. ",Le="Space metadata could not be loaded. ";function me(e,s,t){return s.startsWith("http://")||s.startsWith("https://")?t?e:s:e+s}async function Ie(e,s){try{return(await(await fetch(`https://huggingface.co/api/spaces/${e}/jwt`,{headers:{Authorization:`Bearer ${s}`}})).json()).token||!1}catch{return!1}}function Ue(e){let s={};return e.forEach(({api_name:t},r)=>{t&&(s[t]=r)}),s}async function ze(e){const s=this.options.hf_token?{Authorization:`Bearer ${this.options.hf_token}`}:{};if(s["Content-Type"]="application/json",typeof window<"u"&&window.gradio_config&&location.origin!=="http://localhost:9876"&&!window.gradio_config.dev_mode){const t=window.gradio_config.root,r=window.gradio_config;let n=me(e,r.root,!1);return r.root=n,{...r,path:t}}else if(e){const t=await this.fetch(`${e}/${Te}`,{headers:s});if(t?.status===200){let r=await t.json();return r.path=r.path??"",r.root=e,r}throw new Error(B)}throw new Error(B)}function te(e){if(e.startsWith("http")){const{protocol:s,host:t}=new URL(e);return t.endsWith("hf.space")?{ws_protocol:"wss",host:t,http_protocol:s}:{ws_protocol:s==="https:"?"wss":"ws",http_protocol:s,host:t}}else if(e.startsWith("file:"))return{ws_protocol:"ws",http_protocol:"http:",host:"lite.local"};return{ws_protocol:"wss",http_protocol:"https:",host:e}}const ge=/^[^\/]*\/[^\/]*$/,Be=/.*hf\.space\/{0,1}$/;async function we(e,s){const t={};
2s&&(t.Authorization=`Bearer ${s}`);const r=e.trim();if(ge.test(r))try{const o=(await(await fetch(`https://huggingface.co/api/spaces/${r}/host`,{headers:t})).json()).host;return{space_id:e,...te(o)}}catch(n){throw new Error("Space metadata could not be loaded. "+n.message)}if(Be.test(r)){const{ws_protocol:n,http_protocol:o,host:i}=te(r);return{space_id:i.replace(".hf.space",""),ws_protocol:n,http_protocol:o,host:i}}return{space_id:!1,...te(r)}}function Fe(e,s,t){const r={named_endpoints:{},unnamed_endpoints:{}};return Object.keys(e).forEach(n=>{(n==="named_endpoints"||n==="unnamed_endpoints")&&(r[n]={},Object.entries(e[n]).forEach(([o,{parameters:i,returns:c}])=>{const u=s.dependencies.findIndex(a=>a.api_name===o)||t[o.replace("/","")]||-1,l=u!==-1?s.dependencies[u].types:{continuous:!1,generator:!1},f=(a,p,g,v)=>({...a,description:Ge(a.type,g),type:Me(a.type,p,g,v)||""});r[n][o]={parameters:i.map(a=>f(a,a.component,a.serializer,"parameter")),returns:c.map(a=>f(a,a.component,a.serializer,"return")),type:l}}))}),r}function Me(e,s,t,r){switch(e.type){case"string":return"string";case"boolean":return"boolean";case"number":return"number"}if(t==="JSONSerializable"||t==="StringSerializable")return"any";if(t==="ListStringSerializable")return"string[]";if(s==="Image")return r==="parameter"?"Blob | File | Buffer":"string";if(t==="FileSerializable")return e?.type==="array"?r==="parameter"?"(Blob | File | Buffer)[]":"{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]":r==="parameter"?"Blob | File | Buffer":"{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}";if(t==="GallerySerializable")return r==="parameter"?"[(Blob | File | Buffer), (string | null)][]":"[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]"}function Ge(e,s){return s==="GallerySerializable"?"array of [file, label] tuples":s==="ListStringSerializable"?"array of strings":s==="FileSerializable"?"array of files or single file":e.description}function se(e,s){switch(e.msg){case"send_data":return{type:"data"};case"send_hash":return{type:"hash"};case"queue_full":return{type:"update",status:{queue:!0,message:_e,stage:"error",code:e.code,success:e.success}};case"heartbeat":return{type:"heartbeat"};case"unexpected_error":return{type:"unexpected_error",status:{queue:!0,message:e.message,stage:"error",success:!1}};case"estimation":return{type:"update",status:{queue:!0,stage:s||"pending",code:e.code,size:e.queue_size,position:e.rank,eta:e.rank_eta,success:e.success}};case"progress":return{type:"update",status:{queue:!0,stage:"pending",code:e.code,progress_data:e.progress_data,success:e.success}};case"log":return{type:"log",data:e};case"process_generating":return{type:"generating",status:{queue:!0,message:e.success?null:e.output.error,stage:e.success?"generating":"error",code:e.code,progress_data:e.progress_data,eta:e.average_duration},data:e.success?e.output:null};case"process_completed":return"error"in e.output?{type:"update",status:{queue:!0,message:e.output.error,stage:"error",code:e.code,success:e.success}}:{type:"complete",status:{queue:!0,message:e.success?void 0:e.output.error,stage:e.success?"complete":"error",code:e.code,progress_data:e.progress_data},data:e.success?e.output:null};case"process_starts":return{type:"update",status:{queue:!0,stage:"pending",code:e.code,size:e.rank,position:0,success:e.success,eta:e.eta}}}return{type:"none",status:{stage:"error",queue:!0}}}const Je=(e,s)=>{const t=Object.values(s.named_endpoints).flatMap(o=>o.parameters);if(Array.isArray(e))return e.length>t.length&&console.warn("Too many arguments provided for the endpoint."),e;const r=[],n=Object.keys(e);return t.forEach((o,i)=>{if(e.hasOwnProperty(o.parameter_name))r[i]=e[o.parameter_name];else if(o.parameter_has_default)r[i]=o.parameter_default;else throw new Error(`No value provided for required parameter: ${o.parameter_name}`)}),n.forEach(o=>{if(!t.some(i=>i.parameter_name===o))throw new Error(`Parameter \`${o}\` is not a valid keyword argument. Please refer to the API for usage.`)}),r.forEach((o,i)=>{if(o===void 0&&!t[i].parameter_has_default)throw new Error(`No value provided for required parameter: ${t[i].parameter_name}`)}),r};async function We(){if(this.api_info)return this.api_info;const{hf_token:e}=this.options,{config:s}=this,t={"Content-Type":"application/json"};if(e&&(t.Authorization=`Bearer ${e}
2`),!!s)try{let r;if(de(s?.version||"2.0.0","3.30")<0?r=await this.fetch(je,{method:"POST",body:JSON.stringify({serialize:!1,config:JSON.stringify(s)}),headers:t}):r=await this.fetch(`${s?.root}/${Re}`,{headers:t}),!r.ok)throw new Error(I);let n=await r.json();return"api"in n&&(n=n.api),n.named_endpoints["/predict"]&&!n.unnamed_endpoints[0]&&(n.unnamed_endpoints[0]=n.named_endpoints["/predict"]),Fe(n,s,this.api_map)}catch(r){""+r.message}}async function He(e,s,t){var r;const n={};(r=this==null?void 0:this.options)!=null&&r.hf_token&&(n.Authorization=`Bearer ${this.options.hf_token}`);const o=1e3,i=[];let c;for(let u=0;u<s.length;u+=o){const l=s.slice(u,u+o),f=new FormData;l.forEach(p=>{f.append("files",p)});try{const p=t?`${e}/upload?upload_id=${t}`:`${e}/${Pe}`;c=await this.fetch(p,{method:"POST",body:f,headers:n})}catch(p){throw new Error(I+p.message)}if(!c.ok){const p=await c.text();return{error:`HTTP ${c.status}: ${p}`}}const a=await c.json();a&&i.push(...a)}return{files:i}}async function Ke(e,s,t,r){let n=(Array.isArray(e)?e:[e]).map(i=>i.blob);const o=n.filter(i=>i.size>(r??1/0));if(o.length)throw new Error(`File size exceeds the maximum allowed size of ${r} bytes: ${o.map(i=>i.name).join(", ")}`);return await Promise.all(await this.upload_files(s,n,t).then(async i=>{if(i.error)throw new Error(i.error);return i.files?i.files.map((c,u)=>new ce({...e[u],path:c,url:s+"/file="+c})):[]}))}async function _t(e,s){return e.map(t=>new ce({path:t.name,orig_name:t.name,blob:t,size:t.size,mime_type:t.type,is_stream:s}))}class ce{constructor({path:s,url:t,orig_name:r,size:n,blob:o,is_stream:i,mime_type:c,alt_text:u}){_(this,"path"),_(this,"url"),_(this,"orig_name"),_(this,"size"),_(this,"blob"),_(this,"is_stream"),_(this,"mime_type"),_(this,"alt_text"),_(this,"meta",{_type:"gradio.FileData"}),this.path=s,this.url=t,this.orig_name=r,this.size=n,this.blob=t?void 0:o,this.is_stream=i,this.mime_type=c,this.alt_text=u}}function ue(e,s,t){for(;t.length>1;){const n=t.shift();if(typeof n=="string"||typeof n=="number")e=e[n];else throw new Error("Invalid key type")}const r=t.shift();if(typeof r=="string"||typeof r=="number")e[r]=s;else throw new Error("Invalid key type")}async function ne(e,s=void 0,t=[],r=!1,n=void 0){if(Array.isArray(e)){let o=[];return await Promise.all(e.map(async i=>{var c;let u=t.slice();u.push(i);const l=await ne(e[i],r?((c=n?.parameters[i])==null?void 0:c.component)||void 0:s,u,!1,n);o=o.concat(l)})),o}else{if(globalThis.Buffer&&e instanceof globalThis.Buffer||e instanceof Blob)return[{path:t,blob:s==="Image"?!1:new oe([e]),type:s}];if(typeof e=="object"&&e!==null){let o=[];for(const i of Object.keys(e)){const c=[...t,i],u=e[i];o=o.concat(await ne(u,void 0,c,!1,n))}return!o.length&&!(e instanceof Blob||e instanceof ArrayBuffer||e instanceof Uint8Array)?[{path:t,blob:new oe([JSON.stringify(e)]),type:typeof e}]:o}}return[]}function Ve(e,s){var t,r;return((r=(t=s?.dependencies)==null?void 0:t[e])==null?void 0:r.queue)!==null?!s.dependencies[e].queue:!s.enable_queue}function Ye(e,s){return new Promise((t,r)=>{const n=new MessageChannel;n.port1.onmessage=({data:o})=>{n.port1.close(),t(o)},window.parent.postMessage(e,s,[n.port2])})}async function Qe(e,s,t){const r=this,n=await ne(s,void 0,[],!0,t);return(await Promise.all(n.map(async({path:i,blob:c,type:u})=>
2{if(!c)return{path:i,type:u};const l=await r.upload_files(e,[c]),f=l.files&&l.files[0];return{path:i,file_url:f,type:u,name:c instanceof File?c?.name:void 0}}))).forEach(({path:i,file_url:c,type:u,name:l})=>{if(u==="Gallery")ue(s,c,i);else if(c){const f=new ce({path:c,orig_name:l});ue(s,f,i)}}),s}async function Xe(e,s,t){const r={"Content-Type":"application/json"};this.options.hf_token&&(r.Authorization=`Bearer ${this.options.hf_token}`);try{var n=await this.fetch(e,{method:"POST",body:JSON.stringify(s),headers:{...r,...t}})}catch{return[{error:I},500]}let o,i;try{o=await n.json(),i=n.status}catch(c){o={error:`Could not parse server response: ${c}`},i=500}return[o,i]}async function Ze(e,s){let t=!1,r=!1,n;if(!this.config)throw new Error("Could not resolve app config");if(typeof e=="number")n=this.config.dependencies[e];else{const o=e.replace(/^\//,"");n=this.config.dependencies[this.api_map[o]]}if(n?.types.continuous)throw new Error("Cannot call predict on this function as it may run forever. Use submit instead");return new Promise(async(o,i)=>{const c=this.submit(e,s);let u;c.on("data",l=>{r&&(c.destroy(),o(l)),t=!0,u=l}).on("status",l=>{l.stage==="error"&&i(l),l.stage==="complete"&&(r=!0,t&&(c.destroy(),o(u)))})})}async function re(e,s,t){let r=s==="subdomain"?`https://huggingface.co/api/spaces/by-subdomain/${e}`:`https://huggingface.co/api/spaces/${e}`,n,o;try{if(n=await fetch(r),o=n.status,o!==200)throw new Error;n=await n.json()}
2catch{t({status:"error",load_status:"error",message:qe,detail:"NOT_FOUND"});return}if(!n||o!==200)return;const{runtime:{stage:i},id:c}=n;switch(i){case"STOPPED":case"SLEEPING":t({status:"sleeping",load_status:"pending",message:"Space is asleep. Waking it up...",detail:i}),setTimeout(()=>{re(e,s,t)},1e3);break;case"PAUSED":t({status:"paused",load_status:"error",message:"This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",detail:i,discussions_enabled:await pe(c)});break;case"RUNNING":case"RUNNING_BUILDING":t({status:"running",load_status:"complete",message:"",detail:i});break;case"BUILDING":t({status:"building",load_status:"pending",message:"Space is building...",detail:i}),setTimeout(()=>{re(e,s,t)},1e3);break;default:t({status:"space_error",load_status:"error",message:"This space is experiencing an issue.",detail:i,discussions_enabled:await pe(c)});break}}const et=/^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;async function pe(e){try{const t=(await fetch(`https://huggingface.co/api/spaces/${e}/discussions`,{method:"HEAD"})).headers.get("x-error-message");return!(t&&et.test(t))}catch{return!1}}async function tt(e,s){const t={};s&&(t.Authorization=`Bearer ${s}`);try{const r=await fetch(`https://huggingface.co/api/spaces/${e}/${Ne}`,{headers:t});if(r.status!==200)throw new Error("Space hardware could not be obtained.");const{hardware:n}=await r.json();return n.current}catch(r){throw new Error(r.message)}}async function st(e,s,t){const r={};t&&(r.Authorization=`Bearer ${t}`);const n={seconds:s};try{const o=await fetch(`https://huggingface.co/api/spaces/${e}/${De}`,{method:"POST",headers:{"Content-Type":"application/json",...r},body:JSON.stringify(n)});if(o.status!==200)throw new Error("Could not set sleep timeout on duplicated Space. Please visit *ADD HF LINK TO SETTINGS* to set a timeout manually to reduce billing charges.");return await o.json()}catch(o){throw new Error(o.message)}}const he=["cpu-basic","cpu-upgrade","cpu-xl","t4-small","t4-medium","a10g-small","a10g-large","a10g-largex2","a10g-largex4","a100-large","zero-a10g","h100","h100x8"];async function nt(e,s){const{hf_token:t,private:r,hardware:n,timeout:o}=s;if(n&&!he.includes(n))throw new Error(`Invalid hardware type provided. Valid types are: ${he.map(p=>`"${p}"`).join(",")}.`);const i={Authorization:`Bearer ${t}`,"Content-Type":"application/json"},c=(await(await fetch("https://huggingface.co/api/whoami-v2",{headers:i})).json()).name,u=e.split("/")[1],l={repository:`${c}/${u}`};r&&(l.private=!0);let f;try{n||(f=await tt(e,t))}catch(p){throw Error(Le+p.message)}const a=n||f||"cpu-basic";l.hardware=a;try{const p=await fetch(`https://huggingface.co/api/spaces/${e}/duplicate`,{method:"POST",headers:i,body:JSON.stringify(l)});if(p.status===409)try{return await H.connect(`${c}/${u}`,s)}catch(v){throw console.error("Failed to connect Client instance:",v),v}else if(p.status!==200)throw new Error(p.statusText);const g=await p.json();return await st(`${c}/${u}`,o||300,t),await H.connect(rt(g.url),s)}catch(p){throw new Error(p)}}function rt(e){const s=/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/,t=e.match(s);if(t)return t[1]}async function ot(){let{event_callbacks:e,unclosed_events:s,pending_stream_messages:t,stream_status:r,config:n,jwt:o}=this;if(!n)throw new Error("Could not resolve app config");r.open=!0;let i=null,c=new URLSearchParams({session_hash:this.session_hash}).toString(),u=new URL(`${n.root}/queue/data?${c}`);if(o&&u.searchParams.set("__sign",o),i=await this.stream(u),!i){console.warn("Cannot connect to SSE endpoint: "+u.toString());return}i.onmessage=async function(l){let f=JSON.parse(l.data);if(f.msg==="close_stream"){W(r,i);return}const a=f.event_id;if(!a)await Promise.all(Object.keys(e).map(p=>e[p](f)));else if(e[a]&&n){f.msg==="process_completed"&&["sse","sse_v1","sse_v2","sse_v2.1"].includes(n.protocol)&&(s.delete(a),s.size===0&&W(r,i));let p=e[a];typeof window<"u"?window.setTimeout(p,0,f):setImmediate(p,f)}else t[a]||(t[a]=[]),t[a].push(f)},i.onerror=async function(){await Promise.all(Object.keys(e).map(l=>e[l]({msg:"unexpected_error",message:I}))),W(r,i)}}function W(e,s){e&&s&&(e.open=!1,s?.close())}function it(e,s,t){!e[s]?(e[s]=[],t.data.forEach((n,o)=>{e[s][o]=n})):t.data.forEach((n,o)=>{let i=at(e[s][o],n);e[s][o]=i,t.data[o]=i})}
2function at(e,s){return s.forEach(([t,r,n])=>{e=ct(e,r,t,n)}),e}function ct(e,s,t,r){if(s.length===0){if(t==="replace")return r;if(t==="append")return e+r;throw new Error(`Unsupported action: ${t}`)}let n=e;for(let i=0;i<s.length-1;i++)n=n[s[i]];const o=s[s.length-1];switch(t){case"replace":n[o]=r;break;case"append":n[o]+=r;break;case"add":Array.isArray(n)?n.splice(Number(o),0,r):n[o]=r;break;case"delete":Array.isArray(n)?n.splice(Number(o),1):delete n[o];break;default:throw new Error(`Unknown action: ${t}`)}return e}function lt(e,s,t,r){try{let n=function(w){const A=z[w.type]||[];A?.forEach(m=>m(w))},o=function(w,E){const A=z,m=A[w]||[];return A[w]=m,m?.push(E),{on:o,off:i,cancel:Q,destroy:c}},i=function(w,E){const A=z;let m=A[w]||[];return m=m?.filter(j=>j!==E),A[w]=m,{on:o,off:i,cancel:Q,destroy:c}},c=function(){var w;for(const E in z)z&&((w=z[E])==null||w.forEach(A=>{i(E,A)}))};const{hf_token:u}=this.options,{fetch:l,app_reference:f,config:a,session_hash:p,api_info:g,api_map:v,stream_status:U,pending_stream_messages:F,pending_diff_streams:M,event_callbacks:K,unclosed_events:ve,post_data:V}=this;if(!g)throw new Error("No API found");if(!a)throw new Error("Could not resolve app config");let{fn_index:h,endpoint_info:Se,dependency:Ee}=ut(g,e,v,a),$e=Je(s,g),$,k,R=a.protocol??"ws";const d=typeof e=="number"?"/predict":e;let G,S=null,O=!1;const z={};let Y={},L=typeof window<"u"?new URLSearchParams(window.location.search).toString():"";async function Q(){const w={stage:"complete",queue:!1,time:new Date};O=w,n({...w,type:"status",endpoint:d,fn_index:h});let E={};R==="ws"?($&&$.readyState===0?$.addEventListener("open",()=>{$.close()}):$.close(),E={fn_index:h,session_hash:p}):(k?.close(),E={event_id:S});try{if(!a)throw new Error("Could not resolve app config");await l(`${a.root}/reset`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify(E)})}catch{console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.")}}return this.handle_blob(a.root,$e,Se).then(async w=>{var E;if(G={data:w||[],event_data:t,fn_index:h,trigger_id:r},Ve(h,a))n({type:"status",endpoint:d,stage:"pending",queue:!1,fn_index:h,time:new Date}),V(`${a.root}/run${d.startsWith("/")?d:`/${d}`}${L?"?"+L:""}`,{...G,session_hash:p}).then(([m,j])=>{const N=m.data;j==200?(n({type:"data",endpoint:d,fn_index:h,data:N,time:new Date,event_data:t,trigger_id:r}),n({type:"status",endpoint:d,fn_index:h,stage:"complete",eta:m.average_duration,queue:!1,time:new Date})):n({type:"status",stage:"error",endpoint:d,fn_index:h,message:m.error,queue:!1,time:new Date})}).catch(m=>{n({type:"status",stage:"error",message:m.message,endpoint:d,fn_index:h,queue:!1,time:new Date})});else if(R=="ws"){const{ws_protocol:m,host:j}=await we(f,u);n({type:"status",stage:"pending",queue:!0,endpoint:d,fn_index:h,time:new Date});let N=new URL(`${m}://${me(j,a.path,!0)}/queue/join${L?"?"+L:""}`);this.jwt&&N.searchParams.set("__sign",this.jwt),$=new WebSocket(N),$.onclose=T=>{T.wasClean||n({type:"status",stage:"error",broken:!0,message:I,queue:!0,endpoint:d,fn_index:h,time:new Date})},$.onmessage=function(T){const P=JSON.parse(T.data),{type:b,status:C,data:D}=se(P,Y[h]);if(b==="update"&&C&&!O)n({type:"status",endpoint:d,fn_index:h,time:new Date,...C}),C.stage==="error"&&$.close();else if(b==="hash"){$.send(JSON.stringify({fn_index:h,session_hash:p}));return}else b==="data"?$.send(JSON.stringify({...G,session_hash:p})):b==="complete"?O=C:b==="log"?n({type:"log",log:D.log,level:D.level,endpoint:d,fn_index:h}):b==="generating"&&n({type:"status",time:new Date,...C,stage:C?.stage,queue:!0,endpoint:d,fn_index:h});D&&(n({type:"data",time:new Date,data:D.data,endpoint:d,fn_index:h,event_data:t,trigger_id:r}),O&&(n({type:"status",time:new Date,...O,stage:C?.stage,queue:!0,endpoint:d,fn_index:h}),$.close()))},de(a.version||"2.0.0","3.6")<0&&addEventListener("open",()=>$.send(JSON.stringify({hash:p})))}else if(R=="sse"){n({type:"status",stage:"pending",queue:!0,endpoint:d,fn_index:h,time:new Date});var A=new URLSearchParams({fn_index:h.toString(),session_hash:p}).toString();let m=new URL(`${a.root}/queue/join?${L?L+"&":""}${A}`);if(this.jwt&&m.searchParams.set("__sign",this.jwt),k=await this.stream(m),!k)return Promise.reject(new Error("Cannot connect to SSE endpoint: "+m.toString()));
2k.onmessage=async function(j){const N=JSON.parse(j.data),{type:T,status:P,data:b}=se(N,Y[h]);if(T==="update"&&P&&!O)n({type:"status",endpoint:d,fn_index:h,time:new Date,...P}),P.stage==="error"&&k?.close();else if(T==="data"){S=N.event_id;let[C,D]=await V(`${a.root}/queue/data`,{...G,session_hash:p,event_id:S});D!==200&&(n({type:"status",stage:"error",message:I,queue:!0,endpoint:d,fn_index:h,time:new Date}),k?.close())}else T==="complete"?O=P:T==="log"?n({type:"log",log:b.log,level:b.level,endpoint:d,fn_index:h}):T==="generating"&&n({type:"status",time:new Date,...P,stage:P?.stage,queue:!0,endpoint:d,fn_index:h});b&&(n({type:"data",time:new Date,data:b.data,endpoint:d,fn_index:h,event_data:t,trigger_id:r}),O&&(n({type:"status",time:new Date,...O,stage:P?.stage,queue:!0,endpoint:d,fn_index:h}),k?.close()))}}else if(R=="sse_v1"||R=="sse_v2"||R=="sse_v2.1"||R=="sse_v3"){n({type:"status",stage:"pending",queue:!0,endpoint:d,fn_index:h,time:new Date});let m="";typeof window<"u"&&(m=(E=window?.location)==null?void 0:E.hostname);const N=m.includes(".dev.")?`https://moon-${m.split(".")[1]}.dev.spaces.huggingface.tech`:"https://huggingface.co";(Ee.zerogpu&&window.parent!=window&&a.space_id?Ye("zerogpu-headers",N):Promise.resolve(null)).then(b=>V(`${a.root}/queue/join?${L}`,{...G,session_hash:p},b)).then(async([b,C])=>{if(C===503)n({type:"status",stage:"error",message:_e,queue:!0,endpoint:d,fn_index:h,time:new Date});else if(C!==200)n({type:"status",stage:"error",message:I,queue:!0,endpoint:d,fn_index:h,time:new Date});else{S=b.event_id;let D=async function(X){try{const{type:q,status:y,data:x}=se(X,Y[h]);if(q=="heartbeat")return;if(q==="update"&&y&&!O)n({type:"status",endpoint:d,fn_index:h,time:new Date,...y});else if(q==="complete")O=y;else if(q=="unexpected_error")console.error("Unexpected error",y?.message),n({type:"status",stage:"error",message:y?.message||"An Unexpected Error Occurred!",queue:!0,endpoint:d,fn_index:h,time:new Date});else if(q==="log"){n({type:"log",log:x.log,level:x.level,endpoint:d,fn_index:h});return}else q==="generating"&&(n({type:"status",time:new Date,...y,stage:y?.stage,queue:!0,endpoint:d,fn_index:h}),x&&["sse_v2","sse_v2.1","sse_v3"].includes(R)&&it(M,S,x));x&&(n({type:"data",time:new Date,data:x.data,endpoint:d,fn_index:h}),x.render_config&&n({type:"render",data:x.render_config,endpoint:d,fn_index:h}),O&&n({type:"status",time:new Date,...O,stage:y?.stage,queue:!0,endpoint:d,fn_index:h})),(y?.stage==="complete"||y?.stage==="error")&&(K[S]&&delete K[S],S in M&&delete M[S])}catch(q){console.error("Unexpected client exception",q),n({type:"status",stage:"error",message:"An Unexpected Error Occurred!",queue:!0,endpoint:d,fn_index:h,time:new Date}),["sse_v2","sse_v2.1"].includes(R)&&(W(U,k),U.open=!1)}};S in F&&(F[S].forEach(X=>D(X)),delete F[S]),K[S]=D,ve.add(S),U.open||await this.open_stream()}})}}),{on:o,off:i,cancel:Q,destroy:c}}catch(n){throw console.error("Submit function encountered an error:",n),n}}function ut(e,s,t,r){let n,o,i;if(typeof s=="number")n=s,o=e.unnamed_endpoints[n],i=r.dependencies[s];else{const c=s.replace(/^\//,"");n=t[c],o=e.named_endpoints[s.trim()],i=r.dependencies[t[c]]}if(typeof n!="number")throw new Error("There is no endpoint matching that name of fn_index matching that number.");return{fn_index:n,endpoint_info:o,dependency:i}}class oe extends Blob{constructor(s,t){super(s,t)}}class H{constructor(s,t={}){_(this,"app_reference"),_(this,"options"),_(this,"config"),_(this,"api_info"),_(this,"api_map",{}),_(this,"session_hash",Math.random().toString(36).substring(2)),_(this,"jwt",!1),_(this,"last_status",{}),_(this,"stream_status",{open:!1}),_(this,"pending_stream_messages",{}),_(this,"pending_diff_streams",{}),_(this,"event_callbacks",{}),_(this,"unclosed_events",new Set),_(this,"heartbeat_event",null),_(this,"view_api"),_(this,"upload_files"),_(this,"upload"),_(this,"handle_blob"),_(this,"post_data"),_(this,"submit"),_(this,"predict"),_(this,"open_stream"),_(this,"resolve_config"),this.app_reference=s,this.options=t,this.view_api=We.bind(this),this.upload_files=He.bind(this),this.handle_blob=Qe.bind(this),this.post_data=Xe.bind(this),this.submit=lt.bind(this),this.predict=Ze.bind(this),this.open_stream=ot.bind(this),this.resolve_config=ze.bind(this),this.upload=Ke.bind(this)}fetch(s,t){return fetch(s,t)}async stream(s){if(typeof window>"u"||typeof EventSource>"u")try{const t=await J(()=>import("./eventsource-CfQQVHjX.js").then(r=>r.e),__vite__mapDeps([0,1,2,3]),import.meta.url);return new t.default(s.toString())}catch(t){throw console.error("Failed to load EventSource module:",t),t}else return new EventSource(s.toString())}
2async init(){var s;if((typeof window>"u"||!("WebSocket"in window))&&!global.WebSocket){const t=await J(()=>import("./wrapper-CviSselG-DCvi549i.js"),__vite__mapDeps([4,3]),import.meta.url);oe=(await J(()=>import("./__vite-browser-external-DFe-p4yY.js").then(r=>r._),[],import.meta.url)).Blob,global.WebSocket=t.WebSocket}try{await this._resolve_config().then(async({config:t})=>{if(t&&(this.config=t,this.config&&this.config.connect_heartbeat)){const r=new URL(`${this.config.root}/heartbeat/${this.session_hash}`);this.heartbeat_event=await this.stream(r),this.config.space_id&&this.options.hf_token&&(this.jwt=await Ie(this.config.space_id,this.options.hf_token))}})}catch(t){throw Error(B+t.message)}this.api_info=await this.view_api(),this.api_map=Ue(((s=this.config)==null?void 0:s.dependencies)||[])}static async connect(s,t={}){const r=new this(s,t);return await r.init(),r}close(){var s;(s=this.heartbeat_event)==null||s.close()}static async duplicate(s,t={}){return nt(s,t)}async _resolve_config(){const{http_protocol:s,host:t,space_id:r}=await we(this.app_reference,this.options.hf_token),{status_callback:n}=this.options;let o;try{if(o=await this.resolve_config(`${s}//${t}`),!o)throw new Error(B);return this.config_success(o)}catch(i){console.error(i),r?re(r,ge.test(r)?"space_name":"subdomain",this.handle_space_success):n&&n({status:"error",message:"Could not load this space.",load_status:"error",detail:"NOT_FOUND"})}}async config_success(s){if(this.config=s,typeof window<"u"&&window.location.protocol==="https:"&&(this.config.root=this.config.root.replace("http://","https://")),this.config.auth_required)return this.prepare_return_obj();try{this.api_info=await this.view_api()}catch(t){console.error(xe+t.message)}return this.prepare_return_obj()}async handle_space_success(s){const{status_callback:t}=this.options;if(t&&t(s),s.status==="running")try{if(this.config=await this._resolve_config(),!this.config)throw new Error(B);return await this.config_success(this.config)}catch(r){console.error(r),t&&t({status:"error",message:"Could not load this space.",load_status:"error",detail:"NOT_FOUND"})}}async component_server(s,t,r){var n;if(!this.config)throw new Error(B);const o={},{hf_token:i}=this.options,{session_hash:c}=this;i&&(o.Authorization=`Bearer ${this.options.hf_token}`);let u,l=this.config.components.find(a=>a.id===s);(n=l?.props)!=null&&n.root_url?u=l.props.root_url:u=this.config.root;let f;if("binary"in r){f=new FormData;for(const a in r.data)a!=="binary"&&f.append(a,r.data[a]);f.set("component_id",s.toString()),f.set("fn_name",t),f.set("session_hash",c)}else f=JSON.stringify({data:r,component_id:s,fn_name:t,session_hash:c}),o["Content-Type"]="application/json";i&&(o.Authorization=`Bearer ${i}`);try{const a=await this.fetch(`${u}/component_server/`,{method:"POST",body:f,headers:o});if(!a.ok)throw new Error("Could not connect to component server: "+a.statusText);return await a.json()}catch(a){console.warn(a)}}prepare_return_obj(){return{config:this.config,predict:this.predict,submit:this.submit,view_api:this.view_api,component_server:this.component_server}}}let ye=!1;"attachShadow"in Element.prototype&&"adoptedStyleSheets"in Document.prototype&&(ye="adoptedStyleSheets"in document.createElement("div").attachShadow({mode:"open"}));function fe(e,s){const t=new URL(import.meta.url).origin,r=new URL(e,t).href;if(document.querySelector(`link[href='${r}']`))return Promise.resolve();const o=document.createElement("link");return o.rel="stylesheet",o.href=r,new Promise((i,c)=>{o.addEventListener("load",()=>i()),o.addEventListener("error",()=>{console.error(`Unable to preload CSS for ${r}`),i()}),s.appendChild(o)})}function mt(e,s,t=document.createElement("style")){if(!ye)return null;t.remove();const r=new CSSStyleSheet;r.replaceSync(e);let n="";e=e.replace(/@import\s+url\((.*?)\);\s*/g,(u,l)=>(n+=`@import url(${l}); 3`,""));const o=r.cssRules;let i="",c=`gradio-app .gradio-container.gradio-container-${s} .contain `;for(let u=0;u<o.length;u++){const l=o[u];let f=l.cssText.includes(".dark");if(l instanceof CSSStyleRule){const a=l.selectorText;if(a){const p=a.replace(".dark","").split(",").map(g=>`${f?".dark":""} ${c} ${g.trim()} `).join(",");i+=l.cssText,i+=l.cssText.replace(a,p)}}else if(l instanceof CSSMediaRule){let a=`@media ${l.media.mediaText} {`;
3for(let p=0;p<l.cssRules.length;p++){const g=l.cssRules[p];if(g instanceof CSSStyleRule){let v=g.cssText.includes(".dark ");const U=g.selectorText,F=U.replace(".dark","").split(",").map(M=>`${v?".dark":""} ${c} ${M.trim()} `).join(",");a+=g.cssText.replace(U,F)}}a+="}",i+=a}else if(l instanceof CSSKeyframesRule){i+=`@keyframes ${l.name} {`;for(let a=0;a<l.cssRules.length;a++){const p=l.cssRules[a];p instanceof CSSKeyframeRule&&(i+=`${p.keyText} { ${p.style.cssText} }`)}i+="}"}else l instanceof CSSFontFaceRule&&(i+=`@font-face { ${l.style.cssText} }`)}return i=n+i,t.textContent=i,document.head.appendChild(t),t}const pt="./assets/index-C2tw9baX.css";let ie;ie=[];let ae,be,ht=new Promise(e=>{be=e});async function ft(){ae=(await J(()=>import("./Index-DT6VPx-K.js").then(e=>e.f),__vite__mapDeps([5,1,6]),import.meta.url)).default,be()}function dt(){const e={SvelteComponent:Z.SvelteComponent};for(const t in Z)t!=="SvelteComponent"&&(t==="SvelteComponentDev"?e[t]=e.SvelteComponent:e[t]=Z[t]);window.__gradio__svelte__internal=e;class s extends HTMLElement{constructor(){super(),this.host=this.getAttribute("host"),this.space=this.getAttribute("space"),this.src=this.getAttribute("src"),this.control_page_title=this.getAttribute("control_page_title"),this.initial_height=this.getAttribute("initial_height")??"300px",this.is_embed=this.getAttribute("embed")??"true",this.container=this.getAttribute("container")??"true",this.info=this.getAttribute("info")??!0,this.autoscroll=this.getAttribute("autoscroll"),this.eager=this.getAttribute("eager"),this.theme_mode=this.getAttribute("theme_mode"),this.updating=!1,this.loading=!1}async connectedCallback(){await ft(),this.loading=!0,this.app&&this.app.$destroy(),typeof ie!="string"&&ie.forEach(o=>fe(o,document.head)),await fe(pt,document.head);const r=new CustomEvent("domchange",{bubbles:!0,cancelable:!1,composed:!0});new MutationObserver(o=>{this.dispatchEvent(r)}).observe(this,{childList:!0}),this.app=new ae({target:this,props:{space:this.space?this.space.trim():this.space,src:this.src?this.src.trim():this.src,host:this.host?this.host.trim():this.host,info:this.info!=="false",container:this.container!=="false",is_embed:this.is_embed!=="false",initial_height:this.initial_height,eager:this.eager==="true",version:"4-31-0",theme_mode:this.theme_mode,autoscroll:this.autoscroll==="true",control_page_title:this.control_page_title==="true",Client:H,app_mode:window.__gradio_mode__==="app"}}),this.updating&&this.setAttribute(this.updating.name,this.updating.value),this.loading=!1}static get observedAttributes(){return["src","space","host"]}async attributeChangedCallback(r,n,o){if(await ht,(r==="host"||r==="space"||r==="src")&&o!==n){if(this.updating={name:r,value:o},this.loading)return;this.app&&this.app.$destroy(),this.space=null,this.host=null,this.src=null,r==="host"?this.host=o:r==="space"?this.space=o:r==="src"&&(this.src=o),this.app=new ae({target:this,props:{space:this.space?this.space.trim():this.space,src:this.src?this.src.trim():this.src,host:this.host?this.host.trim():this.host,info:this.info!=="false",container:this.container!=="false",is_embed:this.is_embed!=="false",initial_height:this.initial_height,eager:this.eager==="true",version:"4-31-0",theme_mode:this.theme_mode,autoscroll:this.autoscroll==="true",control_page_title:this.control_page_title==="true",Client:H,app_mode:window.__gradio_mode__==="app"}}),this.updating=!1}}}customElements.get("gradio-app")||customElements.define("gradio-app",s)}dt();export{J as _,mt as a,fe as m,_t as p}; 4//# sourceMappingURL=index-DQnOSUE6.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.