1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/wrapper-CviSselG-DvBuvln1.js","assets/__vite-browser-external-BIHI7g3E.js","assets/vendor-react-DTF1y61S.js"])))=>i.map(i=>d[i]); 2import{_ as ye,j as y}from"./index-BHKWHNqP.js";import{b as B}from"./vendor-react-DTF1y61S.js";import"./vendor-icons-Bx5hBfGb.js";var nt=Object.defineProperty,it=(s,t,e)=>t in s?nt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,u=(s,t,e)=>(it(s,typeof t!="symbol"?t+"":t,e),e),Fe=(s,t,e)=>{if(!t.has(s))throw TypeError("Cannot "+e)},se=(s,t,e)=>(Fe(s,t,"read from private field"),e?e.call(s):t.get(s)),rt=(s,t,e)=>{if(t.has(s))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(s):t.set(s,e)},ot=(s,t,e,n)=>(Fe(s,t,"write to private field"),t.set(s,e),e),W,fe=new Intl.Collator(0,{numeric:1}).compare;function Ue(s,t,e){return s=s.split("."),t=t.split("."),fe(s[0],t[0])||fe(s[1],t[1])||(t[2]=t.slice(2).join("."),e=/[.-]/.test(s[2]=s.slice(2).join(".")),e==/[.-]/.test(t[2])?fe(s[2],t[2]):e?-1:1)}const at="host",ze="queue/data",ct="queue/join",Ae="upload",lt="login",Re="config",ut="info",dt="runtime",pt="sleeptime",ht="heartbeat",ft="component_server",_t="reset",mt="cancel",gt="https://gradio-space-api-fetcher-v2.hf.space/api",Be="This application is currently busy. Please try again. ",V="Connection errored out. ",H="Could not resolve app config. ",wt="Could not get space status. ",yt="Could not get API info. ",xe="Space metadata could not be loaded. ",bt="Invalid URL. A full URL path is required.",vt="Not authorized to access this space. ",Me="Invalid credentials. Could not login. ",xt="Login credentials are required to access this space.",Et="File system access is only available in Node.js environments",Ge="Root URL not found in client config",St="Error uploading file";function We(s,t,e){return t.startsWith("http://")||t.startsWith("https://")?e?s:t:s+t}async function Ie(s,t,e){try{return(await(await fetch(`https://huggingface.co/api/spaces/${s}/jwt`,{headers:{Authorization:`Bearer ${t}`,...e?{Cookie:e}:{}}})).json()).token||!1}catch{return!1}}function kt(s){let t={};return s.forEach(({api_name:e,id:n})=>{e&&(t[e]=n)}),t}async function $t(s){var t;const e=this.options.hf_token?{Authorization:`Bearer ${this.options.hf_token}`}:{};if(e["Content-Type"]="application/json",typeof window<"u"&&window.gradio_config&&location.origin!=="http://localhost:9876"&&!window.gradio_config.dev_mode){const n=window.gradio_config.root,i=window.gradio_config;let o=We(s,i.root,!1);return i.root=o,{...i,path:n}}else if(s){let n=Ve(s,this.deep_link?Re+"?deep_link="+this.deep_link:Re);const i=await this.fetch(n,{headers:e,credentials:"include"});if((i==null?void 0:i.status)===401&&!this.options.auth)throw new Error(xt);if((i==null?void 0:i.status)===401&&this.options.auth)throw new Error(Me);if((i==null?void 0:i.status)===200){let o=await i.json();return o.path=o.path??"",o.root=s,(t=o.dependencies)==null||t.forEach((r,a)=>{r.id===void 0&&(r.id=a)}),o}else if((i==null?void 0:i.status)===401)throw new Error(vt);throw new Error(H)}throw new Error(H)}async function Nt(){const{http_protocol:s,host:t}=await ae(this.app_reference,this.options.hf_token);try{if(this.options.auth){const e=await He(s,t,this.options.auth,this.fetch,this.options.hf_token);e&&this.set_cookies(e)}}catch(e){throw Error(e.message)}}async function He(s,t,e,n,i){const o=new FormData;o.append("username",e==null?void 0:e[0]),o.append("password",e==null?void 0:e[1]);let r={};i&&(r.Authorization=`Bearer ${i}`);const a=await n(`${s}//${t}/${lt}`,{headers:r,method:"POST",body:o,credentials:"include"});if(a.status===200)return a.headers.get("set-cookie");throw a.status===401?new Error(Me):new Error(xe)}function _e(s){if(s.startsWith("http")){const{protocol:t,host:e,pathname:n}=new URL(s);return{ws_protocol:t==="https:"?"wss":"ws",http_protocol:t,host:e+(n!=="/"?n:"")}}else if(s.startsWith("file:"))return{ws_protocol:"ws",http_protocol:"http:",host:"lite.local"};return{ws_protocol:"wss",http_protocol:"https:",host:new URL(s).host}}const Je=s=>{let t=[];return s.split(/,(?=\s*[^\s=;]+=[^\s=;
2]+)/).forEach(n=>{const[i,o]=n.split(";")[0].split("=");i&&o&&t.push(`${i.trim()}=${o.trim()}`)}),t},Ee=/^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/,Tt=/.*hf\.space\/{0,1}.*$/;async function ae(s,t){const e={};t&&(e.Authorization=`Bearer ${t}`);const n=s.trim().replace(/\/$/,"");if(Ee.test(n))try{const o=(await(await fetch(`https://huggingface.co/api/spaces/${n}/${at}`,{headers:e})).json()).host;return{space_id:s,..._e(o)}}catch{throw new Error(xe)}if(Tt.test(n)){const{ws_protocol:i,http_protocol:o,host:r}=_e(n);return{space_id:r.split("/")[0].replace(".hf.space",""),ws_protocol:i,http_protocol:o,host:r}}return{space_id:!1,..._e(n)}}const Ve=(...s)=>{try{return s.reduce((t,e)=>(t=t.replace(/\/+$/,""),e=e.replace(/^\/+/,""),new URL(e,t+"/").toString()))}catch{throw new Error(bt)}};function Dt(s,t,e){const n={named_endpoints:{},unnamed_endpoints:{}};return Object.keys(s).forEach(i=>{(i==="named_endpoints"||i==="unnamed_endpoints")&&(n[i]={},Object.entries(s[i]).forEach(([o,{parameters:r,returns:a}])=>{var l,m,d,p;const _=((l=t.dependencies.find(c=>c.api_name===o||c.api_name===o.replace("/","")))==null?void 0:l.id)||e[o.replace("/","")]||-1,S=_!==-1?(m=t.dependencies.find(c=>c.id==_))==null?void 0:m.types:{generator:!1,cancel:!1};if(_!==-1&&((p=(d=t.dependencies.find(c=>c.id==_))==null?void 0:d.inputs)==null?void 0:p.length)!==r.length){const c=t.dependencies.find(g=>g.id==_).inputs.map(g=>{var $;return($=t.components.find(h=>h.id===g))==null?void 0:$.type});try{c.forEach((g,$)=>{if(g==="state"){const h={component:"state",example:null,parameter_default:null,parameter_has_default:!0,parameter_name:null,hidden:!0};r.splice($,0,h)}})}catch(g){console.error(g)}}const O=(c,g,$,h)=>({...c,description:At(c==null?void 0:c.type,$),type:Ct(c==null?void 0:c.type,g,$,h)||""});n[i][o]={parameters:r.map(c=>O(c,c==null?void 0:c.component,c==null?void 0:c.serializer,"parameter")),returns:a.map(c=>O(c,c==null?void 0:c.component,c==null?void 0:c.serializer,"return")),type:S}}))}),n}function Ct(s,t,e,n){if(t==="Api")return s.type;switch(s==null?void 0:s.type){case"string":return"string";case"boolean":return"boolean";case"number":return"number"}if(e==="JSONSerializable"||e==="StringSerializable")return"any";if(e==="ListStringSerializable")return"string[]";if(t==="Image")return n==="parameter"?"Blob | File | Buffer":"string";if(e==="FileSerializable")return(s==null?void 0:s.type)==="array"?n==="parameter"?"(Blob | File | Buffer)[]":"{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]":n==="parameter"?"Blob | File | Buffer":"{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}";if(e==="GallerySerializable")return n==="parameter"?"[(Blob | File | Buffer), (string | null)][]":"[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]"}function At(s,t){return t==="GallerySerializable"?"array of [file, label] tuples":t==="ListStringSerializable"?"array of strings":t==="FileSerializable"?"array of files or single file":s==null?void 0:s.description}function me(s,t){switch(s.msg){case"send_data":return{type:"data"};case"send_hash":return{type:"hash"};case"queue_full":return{type:"update",status:{queue:!0,message:Be,stage:"error",code:s.code,success:s.success}};case"heartbeat":return{type:"heartbeat"};case"unexpected_error":return{type:"unexpected_error",status:{queue:!0,message:s.message,stage:"error",success:!1}};case"estimation":return{type:"update",status:{queue:!0,stage:t||"pending",code:s.code,size:s.queue_size,position:s.rank,eta:s.rank_eta,success:s.success}};case"progress":return{type:"update",status:{queue:!0,stage:"pending",code:s.code,progress_data:s.progress_data,success:s.success}};case"log":return{type:"log",data:s};case"process_generating":return{type:"generating",status:{queue:!0,message:s.success?null:s.output.error,stage:s.success?"generating":"error",code:s.code,progress_data:s.progress_data,eta:s.average_duration,changed_state_ids:s.success?s.output.changed_state_ids:void 0},data:s.success?s.output:null};case"process_streaming":return{type:"streaming",status:{queue:!0,message:s.output.error,stage:"streaming",time_limit:s.time_limit,code:s.code,progress_data:s.progress_data,eta:s.eta},data:s.output};case"process_completed":return"error"in s.output?{type:"update",status:{queue:!0,title:s.output.title,message:s.output.error,visible:s.output.visible,duration:s.output.duration,stage:"error",code:s.code,success:s.success}}:{type:"complete",status:{queue:!0,message:s.success?void 0:s.output.error,stage:s.success?"complete":"error",code:s.code,progress_data:s.progress_data,changed_state_ids:s.success?s.output.changed_state_ids:void 0},data:s.success?s.output:null};case"process_starts":return{type:"update",status:{queue:!0,stage:"pending",code:s.code,size:s.rank,position:0,success:s.success,eta:s.eta},original_msg:"process_starts"}}return{type:"none",status:{stage:"error",queue:!0}}}const Rt=(s=[],t)=>{const e=t?t.parameters:[];if(Array.isArray(s))return s.length>e.length&&console.warn("Too many arguments provided for the endpoint."),s;const n=[],i=Object.keys(s);return e.forEach((o,r)=>
2{if(s.hasOwnProperty(o.parameter_name))n[r]=s[o.parameter_name];else if(o.parameter_has_default)n[r]=o.parameter_default;else throw new Error(`No value provided for required parameter: ${o.parameter_name}`)}),i.forEach(o=>{if(!e.some(r=>r.parameter_name===o))throw new Error(`Parameter \`${o}\` is not a valid keyword argument. Please refer to the API for usage.`)}),n.forEach((o,r)=>{if(o===void 0&&!e[r].parameter_has_default)throw new Error(`No value provided for required parameter: ${e[r].parameter_name}`)}),n};async function It(){if(this.api_info)return this.api_info;const{hf_token:s}=this.options,{config:t}=this,e={"Content-Type":"application/json"};if(s&&(e.Authorization=`Bearer ${s}`),!!t)try{let n,i;if(typeof window<"u"&&window.gradio_api_info)i=window.gradio_api_info;else{if(Ue((t==null?void 0:t.version)||"2.0.0","3.30")<0)n=await this.fetch(gt,{method:"POST",body:JSON.stringify({serialize:!1,config:JSON.stringify(t)}),headers:e,credentials:"include"});else{const o=Ve(t.root,this.api_prefix,ut);n=await this.fetch(o,{headers:e,credentials:"include"})}if(!n.ok)throw new Error(V);i=await n.json()}return"api"in i&&(i=i.api),i.named_endpoints["/predict"]&&!i.unnamed_endpoints[0]&&(i.unnamed_endpoints[0]=i.named_endpoints["/predict"]),Dt(i,t,this.api_map)}catch(n){throw new Error("Could not get API info. "+n.message)}}async function Ot(s,t,e){var n;const i={};(n=this==null?void 0:this.options)!=null&&n.hf_token&&(i.Authorization=`Bearer ${this.options.hf_token}`);const o=1e3,r=[];let a;for(let l=0;l<t.length;l+=o){const m=t.slice(l,l+o),d=new FormData;m.forEach(_=>{d.append("files",_)});try{const _=e?`${s}${this.api_prefix}/${Ae}?upload_id=${e}`:`${s}${this.api_prefix}/${Ae}`;a=await this.fetch(_,{method:"POST",body:d,headers:i,credentials:"include"})}catch(_){throw new Error(V+_.message)}if(!a.ok){const _=await a.text();return{error:`HTTP ${a.status}: ${_}`}}const p=await a.json();p&&r.push(...p)}return{files:r}}async function jt(s,t,e,n){let i=(Array.isArray(s)?s:[s]).map(r=>r.blob);const o=i.filter(r=>r.size>(n??1/0));if(o.length)throw new Error(`File size exceeds the maximum allowed size of ${n} bytes: ${o.map(r=>r.name).join(", ")}`);return await Promise.all(await this.upload_files(t,i,e).then(async r=>{if(r.error)throw new Error(r.error);return r.files?r.files.map((a,l)=>new Se({...s[l],path:a,url:`${t}${this.api_prefix}/file=${a}`})):[]}))}class Se{constructor({path:t,url:e,orig_name:n,size:i,blob:o,is_stream:r,mime_type:a,alt_text:l,b64:m}){u(this,"path"),u(this,"url"),u(this,"orig_name"),u(this,"size"),u(this,"blob"),u(this,"is_stream"),u(this,"mime_type"),u(this,"alt_text"),u(this,"b64"),u(this,"meta",{_type:"gradio.FileData"}),this.path=t,this.url=e,this.orig_name=n,this.size=i,this.blob=e?void 0:o,this.is_stream=r,this.mime_type=a,this.alt_text=l,this.b64=m}}class Pt{constructor(t,e){u(this,"type"),u(this,"command"),u(this,"meta"),u(this,"fileData"),this.type="command",this.command=t,this.meta=e}}typeof process<"u"&&process.versions&&process.versions.node;function Oe(s,t,e){for(;e.length>1;){const i=e.shift();if(typeof i=="string"||typeof i=="number")s=s[i];else throw new Error("Invalid key type")}const n=e.shift();if(typeof n=="string"||typeof n=="number")s[n]=t;else throw new Error("Invalid key type")}async function be(s,t=void 0,e=[],n=!1,i=void 0){if(Array.isArray(s)){let o=[];return await Promise.all(s.map(async(r,a)=>{var l;let m=e.slice();m.push(String(a));const d=await be(s[a],n?((l=i==null?void 0:i.parameters[a])==null?void 0:l.component)||void 0:t,m,!1,i);o=o.concat(d)})),o}else{if(globalThis.Buffer&&s instanceof globalThis.Buffer||s instanceof Blob)return[{path:e,blob:new Blob([s]),type:t}];if(typeof s=="object"&&s!==null){let o=[];for(const r of Object.keys(s)){const a=[...e,r],l=s[r];o=o.concat(await be(l,void 0,a,!1,i))}return o}}return[]}function Lt(s,t){var e,n;let i=(n=(e=t==null?void 0:t.dependencies)==null?void 0:e.find(o=>o.id==s))==null?void 0:n.queue;return i!=null?!i:!t.enable_queue}function qt(s,t){return new Promise((e,n)=>{const i=new MessageChannel;i.port1.onmessage=({data:o})=>{i.port1.close(),e(o)},window.parent.postMessage(s,t,[i.port2])})}function ne(s,t,e,n,i=!1){if(n==="input"&&!i)throw new Error("Invalid code path. Cannot skip state inputs for input.");if(n==="output"&&i)return s;let o=[],r=0;
vendor: 6,934 bytes, lines 2-3
2const a=n==="input"?t.inputs:t.outputs;for(let l=0;l<a.length;l++){const m=a[l],d=e.find(p=>p.id===m);if((d==null?void 0:d.type)==="state"){if(i)if(s.length===a.length){const p=s[r];o.push(p),r++}else o.push(null);else{r++;continue}continue}else{const p=s[r];o.push(p),r++}}return o}async function Ft(s,t,e){const n=this;await Ut(n,t);const i=await be(t,void 0,[],!0,e);return(await Promise.all(i.map(async({path:r,blob:a,type:l})=>{if(!a)return{path:r,type:l};const m=await n.upload_files(s,[a]),d=m.files&&m.files[0];return{path:r,file_url:d,type:l,name:typeof File<"u"&&a instanceof File?a==null?void 0:a.name:void 0}}))).forEach(({path:r,file_url:a,type:l,name:m})=>{if(l==="Gallery")Oe(t,a,r);else if(a){const d=new Se({path:a,orig_name:m});Oe(t,d,r)}}),t}async function Ut(s,t){var e,n;if(!(((e=s.config)==null?void 0:e.root)||((n=s.config)==null?void 0:n.root_url)))throw new Error(Ge);await Qe(s,t)}async function Qe(s,t,e=[]){for(const n in t)t[n]instanceof Pt?await zt(s,t,n):typeof t[n]=="object"&&t[n]!==null&&await Qe(s,t[n],[...e,n])}async function zt(s,t,e){var n,i;let o=t[e];const r=((n=s.config)==null?void 0:n.root)||((i=s.config)==null?void 0:i.root_url);if(!r)throw new Error(Ge);try{let a,l;if(typeof process<"u"&&process.versions&&process.versions.node){const _=await ye(()=>import("./__vite-browser-external-BIHI7g3E.js"),[]);l=(await ye(()=>import("./__vite-browser-external-BIHI7g3E.js"),[])).resolve(process.cwd(),o.meta.path),a=await _.readFile(l)}else throw new Error(Et);const m=new Blob([a],{type:"application/octet-stream"}),d=await s.upload_files(r,[m]),p=d.files&&d.files[0];if(p){const _=new Se({path:p,orig_name:o.meta.name||""});t[e]=_}}catch(a){console.error(St,a)}}async function Bt(s,t,e){const n={"Content-Type":"application/json"};this.options.hf_token&&(n.Authorization=`Bearer ${this.options.hf_token}`);try{var i=await this.fetch(s,{method:"POST",body:JSON.stringify(t),headers:{...n,...e},credentials:"include"})}catch{return[{error:V},500]}let o,r;try{o=await i.json(),r=i.status}catch(a){o={error:`Could not parse server response: ${a}`},r=500}return[o,r]}async function Mt(s,t={}){let e=!1,n=!1;if(!this.config)throw new Error("Could not resolve app config");if(typeof s=="number")this.config.dependencies.find(i=>i.id==s);else{const i=s.replace(/^\//,"");this.config.dependencies.find(o=>o.id==this.api_map[i])}return new Promise(async(i,o)=>{const r=this.submit(s,t,null,null,!0);let a;for await(const l of r)l.type==="data"&&(n&&i(a),e=!0,a=l),l.type==="status"&&(l.stage==="error"&&o(l),l.stage==="complete"&&(n=!0,e&&i(a)))})}async function ie(s,t,e){let n=t==="subdomain"?`https://huggingface.co/api/spaces/by-subdomain/${s}`:`https://huggingface.co/api/spaces/${s}`,i,o;try{if(i=await fetch(n),o=i.status,o!==200)throw new Error;i=await i.json()}catch{e({status:"error",load_status:"error",message:wt,detail:"NOT_FOUND"});return}if(!i||o!==200)return;const{runtime:{stage:r},id:a}=i;switch(r){case"STOPPED":case"SLEEPING":e({status:"sleeping",load_status:"pending",message:"Space is asleep. Waking it up...",detail:r}),setTimeout(()=>{ie(s,t,e)},1e3);break;case"PAUSED":e({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 je(a)});break;case"RUNNING":case"RUNNING_BUILDING":e({status:"running",load_status:"complete",message:"Space is running.",detail:r});break;case"BUILDING":e({status:"building",load_status:"pending",message:"Space is building...",detail:r}),setTimeout(()=>{ie(s,t,e)},1e3);break;case"APP_STARTING":e({status:"starting",load_status:"pending",message:"Space is starting...",detail:r}),setTimeout(()=>{ie(s,t,e)},1e3);break;default:e({status:"space_error",load_status:"error",message:"This space is experiencing an issue.",detail:r,discussions_enabled:await je(a)});break}}const Ke=async(s,t)=>{let e=0;const n=12,i=5e3;return new Promise(o=>{ie(s,Ee.test(s)?"space_name":"subdomain",r=>{t(r),r.status==="running"||r.status==="error"||r.status==="paused"||r.status==="space_error"?o():(r.status==="sleeping"||r.status==="building")&&(e<n?(e++,setTimeout(()=>{Ke(s,t).then(o)},i)):o())})})},Gt=/^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;async function je(s){try{const t=await fetch(`https://huggingface.co/api/spaces/${s}/discussions`,{method:"HEAD"}),e=t.headers.get("x-error-message");return!(!t.ok||e&&Gt.test(e))}catch{return!1}}async function Wt(s,t){const e={};t&&(e.Authorization=`Bearer ${t}`);try{const n=await fetch(`https://huggingface.co/api/spaces/${s}/${dt}`,{headers:e});if(n.status!==200)throw new Error("Space hardware could not be obtained.");const{hardware:i}=await n.json();return i.current}catch(n){throw new Error(n.message)}}async function Ht(s,t,e){const n={};e&&(n.Authorization=`Bearer ${e}`);const i={seconds:t};try{const o=await fetch(`https://huggingface.co/api/spaces/${s}/${pt}`,{method:"POST",headers:{"Content-Type":"application/json",...n},body:JSON.stringify(i)});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 Pe=["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 Jt(s,t){const{hf_token:e,private:n,hardware:i,timeout:o,auth:r}=t;if(i&&!Pe.includes(i))throw new Error(`Invalid hardware type provided. Valid types are: ${Pe.map(g=>`"${g}"`).join(",")}.`);const{http_protocol:a,host:l}=await ae(s,e);let m=null;if(r){const g=await He(a,l,r,fetch);g&&(m=Je(g))}const d={Authorization:`Bearer ${e}`,"Content-Type":"application/json",...m?{Cookie:m.join("; ")}:{}},p=(await(await fetch("https://huggingface.co/api/whoami-v2",{headers:d})).json()).name,_=s.split("/")[1],S={repository:`${p}/${_}`};n&&(S.private=!0);let O;try{i||(O=await Wt(s,e))}catch(g){throw Error(xe+g.message)}const c=i||O||"cpu-basic";S.hardware=c;try{const g=await fetch(`https://huggingface.co/api/spaces/${s}/duplicate`,{method:"POST",headers:d,body:JSON.stringify(S)});if(g.status===409)try{return await ve.connect(`${p}/${_}`,t)}catch(h){throw console.error("Failed to connect Client instance:",h),h}else if(g.status!==200)throw new Error(g.statusText);const $=await g.json();return await Ht(`${p}/${_}`,o||300,e),await ve.connect(Vt($.url),t)}catch(g){throw new Error(g)}}function Vt(s){const t=/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/,e=s.match(t);if(e)return e[1]}class Qt extends TransformStream{constructor(t={allowCR:!1}){super({transform:(e,n)=>{for(e=se(this,W)+e;;){const i=e.indexOf(` 3`),o=t.allowCR?e.indexOf("\r"):-1;if(o!==-1&&o!==e.length-1&&(i===-1||i-1>o)){n.enqueue(e.slice(0,o)),e=e.slice(o+1);continue}if(i===-1)break;const r=e[i-1]==="\r"?i-1:i;
3n.enqueue(e.slice(0,r)),e=e.slice(i+1)}ot(this,W,e)},flush:e=>{if(se(this,W)==="")return;const n=t.allowCR&&se(this,W).endsWith("\r")?se(this,W).slice(0,-1):se(this,W);e.enqueue(n)}}),rt(this,W,"")}}W=new WeakMap;function Kt(s){let t=new TextDecoderStream,e=new Qt({allowCR:!0});return s.pipeThrough(t).pipeThrough(e)}function Zt(s){let e=/[:]\s*/.exec(s),n=e&&e.index;if(n)return[s.substring(0,n),s.substring(n+e[0].length)]}function Le(s,t,e){s.get(t)||s.set(t,e)}async function*Xt(s,t){if(!s.body)return;let e=Kt(s.body),n,i=e.getReader(),o;for(;;){if(t&&t.aborted)return i.cancel();if(n=await i.read(),n.done)return;if(!n.value){o&&(yield o),o=void 0;continue}let[r,a]=Zt(n.value)||[];r&&(r==="data"?(o||(o={}),o[r]=o[r]?o[r]+` 4`+a:a):r==="event"?(o||(o={}),o[r]=a):r==="id"?(o||(o={}),o[r]=+a||a):r==="retry"&&(o||(o={}),o[r]=+a||void 0))}}async function Yt(s,t){let e=new Request(s,t);Le(e.headers,"Accept","text/event-stream"),Le(e.headers,"Content-Type","application/json");let n=await fetch(e);if(!n.ok)throw n;return Xt(n,e.signal)}async function es(){let{event_callbacks:s,unclosed_events:t,pending_stream_messages:e,stream_status:n,config:i,jwt:o}=this;const r=this;if(!i)throw new Error("Could not resolve app config");n.open=!0;let a=null,l=new URLSearchParams({session_hash:this.session_hash}).toString(),m=new URL(`${i.root}${this.api_prefix}/${ze}?${l}`);if(o&&m.searchParams.set("__sign",o),a=this.stream(m),!a){console.warn("Cannot connect to SSE endpoint: "+m.toString());return}a.onmessage=async function(d){let p=JSON.parse(d.data);if(p.msg==="close_stream"){oe(n,r.abort_controller);return}const _=p.event_id;if(!_)await Promise.all(Object.keys(s).map(S=>s[S](p)));else if(s[_]&&i){p.msg==="process_completed"&&["sse","sse_v1","sse_v2","sse_v2.1","sse_v3"].includes(i.protocol)&&t.delete(_);let S=s[_];typeof window<"u"&&typeof document<"u"?setTimeout(S,0,p):S(p)}else e[_]||(e[_]=[]),e[_].push(p)},a.onerror=async function(){await Promise.all(Object.keys(s).map(d=>s[d]({msg:"unexpected_error",message:V})))}}function oe(s,t){s&&(s.open=!1,t==null||t.abort())}function ts(s,t,e){!s[t]?(s[t]=[],e.data.forEach((i,o)=>{s[t][o]=i})):e.data.forEach((i,o)=>{let r=ss(s[t][o],i);s[t][o]=r,e.data[o]=r})}function ss(s,t){return t.forEach(([e,n,i])=>{s=ns(s,n,e,i)}),s}function ns(s,t,e,n){if(t.length===0){if(e==="replace")return n;if(e==="append")return s+n;throw new Error(`Unsupported action: ${e}`)}let i=s;for(let r=0;r<t.length-1;r++)i=i[t[r]];const o=t[t.length-1];switch(e){case"replace":i[o]=n;break;case"append":i[o]+=n;break;case"add":Array.isArray(i)?i.splice(Number(o),0,n):i[o]=n;break;case"delete":Array.isArray(i)?i.splice(Number(o),1):delete i[o];break;default:throw new Error(`Unknown action: ${e}`)}return s}function is(s,t={}){const e={close:()=>{console.warn("Method not implemented.")},onerror:null,onmessage:null,onopen:null,readyState:0,url:s.toString(),withCredentials:!1,CONNECTING:0,OPEN:1,CLOSED:2,addEventListener:()=>{throw new Error("Method not implemented.")},dispatchEvent:()=>{throw new Error("Method not implemented.")},removeEventListener:()=>{throw new Error("Method not implemented.")}};return Yt(s,t).then(async n=>{e.readyState=e.OPEN;try{for await(const i of n)e.onmessage&&e.onmessage(i);e.readyState=e.CLOSED}catch(i){e.onerror&&e.onerror(i),e.readyState=e.CLOSED}}).catch(n=>{console.error(n),e.onerror&&e.onerror(n),e.readyState=e.CLOSED}),e}function rs(s,t={},e,n,i){var o;try{let r=function(b){(i||Ye[b.type])&&d(b)},a=function(){for(de=!0;te.length>0;)te.shift()({value:void 0,done:!0})},l=function(b){de||(te.length>0?te.shift()(b):pe.push(b))},m=function(b){l(os(b)),a()},d=function(b){l({value:b,done:!1})},p=function(){return pe.length>0?Promise.resolve(pe.shift()):de?Promise.resolve({value:void 0,done:!0}):new Promise(b=>te.push(b))};const{hf_token:_}=this.options,{fetch:S,app_reference:O,config:c,session_hash:g,api_info:$,api_map:h,stream_status:E,pending_stream_messages:x,pending_diff_streams:q,event_callbacks:Q,unclosed_events:ce,post_data:le,options:K,api_prefix:Z}=this,ke=this;if(!$)throw new Error("No API found");if(!c)throw new Error("Could not resolve app config");let{fn_index:f,endpoint_info:$e,dependency:X}=as($,s,h,c),Ze=Rt(t,$e),C,F,U=c.protocol??"ws",Ne="",Xe=()=>Ne;const w=typeof s=="number"?"/predict":s;let ee,N=null,A=!1,ue={},J=typeof window<"u"&&typeof document<"u"?new URLSearchParams(window.location.search).toString():"";const Ye=((o=K==null?void 0:K.events)==null?void 0:o.reduce((b,j)=>(b[j]=!0,b),{}))||{};async function et(){const b={stage:"complete",queue:!1,time:new Date};A=b,r({...b,type:"status",endpoint:w,fn_index:f});let j={},Y={};U==="ws"?(C&&C.readyState===0?C.addEventListener("open",()=>{C.close()}):C.close(),j={fn_index:f,session_hash:g}):(oe(E,ke.abort_controller),a(),j={event_id:N},Y={event_id:N,session_hash:g,fn_index:f});try{if(!c)throw new Error("Could not resolve app config");"event_id"in Y&&await S(`${c.root}${Z}/${mt}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify(Y)}),await S(`${c.root}${Z}/${_t}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify(j)})}catch{console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.")}}const tt=async b=>{await this._resolve_hearbeat(b)};async function Te(b){if(!c)return;let j=b.render_id;c.components=[...c.components.filter(v=>v.props.rendered_in!==j),...b.components],c.dependencies=[...c.dependencies.filter(v=>v.rendered_in!==j),...b.dependencies];const Y=c.components.some(v=>v.type==="state"),re=c.dependencies.some(v=>v.targets.some(M=>M[1]==="unload"));c.connect_heartbeat=Y||re,await tt(c),r({type:"render",data:b,endpoint:w,fn_index:f})}this.handle_blob(c.root,Ze,$e).then(async b=>{var j;if(ee={data:ne(b,X,c.components,"input",!0)||[],event_data:e,fn_index:f,trigger_id:n},Lt(f,c))r({type:"status",endpoint:w,stage:"pending",queue:!1,fn_index:f,time:new Date}),le(`${c.root}${Z}/run${w.startsWith("/")?w:`/${w}`}${J?"?"+J:""}`,{...ee,session_hash:g}).then(([v,M])=>{const G=v.data;M==200?(r({type:"data",endpoint:w,fn_index:f,data:ne(G,X,c.components,"output",K.with_null_state),time:new Date,event_data:e,trigger_id:n}),v.render_config&&Te(v.render_config),r({type:"status",endpoint:w,fn_index:f,stage:"complete",eta:v.average_duration,queue:!1,time:new Date})):r({type:"status",stage:"error",endpoint:w,fn_index:f,message:v.error,queue:!1,time:new Date})}).catch(v=>{r({type:"status",stage:"error",message:v.message,endpoint:w,fn_index:f,queue:!1,time:new Date})});else if(U=="ws"){const{ws_protocol:v,host:M}=await ae(O,_);r({type:"status",stage:"pending",queue:!0,endpoint:w,fn_index:f,time:new Date});let G=new URL(`${v}://${We(M,c.path,!0)}/queue/join${J?"?"+J:""}`);this.jwt&&G.searchParams.set("__sign",this.jwt),C=new WebSocket(G),C.onclose
4=P=>{P.wasClean||r({type:"status",stage:"error",broken:!0,message:V,queue:!0,endpoint:w,fn_index:f,time:new Date})},C.onmessage=function(P){const R=JSON.parse(P.data),{type:T,status:D,data:I}=me(R,ue[f]);if(T==="update"&&D&&!A)r({type:"status",endpoint:w,fn_index:f,time:new Date,...D}),D.stage==="error"&&C.close();else if(T==="hash"){C.send(JSON.stringify({fn_index:f,session_hash:g}));return}else T==="data"?C.send(JSON.stringify({...ee,session_hash:g})):T==="complete"?A=D:T==="log"?r({type:"log",title:I.title,log:I.log,level:I.level,endpoint:w,duration:I.duration,visible:I.visible,fn_index:f}):T==="generating"&&r({type:"status",time:new Date,...D,stage:D==null?void 0:D.stage,queue:!0,endpoint:w,fn_index:f});I&&(r({type:"data",time:new Date,data:ne(I.data,X,c.components,"output",K.with_null_state),endpoint:w,fn_index:f,event_data:e,trigger_id:n}),A&&(r({type:"status",time:new Date,...A,stage:D==null?void 0:D.stage,queue:!0,endpoint:w,fn_index:f}),C.close()))},Ue(c.version||"2.0.0","3.6")<0&&addEventListener("open",()=>C.send(JSON.stringify({hash:g})))}else if(U=="sse"){r({type:"status",stage:"pending",queue:!0,endpoint:w,fn_index:f,time:new Date});var re=new URLSearchParams({fn_index:f.toString(),session_hash:g}).toString();let v=new URL(`${c.root}${Z}/${ze}?${J?J+"&":""}${re}`);if(this.jwt&&v.searchParams.set("__sign",this.jwt),F=this.stream(v),!F)return Promise.reject(new Error("Cannot connect to SSE endpoint: "+v.toString()));F.onmessage=async function(M){const G=JSON.parse(M.data),{type:P,status:R,data:T}=me(G,ue[f]);if(P==="update"&&R&&!A)r({type:"status",endpoint:w,fn_index:f,time:new Date,...R}),R.stage==="error"&&(F==null||F.close(),a());else if(P==="data"){let[D,I]=await le(`${c.root}${Z}/queue/data`,{...ee,session_hash:g,event_id:N});I!==200&&(r({type:"status",stage:"error",message:V,queue:!0,endpoint:w,fn_index:f,time:new Date}),F==null||F.close(),a())}else P==="complete"?A=R:P==="log"?r({type:"log",title:T.title,log:T.log,level:T.level,endpoint:w,duration:T.duration,visible:T.visible,fn_index:f}):(P==="generating"||P==="streaming")&&r({type:"status",time:new Date,...R,stage:R==null?void 0:R.stage,queue:!0,endpoint:w,fn_index:f});T&&(r({type:"data",time:new Date,data:ne(T.data,X,c.components,"output",K.with_null_state),endpoint:w,fn_index:f,event_data:e,trigger_id:n}),A&&(r({type:"status",time:new Date,...A,stage:R==null?void 0:R.stage,queue:!0,endpoint:w,fn_index:f}),F==null||F.close(),a()))}}else if(U=="sse_v1"||U=="sse_v2"||U=="sse_v2.1"||U=="sse_v3"){r({type:"status",stage:"pending",queue:!0,endpoint:w,fn_index:f,time:new Date});let v="";typeof window<"u"&&typeof document<"u"&&(v=(j=window==null?void 0:window.location)==null?void 0:j.hostname);const G=v.includes(".dev.")?`https://moon-${v.split(".")[1]}.dev.spaces.huggingface.tech`:"https://huggingface.co";(typeof window<"u"&&typeof document<"u"&&window.parent!=window&&window.supports_zerogpu_headers?qt("zerogpu-headers",G):Promise.resolve(null)).then(D=>le(`${c.root}${Z}/${ct}?${J}`,{...ee,session_hash:g},D)).then(async([D,I])=>{if(I===503)r({type:"status",stage:"error",message:Be,queue:!0,endpoint:w,fn_index:f,time:new Date});else if(I!==200)r({type:"status",stage:"error",message:V,queue:!0,endpoint:w,fn_index:f,time:new Date});else{N=D.event_id,Ne=N;let Ce=async function(he){try{const{type:z,status:k,data:L,original_msg:st}=me(he,ue[f]);if(z=="heartbeat")return;if(z==="update"&&k&&!A)r({type:"status",endpoint:w,fn_index:f,time:new Date,original_msg:st,...k});else if(z==="complete")A=k;else if(z=="unexpected_error")console.error("Unexpected error",k==null?void 0:k.message),r({type:"status",stage:"error",message:(k==null?void 0:k.message)||"An Unexpected Error Occurred!",queue:!0,endpoint:w,fn_index:f,time:new Date});else if(z==="log"){r({type:"log",title:L.title,log:L.log,level:L.level,endpoint:w,duration:L.duration,visible:L.visible,fn_index:f});return}else(z==="generating"||z==="streaming")&&(r({type:"status",time:new Date,...k,stage:k==null?void 0:k.stage,queue:!0,endpoint:w,fn_index:f}),L&&X.connection!=="stream"&&["sse_v2","sse_v2.1","sse_v3"].includes(U)&&ts(q,N,L));L&&(r({type:"data",time:new Date,data:ne(L.data,X,c.components,"output",K.with_null_state),endpoint:w,fn_index:f}),L.render_config&&await Te(L.render_config),A&&(r({type:"status",time:new Date,...A,stage:k==null?void 0:k.stage,queue:!0,endpoint:w,fn_index:f}),a())),((k==null?void 0:k.stage)==="complete"||(k==null?void 0:k.stage)==="error")&&(Q[N]&&delete Q[N],N in q&&delete q[N])}catch(z){console.error("Unexpected client exception",z),r({type:"status",stage:"error",message:"An Unexpected Error Occurred!",queue:!0,endpoint:w,fn_index:f,time:new Date}),["sse_v2","sse_v2.1","sse_v3"].includes(U)&&(oe(E,ke.abort_controller),E.open=!1,a())}};
4N in x&&(x[N].forEach(he=>Ce(he)),delete x[N]),Q[N]=Ce,ce.add(N),E.open||await this.open_stream()}})}});let de=!1;const pe=[],te=[],De={[Symbol.asyncIterator]:()=>De,next:p,throw:async b=>(m(b),p()),return:async()=>(a(),p()),cancel:et,event_id:Xe};return De}catch(r){throw console.error("Submit function encountered an error:",r),r}}function os(s){return{then:(t,e)=>e(s)}}function as(s,t,e,n){let i,o,r;if(typeof t=="number")i=t,o=s.unnamed_endpoints[i],r=n.dependencies.find(a=>a.id==t);else{const a=t.replace(/^\//,"");i=e[a],o=s.named_endpoints[t.trim()],r=n.dependencies.find(l=>l.id==e[a])}if(typeof i!="number")throw new Error("There is no endpoint matching that name of fn_index matching that number.");return{fn_index:i,endpoint_info:o,dependency:r}}class ve{constructor(t,e={events:["data"]}){u(this,"app_reference"),u(this,"options"),u(this,"deep_link",null),u(this,"config"),u(this,"api_prefix",""),u(this,"api_info"),u(this,"api_map",{}),u(this,"session_hash",Math.random().toString(36).substring(2)),u(this,"jwt",!1),u(this,"last_status",{}),u(this,"cookies",null),u(this,"stream_status",{open:!1}),u(this,"closed",!1),u(this,"pending_stream_messages",{}),u(this,"pending_diff_streams",{}),u(this,"event_callbacks",{}),u(this,"unclosed_events",new Set),u(this,"heartbeat_event",null),u(this,"abort_controller",null),u(this,"stream_instance",null),u(this,"current_payload"),u(this,"ws_map",{}),u(this,"view_api"),u(this,"upload_files"),u(this,"upload"),u(this,"handle_blob"),u(this,"post_data"),u(this,"submit"),u(this,"predict"),u(this,"open_stream"),u(this,"resolve_config"),u(this,"resolve_cookies");var n;this.app_reference=t,this.deep_link=((n=e.query_params)==null?void 0:n.deep_link)||null,e.events||(e.events=["data"]),this.options=e,this.current_payload={},this.view_api=It.bind(this),this.upload_files=Ot.bind(this),this.handle_blob=Ft.bind(this),this.post_data=Bt.bind(this),this.submit=rs.bind(this),this.predict=Mt.bind(this),this.open_stream=es.bind(this),this.resolve_config=$t.bind(this),this.resolve_cookies=Nt.bind(this),this.upload=jt.bind(this),this.fetch=this.fetch.bind(this),this.handle_space_success=this.handle_space_success.bind(this),this.stream=this.stream.bind(this)}get_url_config(t=null){if(!this.config)throw new Error(H);t===null&&(t=window.location.href);const e=r=>r.replace(/^\/+|\/+$/g,"");let n=e(new URL(this.config.root).pathname),i=e(new URL(t).pathname),o;return i.startsWith(n)?o=e(i.substring(n.length)):o="",this.get_page_config(o)}get_page_config(t){if(!this.config)throw new Error(H);let e=this.config;return t in e.page||(t=""),{...e,current_page:t,layout:e.page[t].layout,components:e.components.filter(n=>e.page[t].components.includes(n.id)),dependencies:this.config.dependencies.filter(n=>e.page[t].dependencies.includes(n.id))}}fetch(t,e){const n=new Headers((e==null?void 0:e.headers)||{});if(this&&this.cookies&&n.append("Cookie",this.cookies),this&&this.options.headers)for(const i in this.options.headers)n.append(i,this.options.headers[i]);return fetch(t,{...e,headers:n})}stream(t){const e=new Headers;if(this&&this.cookies&&e.append("Cookie",this.cookies),this&&this.options.headers)for(const n in this.options.headers)e.append(n,this.options.headers[n]);return this.abort_controller=new AbortController,this.stream_instance=is(t.toString(),{credentials:"include",headers:e,signal:this.abort_controller.signal}),this.stream_instance}async init(){var t;if((typeof window>"u"||!("WebSocket"in window))&&!global.WebSocket){const e=await ye(()=>import("./wrapper-CviSselG-DvBuvln1.js"),__vite__mapDeps([0,1,2]));global.WebSocket=e.WebSocket}this.options.auth&&await this.resolve_cookies(),await this._resolve_config().then(({config:e})=>this._resolve_hearbeat(e)),this.api_info=await this.view_api(),this.api_map=kt(((t=this.config)==null?void 0:t.dependencies)||[])}async _resolve_hearbeat(t){if(t&&(this.config=t,this.api_prefix=t.api_prefix||"",this.config&&this.config.connect_heartbeat&&this.config.space_id&&this.options.hf_token&&(this.jwt=await Ie(this.config.space_id,this.options.hf_token,this.cookies))),t.space_id&&this.options.hf_token&&(this.jwt=await Ie(t.space_id,this.options.hf_token)),this.config&&this.config.connect_heartbeat){const e=new URL(`${this.config.root}${this.api_prefix}/${ht}/${this.session_hash}`);this.jwt&&e.searchParams.set("__sign",this.jwt),this.heartbeat_event||(this.heartbeat_event=this.stream(e))}}static async connect(t,e={events:["data"]}){const n=new this(t,e);return await n.init(),n}close(){this.closed=!0,oe(this.stream_status,this.abort_controller)}set_current_payload(t){this.current_payload=t}static async duplicate(t,e={events:["data"]}){return Jt(t,e)}async _resolve_config(){const{http_protocol:t,host:e,space_id:n}=await ae(this.app_reference,this.options.hf_token),{status_callback:i}=this.options;n&&i&&await Ke(n,i);let o;try{let r=`${t}//${e}`;if(o=await this.resolve_config(r),!o)throw new Error(H);return this.config_success(o)}catch(r){if(n&&i)ie(n,Ee.test(n)?"space_name":"subdomain",this.handle_space_success);
4else throw i&&i({status:"error",message:"Could not load this space.",load_status:"error",detail:"NOT_FOUND"}),Error(r)}}async config_success(t){if(this.config=t,this.api_prefix=t.api_prefix||"",typeof window<"u"&&typeof document<"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(e){console.error(yt+e.message)}return this.prepare_return_obj()}async handle_space_success(t){var e;if(!this)throw new Error(H);const{status_callback:n}=this.options;if(n&&n(t),t.status==="running")try{if(this.config=await this._resolve_config(),this.api_prefix=((e=this==null?void 0:this.config)==null?void 0:e.api_prefix)||"",!this.config)throw new Error(H);return await this.config_success(this.config)}catch(i){throw n&&n({status:"error",message:"Could not load this space.",load_status:"error",detail:"NOT_FOUND"}),i}}async component_server(t,e,n){var i;if(!this.config)throw new Error(H);const o={},{hf_token:r}=this.options,{session_hash:a}=this;r&&(o.Authorization=`Bearer ${this.options.hf_token}`);let l,m=this.config.components.find(p=>p.id===t);(i=m==null?void 0:m.props)!=null&&i.root_url?l=m.props.root_url:l=this.config.root;let d;if("binary"in n){d=new FormData;for(const p in n.data)p!=="binary"&&d.append(p,n.data[p]);d.set("component_id",t.toString()),d.set("fn_name",e),d.set("session_hash",a)}else d=JSON.stringify({data:n,component_id:t,fn_name:e,session_hash:a}),o["Content-Type"]="application/json";r&&(o.Authorization=`Bearer ${r}`);try{const p=await this.fetch(`${l}${this.api_prefix}/${ft}/`,{method:"POST",body:d,headers:o,credentials:"include"});if(!p.ok)throw new Error("Could not connect to component server: "+p.statusText);return await p.json()}catch(p){console.warn(p)}}set_cookies(t){this.cookies=Je(t).join("; ")}prepare_return_obj(){return{config:this.config,predict:this.predict,submit:this.submit,view_api:this.view_api,component_server:this.component_server}}async connect_ws(t){return new Promise((e,n)=>{let i;try{i=new WebSocket(t)}catch{this.ws_map[t]="failed";return}i.onopen=()=>{e()},i.onerror=o=>{console.error("WebSocket error:",o),this.close_ws(t),this.ws_map[t]="failed",e()},i.onclose=()=>{delete this.ws_map[t],this.ws_map[t]="failed"},i.onmessage=o=>{},this.ws_map[t]=i})}async send_ws_message(t,e){t in this.ws_map||await this.connect_ws(t);const n=this.ws_map[t];n instanceof WebSocket?n.send(JSON.stringify(e)):this.post_data(t,e)}async close_ws(t){if(t in this.ws_map){const e=this.ws_map[t];e instanceof WebSocket&&(e.close(),delete this.ws_map[t])}}}class cs{constructor(){this.client=null,this.isInitializing=!1,this.initPromise=null,this.SPACE_NAME="Terabit-IT/terabititfaqchatbot"}async initialize(){return this.client?this.client:this.isInitializing&&this.initPromise?this.initPromise:(this.isInitializing=!0,this.initPromise=ve.connect(this.SPACE_NAME).then(t=>(this.client=t,this.isInitializing=!1,console.log("Gradio client initialized successfully"),t)).catch(t=>{throw this.isInitializing=!1,this.initPromise=null,console.error("Failed to initialize Gradio client:",t),t}),this.initPromise)}getClient(){return this.client}isReady(){return this.client!==null}async predict(t){if(!this.client)throw new Error("Client not initialized");const e=await this.client.predict("/predict",{user_question:t});return e&&e.data?Array.isArray(e.data)?e.data[0]:e.data:"Sorry, I couldn't understand your question."}}const ge=new cs,we=["What services does TeraBit IT offer?","Can I hire developers through TeraBit IT?","Do you provide post-launch support?","What industries do you serve?","Are your solutions customizable?","What is managed team augmentation?","Do you work with blockchain technology?","How long does post-maintenance support last?","What makes TeraBit IT different?","Can you build mobile apps?","What do you specialize in?","How do I hire developers from TeraBit IT?","Do you offer maintenance after product launch?","What industries do you work with?","Can your software solutions scale?","What is team augmentation?","Do you develop decentralized apps?","Is post-launch support free?","Why choose TeraBit IT?","Do you create apps for smartphones?"],qe=5,ps=({onClose:s,preInitializedClient:t=null})=>{const[e,n]=B.useState([]),[i,o]=B.useState(""),[r,a]=B.useState(!1),[l,m]=B.useState(!1),[d,p]=B.useState(!1),_=B.useRef(null);B.useEffect(()=>{if(t){p(!0);return}(async()=>{try{await ge.initialize(),p(!0)}
4catch(E){console.error("Error connecting to Gradio Space:",E)}})()},[t]),B.useEffect(()=>{const h={id:Date.now(),sender:"bot",text:"Hi! I'm TeraBit IT's chatbot. How can I assist you today?"},E={id:Date.now()+1,sender:"bot",type:"faq"};n([h,E])},[]),B.useEffect(()=>{_.current&&(_.current.scrollTop=_.current.scrollHeight)},[e]);const S=async h=>{const E=h.toLowerCase();if(E.includes("what industries")||E.includes("industries do you"))return`We tailor solutions for startups and enterprises across 25 industries: 5 6ð¦ Fintech & Banking 7ð E-commerce & Retail 8ð¥ Healthcare & Medical 9ð Logistics & Supply Chain 10ð Education & E-learning 11ð¢ Real Estate & Property Tech 12âï¸ Travel & Hospitality 13ð Food & Beverage 14ð¬ Entertainment & Media 15ð Automotive & Transportation 16ð Manufacturing & Industrial 17ð¾ Agriculture & Agritech 18â¡ Energy & Utilities 19ð± Telecommunications 20ð¡ï¸ Insurance & Insurtech 21âï¸ Legal & Legaltech 22ðï¸ Construction & Engineering 23ð Fashion & Apparel 24ð¢ Marketing & Advertising 25ð¥ Human Resources & Recruitment 26ð Cybersecurity & IT Services 27ð® Gaming & Esports 28ðï¸ Government & Public Sector 29âï¸ Blockchain & Web3 30âï¸ SaaS & Cloud Services 31 32Whatever your industry, we deliver customized, scalable solutions tailored to your specific business needs.`;if(t)try{const x=await t.predict("/predict",{user_question:h});return console.log("Gradio Client Response:",x.data),x&&x.data?Array.isArray(x.data)?x.data[0]:x.data:"Sorry, I couldn't understand your question."}catch(x){return console.error("Error during prediction:",x),"Oops! Something went wrong. Please try again."}if(!ge.isReady())return console.error("Gradio client is not initialized yet."),"Please wait while the chatbot is initializing.";try{return await ge.predict(h)}catch(x){return console.error("Error during prediction:",x),"Oops! Something went wrong. Please try again."}},O=async h=>{const E=h!==void 0?h:i;if(E.trim()===""||r)return;const x={id:Date.now(),sender:"user",text:E};n(q=>[...q,x]),o(""),a(!0);try{const q=await S(E),Q={id:Date.now()+1,sender:"bot",text:q};n(ce=>[...ce,Q])}catch(q){console.error("Failed to send message:",q)}finally{a(!1)}},c=h=>{d&&!r&&O(h)},g=()=>{m(h=>!h)},$=l?we:we.slice(0,qe);return y.jsxs("div",{className:"bg-white shadow-[0_4px_24px_rgba(0,0,0,0.12)] rounded-[20px] md:rounded-br-none w-full md:w-[569px] flex flex-col",children:[y.jsxs("div",{className:"px-5 py-3 flex justify-between items-center gap-3 border-b border-gray-100",children:[y.jsx("img",{src:"https://res.cloudinary.com/du3t23uzz/image/upload/f_auto,q_auto:best/assets/chatbot_01.png",alt:"TeraBit IT ChatBot",className:"h-[16px] w-auto",loading:"lazy"}),y.jsx("button",{onClick:s,"aria-label":"Close chat",className:"w-[36px] h-[36px] rounded-full bg-gray-100 hover:bg-gray-200 flex items-center justify-center transition-colors",children:y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:y.jsx("path",{d:"M1 1L13 13M13 1L1 13",stroke:"#4A5565",strokeWidth:"2",strokeLinecap:"round"})})})]}),y.jsxs("div",{id:"chatbox",ref:_,className:"px-4 py-3 max-h-[40vh] md:max-h-[350px] overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-transparent",style:{scrollbarWidth:"thin",scrollbarColor:"#D1D5DB transparent"},children:[e.map(h=>h.sender!=="bot"||h.text?y.jsx("div",{className:`mb-2 ${h.sender==="user"?"text-right":""}`,children:y.jsx("p",{className:`${h.sender==="user"?"bg-[#008DF3] text-white rounded-[16px] rounded-br-[4px]":"bg-[#EFF4FB] text-[#1D2939] rounded-[16px] rounded-bl-[4px]"} py-2 px-3 inline-block font-outfit text-[13px] leading-[18px] max-w-[85%] whitespace-pre-wrap`,children:h.text})},h.id):h.sender==="bot"&&h.type==="faq"?y.jsx("div",{className:"mb-3",children:y.jsxs("div",{className:"bg-[#EFF4FB] rounded-[16px] rounded-bl-[4px] p-3",children:[y.jsx("p",{className:"font-outfit font-[600] text-[13px] text-[#1D2939] mb-2",children:"Here are some frequently asked questions:"}),y.jsx("div",{className:"flex flex-col gap-1.5 items-start",children:$.map((E,x)=>x===$.length-1&&we.length>qe?y.jsxs("div",{className:"flex items-center gap-2 w-full",children:[y.jsx("button",{onClick:()=>c(E),disabled:!d,className:`bg-white text-[#1D2939] border border-[#DDE2EA] 33 hover:border-[#008DF3] hover:text-[#008DF3] 34 rounded-[8px] px-3 py-1.5 text-left 35 transition duration-200 font-outfit text-[12px] leading-[16
35px] ${d?"cursor-pointer":"opacity-50 cursor-not-allowed"}`,children:E}),y.jsx("button",{onClick:g,disabled:!d,className:`bg-[#008DF3] text-white 36 hover:bg-[#0070C0] 37 rounded-[8px] px-4 py-1.5 38 transition duration-200 font-outfit font-[500] text-[12px] ${d?"cursor-pointer":"opacity-50 cursor-not-allowed"}`,children:l?"Show Less":"See More"})]},x):y.jsx("button",{onClick:()=>c(E),disabled:!d,className:`bg-white text-[#1D2939] border border-[#DDE2EA] 39 hover:border-[#008DF3] hover:text-[#008DF3] 40 rounded-[8px] px-3 py-1.5 text-left 41 transition duration-200 font-outfit text-[12px] leading-[16px] ${d?"cursor-pointer":"opacity-50 cursor-not-allowed"}`,children:E},x))}),!d&&y.jsx("p",{className:"text-xs italic mt-2 text-[#4A5565] font-outfit",children:"Chatbot is initializing, please wait..."})]})},h.id):null),r&&y.jsx("div",{className:"mb-3",children:y.jsx("div",{className:"bg-[#EFF4FB] text-[#4A5565] rounded-[16px] rounded-bl-[4px] py-3 px-4 inline-block",children:y.jsx("div",{className:"flex items-center space-x-1",children:y.jsxs("div",{className:"flex space-x-1",children:[y.jsx("div",{className:"w-2 h-2 bg-[#4A5565] rounded-full animate-bounce"}),y.jsx("div",{className:"w-2 h-2 bg-[#4A5565] rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),y.jsx("div",{className:"w-2 h-2 bg-[#4A5565] rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})})})})]}),y.jsx("div",{className:"px-4 py-3 border-t border-gray-100",children:y.jsxs("div",{className:"flex items-center gap-1 bg-[#F5F7FA] rounded-[12px] pl-3 pr-1 py-1",children:[y.jsx("input",{type:"text",id:"chat-input",value:i,onChange:h=>o(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),O())},placeholder:"Type a message","aria-label":"Type a message",disabled:!d||r,className:"flex-1 bg-transparent font-outfit text-[14px] text-[#1D2939] placeholder-[#9DA4AE] focus:outline-none disabled:opacity-50"}),y.jsx("button",{onClick:()=>O(),disabled:!d||r,className:`bg-[#038DF2] text-white w-[80px] h-[38px] rounded-[52px] 42 hover:bg-[#0070C0] transition duration-300 43 font-outfit font-[500] text-[14px] 44 disabled:opacity-50 disabled:cursor-not-allowed`,children:"Send"})]})})]})};export{ps as default};
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.