1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Blocks-ll2rAV7I.js","./index-Bq2njFOY.js","./index-JtiO_h80.css","./i18n-CGlVUOvE.js","./i18n-DmEW90TJ.css","./html-Bwif0JPw.js","./ScrollFade.svelte_svelte_type_style_lang-D0JPkGar.js","./snippet-BG7qkY_1.js","./ScrollFade-DXC81vHi.css","./size-CWi277d_.js","./StreamingBar.svelte_svelte_type_style_lang-DWGn5tT_.js","./MarkdownCode.svelte_svelte_type_style_lang-B29zDiob.js","./prism-python-NrKIQnfs.js","./MarkdownCode-hl0Esrgh.css","./StreamingBar-M0OJiclA.css","./state.svelte-eX_HNnCz.js","./index-1GCmrSlD.js","./Clear-C8Tfa7QP.js","./utils.svelte-Bi9ASwv9.js","./index-CjLnGHRW.js","./index-DnoGeqVF.js","./Blocks-B8btW7fB.css","./Login-DgfcN0FC.js","./BaseForm-BF0VUPNl.js","./BaseForm-B79fGGKa.css","./Textbox-BXTb2K73.js","./actions-CgRQ2lHA.js","./input-CXpCw23l.js","./BlockTitle-Bcj082QO.js","./Info-CfqzbVCN.js","./MarkdownCode-BYKuypS7.js","./Check-BKMHx_DF.js","./Copy-BQlJe6-D.js","./Send-CFiHLThw.js","./Square-kMgNk9Wy.js","./IconButtonWrapper-DAsvkfJg.js","./Textbox-DbZXQzbK.css","./Block-DNK-JdLJ.js","./Button-By21KHDn.js","./Image-XuMqTTwB.js","./misc-D8a4ZbMA.js","./Image-DQfoGqtb.css","./Button-CoUFCYL9.css","./ImagePreview-CAbFrrhc.css","./Index.svelte_svelte_type_style_lang-B7TVXWMD.js","./Index-D0q0pAfU.css","./Login-CJk1KhUZ.css","./Example-BlSzJhEn.css"])))=>i.map(i=>d[i]); 2import { M as push, $ as set, a1 as createEventDispatcher, a8 as onMount, af as onDestroy, Y as legacy_pre_effect, _ as legacy_pre_effect_reset, O as pop, P as flushSync, Z as get, y as deep_read_state, a3 as comment, N as first_child, a as append, a0 as mutable_source, ae as derived_safe_equal, w as untrack, S as sibling, R as from_html, t as template_effect, X as set_text, Q as child, ag as __vitePreload, T as reset, a5 as next } from './index-Bq2njFOY.js'; 3import { y as setupi18n, p as prop, e as init$1, E as Embed, m as setup_stores, i as if_block, q as store_get, $ as $format, w as writable, z as prefix_css, A as mount_css, a as set_attribute, g as spread_props } from './i18n-CGlVUOvE.js'; 4import { S as Static } from './index-1GCmrSlD.js'; 5import './StreamingBar.svelte_svelte_type_style_lang-DWGn5tT_.js'; 6import './ScrollFade.svelte_svelte_type_style_lang-D0JPkGar.js'; 7import './snippet-BG7qkY_1.js'; 8import './MarkdownCode.svelte_svelte_type_style_lang-B29zDiob.js'; 9import './prism-python-NrKIQnfs.js'; 10import './Clear-C8Tfa7QP.js'; 11import './html-Bwif0JPw.js'; 12
13// src/inject_fonts.ts 14var inject_fonts = () => { 15 const source_sans_pro = document.createElement("link"); 16 source_sans_pro.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"; 17 source_sans_pro.rel = "stylesheet"; 18 const ibm_mono = document.createElement("link"); 19 ibm_mono.href = "https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600;700&display=swap"; 20 ibm_mono.rel = "stylesheet"; 21 document.head.appendChild(source_sans_pro); 22 document.head.appendChild(ibm_mono); 23}; 24
25// src/header/components/box.ts 26var Box = () => { 27 const box = document.createElement("div"); 28 box.style.backgroundImage = "linear-gradient(to top, #f9fafb, white)"; 29 box.style.border = "1px solid #e5e7eb"; 30 box.style.borderRadius = "0.75rem"; 31 box.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.1)"; 32 box.style.color = "#374151"; 33 box.style.display = "flex"; 34 box.style.flexDirection = "row"; 35 box.style.alignItems = "center"; 36 box.style.height = "40px"; 37 box.style.justifyContent = "space-between"; 38 box.style.overflow = "hidden"; 39 box.style.position = "fixed"; 40 box.style.right = ".75rem"; 41 box.style.top = ".75rem"; 42 box.style.width = "auto"; 43 box.style.zIndex = "20"; 44 box.style.paddingLeft = "1rem"; 45 box.setAttribute("id", "huggingface-space-header"); 46 window.matchMedia("(max-width: 768px)").addEventListener("change", (e) => { 47 if (e.matches) { 48 box.style.display = "none"; 49 } else { 50 box.style.display = "flex"; 51 } 52 }); 53 return box; 54}; 55
56// src/header/components/collapse/arrow.ts 57var ArrowCollapse = () => { 58 const arrow = document.createElementNS("http://www.w3.org/2000/svg", "svg"); 59 arrow.setAttribute("xmlns", "http://www.w3.org/2000/svg"); 60 arrow.setAttribute("xmlns:link", "http://www.w3.org/1999/xlink"); 61 arrow.setAttribute("aria-hidden", "true"); 62 arrow.setAttribute("focusable", "false"); 63 arrow.setAttribute("role", "img"); 64 arrow.setAttribute("width", "1em"); 65 arrow.setAttribute("height", "1em"); 66 arrow.setAttribute("preserveAspectRatio", "xMidYMid meet"); 67 arrow.setAttribute("viewBox", "0 0 12 12"); 68 arrow.setAttribute("fill", "currentColor"); 69 const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); 70 path.setAttribute( 71 "d", 72 "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" 73 ); 74 arrow.appendChild(path); 75 return arrow; 76}; 77
78// src/header/components/collapse/index.ts 79var Collapse = (space, callback) => { 80 const box = document.createElement("div"); 81 box.setAttribute("id", "space-header__collapse"); 82 box.style.display = "flex"; 83 box.style.flexDirection = "row"; 84 box.style.alignItems = "center"; 85 box.style.justifyContent = "center"; 86 box.style.fontSize = "16px"; 87 box.style.paddingLeft = "10px"; 88 box.style.paddingRight = "10px"; 89 box.style.height = "40px"; 90 box.style.cursor = "pointer"; 91 box.style.color = "#40546e"; 92 box.style.transitionDuration = "0.1s"; 93 box.style.transitionProperty = "all"; 94 box.style.transitionTimingFunction = "ease-in-out"; 95 box.appendChild(ArrowCollapse()); 96 box.addEventListener("click", (e) => { 97 e.preventDefault(); 98 e.stopPropagation(); 99 callback(); 100 }); 101 box.addEventListener("mouseenter", () => { 102 box.style.color = "#213551"; 103 }); 104 box.addEventListener("mouseleave", () => { 105 box.style.color = "#40546e"; 106 }); 107 return box; 108}; 109
110// src/header/components/like/count.ts 111var Count = (count) => { 112 const text = document.createElement("p"); 113 text.style.margin = "0"; 114 text.style.padding = "0"; 115 text.style.color = "#9ca3af"; 116 text.style.fontSize = "14px"; 117 text.style.fontFamily = "Source Sans Pro, sans-serif"; 118 text.style.padding = "0px 6px"; 119 text.style.borderLeft = "1px solid #e5e7eb"; 120 text.style.marginLeft = "4px"; 121 text.textContent = (count != null ? count : 0).toString(); 122 return text; 123}; 124
125// src/header/components/like/heart.ts 126var Heart = () => { 127 const heart = document.createElementNS("http://www.w3.org/2000/svg", "svg"); 128 heart.setAttribute("xmlns", "http://www.w3.org/2000/svg"); 129 heart.setAttribute("xmlns:link", "http://www.w3.org/1999/xlink"); 130 heart.setAttribute("aria-hidden", "true"); 131 heart.setAttribute("focusable", "false"); 132 heart.setAttribute("role", "img"); 133 heart.setAttribute("width", "1em"); 134 heart.setAttribute("height", "1em"); 135 heart.setAttribute("preserveAspectRatio", "xMidYMid meet"); 136 heart.setAttribute("viewBox", "0 0 32 32"); 137 heart.setAttribute("fill", "#6b7280"); 138 const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); 139 path.setAttribute( 140 "d", 141 "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" 142 ); 143 heart.appendChild(path); 144 return heart; 145}; 146
147// src/header/components/like/index.ts 148var Like = (space) => { 149 const box = document.createElement("a"); 150 box.setAttribute("href", `https://huggingface.co/spaces/${space.id}`); 151 box.setAttribute("rel", "noopener noreferrer"); 152 box.setAttribute("target", "_blank"); 153 box.style.border = "1px solid #e5e7eb"; 154 box.style.borderRadius = "6px"; 155 box.style.display = "flex"; 156 box.style.flexDirection = "row"; 157 box.style.alignItems = "center"; 158 box.style.margin = "0 0 0 12px"; 159 box.style.fontSize = "14px"; 160 box.style.paddingLeft = "4px"; 161 box.style.textDecoration = "none"; 162 box.appendChild(Heart()); 163 box.appendChild(Count(space.likes)); 164 return box; 165}; 166
167// src/header/components/content/avatar.ts 168var Avatar = (username, type = "user") => { 169 const route = type === "user" ? "users" : "organizations"; 170 const element = document.createElement("img"); 171 element.src = `https://huggingface.co/api/${route}/${username}/avatar`; 172 element.style.width = "0.875rem"; 173 element.style.height = "0.875rem"; 174 element.style.borderRadius = "50%"; 175 element.style.flex = "none"; 176 element.style.marginRight = "0.375rem"; 177 return element; 178}; 179
180// src/header/components/content/namespace.ts 181var Namespace = (id) => { 182 const [_, spaceName] = id.split("/"); 183 const element = document.createElement("a"); 184 element.setAttribute("href", `https://huggingface.co/spaces/${id}`); 185 element.setAttribute("rel", "noopener noreferrer"); 186 element.setAttribute("target", "_blank"); 187 element.style.color = "#1f2937"; 188 element.style.textDecoration = "none"; 189 element.style.fontWeight = "600"; 190 element.style.fontSize = "15px"; 191 element.style.lineHeight = "24px"; 192 element.style.flex = "none"; 193 element.style.fontFamily = "IBM Plex Mono, sans-serif"; 194 element.addEventListener("mouseover", () => { 195 element.style.color = "#2563eb"; 196 }); 197 element.addEventListener("mouseout", () => { 198 element.style.color = "#1f2937"; 199 }); 200 element.textContent = spaceName; 201 return element; 202}; 203
204// src/header/components/content/separation.ts 205var Separation = () => { 206 const separation = document.createElement("div"); 207 separation.style.marginLeft = ".125rem"; 208 separation.style.marginRight = ".125rem"; 209 separation.style.color = "#d1d5db"; 210 separation.textContent = "/"; 211 return separation; 212}; 213
214// src/header/components/content/username.ts 215var Username = (username) => { 216 const element = document.createElement("a"); 217 element.setAttribute("href", `https://huggingface.co/${username}`); 218 element.setAttribute("rel", "noopener noreferrer"); 219 element.setAttribute("target", "_blank"); 220 element.style.color = "rgb(107, 114, 128)"; 221 element.style.textDecoration = "none"; 222 element.style.fontWeight = "400"; 223 element.style.fontSize = "16px"; 224 element.style.lineHeight = "24px"; 225 element.style.flex = "none"; 226 element.style.fontFamily = "Source Sans Pro, sans-serif"; 227 element.addEventListener("mouseover", () => { 228 element.style.color = "#2563eb"; 229 }); 230 element.addEventListener("mouseout", () => { 231 element.style.color = "rgb(107, 114, 128)"; 232 }); 233 element.textContent = username; 234 return element; 235}; 236
237// src/header/components/content/index.ts 238var Content = (space) => { 239 const content = document.createElement("div"); 240 content.style.display = "flex"; 241 content.style.flexDirection = "row"; 242 content.style.alignItems = "center"; 243 content.style.justifyContent = "center"; 244 content.style.borderRight = "1px solid #e5e7eb"; 245 content.style.paddingRight = "12px"; 246 content.style.height = "40px"; 247 if (space.type !== "unknown") { 248 content.appendChild(Avatar(space.author, space.type)); 249 } 250 content.appendChild(Username(space.author)); 251 content.appendChild(Separation()); 252 content.appendChild(Namespace(space.id)); 253 content.appendChild(Like(space)); 254 return content; 255}; 256
257// src/header/create.ts 258var create = (space) => { 259 const box = Box(); 260 const handleCollapse = () => box.style.display = "none"; 261 box.appendChild(Content(space)); 262 box.appendChild(Collapse(space, handleCollapse)); 263 return box; 264}; 265
266// src/utils/check_avatar.ts 267var check_avatar = async (username, type = "user") => { 268 const route = type === "user" ? "users" : "organizations"; 269 try { 270 const response = await fetch(`https://huggingface.co/api/${route}/${username}/avatar`); 271 return response.ok; 272 } catch (error) { 273 return false; 274 } 275}; 276
277// src/utils/get_space.ts 278var get_space = async (space_id) => { 279 try { 280 const response = await fetch(`https://huggingface.co/api/spaces/${space_id}`); 281 const data = await response.json(); 282 return data; 283 } catch (error) { 284 return null; 285 } 286}; 287
288// src/inject.ts 289var inject = (element, options) => { 290 if (document.body === null) { 291 return console.error("document.body is null"); 292 } 293 document.body.appendChild(element); 294}; 295
296// src/index.ts 297async function main(initialSpace, options) { 298 var _a, _b; 299 if (window === void 0) return console.error("Please run this script in a browser environment"); 300 const has_huggingface_ancestor = Object.values( 301 (_b = (_a = window.location) == null ? void 0 : _a.ancestorOrigins) != null ? _b : { 302 0: window.document.referrer 303 } 304 ).some((origin) => { 305 var _a2; 306 return ((_a2 = new URL(origin)) == null ? void 0 : _a2.origin) === "https://huggingface.co"; 307 }); 308 if (has_huggingface_ancestor) return; 309 inject_fonts(); 310 let space; 311 if (typeof initialSpace === "string") { 312 space = await get_space(initialSpace); 313 if (space === null) return console.error("Space not found"); 314 } else { 315 space = initialSpace; 316 } 317 const [user, org] = await Promise.all([check_avatar(space.author, "user"), check_avatar(space.author, "org")]); 318 space.type = user ? "user" : org ? "org" : "unknown"; 319 const mini_header_element = create(space); 320 inject(mini_header_element); 321 return { 322 element: mini_header_element 323 }; 324} 325var init = (space, options) => main(space); 326 327let id = -1; 328function create_intersection_store() { 329 const intersecting2 = writable({}); 330 const els = /* @__PURE__ */ new Map(); 331 const observer = new IntersectionObserver((entries) => { 332 entries.forEach((entry) => { 333 if (entry.isIntersecting) { 334 let _el = els.get(entry.target); 335 if (_el !== void 0) intersecting2.update((s) => ({ ...s, [_el]: true })); 336 } 337 }); 338 }); 339 function register(_id, el) { 340 els.set(el, _id); 341 observer.observe(el); 342 } 343 return { register, subscribe: intersecting2.subscribe }; 344} 345const intersecting = create_intersection_store(); 346var root_6 = from_html(`<p>If your custom component never loads, consult the troubleshooting <a style="color: blue;" href="https://www.gradio.app/guides/frequently-asked-questions#the-development-server-didnt-work-for-me" class="svelte-15izthb">guide</a>.</p>`); 347var root_5 = from_html(`<div class="load-text" slot="additional-loading-text"><!></div>`); 348var root_8 = from_html(`<p class="svelte-15izthb">Please <a class="svelte-15izthb">contact the author of the space</a> to let them know.</p>`); 349var root_10 = from_html(`<p class="svelte-15izthb"> </p>`); 350var root_7 = from_html(`<div class="error svelte-15izthb" slot="error"><p class="svelte-15izthb"><strong> </strong></p> <!></div>`); 351var root_3 = from_html(`<!> <!>`, 1); 352function Index($$anchor, $$props) { 353 push($$props, false); 354 const $intersecting = () => store_get(intersecting, "$intersecting", $$stores); 355 const $_ = () => store_get($format, "$_", $$stores); 356 const [$$stores, $$cleanup] = setup_stores(); 357 let i18n_ready = mutable_source(false); 358 setupi18n().then(() => { 359 set(i18n_ready, true); 360 }); 361 const dispatch = createEventDispatcher(); 362 let autoscroll = prop($$props, "autoscroll", 12); 363 let version = prop($$props, "version", 12); 364 let initial_height = prop($$props, "initial_height", 12); 365 let app_mode = prop($$props, "app_mode", 12); 366 let is_embed = prop($$props, "is_embed", 12); 367 let theme_mode = prop($$props, "theme_mode", 12, "system"); 368 let control_page_title = prop($$props, "control_page_title", 12); 369 let container = prop($$props, "container", 12); 370 let info = prop($$props, "info", 12); 371 let eager = prop($$props, "eager", 12); 372 let stream; 373 let pages = mutable_source([]); 374 let current_page = mutable_source(); 375 let root = mutable_source(); 376 let Client = prop($$props, "Client", 12);
377 let space = prop($$props, "space", 12); 378 let src = prop($$props, "src", 12); 379 let _id = id++; 380 let loader_status = mutable_source("pending"); 381 let app_id = mutable_source(null); 382 let wrapper = mutable_source(); 383 let ready = mutable_source(false); 384 let render_complete = mutable_source(false); 385 let config = mutable_source(); 386 let loading_text = mutable_source("Loading..."); 387 let active_theme_mode = mutable_source(); 388 let api_url; 389 let css_text_stylesheet = null; 390 async function mount_custom_css(css_string) { 391 if (css_string) { 392 if (!css_text_stylesheet) { 393 css_text_stylesheet = document.createElement("style"); 394 document.head.appendChild(css_text_stylesheet); 395 } 396 css_text_stylesheet.textContent = prefix_css(css_string, version(), css_text_stylesheet); 397 } 398 await mount_css(get(config).root + "/theme.css?v=" + get(config).theme_hash, document.head); 399 if (!get(config).stylesheets) return; 400 await Promise.all(get(config).stylesheets.map((stylesheet) => { 401 let absolute_link = stylesheet.startsWith("http:") || stylesheet.startsWith("https:"); 402 if (absolute_link) { 403 return mount_css(stylesheet, document.head); 404 } 405 return fetch(get(config).root + "/" + stylesheet).then((response) => response.text()).then((css_string2) => { 406 prefix_css(css_string2, version()); 407 }); 408 })); 409 } 410 async function add_custom_html_head(head_string) { 411 if (head_string) { 412 const parser = new DOMParser(); 413 const parsed_head_html = Array.from(parser.parseFromString(head_string, "text/html").head.children); 414 if (parsed_head_html) { 415 for (let head_element of parsed_head_html) { 416 let newElement = document.createElement(head_element.tagName); 417 Array.from(head_element.attributes).forEach((attr) => { 418 newElement.setAttribute(attr.name, attr.value); 419 }); 420 newElement.textContent = head_element.textContent; 421 if (newElement.tagName == "META") { 422 const propertyAttr = newElement.getAttribute("property"); 423 const nameAttr = newElement.getAttribute("name"); 424 if (propertyAttr || nameAttr) { 425 const domMetaList = Array.from(document.head.getElementsByTagName("meta") ?? []); 426 const matched = domMetaList.find((el) => { 427 if (propertyAttr && el.getAttribute("property") === propertyAttr) { 428 return !el.isEqualNode(newElement); 429 } 430 if (nameAttr && el.getAttribute("name") === nameAttr) { 431 return !el.isEqualNode(newElement); 432 } 433 return false; 434 }); 435 if (matched) { 436 document.head.replaceChild(newElement, matched); 437 continue; 438 } 439 } 440 } 441 document.head.appendChild(newElement); 442 } 443 } 444 } 445 } 446 function handle_theme_mode(target) { 447 const force_light = window.__gradio_mode__ === "website"; 448 let new_theme_mode; 449 if (force_light) { 450 new_theme_mode = "light"; 451 } else { 452 const url = new URL(window.location.toString()); 453 const url_color_mode = url.searchParams.get("__theme"); 454 new_theme_mode = theme_mode() || url_color_mode || "system"; 455 } 456 if (new_theme_mode === "dark" || new_theme_mode === "light") { 457 apply_theme(target, new_theme_mode); 458 } else { 459 new_theme_mode = sync_system_theme(target); 460 } 461 return new_theme_mode; 462 } 463 function sync_system_theme(target) { 464 const theme = update_scheme(); 465 window?.matchMedia("(prefers-color-scheme: dark)")?.addEventListener("change", update_scheme); 466 function update_scheme() { 467 let _theme = window?.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light"; 468 apply_theme(target, _theme); 469 return _theme; 470 } 471 return theme; 472 } 473 function apply_theme(target, theme) { 474 const dark_class_element = is_embed() ? target.parentElement : document.body; 475 const bg_element = is_embed() ? target : target.parentElement; 476 bg_element.style.background = "var(--body-background-fill)"; 477 if (theme === "dark") { 478 dark_class_element.classList.add("dark"); 479 } else { 480 dark_class_element.classList.remove("dark"); 481 } 482 } 483 let status = mutable_source({ 484 message: "", 485 load_status: "pending", 486 status: "sleeping", 487 detail: "SLEEPING" 488 }); 489 let app = mutable_source(); 490 let css_ready = mutable_source(false); 491 function handle_status(_status) { 492 set(status, _status); 493 } 494 const gradio_dev_mode = window.__GRADIO_DEV__; 495 let pending_deep_link_error = mutable_source(false); 496 let new_message_fn = mutable_source(); 497 let reload_count = mutable_source(0); 498 onMount(async () => { 499 set(active_theme_mode, handle_theme_mode(get(wrapper))); 500 const server_port = window.__GRADIO__SERVER_PORT__; 501 api_url = gradio_dev_mode === "dev" ? `http://localhost:${typeof server_port === "number" ? server_port : 7860}` : space() || src() || new URL(location.pathname, location.origin).href.replace(/\/$/, ""); 502 const deep_link = new URLSearchParams(window.location.search).get("deep_link"); 503 const query_params = {}; 504 if (deep_link) { 505 query_params.deep_link = deep_link; 506 } 507 set(app, await Client().connect(api_url, { 508 status_callback: handle_status, 509 with_null_state: true, 510 events: ["data", "log", "status", "render"], 511 query_params 512 })); 513 window.addEventListener("beforeunload", () => { 514 get(app).close(); 515 }); 516 if (!get(app).config && !get(config)?.auth_required) { 517 throw new Error("Could not resolve app config"); 518 } 519 set(config, get(app).get_url_config()); 520 window.__gradio_space__ = get(config).space_id; 521 if (get(app).config?.i18n_translations) { 522 await setupi18n(get(app).config.i18n_translations); 523 set(i18n_ready, true); 524 } 525 window.__gradio_session_hash__ = get(app).session_hash; 526 set(status, { 527 message: "", 528 load_status: "complete", 529 status: "running", 530 detail: "RUNNING" 531 }); 532 await mount_custom_css(get(config).css); 533 await add_custom_html_head(get(config).head); 534 set(css_ready, true); 535 window.__is_colab__ = get(config).is_colab; 536 const supports_zerogpu_headers = "supports-zerogpu-headers"; 537 window.addEventListener("message", (event) => {
538 if (event.data === supports_zerogpu_headers) { 539 window.supports_zerogpu_headers = true; 540 } 541 }); 542 const hostname = window.location.hostname; 543 const is_hf_host = hostname.includes(".dev.") || hostname.endsWith(".hf.space"); 544 if (is_hf_host) { 545 const origin = hostname.includes(".dev.") ? `https://moon-${hostname.split(".")[1]}.dev.spaces.huggingface.tech` : `https://huggingface.co`; 546 window.parent.postMessage(supports_zerogpu_headers, origin); 547 } 548 dispatch("loaded"); 549 set(pages, get(config).pages); 550 set(current_page, get(config).current_page); 551 set(root, get(config).root); 552 if (get(config).deep_link_state === "invalid") { 553 set(pending_deep_link_error, true); 554 } 555 if (get(config).js) { 556 try { 557 const script = document.createElement("script"); 558 script.textContent = get(config).js; 559 document.head.appendChild(script); 560 } catch (e) { 561 console.error("Error executing custom JS:", e); 562 } 563 } 564 if (get(config).dev_mode) { 565 setTimeout( 566 () => { 567 const { host } = new URL(api_url); 568 let url = new URL(`${window.location.protocol}//${host}${get(app).api_prefix}/dev/reload`); 569 stream = new EventSource(url); 570 stream.addEventListener("error", async (e) => { 571 let event_data = e.data; 572 if (event_data) { 573 get(new_message_fn)("Error", "Error reloading app", -1, "error", 10, true); 574 console.error(JSON.parse(event_data)); 575 } 576 }); 577 stream.addEventListener("reload", async (event) => { 578 get(app).close(); 579 set(app, await Client().connect(api_url, { 580 status_callback: handle_status, 581 with_null_state: true, 582 events: ["data", "log", "status", "render"], 583 session_hash: get(app).session_hash 584 })); 585 if (!get(app).config) { 586 throw new Error("Could not resolve app config"); 587 } 588 set(config, get(app).get_url_config()); 589 window.__gradio_space__ = get(config).space_id; 590 await mount_custom_css(get(config).css); 591 await add_custom_html_head(get(config).head); 592 set(css_ready, true); 593 window.__is_colab__ = get(config).is_colab; 594 set(reload_count, get(reload_count) + 1); 595 dispatch("loaded"); 596 }); 597 }, 598 200 599 ); 600 } 601 }); 602 let Blocks = mutable_source(); 603 let Login = mutable_source(); 604 async function get_blocks() { 605 set(Blocks, (await __vitePreload(async () => { const {default: __vite_default__} = await import('./Blocks-ll2rAV7I.js').then(n => n.B);return { default: __vite_default__ }},true ?__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]):void 0,import.meta.url)).default); 606 } 607 async function get_login() { 608 set(Login, (await __vitePreload(async () => { const {default: __vite_default__} = await import('./Login-DgfcN0FC.js');return { default: __vite_default__ }},true ?__vite__mapDeps([22,3,1,2,4,5,23,24,25,26,27,6,7,8,28,29,30,11,12,13,31,32,33,34,35,36,10,14,37,38,39,40,41,42,43,44,16,17,45,46,47]):void 0,import.meta.url)).default); 609 } 610 function load_demo() { 611 if (get(config).auth_required) get_login(); 612 else get_blocks(); 613 } 614 let discussion_message = mutable_source(); 615 onMount(async () => { 616 intersecting.register(_id, get(wrapper)); 617 }); 618 let spaceheader; 619 async function mount_space_header(space_id, is_embed2) { 620 if (space_id && !is_embed2 && window.self === window.top) { 621 if (spaceheader) { 622 spaceheader.remove(); 623 spaceheader = void 0; 624 } 625 const header = await init(space_id); 626 if (header) spaceheader = header.element; 627 } 628 } 629 onDestroy(() => { 630 spaceheader?.remove(); 631 }); 632 legacy_pre_effect(() => get(config), () => { 633 if (get(config)?.app_id) { 634 set(app_id, get(config).app_id); 635 } 636 }); 637 legacy_pre_effect(() => (get(new_message_fn), get(pending_deep_link_error)), () => { 638 if (get(new_message_fn) && get(pending_deep_link_error)) {
639 get(new_message_fn)("Error", "Deep link was not valid", -1, "error", 10, true); 640 set(pending_deep_link_error, false); 641 } 642 }); 643 legacy_pre_effect(() => (get(ready), get(status)), () => { 644 set(loader_status, !get(ready) && get(status).load_status !== "error" ? "pending" : !get(ready) && get(status).load_status === "error" ? "error" : get(status).load_status); 645 }); 646 legacy_pre_effect(() => (get(config), deep_read_state(eager()), $intersecting()), () => { 647 get(config) && (eager() || $intersecting()[_id]) && load_demo(); 648 }); 649 legacy_pre_effect(() => (get(i18n_ready), $_()), () => { 650 if (get(i18n_ready)) { 651 set(loading_text, $_()("common.loading") + "..."); 652 set(discussion_message, { 653 readable_error: { 654 NO_APP_FILE: $_()("errors.no_app_file"), 655 CONFIG_ERROR: $_()("errors.config_error"), 656 BUILD_ERROR: $_()("errors.build_error"), 657 RUNTIME_ERROR: $_()("errors.runtime_error"), 658 PAUSED: $_()("errors.space_paused") 659 }, 660 title(error) { 661 return encodeURIComponent($_()("errors.space_not_working")); 662 }, 663 description(error, site) { 664 return encodeURIComponent(`Hello, 665 666Firstly, thanks for creating this space! 667 668I noticed that the space isn't working correctly because there is ${this.readable_error[error] || "an error"}. 669 670It would be great if you could take a look at this because this space is being embedded on ${site}. 671 672Thanks!`); 673 } 674 }); 675 } 676 }); 677 legacy_pre_effect(() => (get(render_complete), get(wrapper)), () => { 678 if (get(render_complete)) { 679 get(wrapper).dispatchEvent(new CustomEvent("render", { bubbles: true, cancelable: false, composed: true })); 680 } 681 }); 682 legacy_pre_effect(() => (get(app), deep_read_state(is_embed())), () => { 683 get(app)?.config && mount_space_header(get(app)?.config?.space_id, is_embed()); 684 }); 685 legacy_pre_effect_reset(); 686 var $$exports = { 687 get autoscroll() { 688 return autoscroll(); 689 }, 690 set autoscroll($$value) { 691 autoscroll($$value); 692 flushSync(); 693 }, 694 get version() { 695 return version(); 696 }, 697 set version($$value) { 698 version($$value); 699 flushSync(); 700 }, 701 get initial_height() { 702 return initial_height(); 703 }, 704 set initial_height($$value) { 705 initial_height($$value); 706 flushSync(); 707 }, 708 get app_mode() { 709 return app_mode(); 710 }, 711 set app_mode($$value) { 712 app_mode($$value); 713 flushSync(); 714 }, 715 get is_embed() { 716 return is_embed(); 717 }, 718 set is_embed($$value) { 719 is_embed($$value); 720 flushSync(); 721 }, 722 get theme_mode() { 723 return theme_mode(); 724 }, 725 set theme_mode($$value) { 726 theme_mode($$value); 727 flushSync(); 728 }, 729 get control_page_title() { 730 return control_page_title(); 731 }, 732 set control_page_title($$value) { 733 control_page_title($$value); 734 flushSync(); 735 }, 736 get container() { 737 return container(); 738 }, 739 set container($$value) { 740 container($$value); 741 flushSync(); 742 }, 743 get info() { 744 return info(); 745 }, 746 set info($$value) { 747 info($$value); 748 flushSync(); 749 }, 750 get eager() { 751 return eager(); 752 }, 753 set eager($$value) { 754 eager($$value); 755 flushSync(); 756 }, 757 get Client() { 758 return Client(); 759 }, 760 set Client($$value) { 761 Client($$value); 762 flushSync(); 763 }, 764 get space() { 765 return space(); 766 }, 767 set space($$value) { 768 space($$value); 769 flushSync(); 770 }, 771 get src() { 772 return src(); 773 }, 774 set src($$value) { 775 src($$value); 776 flushSync(); 777 } 778 }; 779 init$1(); 780 { 781 let $0 = derived_safe_equal(() => container() && is_embed()); 782 let $1 = derived_safe_equal(() => !!space() && info()); 783 let $2 = derived_safe_equal(() => get(loader_status) === "complete"); 784 let $3 = derived_safe_equal(() => (get(config), untrack(() => get(config)?.fill_width || false))); 785 let $4 = derived_safe_equal(() => (get(config), untrack(() => get(config)?.components || []))); 786 Embed($$anchor, { 787 get display() { 788 return get($0); 789 }, 790 get is_embed() { 791 return is_embed(); 792 }, 793 get info() { 794 return get($1); 795 }, 796 get version() { 797 return version(); 798 }, 799 get initial_height() { 800 return initial_height(); 801 }, 802 get space() { 803 return space(); 804 }, 805 get loaded() { 806 return get($2); 807 }, 808 get fill_width() { 809 return get($3); 810 }, 811 get pages() { 812 return get(pages); 813 }, 814 get current_page() { 815 return get(current_page); 816 }, 817 get root() { 818 return get(root); 819 }, 820 get components() { 821 return get($4); 822 }, 823 get wrapper() { 824 return get(wrapper); 825 }, 826 set wrapper($$value) { 827 set(wrapper, $$value); 828 },
829 children: ($$anchor2, $$slotProps) => { 830 var fragment_1 = comment(); 831 var node = first_child(fragment_1); 832 { 833 var consequent_6 = ($$anchor3) => { 834 var fragment_2 = root_3(); 835 var node_1 = first_child(fragment_2); 836 { 837 var consequent_3 = ($$anchor4) => { 838 { 839 let $02 = derived_safe_equal(() => !is_embed()); 840 Static($$anchor4, { 841 get absolute() { 842 return get($02); 843 }, 844 get status() { 845 return get(loader_status); 846 }, 847 timer: false, 848 queue_position: null, 849 queue_size: null, 850 translucent: true, 851 get loading_text() { 852 return get(loading_text); 853 }, 854 get i18n() { 855 return $_(); 856 }, 857 get autoscroll() { 858 return autoscroll(); 859 }, 860 $$slots: { 861 "additional-loading-text": ($$anchor5, $$slotProps2) => { 862 var div = root_5(); 863 var node_2 = child(div); 864 { 865 var consequent = ($$anchor6) => { 866 var p = root_6(); 867 append($$anchor6, p); 868 }; 869 if_block(node_2, ($$render) => { 870 if (gradio_dev_mode === "dev") $$render(consequent); 871 }); 872 } 873 reset(div); 874 append($$anchor5, div); 875 }, 876 error: ($$anchor5, $$slotProps2) => { 877 var div_1 = root_7(); 878 var p_1 = child(div_1); 879 var strong = child(p_1); 880 var text = child(strong, true); 881 reset(strong); 882 reset(p_1); 883 var node_3 = sibling(p_1, 2); 884 { 885 var consequent_1 = ($$anchor6) => { 886 var p_2 = root_8(); 887 var a = sibling(child(p_2)); 888 next(); 889 reset(p_2); 890 template_effect(($03, $12) => set_attribute(a, "href", `https://huggingface.co/spaces/${space() ?? ""}/discussions/new?title=${$03 ?? ""}&description=${$12 ?? ""}`), [ 891 () => (get(discussion_message), get(status), untrack(() => get(discussion_message).title(get(status)?.detail))), 892 () => (get(discussion_message), get(status), untrack(() => get(discussion_message).description(get(status)?.detail, location.origin))) 893 ]); 894 append($$anchor6, p_2); 895 }; 896 var alternate = ($$anchor6) => { 897 var fragment_4 = comment(); 898 var node_4 = first_child(fragment_4); 899 { 900 var consequent_2 = ($$anchor7) => { 901 var p_3 = root_10(); 902 var text_1 = child(p_3, true); 903 reset(p_3); 904 template_effect(($03) => set_text(text_1, $03), [ 905 () => ($_(), untrack(() => $_()("errors.contact_page_author"))) 906 ]); 907 append($$anchor7, p_3); 908 }; 909 if_block( 910 node_4, 911 ($$render) => { 912 if (get(i18n_ready)) $$render(consequent_2); 913 }, 914 true 915 ); 916 } 917 append($$anchor6, fragment_4); 918 }; 919 if_block(node_3, ($$render) => { 920 if (get(status), get(discussion_message), untrack(() => (get(status).status === "space_error" || get(status).status === "paused") && get(status).discussions_enabled && get(discussion_message))) $$render(consequent_1); 921 else $$render(alternate, false); 922 }); 923 } 924 reset(div_1); 925 template_effect(() =>
925 set_text(text, (get(status), untrack(() => get(status)?.message || "")))); 926 append($$anchor5, div_1); 927 } 928 } 929 }); 930 } 931 }; 932 if_block(node_1, ($$render) => { 933 if (get(loader_status), get(config), untrack(() => (get(loader_status) === "pending" || get(loader_status) === "error") && !(get(config) && get(config)?.auth_required))) $$render(consequent_3); 934 }); 935 } 936 var node_5 = sibling(node_1, 2); 937 { 938 var consequent_4 = ($$anchor4) => { 939 { 940 let $02 = derived_safe_equal(() => get(i18n_ready) ? $_() : (s) => s); 941 get(Login)($$anchor4, { 942 get auth_message() { 943 return get(config), untrack(() => get(config).auth_message); 944 }, 945 get root() { 946 return get(config), untrack(() => get(config).root); 947 }, 948 get space_id() { 949 return space(); 950 }, 951 get i18n() { 952 return get($02); 953 }, 954 get app_mode() { 955 return app_mode(); 956 } 957 }); 958 } 959 }; 960 var alternate_1 = ($$anchor4) => { 961 var fragment_6 = comment(); 962 var node_6 = first_child(fragment_6); 963 { 964 var consequent_5 = ($$anchor5) => { 965 { 966 let $02 = derived_safe_equal(() => (deep_read_state(is_embed()), get(config), untrack(() => !is_embed() && get(config).fill_height))); 967 let $12 = derived_safe_equal(() => (deep_read_state(is_embed()), get(config), untrack(() => is_embed() ? [] : get(config).footer_links))); 968 let $22 = derived_safe_equal(() => (get(config), untrack(() => get(config).api_prefix || ""))); 969 get(Blocks)($$anchor5, spread_props( 970 { 971 get app() { 972 return get(app); 973 } 974 }, 975 () => get(config), 976 { 977 get fill_height() { 978 return get($02); 979 }, 980 get theme_mode() { 981 return get(active_theme_mode); 982 }, 983 get control_page_title() { 984 return control_page_title(); 985 }, 986 get target() { 987 return get(wrapper); 988 }, 989 get autoscroll() { 990 return autoscroll(); 991 }, 992 get footer_links() { 993 return get($12); 994 }, 995 get app_mode() { 996 return app_mode(); 997 }, 998 get version() { 999 return version(); 1000 }, 1001 get api_prefix() { 1002 return get($22); 1003 }, 1004 get max_file_size() { 1005 return get(config), untrack(() => get(config).max_file_size); 1006 }, 1007 initial_layout: void 0, 1008 search_params: untrack(() => new URLSearchParams(window.location.search)), 1009 get reload_count() { 1010 return get(reload_count); 1011 }, 1012 get ready() { 1013 return get(ready); 1014 }, 1015 set ready($$value) { 1016 set(ready, $$value); 1017 }, 1018 get render_complete() { 1019 return get(render_complete); 1020 }, 1021 set render_complete($$value) { 1022 set(render_complete, $$value); 1023 }, 1024 get add_new_message() { 1025 return get(new_message_fn); 1026 }, 1027 set add_new_message($$value) { 1028 set(new_message_fn, $$value); 1029 }, 1030 $$legacy: true 1031 } 1032 )); 1033 } 1034 }; 1035 if_block( 1036 node_6, 1037 ($$render) => { 1038 if (get(config) && get(Blocks) && get(css_ready)) $$render(consequent_5); 1039 }, 1040 true 1041 ); 1042 } 1043 append($$anchor4, fragment_6); 1044 }; 1045 if_block(node_5, ($$render) => { 1046 if (get(config), get(Login), untrack(() => get(config)?.auth_required && get(Login))) $$render(consequent_4); 1047 else $$render(alternate_1, false); 1048 }); 1049 } 1050 append($$anchor3, fragment_2); 1051 }; 1052 if_block(node, ($$render) => { 1053 if (get(i18n_ready)) $$render(consequent_6); 1054 }); 1055 } 1056 append($$anchor2, fragment_1); 1057 }, 1058 $$slots: { default: true }, 1059 $$legacy: true 1060 }); 1061 } 1062 var $$pop = pop($$exports); 1063 $$cleanup(); 1064 return $$pop; 1065} 1066 1067export { Index as default }; 1068//# sourceMappingURL=Index-CV3JHPjL.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.