1const __vite__fileDeps=["./eventsource-CfQQVHjX.js","./_commonjsHelpers-BosuxZz1.js","./url-BybKzMWq.js","./__vite-browser-external-DFe-p4yY.js","./wrapper-CviSselG-DCvi549i.js","./Index-DvJ399W-.js","./Index-B4pUrfBk.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"]'))i(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const r of o.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).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 i(n){if(n.ep)return;n.ep=!0;const o=t(n);fetch(n.href,o)}})();const Ee="modulepreload",$e=function(e,s){return new URL(e,s).href},le={},J=function(s,t,i){let n=Promise.resolve();if(t&&t.length>0){const o=document.getElementsByTagName("link"),r=document.querySelector("meta[property=csp-nonce]"),c=r?.nonce||r?.getAttribute("nonce");n=Promise.all(t.map(u=>{if(u=$e(u,i),u in le)return;le[u]=!0;const l=u.endsWith(".css"),f=l?'[rel="stylesheet"]':"";if(!!i)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":Ee,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 r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=o,window.dispatchEvent(r),!r.defaultPrevented)throw o})};var Ce=Object.defineProperty,Oe=(e,s,t)=>s in e?Ce(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,_=(e,s,t)=>(Oe(e,typeof s!="symbol"?s+"":s,t),t),ee=new Intl.Collator(0,{numeric:1}).compare;function Ae(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 ke="upload",Te="config",Re="info",Pe="runtime",Ne="sleeptime",De="https://gradio-space-api-fetcher-v2.hf.space/api",de="This application is currently busy. Please try again. ",L="Connection errored out. ",B="Could not resolve app config. ",xe="Could not get space status. ",je="Could not get API info. ",qe="Space metadata could not be loaded. ";function _e(e,s,t){return s.startsWith("http://")||s.startsWith("https://")?t?e:s:e+s}async function Le(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 Ie(e){let s={};return e.forEach(({api_name:t},i)=>{t&&(s[t]=i)}),s}async function Ue(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,i=window.gradio_config;let n=_e(e,i.root,!1);return i.root=n,{...i,path:t}}else if(e){const t=await this.fetch(`${e}/${Te}`,{headers:s});if(t?.status===200){let i=await t.json();return i.path=i.path??"",i.root=e,i}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 me=/^[^\/]*\/[^\/]*$/,ze=/.*hf\.space\/{0,1}$/;async function ge(e,s){const t={};
2s&&(t.Authorization=`Bearer ${s}`);const i=e.trim();if(me.test(i))try{const o=(await(await fetch(`https://huggingface.co/api/spaces/${i}/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(ze.test(i)){const{ws_protocol:n,http_protocol:o,host:r}=te(i);return{space_id:r.replace(".hf.space",""),ws_protocol:n,http_protocol:o,host:r}}return{space_id:!1,...te(i)}}function Be(e,s,t){const i={named_endpoints:{},unnamed_endpoints:{}};return Object.keys(e).forEach(n=>{(n==="named_endpoints"||n==="unnamed_endpoints")&&(i[n]={},Object.entries(e[n]).forEach(([o,{parameters:r,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:Me(a.type,g),type:Fe(a.type,p,g,v)||""});i[n][o]={parameters:r.map(a=>f(a,a.component,a.serializer,"parameter")),returns:c.map(a=>f(a,a.component,a.serializer,"return")),type:l}}))}),i}function Fe(e,s,t,i){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 i==="parameter"?"Blob | File | Buffer":"string";if(t==="FileSerializable")return e?.type==="array"?i==="parameter"?"(Blob | File | Buffer)[]":"{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]":i==="parameter"?"Blob | File | Buffer":"{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}";if(t==="GallerySerializable")return i==="parameter"?"[(Blob | File | Buffer), (string | null)][]":"[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]"}function Me(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:de,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}}}async function Ge(){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}`),!!s)try{let i;if(Ae(s?.version||"2.0.0","3.30")<0?i=await this.fetch(De,{method:"POST",body:JSON.stringify({serialize:!1,config:JSON.stringify(s)}),headers:t}):i=await this.fetch(`${s?.root}/${Re}`,{headers:t}),!i.ok)throw new Error(L);let n=await i.json();return"api"in n&&(n=n.api),n.named_endpoints["/predict"]&&!n.unnamed_endpoints[0]&&(n.unnamed_endpoints[0]=n.named_endpoints["/predict"]),Be(n,s,this.api_map)}catch(i){""+i.message}}async function Je(e,s,t){var i;const n={};(i=this==null?void 0:this.options)!=null&&i.hf_token&&(n.Authorization=`Bearer ${this.options.hf_token}`);const o=1e3,r=[];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}/${ke}`;c=await this.fetch(p,{method:"POST",body:f,headers:n})}catch(p){throw new Error(L+p.message)}if(!c.ok){const p=await c.text();return{error:`HTTP ${c.status}: ${p}`}}const a=await c.json();a&&r.push(...a)}return{files:r}}async function We(e,s,t,i){let n=(Array.isArray(e)?e:[e]).map(r=>r.blob);const o=n.filter(r=>r.size>(i??1/0));if(o.length)throw new Error(`File size exceeds the maximum allowed size of ${i} bytes: ${o.map(r=>r.name).join(", ")}`);return await Promise.all(await this.upload_files(s,n,t).then(async r=>{if(r.error)throw new Error(r.error);return r.files?r.files.map((c,u)=>new ce({...e[u],path:c,url:s+"/file="+c})):[]}))}async function ft(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
2:s}))}class ce{constructor({path:s,url:t,orig_name:i,size:n,blob:o,is_stream:r,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=i,this.size=n,this.blob=t?void 0:o,this.is_stream=r,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 i=t.shift();if(typeof i=="string"||typeof i=="number")e[i]=s;else throw new Error("Invalid key type")}async function ne(e,s=void 0,t=[],i=!1,n=void 0){if(Array.isArray(e)){let o=[];return await Promise.all(e.map(async r=>{var c;let u=t.slice();u.push(r);const l=await ne(e[r],i?((c=n?.parameters[r])==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 r of Object.keys(e)){const c=[...t,r],u=e[r];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 He(e,s){var t,i;return((i=(t=s?.dependencies)==null?void 0:t[e])==null?void 0:i.queue)!==null?!s.dependencies[e].queue:!s.enable_queue}function Ke(e,s){return new Promise((t,i)=>{const n=new MessageChannel;n.port1.onmessage=({data:o})=>{n.port1.close(),t(o)},window.parent.postMessage(e,s,[n.port2])})}async function Ve(e,s,t){const i=this,n=await ne(s,void 0,[],!0,t);return(await Promise.all(n.map(async({path:r,blob:c,type:u})=>
2{if(!c)return{path:r,type:u};const l=await i.upload_files(e,[c]),f=l.files&&l.files[0];return{path:r,file_url:f,type:u,name:c instanceof File?c?.name:void 0}}))).forEach(({path:r,file_url:c,type:u,name:l})=>{if(u==="Gallery")ue(s,c,r);else if(c){const f=new ce({path:c,orig_name:l});ue(s,f,r)}}),s}async function Ye(e,s,t){const i={"Content-Type":"application/json"};this.options.hf_token&&(i.Authorization=`Bearer ${this.options.hf_token}`);try{var n=await this.fetch(e,{method:"POST",body:JSON.stringify(s),headers:{...i,...t}})}catch{return[{error:L},500]}let o,r;try{o=await n.json(),r=n.status}catch(c){o={error:`Could not parse server response: ${c}`},r=500}return[o,r]}async function Qe(e,s){let t=!1,i=!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,r)=>{const c=this.submit(e,s||[]);let u;c.on("data",l=>{i&&(c.destroy(),o(l)),t=!0,u=l}).on("status",l=>{l.stage==="error"&&r(l),l.stage==="complete"&&(i=!0,t&&(c.destroy(),o(u)))})})}async function ie(e,s,t){let i=s==="subdomain"?`https://huggingface.co/api/spaces/by-subdomain/${e}`:`https://huggingface.co/api/spaces/${e}`,n,o;try{if(n=await fetch(i),o=n.status,o!==200)throw new Error;n=await n.json()}catch{t({status:"error",load_status:"error",message:xe,detail:"NOT_FOUND"});return}if(!n||o!==200)return;const{runtime:{stage:r},id:c}=n;switch(r){case"STOPPED":case"SLEEPING":t({status:"sleeping",load_status:"pending",message:"Space is asleep. Waking it up...",detail:r}),setTimeout(()=>{ie(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:r,discussions_enabled:await pe(c)});break;case"RUNNING":case"RUNNING_BUILDING":t({status:"running",load_status:"complete",message:"",detail:r});break;case"BUILDING":t({status:"building",load_status:"pending",message:"Space is building...",detail:r}),setTimeout(()=>{ie(e,s,t)},1e3);break;default:t({status:"space_error",load_status:"error",message:"This space is experiencing an issue.",detail:r,discussions_enabled:await pe(c)});break}}const Xe=/^(?=[^]*\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&&Xe.test(t))}catch{return!1}}async function Ze(e,s){const t={};s&&(t.Authorization=`Bearer ${s}`);try{const i=await fetch(`https://huggingface.co/api/spaces/${e}/${Pe}`,{headers:t});if(i.status!==200)throw new Error("Space hardware could not be obtained.");const{hardware:n}=await i.json();return n.current}catch(i){throw new Error(i.message)}}async function et(e,s,t){const i={};t&&(i.Authorization=`Bearer ${t}`);const n={seconds:s};try{const o=await fetch(`https://huggingface.co/api/spaces/${e}/${Ne}`,{method:"POST",headers:{"Content-Type":"application/json",...i},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 tt(e,s){const{hf_token:t,private:i,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 r={Authorization:`Bearer ${t}`,"Content-Type":"application/json"},c=(await(await fetch("https://huggingface.co/api/whoami-v2",{headers:r})).json()).name,u=e.split("/")[1],l={repository:`${c}/${u}`};i&&(l.private=!0);let f;try{n||(f=await Ze(e,t))}catch(p){throw Error(qe+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:r,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 et(`${c}/${u}`,o||300,t),await H.connect(st(g.url),s)}catch(p){throw new Error(p)}}function st(e){const s=/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/,t=e.match(s);if(t)return t[1]}function nt(){let{event_callbacks:e,unclosed_events:s,pending_stream_messages:t,stream_status:i,config:n,jwt:o}=this;if(!n)throw new Error("Could not resolve app config");i.open=!0;let r=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),r=this.stream_factory(u),!r){console.warn("Cannot connect to SSE endpoint: "+u.toString());return}r.onmessage=async function(l){let f=JSON.parse(l.data);if(f.msg==="close_stream"){W(i,r);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(i,r));let p=e[a];typeof window<"u"?window.setTimeout(p,0,f):setImmediate(p,f)}else t[a]||(t[a]=[]),t[a].push(f)},r.onerror=async function(){await Promise.all(Object.keys(e).map(l=>e[l]({msg:"unexpected_error",message:L}))),W(i,r)}}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 r=ot(e[s][o],n);e[s][o]=r,t.data[o]=r})}
2function ot(e,s){return s.forEach(([t,i,n])=>{e=rt(e,i,t,n)}),e}function rt(e,s,t,i){if(s.length===0){if(t==="replace")return i;if(t==="append")return e+i;throw new Error(`Unsupported action: ${t}`)}let n=e;for(let r=0;r<s.length-1;r++)n=n[s[r]];const o=s[s.length-1];switch(t){case"replace":n[o]=i;break;case"append":n[o]+=i;break;case"add":Array.isArray(n)?n.splice(Number(o),0,i):n[o]=i;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 at(e,s,t,i){try{let n=function(w){const O=U[w.type]||[];O?.forEach(m=>m(w))},o=function(w,E){const O=U,m=O[w]||[];return O[w]=m,m?.push(E),{on:o,off:r,cancel:Q,destroy:c}},r=function(w,E){const O=U;let m=O[w]||[];return m=m?.filter(x=>x!==E),O[w]=m,{on:o,off:r,cancel:Q,destroy:c}},c=function(){var w;for(const E in U)U&&((w=U[E])==null||w.forEach(O=>{r(E,O)}))};const{hf_token:u}=this.options,{fetch:l,app_reference:f,config:a,session_hash:p,api_info:g,api_map:v,stream_status:I,pending_stream_messages:F,pending_diff_streams:M,event_callbacks:K,unclosed_events:be,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:ve,dependency:Se}=ct(g,e,v,a),$,k,P=a.protocol??"ws";const d=typeof e=="number"?"/predict":e;let G,S=null,C=!1;const U={};let Y={},q=typeof window<"u"?new URLSearchParams(window.location.search).toString():"";async function Q(){const w={stage:"complete",queue:!1,time:new Date};C=w,n({...w,type:"status",endpoint:d,fn_index:h});let E={};P==="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,s,ve).then(async w=>{var E;if(G={data:w||[],event_data:t,fn_index:h,trigger_id:i},He(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}`}${q?"?"+q:""}`,{...G,session_hash:p}).then(([m,x])=>{const N=m.data;x==200?(n({type:"data",endpoint:d,fn_index:h,data:N,time:new Date,event_data:t,trigger_id:i}),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(P=="ws"){const{ws_protocol:m,host:x}=await ge(f,u);n({type:"status",stage:"pending",queue:!0,endpoint:d,fn_index:h,time:new Date});let N=new URL(`${m}://${_e(x,a.path,!0)}/queue/join${q?"?"+q:""}`);this.jwt&&N.searchParams.set("__sign",this.jwt),$=new WebSocket(N),$.onclose=R=>{R.wasClean||n({type:"status",stage:"error",broken:!0,message:L,queue:!0,endpoint:d,fn_index:h,time:new Date})},$.onmessage=function(R){const T=JSON.parse(R.data),{type:b,status:A,data:D}=se(T,Y[h]);if(b==="update"&&A&&!C)n({type:"status",endpoint:d,fn_index:h,time:new Date,...A}),A.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"?C=A:b==="log"?n({type:"log",log:D.log,level:D.level,endpoint:d,fn_index:h}):b==="generating"&&n({type:"status",time:new Date,...A,stage:A?.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:i}),C&&(n({type:"status",time:new Date,...C,stage:A?.stage,queue:!0,endpoint:d,fn_index:h}),$.close()))},semiver(a.version||"2.0.0","3.6")<0&&addEventListener("open",()=>$.send(JSON.stringify({hash:p})))}else if(P=="sse"){n({type:"status",stage:"pending",queue:!0,endpoint:d,fn_index:h,time:new Date});var O=new URLSearchParams({fn_index:h.toString(),session_hash:p}).toString();let m=new URL(`${a.root}/queue/join?${q?q+"&":""}${O}`);if(this.jwt&&m.searchParams.set("__sign",this.jwt),k=this.stream_factory(m),!k)return Promise.reject(new Error("Cannot connect to SSE endpoint: "+m.toString()));
2k.onmessage=async function(x){const N=JSON.parse(x.data),{type:R,status:T,data:b}=se(N,Y[h]);if(R==="update"&&T&&!C)n({type:"status",endpoint:d,fn_index:h,time:new Date,...T}),T.stage==="error"&&k?.close();else if(R==="data"){S=N.event_id;let[A,D]=await V(`${a.root}/queue/data`,{...G,session_hash:p,event_id:S});D!==200&&(n({type:"status",stage:"error",message:L,queue:!0,endpoint:d,fn_index:h,time:new Date}),k?.close())}else R==="complete"?C=T:R==="log"?n({type:"log",log:b.log,level:b.level,endpoint:d,fn_index:h}):R==="generating"&&n({type:"status",time:new Date,...T,stage:T?.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:i}),C&&(n({type:"status",time:new Date,...C,stage:T?.stage,queue:!0,endpoint:d,fn_index:h}),k?.close()))}}else if(P=="sse_v1"||P=="sse_v2"||P=="sse_v2.1"||P=="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";(Se.zerogpu&&window.parent!=window&&a.space_id?Ke("zerogpu-headers",N):Promise.resolve(null)).then(b=>V(`${a.root}/queue/join?${q}`,{...G,session_hash:p},b)).then(([b,A])=>{if(A===503)n({type:"status",stage:"error",message:de,queue:!0,endpoint:d,fn_index:h,time:new Date});else if(A!==200)n({type:"status",stage:"error",message:L,queue:!0,endpoint:d,fn_index:h,time:new Date});else{S=b.event_id;let D=async function(X){try{const{type:j,status:y,data:z}=se(X,Y[h]);if(j=="heartbeat")return;if(j==="update"&&y&&!C)n({type:"status",endpoint:d,fn_index:h,time:new Date,...y});else if(j==="complete")C=y;else if(j=="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(j==="log"){n({type:"log",log:z.log,level:z.level,endpoint:d,fn_index:h});return}else j==="generating"&&(n({type:"status",time:new Date,...y,stage:y?.stage,queue:!0,endpoint:d,fn_index:h}),z&&["sse_v2","sse_v2.1","sse_v3"].includes(P)&&it(M,S,z));z&&(n({type:"data",time:new Date,data:z.data,endpoint:d,fn_index:h}),C&&n({type:"status",time:new Date,...C,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(j){console.error("Unexpected client exception",j),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(P)&&(W(I,k),I.open=!1)}};S in F&&(F[S].forEach(X=>D(X)),delete F[S]),K[S]=D,be.add(S),I.open||this.open_stream()}})}}),{on:o,off:r,cancel:Q,destroy:c}}catch(n){throw console.error("Submit function encountered an error:",n),n}}function ct(e,s,t,i){let n,o,r;if(typeof s=="number")n=s,o=e.unnamed_endpoints[n],r=i.dependencies[s];else{const c=s.replace(/^\//,"");n=t[c],o=e.named_endpoints[s.trim()],r=i.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:r}}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=Ge.bind(this),this.upload_files=Je.bind(this),this.handle_blob=Ve.bind(this),this.post_data=Ye.bind(this),this.submit=at.bind(this),this.predict=Qe.bind(this),this.open_stream=nt.bind(this),this.resolve_config=Ue.bind(this),this.upload=We.bind(this)}fetch(s,t){return fetch(s,t)}stream_factory(s){if(typeof window>"u"||typeof EventSource>"u")J(()=>import("./eventsource-CfQQVHjX.js").then(t=>t.e),__vite__mapDeps([0,1,2,3]),import.meta.url).then(t=>
2new t.default(s.toString())).catch(t=>console.error("Failed to load EventSource module:",t));else return new EventSource(s.toString());return null}async 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(i=>i._),[],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 i=new URL(`${this.config.root}/heartbeat/${this.session_hash}`);this.heartbeat_event=this.stream_factory(i),this.config.space_id&&this.options.hf_token&&(this.jwt=await Le(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=Ie(((s=this.config)==null?void 0:s.dependencies)||[])}static async connect(s,t={}){const i=new this(s,t);return await i.init(),i}close(){var s;(s=this.heartbeat_event)==null||s.close()}static async duplicate(s,t={}){return tt(s,t)}async _resolve_config(){const{http_protocol:s,host:t,space_id:i}=await ge(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(r){console.error(r),i?ie(i,me.test(i)?"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(je+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(i){console.error(i),t&&t({status:"error",message:"Could not load this space.",load_status:"error",detail:"NOT_FOUND"})}}async component_server(s,t,i){var n;if(!this.config)throw new Error(B);const o={},{hf_token:r}=this.options,{session_hash:c}=this;r&&(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 i){f=new FormData;for(const a in i.data)a!=="binary"&&f.append(a,i.data[a]);f.set("component_id",s.toString()),f.set("fn_name",t),f.set("session_hash",c)}else f=JSON.stringify({data:i,component_id:s,fn_name:t,session_hash:c}),o["Content-Type"]="application/json";r&&(o.Authorization=`Bearer ${r}`);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 we=!1;"attachShadow"in Element.prototype&&"adoptedStyleSheets"in Document.prototype&&(we="adoptedStyleSheets"in document.createElement("div").attachShadow({mode:"open"}));function fe(e,s){const t=new URL(import.meta.url).origin,i=new URL(e,t).href;if(document.querySelector(`link[href='${i}']`))return Promise.resolve();const o=document.createElement("link");return o.rel="stylesheet",o.href=i,new Promise((r,c)=>{o.addEventListener("load",()=>r()),o.addEventListener("error",()=>{console.error(`Unable to preload CSS for ${i}`),r()}),s.appendChild(o)})}function dt(e,s,t=document.createElement("style")){if(!we)return null;t.remove();const i=new CSSStyleSheet;i.replaceSync(e);let n="";e=e.replace(/@import\s+url\((.*?)\);\s*/g,(u,l)=>(n+=`@import url(${l}); 3`,""));const o=i.cssRules;let r="",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(",");r+=l.cssText,r+=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 I=g.selectorText,F=I.replace(".dark","").split(",").map(M=>`${v?".dark":""} ${c} ${M.trim()} `).join(",");a+=g.cssText.replace(I,F)}}a+="}",r+=a}else if(l instanceof CSSKeyframesRule){r+=`@keyframes ${l.name} {`;for(let a=0;a<l.cssRules.length;a++){const p=l.cssRules[a];p instanceof CSSKeyframeRule&&(r+=`${p.keyText} { ${p.style.cssText} }`)}r+="}"}else l instanceof CSSFontFaceRule&&(r+=`@font-face { ${l.style.cssText} }`)}return r=n+r,t.textContent=r,document.head.appendChild(t),t}const lt="./assets/index-Ds_LdHYW.css";let re;re=[];let ae,ye,ut=new Promise(e=>{ye=e});async function pt(){ae=(await J(()=>import("./Index-DvJ399W-.js").then(e=>e.f),__vite__mapDeps([5,1,6]),import.meta.url)).default,ye()}function ht(){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 pt(),this.loading=!0,this.app&&this.app.$destroy(),typeof re!="string"&&re.forEach(o=>fe(o,document.head)),await fe(lt,document.head);const i=new CustomEvent("domchange",{bubbles:!0,cancelable:!1,composed:!0});new MutationObserver(o=>{this.dispatchEvent(i)}).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-29-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(i,n,o){if(await ut,(i==="host"||i==="space"||i==="src")&&o!==n){if(this.updating={name:i,value:o},this.loading)return;this.app&&this.app.$destroy(),this.space=null,this.host=null,this.src=null,i==="host"?this.host=o:i==="space"?this.space=o:i==="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-29-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)}ht();export{J as _,dt as a,fe as m,ft as p}; 4//# sourceMappingURL=index-D6iiusuW.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.