import { w as writable } from './async-Djx13DAD.js';
import { h as head, a as attr, e as ensure_array_like, s as store_get, b as spread_props, u as unsubscribe_stores, c as bind_props, d as attr_class, f as html, g as attr_style } from './index-B7gr0Dsc.js';
import { r as run } from './legacy-server-DGCTSQ6f.js';
import { s as setContext, g as getContext } from './context-BZS6UlnY.js';
import { Embed as ct$1, AppTree as ht$1 } from './index-DclgKfz7.js';
import { E as Es, m as mr, _ as _s, f as fs, g as gs } from './2-CeYbpaU1.js';
import { e, s } from './dev-fallback-Bc5Ork7Y.js';
import { A } from './client2-Doo_0n4m.js';
import { a } from './index5-BoOEKc6P.js';
import './MarkdownCode.svelte_svelte_type_style_lang-DJRtJayx.js';
import { l } from './utils.svelte-D8Xdzglu.js';
import { I, D } from './state.svelte-Bs3qJxtO.js';
import { o } from './BaseForm-CH6f7i7V.js';
import { p as pt$1 } from './Textbox-BWLUCQsC.js';
import { G } from './Block-2-03Azgw.js';
import { B } from './Button-Ddd9rkRS.js';
import { y } from './Index.svelte_svelte_type_style_lang-CcY1Z0Y9.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import './uneval-DjLoL4oF.js';
import './clone-BLo8hHdj.js';
import './index-server-lqjMX237.js';
import './index6-vb2nI4_V.js';
import './exports-DjtMXPv8.js';
import './prism-python-BaDPvmdn.js';
import './index35-D6cyUa2I.js';
import 'path';
import 'url';
import 'fs';
import './spring-DyDQVd5U.js';
import './BlockTitle-CMSrY_fB.js';
import './Info-D8EmJbKn.js';
import './MarkdownCode-zMHESTz4.js';
import './IconButton-7VBZdgpA.js';
import './Check-THd8EJll.js';
import './Copy-DNPvPwdp.js';
import './Send-DqNOmoCe.js';
import './Square-DrWSae15.js';
import './IconButtonWrapper-DlgTGGi-.js';
import './Image-Bw5_tidM.js';
import './index3-DONAw0dG.js';
import './Clear-CiR-WD8W.js';

