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