const me=()=>{const s$1=s?A:getContext("__svelte__");return {page:{subscribe:s$1.page.subscribe},navigating:{subscribe:s$1.navigating.subscribe},updated:s$1.updated}},Ie={subscribe(s){return (e?Ne("page"):me().page).subscribe(s)}};function Ne(s){try{return me()[s]}catch{throw new Error(`Cannot subscribe to '${s}' store on the server outside of a Svelte component, as it is bound to the current request via component context. This prevents state from leaking between users.For more information, see https://svelte.dev/docs/kit/state-management#avoid-shared-state-on-the-server`)}}var Te=()=>{const s=document.createElement("link");s.href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900&display=swap",s.rel="stylesheet";const e=document.createElement("link");e.href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600;700&display=swap",e.rel="stylesheet",document.head.appendChild(s),document.head.appendChild(e);},Ge=()=>{const s=document.createElement("div");return s.style.backgroundImage="linear-gradient(to top, #f9fafb, white)",s.style.border="1px solid #e5e7eb",s.style.borderRadius="0.75rem",s.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",s.style.color="#374151",s.style.display="flex",s.style.flexDirection="row",s.style.alignItems="center",s.style.height="40px",s.style.justifyContent="space-between",s.style.overflow="hidden",s.style.position="fixed",s.style.right=".75rem",s.style.top=".75rem",s.style.width="auto",s.style.zIndex="20",s.style.paddingLeft="1rem",s.setAttribute("id","huggingface-space-header"),window.matchMedia("(max-width: 768px)").addEventListener("change",e=>{e.matches?s.style.display="none":s.style.display="flex";}),s},Ve=()=>{const s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("xmlns","http://www.w3.org/2000/svg"),s.setAttribute("xmlns:link","http://www.w3.org/1999/xlink"),s.setAttribute("aria-hidden","true"),s.setAttribute("focusable","false"),s.setAttribute("role","img"),s.setAttribute("width","1em"),s.setAttribute("height","1em"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),s.setAttribute("viewBox","0 0 12 12"),s.setAttribute("fill","currentColor");const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d","M0.375001 10.3828L0.375 1.61719C0.375 1.104 0.816001 0.687501 1.35938 0.687501L10.6406 0.6875C10.9017 0.6875 11.1521 0.785449 11.3367 0.959797C11.5213 1.13415 11.625 1.37062 11.625 1.61719V10.3828C11.625 10.6294 11.5213 10.8659 11.3367 11.0402C11.1521 11.2145 10.9017 11.3125 10.6406 11.3125H1.35938C0.816001 11.3125 0.375001 10.896 0.375001 10.3828ZM1.35938 10.5156H10.6406C10.7183 10.5156 10.7813 10.4561 10.7813 10.3828V4.40625H1.21875V10.3828C1.21875 10.418 1.23356 10.4518 1.25994 10.4767C1.28631 10.5017 1.32208 10.5156 1.35938 10.5156ZM4.61052 6.38251L5.9999 7.69472L7.38927 6.38251C7.44083 6.33007 7.50645 6.29173 7.57913 6.27153C7.6518 6.25134 7.72898 6.25003 7.8024 6.26776C7.87583 6.28549 7.9428 6.3216 7.99628 6.37227C8.04983 6.42295 8.08785 6.48631 8.10645 6.5557C8.12528 6.62497 8.12393 6.69773 8.10263 6.76635C8.0814 6.83497 8.0409 6.8969 7.98555 6.94564L6.29802 8.53936C6.21892 8.61399 6.11169 8.65592 5.9999 8.65592C5.8881 8.65592 5.78087 8.61399 5.70177 8.53936L4.01427 6.94564C3.95874 6.89694 3.91814 6.835 3.89676 6.76633C3.87538 6.69766 3.874 6.62483 3.89277 6.55549C3.91154 6.48615 3.94977 6.42287 4.00343 6.37233C4.05708 6.32179 4.12418 6.28585 4.19765 6.2683C4.27098 6.25054 4.34803 6.25178 4.42068 6.27188C4.49334 6.29198 4.55891 6.3302 4.61052 6.38251Z"),s.appendChild(e),s},We=(s,e)=>{const i=document.createElement("div");return i.setAttribute("id","space-header__collapse"),i.style.display="flex",i.style.flexDirection="row",i.style.alignItems="center",i.style.justifyContent="center",i.style.fontSize="16px",i.style.paddingLeft="10px",i.style.paddingRight="10px",i.style.height="40px",i.style.cursor="pointer",i.style.color="#40546e",i.style.transitionDuration="0.1s",i.style.transitionProperty="all",i.style.transitionTimingFunction="ease-in-out",i.appendChild(Ve()),i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),e();}),i.addEventListener("mouseenter",()=>{i.style.color="#213551";}),i.addEventListener("mouseleave",()=>{i.style.color="#40546e";}),i},Ze=s=>{const e=document.createElement("p");return e.style.margin="0",e.style.padding="0",e.style.color="#9ca3af",e.style.fontSize="14px",e.style.fontFamily="Source Sans Pro, sans-serif",e.style.padding="0px 6px",e.style.borderLeft="1px solid #e5e7eb",e.style.marginLeft="4px",e.textContent=(s??0).toString(),e},He=()=>{const s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("xmlns","http://www.w3.org/2000/svg"),s.setAttribute("xmlns:link","http://www.w3.org/1999/xlink"),s.setAttribute("aria-hidden","true"),s.setAttribute("focusable","false"),s.setAttribute("role","img"),s.setAttribute("width","1em"),s.setAttribute("height","1em"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),s.setAttribute("viewBox","0 0 32 32"),s.setAttribute("fill","#6b7280");const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d","M22.45,6a5.47,5.47,0,0,1,3.91,1.64,5.7,5.7,0,0,1,0,8L16,26.13,5.64,15.64a5.7,5.7,0,0,1,0-8,5.48,5.48,0,0,1,7.82,0L16,10.24l2.53-2.58A5.44,5.44,0,0,1,22.45,6m0-2a7.47,7.47,0,0,0-5.34,2.24L16,7.36,14.89,6.24a7.49,7.49,0,0,0-10.68,0,7.72,7.72,0,0,0,0,10.82L16,29,27.79,17.06a7.72,7.72,0,0,0,0-10.82A7.49,7.49,0,0,0,22.45,4Z"),s.appendChild(e),s},Je=s=>{const e=document.createElement("a");return e.setAttribute("href",`https://huggingface.co/spaces/${s.id}`),e.setAttribute("rel","noopener noreferrer"),e.setAttribute("target","_blank"),e.style.border="1px solid #e5e7eb",e.style.borderRadius="6px",e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="center",e.style.margin="0 0 0 12px",e.style.fontSize="14px",e.style.paddingLeft="4px",e.style.textDecoration="none",e.appendChild(He()),e.appendChild(Ze(s.likes)),e},Ye=(s,e="user")=>{const i=e==="user"?"users":"organizations",t=document.createElement("img");return t.src=`https://huggingface.co/api/${i}/${s}/avatar`,t.style.width="0.875rem",t.style.height="0.875rem",t.style.borderRadius="50%",t.style.flex="none",t.style.marginRight="0.375rem",t},Qe=s=>{const[e,i]=s.split("/"),t=document.createElement("a");return t.setAttribute("href",`https://huggingface.co/spaces/${s}`),t.setAttribute("rel","noopener noreferrer"),t.setAttribute("target","_blank"),t.style.color="#1f2937",t.style.textDecoration="none",t.style.fontWeight="600",t.style.fontSize="15px",t.style.lineHeight="24px",t.style.flex="none",t.style.fontFamily="IBM Plex Mono, sans-serif",t.addEventListener("mouseover",()=>{t.style.color="#2563eb";}),t.addEventListener("mouseout",()=>{t.style.color="#1f2937";}),t.textContent=i,t},Ke=()=>{const s=document.createElement("div");return s.style.marginLeft=".125rem",s.style.marginRight=".125rem",s.style.color="#d1d5db",s.textContent="/",s},Xe=s=>{const e=document.createElement("a");return e.setAttribute("href",`https://huggingface.co/${s}`),e.setAttribute("rel","noopener noreferrer"),e.setAttribute("target","_blank"),e.style.color="rgb(107, 114, 128)",e.style.textDecoration="none",e.style.fontWeight="400",e.style.fontSize="16px",e.style.lineHeight="24px",e.style.flex="none",e.style.fontFamily="Source Sans Pro, sans-serif",e.addEventListener("mouseover",()=>{e.style.color="#2563eb";}),e.addEventListener("mouseout",()=>{e.style.color="rgb(107, 114, 128)";}),e.textContent=s,e},$e=s=>{const e=document.createElement("div");return e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="center",e.style.justifyContent="center",e.style.borderRight="1px solid #e5e7eb",e.style.paddingRight="12px",e.style.height="40px",s.type!=="unknown"&&e.appendChild(Ye(s.author,s.type)),e.appendChild(Xe(s.author)),e.appendChild(Ke()),e.appendChild(Qe(s.id)),e.appendChild(Je(s)),e},et=s=>{const e=Ge(),i=()=>e.style.display="none";return e.appendChild($e(s)),e.appendChild(We(s,i)),e},he=async(s,e="user")=>{const i=e==="user"?"users":"organizations";try{return (await fetch(`https://huggingface.co/api/${i}/${s}/avatar`)).ok}catch{return  false}},tt=async s=>{try{return await(await fetch(`https://huggingface.co/api/spaces/${s}`)).json()}catch{return null}},st=(s,e)=>{if(document.body===null)return console.error("document.body is null");document.body.appendChild(s);};async function it(s,e){if(window===void 0)return console.error("Please run this script in a browser environment");if(Object.values(window.location?.ancestorOrigins??{0:window.document.referrer}).some(d=>new URL(d)?.origin==="https://huggingface.co"))return;Te();let t;if(typeof s=="string"){if(t=await tt(s),t===null)return console.error("Space not found")}else t=s;const[a,n]=await Promise.all([he(t.author,"user"),he(t.author,"org")]);t.type=a?"user":n?"org":"unknown";const l=et(t);return st(l),{element:l}}var at=(s,e)=>it(s);function be(s$1,e){s$1.component(i=>{let{node:t}=e;var a,n=i.run([async()=>a=await t.component]);i.async_block([n[0]],l=>{t&&a?(l.push("<!--[-->"),l.async_block([n[0]],d=>{t.props.shared_props.visible?(d.push("<!--[-->"),d.async_block([n[0]],f=>{f.push("<!---->"),a.default?.(f,{shared_props:t.props.shared_props,props:t.props.props,children:C=>{C.async_block([n[0]],E=>{t.children&&t.children.length?(E.push("<!--[-->"),E.push("<!--[-->"),E.async_block([n[0]],h=>{const x=ensure_array_like(t.children);for(let y=0,F=x.length;y<F;y++){let u=x[y];be(h,{node:u});}}),E.push("<!--]-->")):E.push("<!--[!-->");}),C.push("<!--]-->");},$$slots:{default:true}});})):d.push("<!--[!-->");}),l.push("<!--]-->")):l.push("<!--[!-->");}),i.push("<!--]-->");});}const nt="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='576'%20height='576'%20viewBox='0%200%20576%20576'%20fill='none'%3e%3cpath%20d='M287.5%20229L86%20344.5L287.5%20460L489%20344.5L287.5%20229Z'%20stroke='url(%23paint0_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='round'/%3e%3cpath%20d='M287.5%20116L86%20231.5L287.5%20347L489%20231.5L287.5%20116Z'%20stroke='url(%23paint1_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='round'/%3e%3cpath%20d='M86%20344L288%20229'%20stroke='url(%23paint2_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='bevel'/%3e%3cdefs%3e%3clinearGradient%20id='paint0_linear_102_7'%20x1='60'%20y1='341'%20x2='429.5'%20y2='344'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3clinearGradient%20id='paint1_linear_102_7'%20x1='513.5'%20y1='231'%20x2='143.5'%20y2='231'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3clinearGradient%20id='paint2_linear_102_7'%20x1='60'%20y1='344'%20x2='428.987'%20y2='341.811'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3c/defs%3e%3c/svg%3e",ot="data:image/svg+xml,%3csvg%20width='28'%20height='28'%20viewBox='0%200%2028%2028'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M26.9425%202.94265C27.4632%202.42195%2027.4632%201.57773%2026.9425%201.05703C26.4218%200.536329%2025.5776%200.536329%2025.0569%201.05703L22.5713%203.54256C21.1213%202.59333%2019.5367%202.43378%2018.1753%202.64006C16.5495%202.88638%2015.1127%203.66838%2014.3905%204.39053L12.3905%206.39053C12.1405%206.64058%2012%206.97972%2012%207.33334C12%207.68697%2012.1405%208.0261%2012.3905%208.27615L19.7239%2015.6095C20.2446%2016.1302%2021.0888%2016.1302%2021.6095%2015.6095L23.6095%2013.6095C24.3316%2012.8873%2025.1136%2011.4505%2025.36%209.82475C25.5663%208.46312%2025.4066%206.87827%2024.4571%205.42807L26.9425%202.94265Z'%20fill='%233c4555'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M12.276%2012.9426C12.7967%2012.4219%2012.7967%2011.5777%2012.276%2011.057C11.7553%2010.5363%2010.9111%2010.5363%2010.3904%2011.057L8.66651%2012.7809L8.27615%2012.3905C8.0261%2012.1405%207.68697%2012%207.33334%2012C6.97972%2012%206.64058%2012.1405%206.39053%2012.3905L4.39053%2014.3905C3.66838%2015.1127%202.88638%2016.5495%202.64006%2018.1753C2.43377%2019.5367%202.59333%2021.1214%203.54262%2022.5714L1.05703%2025.057C0.536329%2025.5777%200.536329%2026.4219%201.05703%2026.9426C1.57773%2027.4633%202.42195%2027.4633%202.94265%2026.9426L5.42817%2024.4571C6.87835%2025.4066%208.46315%2025.5663%209.82475%2025.36C11.4505%2025.1136%2012.8873%2024.3316%2013.6095%2023.6095L15.6095%2021.6095C16.1302%2021.0888%2016.1302%2020.2446%2015.6095%2019.7239L15.2188%2019.3332L16.9426%2017.6093C17.4633%2017.0886%2017.4633%2016.2444%2016.9426%2015.7237C16.4219%2015.203%2015.5777%2015.203%2015.057%2015.7237L13.3332%2017.4475L10.5521%2014.6665L12.276%2012.9426Z'%20fill='%23FF7C00'/%3e%3c/svg%3e",rt="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3c!--%20Outer%20gear%20teeth%20(gray)%20--%3e%3cpath%20d='M19.14%2012.94c.04-.3.06-.61.06-.94%200-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24%200-.43.17-.47.41l-.36%202.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47%200-.59.22L2.74%208.87c-.12.21-.08.47.12.61l2.03%201.58c-.05.3-.07.62-.07.94s.02.64.07.94l-2.03%201.58c-.18.14-.23.41-.12.61l1.92%203.32c.12.22.37.29.59.22l2.39-.96c.5.38%201.03.7%201.62.94l.36%202.54c.05.24.24.41.48.41h3.84c.24%200%20.44-.17.47-.41l.36-2.54c.59-.24%201.13-.56%201.62-.94l2.39.96c.22.08.47%200%20.59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12%2015.6c-1.98%200-3.6-1.62-3.6-3.6s1.62-3.6%203.6-3.6%203.6%201.62%203.6%203.6-1.62%203.6-3.6%203.6z'%20fill='%23808080'/%3e%3c!--%20Inner%20circle%20(now%20gray)%20--%3e%3ccircle%20cx='12'%20cy='12'%20r='2.5'%20fill='%23808080'/%3e%3c/svg%3e",lt="data:image/svg+xml,%3csvg%20viewBox='0%200%2020%2020'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='%23000000'%3e%3cg%20id='SVGRepo_bgCarrier'%20stroke-width='0'%3e%3c/g%3e%3cg%20id='SVGRepo_tracerCarrier'%20stroke-linecap='round'%20stroke-linejoin='round'%3e%3c/g%3e%3cg%20id='SVGRepo_iconCarrier'%3e%3ctitle%3erecord%20[%23982]%3c/title%3e%3cdesc%3eCreated%20with%20Sketch.%3c/desc%3e%3cdefs%3e%3c/defs%3e%3cg%20id='Page-1'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cg%20id='Dribbble-Light-Preview'%20transform='translate(-380.000000,%20-3839.000000)'%20fill='%23FF0000'%3e%3cg%20id='icons'%20transform='translate(56.000000,%20160.000000)'%3e%3cpath%20d='M338,3689%20C338,3691.209%20336.209,3693%20334,3693%20C331.791,3693%20330,3691.209%20330,3689%20C330,3686.791%20331.791,3685%20334,3685%20C336.209,3685%20338,3686.791%20338,3689%20M334,3697%20C329.589,3697%20326,3693.411%20326,3689%20C326,3684.589%20329.589,3681%20334,3681%20C338.411,3681%20342,3684.589%20342,3689%20C342,3693.411%20338.411,3697%20334,3697%20M334,3679%20C328.477,3679%20324,3683.477%20324,3689%20C324,3694.523%20328.477,3699%20334,3699%20C339.523,3699%20344,3694.523%20344,3689%20C344,3683.477%20339.523,3679%20334,3679'%20id='record-[%23982]'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e",ct=/^'([^]+)'$/,ge=Symbol("NOVALUE");class ut{id;inputs;outputs;cancels;pending=false;trigger_modes;event_args={};targets=[];connection_type;triggers=[];original_trigger_id=null;show_progress_on=null;component_prop_inputs=[];show_progress;functions;constructor(e){this.id=e.id,this.original_trigger_id=e.id,this.inputs=e.inputs,this.outputs=e.outputs,this.connection_type=e.connection,this.show_progress=e.show_progress,this.functions={frontend:e.js?ht(e.js,e.backend_fn,e.inputs.length,e.outputs.length):void 0,backend:e.backend_fn,backend_js:e.js_implementation?new gs(`let result = await (${e.js_implementation})(...arguments);
						return (!Array.isArray(result)) ? [result] : result;`):void 0},this.targets=e.targets,this.cancels=e.cancels,this.trigger_modes=e.trigger_mode,this.show_progress_on=e.show_progress_on||null,this.component_prop_inputs=e.component_prop_inputs||[];for(let i=0;i<e.event_specific_args?.length;i++){const t=e.event_specific_args[i];this.event_args[t]=e[t]??null;}}async run(e,i,t,a){let n=i;return this.functions.backend_js?{type:"data",data:await this.functions.backend_js(...n)}:(this.functions.frontend&&(n=await this.functions.frontend(i)),this.functions.backend?{type:"submit",data:e.submit(this.id,n,t,a,void 0,{"x-gradio-user":"app"})}:this.functions.frontend?{type:"data",data:n}:{type:"void",data:null})}add_trigger(e,i){this.triggers.push([e,i]);}get_triggers(){return {success:this.triggers.filter(([,e])=>e==="success").map(([e])=>e),failure:this.triggers.filter(([,e])=>e==="failure").map(([e])=>e),all:this.triggers.filter(([,e])=>e==="all").map(([e])=>e)}}}class dt{dependencies_by_fn=new Map;dependencies_by_event=new Map;render_id_deps=new Map;submissions=new Map;client;queue=new Set;add_to_api_calls;update_state_cb;get_state_cb;rerender_cb;log_cb;loading_stati=new I;constructor(e,i,t,a,n,l,d){this.add_to_api_calls=d,this.log_cb=l,this.update_state_cb=t,this.get_state_cb=a,this.rerender_cb=n,this.client=i,this.reload(e,t,a,n,i);}reload(e,i,t,a,n){const{by_id:l,by_event:d}=this.create(e);this.dependencies_by_event=d,this.dependencies_by_fn=l,this.client=n,this.update_state_cb=i,this.get_state_cb=t,this.rerender_cb=a;for(const[f,C]of this.dependencies_by_fn)for(const[E]of C.targets)this.set_event_args(E,C.event_args);this.register_loading_stati(l);}register_loading_stati(e){for(const[i,t]of e)this.loading_stati.register(t.id,t.show_progress_on||t.outputs,t.inputs,t.show_progress);}clear_loading_status(e){this.loading_stati.clear(e);}async update_loading_stati_state(){for(const[e,i]of Object.entries(this.loading_stati.current))this.update_state_cb(Number(e),{loading_status:i},false);}dispatch_state_change_events(e){if(e.changed_state_ids)for(const i of e.changed_state_ids)this.dependencies_by_event.get("change-"+i)?.forEach(a=>{this.dispatch({type:"fn",fn_index:a.id,target_id:i,event_data:null});});}async dispatch(e){let i;if(e.type==="fn"){const t=this.dependencies_by_fn.get(e.fn_index);t&&(i=[t]);}else i=this.dependencies_by_event.get(`${e.event_name}-${e.target_id}`);for(let t=0;t<(i?.length||0);t++){const a=i?i[t]:void 0;if(a){this.cancel(a.cancels);const n=_t(a.trigger_modes,this.submissions.has(a.id));if(n==="skip")continue;if(n==="defer"){this.queue.add(a.id);continue}a.functions.backend&&(this.loading_stati.update({status:"pending",fn_index:a.id,stream_state:null}),this.update_loading_stati_state());const l=await this.gather_state(a.inputs,a.component_prop_inputs),d=await Promise.all(a.targets.map(([h])=>this.set_event_args(h,a.event_args))),{success:f,failure:C,all:E}=a.get_triggers();try{let h=null;if(e.target_id!==void 0||e.type==="event"?h=e.target_id||null:h=a.original_trigger_id,a.connection_type==="stream"&&this.submissions.has(a.id)){const y=this.submissions.get(a.id);let F={fn_index:a.id,data:l,event_data:e.event_data};y.send_chunk(F),d.forEach(u=>u());continue}this.add_to_api_calls({fn_index:a.id,data:l,event_data:e.event_data,trigger_id:h});const x=await a.run(this.client,l,e.event_data,h);if(x.type==="void")d.forEach(y=>y());else if(x.type==="data")await this.handle_data(a.outputs,x.data),d.forEach(y=>y());else {let y=null;a.connection_type==="stream"&&!this.submissions.has(a.id)&&(y="waiting"),this.submissions.set(a.id,x.data);let F=0;e:for await(const u of x.data)if(F===0&&a.inputs.forEach(g=>{this.update_state_cb(g,{loading_status:{validation_error:null}},!1);}),F+=1,u!==null){if(u.type==="data"&&await this.handle_data(a.outputs,u.data),u.type==="status"){u.original_msg==="process_starts"&&a.connection_type==="stream"&&(y="open");const{fn_index:g,...v}=u;if(u.stage==="complete"){y="closed",f.forEach(S=>{this.dispatch({type:"fn",fn_index:S,event_data:null,target_id:h});}),this.dispatch_state_change_events(u),this.loading_stati.update({...v,status:v.stage,fn_index:a.id,stream_state:y}),this.update_loading_stati_state();break e}else if(u.stage==="generating")this.dispatch_state_change_events(u),this.loading_stati.update({...v,status:v.stage,fn_index:a.id,stream_state:y}),this.update_loading_stati_state();else if(u.stage==="error"){if(Array.isArray(u?.message)){u.message.forEach((k,O)=>{this.update_state_cb(a.inputs[O],{loading_status:{validation_error:k.is_valid?null:k.message,show_validation_error:!0}},!1);}),a.outputs.forEach(k=>{a.inputs.includes(k)||this.update_state_cb(k,{loading_status:{status:null}},!1);}),d.forEach(k=>k()),this.submissions.delete(a.id),this.queue.has(a.id)&&(this.queue.delete(a.id),this.dispatch(e));return}const S=u?.message?.replace(ct,(k,O)=>O);throw this.log_cb(u?._title??"Error",S||"",g,"error",v.duration,v.visible),new Error("Dependency function failed")}else this.loading_stati.update({...v,status:v.stage,fn_index:a.id,stream_state:y}),this.update_loading_stati_state();}if(u.type==="render"){this.loading_stati.update({status:"complete",fn_index:a.id,stream_state:null}),this.update_loading_stati_state();const{layout:g,components:v,render_id:S,dependencies:k}=u.data;this.rerender_cb(v,g);const{by_id:O,by_event:J}=this.create(k);this.register_loading_stati(O),O.forEach(z=>this.dependencies_by_fn.set(z.id,z)),J.forEach((z,I)=>this.dependencies_by_event.set(I,z));const V=this.render_id_deps.get(S);V&&V.forEach(z=>{O.has(z)||this.dependencies_by_fn.delete(z);}),this.render_id_deps.set(S,new Set(Array.from(O.keys()))),this.register_loading_stati(O);break e}u.type==="log"&&this.handle_log(u);}E.forEach(u=>{this.dispatch({type:"fn",fn_index:u,event_data:null,target_id:h});}),d.forEach(u=>u()),this.submissions.delete(a.id),this.queue.has(a.id)&&(this.queue.delete(a.id),this.dispatch(e));}}catch{this.loading_stati.update({status:"error",fn_index:a.id,eta:0,queue:false,stream_state:null}),this.update_loading_stati_state(),this.submissions.delete(a.id),C.forEach(x=>{this.dispatch({type:"fn",fn_index:x,event_data:null});});}}}}create(e){const i=new Map,t=new Map,a=[];for(const n of e){const l=new ut(n);for(const[d,f]of n.targets)t.has(`${f}-${d}`)||t.set(`${f}-${d}`,[]),t.get(`${f}-${d}`)?.push(l);if(i.set(n.id,l),n.trigger_after!==void 0){const d=n.trigger_only_on_failure?"failure":n.trigger_only_on_success?"success":"all";a.push([n.id,n.trigger_after,d]);}}for(const[n,l,d]of a){const f=i.get(l);f&&(f.add_trigger(n,d),f.original_trigger_id=gt(e,l));}return {by_id:i,by_event:t}}handle_log(e){const{title:i,log:t,fn_index:a,level:n,duration:l,visible:d}=e;this.log_cb(i,t,a,n,l,d);}async handle_data(e,i){await Promise.all(e.map(async(t,a)=>{const n=i[a]===void 0?ge:i[a];if(n!==ge)if(pt(n)){let l=false,d=null;for(const[f,C]of Object.entries(n))if(f!=="__type__"){if(f==="visible"){l=true,d=C;continue}await this.update_state_cb(e[a],{[f]:C},false);}l&&await this.update_state_cb(e[a],{visible:d},true);}else await this.update_state_cb(t,{value:n},false);}));}async gather_state(e,i=[]){return (await Promise.all(e.map(t=>this.get_state_cb(t)))).map((t,a)=>i.includes(a)?t??null:t?.value??null)}async set_event_args(e,i){let t={};const a=await this.get_state_cb?.(e);if(!a)return ()=>{};for(const[n]of Object.entries(i))t[n]=a?.[n]??null;return Object.keys(i).length===0?()=>{}:(await this.update_state_cb(e,i,false),()=>{this.update_state_cb(e,t,false);})}async cancel(e){if(e)for(const i of e){const t=this.submissions.get(i);t&&(await t.cancel(),this.loading_stati.update({status:"complete",fn_index:i,eta:0,queue:false,stream_state:null}),this.update_loading_stati_state(),this.submissions.delete(i));}}dispatch_load_events(){this.dependencies_by_fn.forEach(e=>{e.targets.forEach(([i,t])=>{t==="load"&&this.dispatch({type:"fn",fn_index:e.id,event_data:null,target_id:i});});});}get_fns_from_targets(e){const i=[];return this.dependencies_by_event.forEach((t,a)=>{const[,n]=a.split("-");Number(n)===e&&t.forEach(l=>{i.push(l.id);});}),i}close_stream(e){const i=this.get_fns_from_targets(e);for(const t of i){const a=this.submissions.get(t);a&&(a.close_stream(),this.submissions.delete(t)),this.loading_stati.update({status:"complete",fn_index:t,eta:0,queue:false,stream_state:"closed"});}this.update_loading_stati_state();}}function pt(s){return typeof s=="object"&&s!==null&&"__type__"in s&&s?.__type__==="update"}function _t(s,e){return e?s==="always_last"?"defer":s==="multiple"?"run":s==="once"?"skip":"run":"run"}function ht(s,e,i,t){const a=e?i===1:t===1;try{return new gs("__fn_args",`  let result = await (${s})(...__fn_args);
  if (typeof result === "undefined") return [];
  return (${a} && !Array.isArray(result)) ? [result] : result;`)}catch(n){throw n}}function gt(s,e){let i=new Map,t=e,a=0;for(;a<100;){const n=i.get(t)||s.find(l=>l.id===t);if(!n||(i.set(n.id,n),n.trigger_after===null||n.trigger_after===void 0))break;t=n.trigger_after,a+=1;}return t}function ft(s$1,e){s$1.component(i=>{var t;let{root:a,components:n,layout:l$1,dependencies:d,title:f,target:C,autoscroll:E,footer_links:h,control_page_title:x,app_mode:y,theme_mode:F,app:u,space_id:g,version:v,js:S,fill_height:k,username:O,api_prefix:J,max_file_size:V,initial_layout:z,css:I,vibe_mode:N,search_params:W,render_complete:R=false,ready:X=false,reload_count:Y=0,add_new_message:Q=void 0}=e;n.forEach(o=>{o.props.i18n||(o.props.i18n=store_get(t??={},"$reactive_formatter",_s));});let B=[];function T(o,_,j){if(_==="share"){const{title:H,description:ue}=j;}else if(_==="error")q("Error",j,-1,_,10,true);else if(_==="warning")q("Warning",j,-1,_,10,true);else if(_==="info")q("Info",j,-1,_,10,true);else if(_==="gradio_expand"||_==="gradio_tab_select"){const H=_==="gradio_expand"?o:j.component_id;L.render_previously_invisible_children(H);}else if(_=="clear_status")L.update_state(o,{loading_status:{}},false),G.clear_loading_status(o);else if(_=="close_stream")G.close_stream(o);else if(_==="custom_button_click"){const H=j.id;p(H,"click",null);}else _==="select"&&o in L.initial_tabs&&(o=j.id),G.dispatch({type:"event",event_name:_,target_id:o,event_data:j});}let L=new ht$1(n,l$1,d,{root:a,theme:F,version:v,api_prefix:J,max_file_size:V,autoscroll:E},u,store_get(t??={},"$reactive_formatter",_s),T);function p(o,_,j){G.dispatch({type:"event",event_name:_,target_id:o,event_data:j});}setContext(l,{register:L.register_component.bind(L),dispatcher:T});let $=[],U=null,K=o=>{U=o,b&&($=[...$,U]);},G=new dt(d,u,L.update_state.bind(L),L.get_state.bind(L),L.rerender.bind(L),q,K),w=350,c=W.get("view")==="api"&&h.includes("api"),m=W.get("view")==="settings",b=W.get("view")==="api-recorder"&&h.includes("api"),A=null,M=null;function q(o,_,j,H,ue=10,de=false){de&&B.push({title:o,message:_,fn_index:j,type:H,id:++Z,duration:ue,visible:de});}Q=q;let Z=-1;store_get(t??={},"$reactive_formatter",_s)("blocks.long_requests_queue"),store_get(t??={},"$reactive_formatter",_s)("blocks.connection_can_break"),store_get(t??={},"$reactive_formatter",_s)("blocks.waiting_for_inputs");let re=writable(false);function ve(o){B=B.filter(_=>_.id!==o);}let ce=true,ie;function we(o){head("zxu34v",o,_=>{x?(_.push("<!--[-->"),_.title(j=>{j.push(`<title>${escape_html(f)}</title>`);})):_.push("<!--[!-->"),_.push("<!--]--> "),I?(_.push("<!--[-->"),_.push(`${html(`<style>${fs(I,v)}</style>`)}`)):_.push("<!--[!-->"),_.push("<!--]-->");}),o.push(`<div class="wrap svelte-zxu34v"${attr_style("",{"min-height":y?"100%":"auto"})}><main class="contain svelte-zxu34v"${attr_style("",{"flex-grow":y?"1":"auto","margin-right":N?`${w}px`:"0"})}>`),be(o,{node:L.root}),o.push("<!----></main> "),h.length>0?(o.push("<!--[-->"),o.push('<footer aria-label="Gradio footer navigation" class="svelte-zxu34v">'),h.includes("api")?(o.push("<!--[-->"),o.push('<button class="show-api svelte-zxu34v">'),u.config?.mcp_server?(o.push("<!--[-->"),o.push(`${escape_html(store_get(t??={},"$reactive_formatter",_s)("errors.use_via_api_or_mcp"))}`)):(o.push("<!--[!-->"),o.push(`${escape_html(store_get(t??={},"$reactive_formatter",_s)("errors.use_via_api"))}`)),o.push(`<!--]--> <img${attr("src",ot)}${attr("alt",store_get(t??={},"$reactive_formatter",_s)("common.logo"))} class="svelte-zxu34v"/></button>`)):o.push("<!--[!-->"),o.push("<!--]--> "),h.includes("gradio")?(o.push("<!--[-->"),o.push(`<div class="divider show-api-divider svelte-zxu34v">·</div> <a href="https://gradio.app" class="built-with svelte-zxu34v" target="_blank" rel="noreferrer">${escape_html(store_get(t??={},"$reactive_formatter",_s)("common.built_with_gradio"))} <img${attr("src",nt)}${attr("alt",store_get(t??={},"$reactive_formatter",_s)("common.logo"))} class="svelte-zxu34v"/></a>`)):o.push("<!--[!-->"),o.push(`<!--]--> <button${attr_class("record svelte-zxu34v",void 0,{hidden:!store_get(t??={},"$is_screen_recording",re)})}>${escape_html(store_get(t??={},"$reactive_formatter",_s)("common.stop_recording"))} <img${attr("src",lt)}${attr("alt",store_get(t??={},"$reactive_formatter",_s)("common.stop_recording"))} class="svelte-zxu34v"/></button> <div class="divider svelte-zxu34v">·</div> `),h.includes("settings")?(o.push("<!--[-->"),o.push(`<div${attr_class("divider svelte-zxu34v",void 0,{hidden:!store_get(t??={},"$is_screen_recording",re)})}>·</div> <button class="settings svelte-zxu34v">${escape_html(store_get(t??={},"$reactive_formatter",_s)("common.settings"))} <img${attr("src",rt)}${attr("alt",store_get(t??={},"$reactive_formatter",_s)("common.settings"))} class="svelte-zxu34v"/></button>`)):o.push("<!--[!-->"),o.push("<!--]--></footer>")):o.push("<!--[!-->"),o.push("<!--]--> "),o.push("<!--[!-->"),o.push("<!--]--> "),c&&L.root&&A||o.push("<!--[!-->"),o.push("<!--]--> "),m&&u.config&&L.root&&M||o.push("<!--[!-->"),o.push("<!--]--> "),o.push("<!--[!-->"),o.push("<!--]--></div> "),B?(o.push("<!--[-->"),D(o,{messages:B,on_close:ve})):o.push("<!--[!-->"),o.push("<!--]-->");}do ce=true,ie=i.copy(),we(ie);while(!ce);i.subsume(ie),t&&unsubscribe_stores(t),bind_props(e,{ready:X,reload_count:Y,add_new_message:Q});});}function mt(s$1,e){s$1.component(i=>{let t=e.root,a=e.auth_message,n=e.app_mode,l=e.space_id,d=e.i18n,f="",C="",E=false;const h=async()=>{const u=new FormData;u.append("username",f),u.append("password",C);const g=new URL("login",t.endsWith("/")?t:t+"/").href;let v=await fetch(g,{method:"POST",body:u});v.status===400?(E=true,f="",C=""):v.status==200&&location.reload();};let x=true,y$1;function F(u){u.push(`<div${attr_class("wrap svelte-14xt79u",void 0,{"min-h-screen":n})}>`),y(u,{variant:"panel",min_width:480,children:g=>{g.push(`<h2 class="svelte-14xt79u">${escape_html(d("login.login"))}</h2> `),a?(g.push("<!--[-->"),g.push(`<p class="auth svelte-14xt79u">${html(a)}</p>`)):g.push("<!--[!-->"),g.push("<!--]--> "),l?(g.push("<!--[-->"),g.push(`<p class="auth svelte-14xt79u">${escape_html(d("login.enable_cookies"))}</p>`)):g.push("<!--[!-->"),g.push("<!--]--> "),E?(g.push("<!--[-->"),g.push(`<p class="creds svelte-14xt79u">${escape_html(d("login.incorrect_credentials"))}</p>`)):g.push("<!--[!-->"),g.push("<!--]--> "),o(g,{children:v=>{G(v,{children:S=>{pt$1(S,{label:d("login.username"),lines:1,show_label:true,max_lines:1,onsubmit:h,get value(){return f},set value(k){f=k,x=false;}});},$$slots:{default:true}}),v.push("<!----> "),G(v,{children:S=>{pt$1(S,{label:d("login.password"),lines:1,show_label:true,max_lines:1,type:"password",onsubmit:h,get value(){return C},set value(k){C=k,x=false;}});},$$slots:{default:true}}),v.push("<!---->");},$$slots:{default:true}}),g.push("<!----> "),B(g,{size:"lg",variant:"primary",onclick:h,children:v=>{v.push(`<!---->${escape_html(d("login.login"))}`);}}),g.push("<!---->");},$$slots:{default:true}}),u.push("<!----></div>");}do x=true,y$1=i.copy(),F(y$1);while(!x);i.subsume(y$1),bind_props(e,{root:t,auth_message:a,app_mode:n,space_id:l,i18n:d});});}function Tt(s$1,e){s$1.component(i=>{var t;let {data:l,autoscroll:d=false,version:f="6-5-0",initial_height:C,app_mode:E=true,is_embed:h=false,theme_mode:x=null,control_page_title:y=true,container:F,space:u}=e;function g(w){let c;const b=new URL(window.location.toString()).searchParams.get("__theme");return c=x||b||"system",c==="dark"||c==="light"?S(w,c):c=v(w),c}function v(w){const c=m();window?.matchMedia("(prefers-color-scheme: dark)")?.addEventListener("change",m);function m(){let b=window?.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light";return S(w,b),b}return c}function S(w,c){const m=h?w.parentElement:document.body,b=h?w:w.parentElement;b.style.background="var(--body-background-fill)",m.classList.add("theme-loaded"),c==="dark"?m.classList.add("dark"):m.classList.remove("dark");}let k;a&&(k=g(document.body));let V="complete",z,I=false,N=false;({subscribe:writable({}).subscribe});let R=l.app;let Y=false,Q=false;Es().then(()=>{Q=true;}),a&&l.config&&(window.gradio_config=l.config);let B;let T;async function L(w,c){if(w&&!c&&window.self===window.top){T&&(T.remove(),T=void 0);const m=await at(w);m&&(T=m.element);}}let p=l.config,$=(()=>{if(!a)return p.root;const w=new URL(window.location.toString()),c=new URL(p.root);return new URL(c.pathname,w).toString()})();run(()=>{p?.app_id&&p.app_id;}),run(()=>{B&&Y&&(B("Error","Deep link was not valid",-1,"error",10,true),Y=false);}),run(()=>{N&&z.dispatchEvent(new CustomEvent("render",{bubbles:true,cancelable:false,composed:true}));}),run(()=>{R?.config&&a&&L(R?.config?.space_id,h);});let U=true,K;function G(w){head("1gmqcbx",w,c=>{if(c.push(`<link rel="stylesheet"${attr("href",$+"/theme.css?v="+p?.theme_hash)}/> `),p?.stylesheets){c.push("<!--[-->"),c.push("<!--[-->");const m=ensure_array_like(p.stylesheets);for(let b=0,A=m.length;b<A;b++){let M=m[b];M.startsWith("http:")||M.startsWith("https:")?(c.push("<!--[-->"),c.push(`<link rel="stylesheet"${attr("href",M)}/>`)):c.push("<!--[!-->"),c.push("<!--]-->");}c.push("<!--]-->");}else c.push("<!--[!-->");c.push('<!--]--> <link rel="manifest" href="/manifest.json"/>');}),ct$1(w,{display:F&&h,is_embed:h,info:false,version:f,initial_height:C,space:u,pages:p.pages,current_page:p.current_page,root:p.root,components:p.components,loaded:V==="complete",fill_width:p?.fill_width||false,get wrapper(){return z},set wrapper(c){z=c,U=false;},children:c=>{p?.auth_required?(c.push("<!--[-->"),mt(c,{auth_message:p.auth_message,root:p.root,space_id:u,app_mode:E,i18n:Q?store_get(t??={},"$_",mr):m=>m})):(c.push("<!--[!-->"),p&&R?(c.push("<!--[-->"),ft(c,spread_props([{app:R},p,{fill_height:!h&&p.fill_height,theme_mode:k,control_page_title:y,target:z,autoscroll:d,footer_links:h?[]:p.footer_links,app_mode:E,version:f,search_params:store_get(t??={},"$page",Ie).url.searchParams,initial_layout:l.layout,get ready(){return I},set ready(m){I=m,U=false;},get render_complete(){return N},set render_complete(m){N=m,U=false;},get add_new_message(){return B},set add_new_message(m){B=m,U=false;}}]))):c.push("<!--[!-->"),c.push("<!--]-->")),c.push("<!--]-->");},$$slots:{default:true}});}do U=true,K=i.copy(),G(K);while(!U);i.subsume(K),t&&unsubscribe_stores(t);});}

export { Tt as default };
//# sourceMappingURL=_page.svelte-Cw2aVpTR.js.map
