1import * as svelte from './svelte/svelte.js'; 2 3true&&(function polyfill() { 4 const relList = document.createElement('link').relList; 5 if (relList && relList.supports && relList.supports('modulepreload')) { 6 return; 7 } 8 for (const link of document.querySelectorAll('link[rel="modulepreload"]')) { 9 processPreload(link); 10 } 11 new MutationObserver((mutations) => { 12 for (const mutation of mutations) { 13 if (mutation.type !== 'childList') { 14 continue; 15 } 16 for (const node of mutation.addedNodes) { 17 if (node.tagName === 'LINK' && node.rel === 'modulepreload') 18 processPreload(node); 19 } 20 } 21 }).observe(document, { childList: true, subtree: true }); 22 function getFetchOpts(link) { 23 const fetchOpts = {}; 24 if (link.integrity) 25 fetchOpts.integrity = link.integrity; 26 if (link.referrerPolicy) 27 fetchOpts.referrerPolicy = link.referrerPolicy; 28 if (link.crossOrigin === 'use-credentials') 29 fetchOpts.credentials = 'include'; 30 else if (link.crossOrigin === 'anonymous') 31 fetchOpts.credentials = 'omit'; 32 else 33 fetchOpts.credentials = 'same-origin'; 34 return fetchOpts; 35 } 36 function processPreload(link) { 37 if (link.ep) 38 // ep marker = processed 39 return; 40 link.ep = true; 41 // prepopulate the load record 42 const fetchOpts = getFetchOpts(link); 43 fetch(link.href, fetchOpts); 44 } 45}()); 46 47const scriptRel = 'modulepreload';const assetsURL = function(dep, importerUrl) { return new URL(dep, importerUrl).href };const seen = {};const __vitePreload = function preload(baseModule, deps, importerUrl) { 48 // @ts-expect-error true will be replaced with boolean later 49 if (!true || !deps || deps.length === 0) { 50 return baseModule(); 51 } 52 const links = document.getElementsByTagName('link'); 53 return Promise.all(deps.map((dep) => { 54 // @ts-expect-error assetsURL is declared before preload.toString() 55 dep = assetsURL(dep, importerUrl); 56 if (dep in seen) 57 return; 58 seen[dep] = true; 59 const isCss = dep.endsWith('.css'); 60 const cssSelector = isCss ? '[rel="stylesheet"]' : ''; 61 const isBaseRelative = !!importerUrl; 62 // check if the file is already preloaded by SSR markup 63 if (isBaseRelative) { 64 // When isBaseRelative is true then we have `importerUrl` and `dep` is 65 // already converted to an absolute URL by the `assetsURL` function 66 for (let i = links.length - 1; i >= 0; i--) { 67 const link = links[i]; 68 // The `links[i].href` is an absolute URL thanks to browser doing the work 69 // for us. See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-domstring-5 70 if (link.href === dep && (!isCss || link.rel === 'stylesheet')) { 71 return; 72 } 73 } 74 } 75 else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) { 76 return; 77 } 78 const link = document.createElement('link'); 79 link.rel = isCss ? 'stylesheet' : scriptRel; 80 if (!isCss) { 81 link.as = 'script'; 82 link.crossOrigin = ''; 83 } 84 link.href = dep; 85 document.head.appendChild(link); 86 if (isCss) { 87 return new Promise((res, rej) => { 88 link.addEventListener('load', res); 89 link.addEventListener('error', () => rej(new Error(`Unable to preload CSS for ${dep}`))); 90 }); 91 } 92 })).then(() => baseModule()); 93}; 94 95const reset = ''; 96 97const global$1 = ''; 98 99const pollen = ''; 100 101const typography = ''; 102 103var fn = new Intl.Collator(0, { numeric: 1 }).compare; 104function semiver(a, b, bool) { 105 a = a.split("."); 106 b = b.split("."); 107 return fn(a[0], b[0]) || fn(a[1], b[1]) || (b[2] = b.slice(2).join("."), bool = /[.-]/.test(a[2] = a.slice(2).join(".")), bool == /[.-]/.test(b[2]) ? fn(a[2], b[2]) : bool ? -1 : 1); 108} 109function resolve_root(base_url, root_path, prioritize_base) { 110 if (root_path.startsWith("http://") || root_path.startsWith("https://")) { 111 return prioritize_base ? base_url : root_path; 112 } 113 return base_url + root_path; 114} 115function determine_protocol(endpoint) { 116 if (endpoint.startsWith("http")) { 117 const { protocol, host } = new URL(endpoint); 118 if (host.endsWith("hf.space")) { 119 return { 120 ws_protocol: "wss", 121 host, 122 http_protocol: protocol 123 }; 124 } 125 return { 126 ws_protocol: protocol === "https:" ? "wss" : "ws", 127 http_protocol: protocol, 128 host 129 }; 130 } else if (endpoint.startsWith("file:")) { 131 return { 132 ws_protocol: "ws", 133 http_protocol: "http:", 134 host: "lite.local" 135 // Special fake hostname only used for this case. This matches the hostname allowed in `is_self_host()` in `js/wasm/network/host.ts`. 136 }; 137 } 138 return { 139 ws_protocol: "wss", 140 http_protocol: "https:", 141 host: endpoint 142 }; 143} 144const RE_SPACE_NAME = /^[^\/]*\/[^\/]*$/; 145const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}$/; 146async function process_endpoint(app_reference, token) { 147 const headers = {}; 148 if (token) { 149 headers.Authorization = `Bearer ${token}`; 150 } 151 const _app_reference = app_reference.trim(); 152 if (RE_SPACE_NAME.test(_app_reference)) { 153 try { 154 const res = await fetch( 155 `https://huggingface.co/api/spaces/${_app_reference}/host`, 156 { headers } 157 ); 158 if (res.status !== 200) 159 throw new Error("Space metadata could not be loaded."); 160 const _host = (await res.json()).host; 161 return { 162 space_id: app_reference, 163 ...determine_protocol(_host) 164 }; 165 } catch (e) { 166 throw new Error("Space metadata could not be loaded." + e.message); 167 } 168 } 169 if (RE_SPACE_DOMAIN.test(_app_reference)) { 170 const { ws_protocol, http_protocol, host } = determine_protocol(_app_reference); 171 return { 172 space_id: host.replace(".hf.space", ""), 173 ws_protocol, 174 http_protocol, 175 host 176 }; 177 } 178 return { 179 space_id: false, 180 ...determine_protocol(_app_reference) 181 }; 182} 183function map_names_to_ids(fns) { 184 let apis = {}; 185 fns.forEach(({ api_name }, i) => { 186 if (api_name) 187 apis[api_name] = i; 188 }); 189 return apis; 190} 191const RE_DISABLED_DISCUSSION = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/; 192async function discussions_enabled(space_id) { 193 try { 194 const r = await fetch( 195 `https://huggingface.co/api/spaces/${space_id}/discussions`, 196 { 197 method: "HEAD" 198 } 199 ); 200 const error = r.headers.get("x-error-message"); 201 if (error && RE_DISABLED_DISCUSSION.test(error)) 202 return false;
203 return true; 204 } catch (e) { 205 return false; 206 } 207} 208function normalise_file(file, server_url, proxy_url) { 209 if (file == null) { 210 return null; 211 } 212 if (Array.isArray(file)) { 213 const normalized_file = []; 214 for (const x of file) { 215 if (x == null) { 216 normalized_file.push(null); 217 } else { 218 normalized_file.push(normalise_file(x, server_url, proxy_url)); 219 } 220 } 221 return normalized_file; 222 } 223 if (file.is_stream) { 224 if (proxy_url == null) { 225 return new FileData({ 226 ...file, 227 url: server_url + "/stream/" + file.path 228 }); 229 } 230 return new FileData({ 231 ...file, 232 url: "/proxy=" + proxy_url + "stream/" + file.path 233 }); 234 } 235 return new FileData({ 236 ...file, 237 url: get_fetchable_url_or_file(file.path, server_url, proxy_url) 238 }); 239} 240function is_url(str) { 241 try { 242 const url = new URL(str); 243 return url.protocol === "http:" || url.protocol === "https:"; 244 } catch { 245 return false; 246 } 247} 248function get_fetchable_url_or_file(path, server_url, proxy_url) { 249 if (path == null) { 250 return proxy_url ? `/proxy=${proxy_url}file=` : `${server_url}/file=`; 251 } 252 if (is_url(path)) { 253 return path; 254 } 255 return proxy_url ? `/proxy=${proxy_url}file=${path}` : `${server_url}/file=${path}`; 256} 257async function upload(file_data, root, upload_id, upload_fn = upload_files) { 258 let files = (Array.isArray(file_data) ? file_data : [file_data]).map( 259 (file_data2) => file_data2.blob 260 ); 261 return await Promise.all( 262 await upload_fn(root, files, void 0, upload_id).then( 263 async (response) => { 264 if (response.error) { 265 throw new Error(response.error); 266 } else { 267 if (response.files) { 268 return response.files.map((f, i) => { 269 const file = new FileData({ ...file_data[i], path: f }); 270 return normalise_file(file, root, null); 271 }); 272 } 273 return []; 274 } 275 } 276 ) 277 ); 278} 279async function prepare_files(files, is_stream) { 280 return files.map( 281 (f, i) => new FileData({ 282 path: f.name, 283 orig_name: f.name, 284 blob: f, 285 size: f.size, 286 mime_type: f.type, 287 is_stream 288 }) 289 ); 290} 291class FileData { 292 constructor({ 293 path, 294 url, 295 orig_name, 296 size, 297 blob, 298 is_stream, 299 mime_type, 300 alt_text 301 }) { 302 this.path = path; 303 this.url = url; 304 this.orig_name = orig_name; 305 this.size = size; 306 this.blob = url ? void 0 : blob; 307 this.is_stream = is_stream; 308 this.mime_type = mime_type; 309 this.alt_text = alt_text; 310 } 311} 312const QUEUE_FULL_MSG = "This application is too busy. Keep trying!"; 313const BROKEN_CONNECTION_MSG = "Connection errored out."; 314let NodeBlob; 315function api_factory(fetch_implementation, EventSource_factory) { 316 return { post_data: post_data2, upload_files: upload_files2, client: client2, handle_blob: handle_blob2 }; 317 async function post_data2(url, body, token) { 318 const headers = { "Content-Type": "application/json" }; 319 if (token) { 320 headers.Authorization = `Bearer ${token}`; 321 } 322 try { 323 var response = await fetch_implementation(url, { 324 method: "POST", 325 body: JSON.stringify(body), 326 headers 327 }); 328 } catch (e) { 329 return [{ error: BROKEN_CONNECTION_MSG }, 500]; 330 } 331 let output; 332 let status; 333 try { 334 output = await response.json(); 335 status = response.status; 336 } catch (e) { 337 output = { error: `Could not parse server response: ${e}` }; 338 status = 500; 339 } 340 return [output, status]; 341 } 342 async function upload_files2(root, files, token, upload_id) { 343 const headers = {}; 344 if (token) { 345 headers.Authorization = `Bearer ${token}`; 346 } 347 const chunkSize = 1e3; 348 const uploadResponses = []; 349 for (let i = 0; i < files.length; i += chunkSize) { 350 const chunk = files.slice(i, i + chunkSize); 351 const formData = new FormData(); 352 chunk.forEach((file) => { 353 formData.append("files", file); 354 }); 355 try { 356 const upload_url = upload_id ? `${root}/upload?upload_id=${upload_id}` : `${root}/upload`; 357 var response = await fetch_implementation(upload_url, { 358 method: "POST", 359 body: formData, 360 headers 361 }); 362 } catch (e) { 363 return { error: BROKEN_CONNECTION_MSG }; 364 } 365 const output = await response.json(); 366 uploadResponses.push(...output); 367 } 368 return { files: uploadResponses }; 369 } 370 async function client2(app_reference, options = { normalise_files: true }) { 371 return new Promise(async (res) => { 372 const { status_callback, hf_token, normalise_files } = options; 373 const return_obj = { 374 predict, 375 submit, 376 view_api, 377 component_server 378 }; 379 const transform_files = normalise_files ?? true; 380 if ((typeof window === "undefined" || !("WebSocket" in window)) && !global.Websocket) { 381 const ws = await __vitePreload(() => import('./wrapper-6f348d45-eeeb8bd1.js'),true?["./wrapper-6f348d45-eeeb8bd1.js","./__vite-browser-external-cb19bde2.js"]:void 0,import.meta.url); 382 NodeBlob = (await __vitePreload(() => import('./__vite-browser-external-cb19bde2.js').then(n => n._),true?[]:void 0,import.meta.url)).Blob; 383 global.WebSocket = ws.WebSocket; 384 } 385 const { ws_protocol, http_protocol, host, space_id } = await process_endpoint(app_reference, hf_token); 386 const session_hash = Math.random().toString(36).substring(2); 387 const last_status = {}; 388 let stream_open = false;
389 let pending_stream_messages = {}; 390 let event_stream = null; 391 const event_callbacks = {}; 392 const unclosed_events = /* @__PURE__ */ new Set(); 393 let config; 394 let api_map = {}; 395 let jwt = false; 396 if (hf_token && space_id) { 397 jwt = await get_jwt(space_id, hf_token); 398 } 399 async function config_success(_config) { 400 config = _config; 401 api_map = map_names_to_ids((_config == null ? void 0 : _config.dependencies) || []); 402 if (config.auth_required) { 403 return { 404 config, 405 ...return_obj 406 }; 407 } 408 try { 409 api = await view_api(config); 410 } catch (e) { 411 console.error(`Could not get api details: ${e.message}`); 412 } 413 return { 414 config, 415 ...return_obj 416 }; 417 } 418 let api; 419 async function handle_space_sucess(status) { 420 if (status_callback) 421 status_callback(status); 422 if (status.status === "running") 423 try { 424 config = await resolve_config( 425 fetch_implementation, 426 `${http_protocol}//${host}`, 427 hf_token 428 ); 429 const _config = await config_success(config); 430 res(_config); 431 } catch (e) { 432 console.error(e); 433 if (status_callback) { 434 status_callback({ 435 status: "error", 436 message: "Could not load this space.", 437 load_status: "error", 438 detail: "NOT_FOUND" 439 }); 440 } 441 } 442 } 443 try { 444 config = await resolve_config( 445 fetch_implementation, 446 `${http_protocol}//${host}`, 447 hf_token 448 ); 449 const _config = await config_success(config); 450 res(_config); 451 } catch (e) { 452 console.error(e); 453 if (space_id) { 454 check_space_status( 455 space_id, 456 RE_SPACE_NAME.test(space_id) ? "space_name" : "subdomain", 457 handle_space_sucess 458 ); 459 } else { 460 if (status_callback) 461 status_callback({ 462 status: "error", 463 message: "Could not load this space.", 464 load_status: "error", 465 detail: "NOT_FOUND" 466 }); 467 } 468 } 469 function predict(endpoint, data, event_data) { 470 let data_returned = false; 471 let status_complete = false; 472 let dependency; 473 if (typeof endpoint === "number") { 474 dependency = config.dependencies[endpoint]; 475 } else { 476 const trimmed_endpoint = endpoint.replace(/^\//, ""); 477 dependency = config.dependencies[api_map[trimmed_endpoint]]; 478 } 479 if (dependency.types.continuous) { 480 throw new Error( 481 "Cannot call predict on this function as it may run forever. Use submit instead" 482 ); 483 } 484 return new Promise((res2, rej) => { 485 const app = submit(endpoint, data, event_data); 486 let result; 487 app.on("data", (d) => { 488 if (status_complete) { 489 app.destroy(); 490 res2(d); 491 } 492 data_returned = true; 493 result = d; 494 }).on("status", (status) => { 495 if (status.stage === "error") 496 rej(status); 497 if (status.stage === "complete") { 498 status_complete = true; 499 if (data_returned) { 500 app.destroy(); 501 res2(result); 502 } 503 } 504 }); 505 }); 506 } 507 function submit(endpoint, data, event_data, trigger_id = null) { 508 let fn_index; 509 let api_info; 510 if (typeof endpoint === "number") { 511 fn_index = endpoint; 512 api_info = api.unnamed_endpoints[fn_index]; 513 } else { 514 const trimmed_endpoint = endpoint.replace(/^\//, ""); 515 fn_index = api_map[trimmed_endpoint]; 516 api_info = api.named_endpoints[endpoint.trim()]; 517 } 518 if (typeof fn_index !== "number") { 519 throw new Error( 520 "There is no endpoint matching that name of fn_index matching that number." 521 ); 522 } 523 let websocket; 524 let eventSource; 525 let protocol = config.protocol ?? "ws"; 526 const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint; 527 let payload; 528 let event_id = null; 529 let complete = false;
530 const listener_map = {}; 531 let url_params = ""; 532 if (typeof window !== "undefined") { 533 url_params = new URLSearchParams(window.location.search).toString(); 534 } 535 handle_blob2(`${config.root}`, data, api_info, hf_token).then( 536 (_payload) => { 537 payload = { 538 data: _payload || [], 539 event_data, 540 fn_index, 541 trigger_id 542 }; 543 if (skip_queue(fn_index, config)) { 544 fire_event({ 545 type: "status", 546 endpoint: _endpoint, 547 stage: "pending", 548 queue: false, 549 fn_index, 550 time: /* @__PURE__ */ new Date() 551 }); 552 post_data2( 553 `${config.root}/run${_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`}${url_params ? "?" + url_params : ""}`, 554 { 555 ...payload, 556 session_hash 557 }, 558 hf_token 559 ).then(([output, status_code]) => { 560 const data2 = transform_files ? transform_output( 561 output.data, 562 api_info, 563 config.root, 564 config.root_url 565 ) : output.data; 566 if (status_code == 200) { 567 fire_event({ 568 type: "data", 569 endpoint: _endpoint, 570 fn_index, 571 data: data2, 572 time: /* @__PURE__ */ new Date() 573 }); 574 fire_event({ 575 type: "status", 576 endpoint: _endpoint, 577 fn_index, 578 stage: "complete", 579 eta: output.average_duration, 580 queue: false, 581 time: /* @__PURE__ */ new Date() 582 }); 583 } else { 584 fire_event({ 585 type: "status", 586 stage: "error", 587 endpoint: _endpoint, 588 fn_index, 589 message: output.error, 590 queue: false, 591 time: /* @__PURE__ */ new Date() 592 }); 593 } 594 }).catch((e) => { 595 fire_event({ 596 type: "status", 597 stage: "error", 598 message: e.message, 599 endpoint: _endpoint, 600 fn_index, 601 queue: false, 602 time: /* @__PURE__ */ new Date() 603 }); 604 }); 605 } else if (protocol == "ws") { 606 fire_event({ 607 type: "status", 608 stage: "pending", 609 queue: true, 610 endpoint: _endpoint, 611 fn_index, 612 time: /* @__PURE__ */ new Date() 613 }); 614 let url = new URL(`${ws_protocol}://${resolve_root( 615 host, 616 config.path, 617 true 618 )} 619 /queue/join${url_params ? "?" + url_params : ""}`); 620 if (jwt) { 621 url.searchParams.set("__sign", jwt); 622 } 623 websocket = new WebSocket(url); 624 websocket.onclose = (evt) => { 625 if (!evt.wasClean) { 626 fire_event({ 627 type: "status", 628 stage: "error", 629 broken: true, 630 message: BROKEN_CONNECTION_MSG, 631 queue: true, 632 endpoint: _endpoint, 633 fn_index, 634 time: /* @__PURE__ */ new Date() 635 }); 636 } 637 }; 638 websocket.onmessage = function(event) { 639 const _data = JSON.parse(event.data); 640 const { type, status, data: data2 } = handle_message( 641 _data, 642 last_status[fn_index] 643 ); 644 if (type === "update" && status && !complete) { 645 fire_event({ 646 type: "status", 647 endpoint: _endpoint, 648 fn_index, 649 time: /* @__PURE__ */ new Date(), 650 ...status 651 }); 652 if (status.stage === "error") { 653 websocket.close(); 654 } 655 } else if (type === "hash") { 656 websocket.send(JSON.stringify({ fn_index, session_hash })); 657 return; 658 } else if (type === "data") { 659 websocket.send(JSON.stringify({ ...payload, session_hash })); 660 } else if (type === "complete") { 661 complete = status; 662 } else if (type === "log") { 663 fire_event({ 664 type: "log", 665 log: data2.log, 666 level: data2.level, 667 endpoint: _endpoint, 668 fn_index 669 }); 670 } else if (type === "generating") { 671 fire_event({ 672 type: "status", 673 time: /* @__PURE__ */ new Date(), 674 ...status, 675 stage: status == null ? void 0 : status.stage, 676 queue: true, 677 endpoint: _endpoint, 678 fn_index 679 }); 680 } 681 if (data2) { 682 fire_event({ 683 type: "data", 684 time: /* @__PURE__ */ new Date(), 685 data: transform_files ? transform_output( 686 data2.data, 687 api_info, 688 config.root, 689 config.root_url 690 ) : data2.data, 691 endpoint: _endpoint, 692 fn_index 693 }); 694 if (complete) { 695 fire_event({ 696 type: "status", 697 time: /* @__PURE__ */ new Date(), 698 ...complete, 699 stage: status == null ? void 0 : status.stage, 700 queue: true, 701 endpoint: _endpoint, 702 fn_index 703 }); 704 websocket.close(); 705 } 706 } 707 }; 708 if (semiver(config.version || "2.0.0", "3.6") < 0) { 709 addEventListener( 710 "open", 711 () => websocket.send(JSON.stringify({ hash: session_hash })) 712 ); 713 } 714 } else if (protocol == "sse") { 715 fire_event({ 716 type: "status", 717 stage: "pending", 718 queue: true, 719 endpoint: _endpoint, 720 fn_index, 721 time: /* @__PURE__ */ new Date() 722 }); 723 var params = new URLSearchParams({ 724 fn_index: fn_index.toString(), 725 session_hash 726 }).toString(); 727 let url = new URL( 728 `${config.root}/queue/join?${url_params ? url_params + "&" : ""}${params}` 729 ); 730 eventSource = EventSource_factory(url); 731 eventSource.onmessage = async function(event) { 732 const _data = JSON.parse(event.data); 733 const { type, status, data: data2 } = handle_message( 734 _data, 735 last_status[fn_index] 736 ); 737 if (type === "update" && status && !complete) { 738 fire_event({ 739 type: "status", 740 endpoint: _endpoint, 741 fn_index, 742 time: /* @__PURE__ */ new Date(), 743 ...status 744 }); 745 if (status.stage === "error") { 746 eventSource.close(); 747 } 748 } else if (type === "data") { 749 event_id = _data.event_id; 750 let [_, status2] = await post_data2( 751 `${config.root}/queue/data`, 752 { 753 ...payload, 754 session_hash, 755 event_id 756 }, 757 hf_token 758 ); 759 if (status2 !== 200) { 760 fire_event({ 761 type: "status", 762 stage: "error", 763 message: BROKEN_CONNECTION_MSG, 764 queue: true, 765 endpoint: _endpoint, 766 fn_index, 767 time: /* @__PURE__ */ new Date() 768 }); 769 eventSource.close(); 770 } 771 } else if (type === "complete") { 772 complete = status; 773 } else if (type === "log") { 774 fire_event({ 775 type: "log", 776 log: data2.log, 777 level: data2.level, 778 endpoint: _endpoint, 779 fn_index 780 }); 781 } else if (type === "generating") { 782 fire_event({ 783 type: "status", 784 time: /* @__PURE__ */ new Date(), 785 ...status, 786 stage: status == null ? void 0 : status.stage, 787 queue: true, 788 endpoint: _endpoint, 789 fn_index 790 }); 791 } 792 if (data2) { 793 fire_event({ 794 type: "data", 795 time: /* @__PURE__ */ new Date(), 796 data: transform_files ? transform_output( 797 data2.data, 798 api_info, 799 config.root, 800 config.root_url 801 ) : data2.data, 802 endpoint: _endpoint, 803 fn_index 804 }); 805 if (complete) { 806 fire_event({ 807 type: "status", 808 time: /* @__PURE__ */ new Date(), 809 ...complete, 810 stage: status == null ? void 0 : status.stage, 811 queue: true, 812 endpoint: _endpoint, 813 fn_index 814 }); 815 eventSource.close(); 816 } 817 } 818 }; 819 } else if (protocol == "sse_v1") { 820 fire_event({ 821 type: "status", 822 stage: "pending", 823 queue: true, 824 endpoint: _endpoint, 825 fn_index, 826 time: /* @__PURE__ */ new Date() 827 }); 828 post_data2( 829 `${config.root}/queue/join?${url_params}`, 830 { 831 ...payload, 832 session_hash 833 }, 834 hf_token 835 ).then(([response, status]) => { 836 if (status === 503) { 837 fire_event({ 838 type: "status", 839 stage: "error", 840 message: QUEUE_FULL_MSG, 841 queue: true, 842 endpoint: _endpoint, 843 fn_index, 844 time: /* @__PURE__ */ new Date() 845 }); 846 } else if (status !== 200) { 847 fire_event({ 848 type: "status", 849 stage: "error", 850 message: BROKEN_CONNECTION_MSG, 851 queue: true, 852 endpoint: _endpoint, 853 fn_index, 854 time: /* @__PURE__ */ new Date() 855 }); 856 } else { 857 event_id = response.event_id; 858 let callback = async function(_data) { 859 try { 860 const { type, status: status2, data: data2 } = handle_message( 861 _data, 862 last_status[fn_index] 863 ); 864 if (type == "heartbeat") { 865 return; 866 } 867 if (type === "update" && status2 && !complete) { 868 fire_event({ 869 type: "status", 870 endpoint: _endpoint, 871 fn_index, 872 time: /* @__PURE__ */ new Date(), 873 ...status2 874 }); 875 } else if (type === "complete") { 876 complete = status2; 877 } else if (type == "unexpected_error") { 878 console.error("Unexpected error", status2 == null ? void 0 : status2.message); 879 fire_event({ 880 type: "status", 881 stage: "error", 882 message: (status2 == null ? void 0 : status2.message) || "An Unexpected Error Occurred!", 883 queue: true, 884 endpoint: _endpoint, 885 fn_index, 886 time: /* @__PURE__ */ new Date() 887 }); 888 } else if (type === "log") { 889 fire_event({ 890 type: "log", 891 log: data2.log, 892 level: data2.level, 893 endpoint: _endpoint, 894 fn_index 895 }); 896 return; 897 } else if (type === "generating") { 898 fire_event({ 899 type: "status", 900 time: /* @__PURE__ */ new Date(), 901 ...status2, 902 stage: status2 == null ? void 0 : status2.stage, 903 queue: true, 904 endpoint: _endpoint, 905 fn_index 906 }); 907 } 908 if (data2) { 909 fire_event({ 910 type: "data", 911 time: /* @__PURE__ */ new Date(), 912 data: transform_files ? transform_output( 913 data2.data, 914 api_info, 915 config.root, 916 config.root_url 917 ) : data2.data, 918 endpoint: _endpoint, 919 fn_index 920 }); 921 if (complete) { 922 fire_event({ 923 type: "status", 924 time: /* @__PURE__ */ new Date(), 925 ...complete, 926 stage: status2 == null ? void 0 : status2.stage, 927 queue: true, 928 endpoint: _endpoint, 929 fn_index 930 }); 931 } 932 } 933 if ((status2 == null ? void 0 : status2.stage) === "complete" || (status2 == null ? void 0 : status2.stage) === "error") { 934 if (event_callbacks[event_id]) { 935 delete event_callbacks[event_id]; 936 } 937 } 938 } catch (e) { 939 console.error("Unexpected client exception", e); 940 fire_event({ 941 type: "status", 942 stage: "error", 943 message: "An Unexpected Error Occurred!", 944 queue: true, 945 endpoint: _endpoint, 946 fn_index, 947 time: /* @__PURE__ */ new Date() 948 }); 949 close_stream(); 950 } 951 }; 952 if (event_id in pending_stream_messages) {
953 pending_stream_messages[event_id].forEach( 954 (msg) => callback(msg) 955 ); 956 delete pending_stream_messages[event_id]; 957 } 958 event_callbacks[event_id] = callback; 959 unclosed_events.add(event_id); 960 if (!stream_open) { 961 open_stream(); 962 } 963 } 964 }); 965 } 966 } 967 ); 968 function fire_event(event) { 969 const narrowed_listener_map = listener_map; 970 const listeners = narrowed_listener_map[event.type] || []; 971 listeners == null ? void 0 : listeners.forEach((l) => l(event)); 972 } 973 function on(eventType, listener) { 974 const narrowed_listener_map = listener_map; 975 const listeners = narrowed_listener_map[eventType] || []; 976 narrowed_listener_map[eventType] = listeners; 977 listeners == null ? void 0 : listeners.push(listener); 978 return { on, off, cancel, destroy }; 979 } 980 function off(eventType, listener) { 981 const narrowed_listener_map = listener_map; 982 let listeners = narrowed_listener_map[eventType] || []; 983 listeners = listeners == null ? void 0 : listeners.filter((l) => l !== listener); 984 narrowed_listener_map[eventType] = listeners; 985 return { on, off, cancel, destroy }; 986 } 987 async function cancel() { 988 const _status = { 989 stage: "complete", 990 queue: false, 991 time: /* @__PURE__ */ new Date() 992 }; 993 complete = _status; 994 fire_event({ 995 ..._status, 996 type: "status", 997 endpoint: _endpoint, 998 fn_index 999 }); 1000 let cancel_request = {}; 1001 if (protocol === "ws") { 1002 if (websocket && websocket.readyState === 0) { 1003 websocket.addEventListener("open", () => { 1004 websocket.close(); 1005 }); 1006 } else { 1007 websocket.close(); 1008 } 1009 cancel_request = { fn_index, session_hash }; 1010 } else { 1011 eventSource.close(); 1012 cancel_request = { event_id }; 1013 } 1014 try { 1015 await fetch_implementation(`${config.root}/reset`, { 1016 headers: { "Content-Type": "application/json" }, 1017 method: "POST", 1018 body: JSON.stringify(cancel_request) 1019 }); 1020 } catch (e) { 1021 console.warn( 1022 "The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable." 1023 ); 1024 } 1025 } 1026 function destroy() { 1027 for (const event_type in listener_map) { 1028 listener_map[event_type].forEach((fn2) => { 1029 off(event_type, fn2); 1030 }); 1031 } 1032 } 1033 return { 1034 on, 1035 off, 1036 cancel, 1037 destroy 1038 }; 1039 } 1040 function open_stream() { 1041 stream_open = true; 1042 let params = new URLSearchParams({ 1043 session_hash 1044 }).toString(); 1045 let url = new URL(`${config.root}/queue/data?${params}`); 1046 event_stream = EventSource_factory(url); 1047 event_stream.onmessage = async function(event) { 1048 let _data = JSON.parse(event.data); 1049 const event_id = _data.event_id; 1050 if (!event_id) { 1051 await Promise.all( 1052 Object.keys(event_callbacks).map( 1053 (event_id2) => event_callbacks[event_id2](_data) 1054 ) 1055 ); 1056 } else if (event_callbacks[event_id]) { 1057 if (_data.msg === "process_completed") { 1058 unclosed_events.delete(event_id); 1059 if (unclosed_events.size === 0) { 1060 close_stream(); 1061 } 1062 } 1063 let fn2 = event_callbacks[event_id]; 1064 window.setTimeout(fn2, 0, _data); 1065 } else { 1066 if (!pending_stream_messages[event_id]) { 1067 pending_stream_messages[event_id] = []; 1068 } 1069 pending_stream_messages[event_id].push(_data); 1070 } 1071 }; 1072 event_stream.onerror = async function(event) { 1073 await Promise.all( 1074 Object.keys(event_callbacks).map( 1075 (event_id) => event_callbacks[event_id]({ 1076 msg: "unexpected_error", 1077 message: BROKEN_CONNECTION_MSG 1078 }) 1079 ) 1080 ); 1081 close_stream(); 1082 }; 1083 } 1084 function close_stream() { 1085 stream_open = false;
1086 event_stream == null ? void 0 : event_stream.close(); 1087 } 1088 async function component_server(component_id, fn_name, data) { 1089 var _a; 1090 const headers = { "Content-Type": "application/json" }; 1091 if (hf_token) { 1092 headers.Authorization = `Bearer ${hf_token}`; 1093 } 1094 let root_url; 1095 let component = config.components.find( 1096 (comp) => comp.id === component_id 1097 ); 1098 if ((_a = component == null ? void 0 : component.props) == null ? void 0 : _a.root_url) { 1099 root_url = component.props.root_url; 1100 } else { 1101 root_url = config.root; 1102 } 1103 const response = await fetch_implementation( 1104 `${root_url}/component_server/`, 1105 { 1106 method: "POST", 1107 body: JSON.stringify({ 1108 data, 1109 component_id, 1110 fn_name, 1111 session_hash 1112 }), 1113 headers 1114 } 1115 ); 1116 if (!response.ok) { 1117 throw new Error( 1118 "Could not connect to component server: " + response.statusText 1119 ); 1120 } 1121 const output = await response.json(); 1122 return output; 1123 } 1124 async function view_api(config2) { 1125 if (api) 1126 return api; 1127 const headers = { "Content-Type": "application/json" }; 1128 if (hf_token) { 1129 headers.Authorization = `Bearer ${hf_token}`; 1130 } 1131 let response; 1132 if (semiver(config2.version || "2.0.0", "3.30") < 0) { 1133 response = await fetch_implementation( 1134 "https://gradio-space-api-fetcher-v2.hf.space/api", 1135 { 1136 method: "POST", 1137 body: JSON.stringify({ 1138 serialize: false, 1139 config: JSON.stringify(config2) 1140 }), 1141 headers 1142 } 1143 ); 1144 } else { 1145 response = await fetch_implementation(`${config2.root}/info`, { 1146 headers 1147 }); 1148 } 1149 if (!response.ok) { 1150 throw new Error(BROKEN_CONNECTION_MSG); 1151 } 1152 let api_info = await response.json(); 1153 if ("api" in api_info) { 1154 api_info = api_info.api; 1155 } 1156 if (api_info.named_endpoints["/predict"] && !api_info.unnamed_endpoints["0"]) { 1157 api_info.unnamed_endpoints[0] = api_info.named_endpoints["/predict"]; 1158 } 1159 const x = transform_api_info(api_info, config2, api_map); 1160 return x; 1161 } 1162 }); 1163 } 1164 async function handle_blob2(endpoint, data, api_info, token) { 1165 const blob_refs = await walk_and_store_blobs( 1166 data, 1167 void 0, 1168 [], 1169 true, 1170 api_info 1171 ); 1172 return Promise.all( 1173 blob_refs.map(async ({ path, blob, type }) => { 1174 if (blob) { 1175 const file_url = (await upload_files2(endpoint, [blob], token)).files[0]; 1176 return { path, file_url, type, name: blob == null ? void 0 : blob.name }; 1177 } 1178 return { path, type }; 1179 }) 1180 ).then((r) => { 1181 r.forEach(({ path, file_url, type, name }) => { 1182 if (type === "Gallery") { 1183 update_object(data, file_url, path); 1184 } else if (file_url) { 1185 const file = new FileData({ path: file_url, orig_name: name }); 1186 update_object(data, file, path); 1187 } 1188 }); 1189 return data; 1190 }); 1191 } 1192} 1193const { post_data, upload_files, client, handle_blob } = api_factory( 1194 fetch, 1195 (...args) => new EventSource(...args) 1196); 1197function transform_output(data, api_info, root_url, remote_url) { 1198 return data.map((d, i) => { 1199 var _a, _b, _c, _d; 1200 if (((_b = (_a = api_info == null ? void 0 : api_info.returns) == null ? void 0 : _a[i]) == null ? void 0 : _b.component) === "File") { 1201 return normalise_file(d, root_url, remote_url); 1202 } else if (((_d = (_c = api_info == null ? void 0 : api_info.returns) == null ? void 0 : _c[i]) == null ? void 0 : _d.component) === "Gallery") { 1203 return d.map((img) => { 1204 return Array.isArray(img) ? [normalise_file(img[0], root_url, remote_url), img[1]] : [
1204normalise_file(img, root_url, remote_url), null]; 1205 }); 1206 } else if (typeof d === "object" && d.path) { 1207 return normalise_file(d, root_url, remote_url); 1208 } 1209 return d; 1210 }); 1211} 1212function get_type(type, component, serializer, signature_type) { 1213 switch (type.type) { 1214 case "string": 1215 return "string"; 1216 case "boolean": 1217 return "boolean"; 1218 case "number": 1219 return "number"; 1220 } 1221 if (serializer === "JSONSerializable" || serializer === "StringSerializable") { 1222 return "any"; 1223 } else if (serializer === "ListStringSerializable") { 1224 return "string[]"; 1225 } else if (component === "Image") { 1226 return signature_type === "parameter" ? "Blob | File | Buffer" : "string"; 1227 } else if (serializer === "FileSerializable") { 1228 if ((type == null ? void 0 : type.type) === "array") { 1229 return signature_type === "parameter" ? "(Blob | File | Buffer)[]" : `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]`; 1230 } 1231 return signature_type === "parameter" ? "Blob | File | Buffer" : `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}`; 1232 } else if (serializer === "GallerySerializable") { 1233 return signature_type === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : `[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]`; 1234 } 1235} 1236function get_description(type, serializer) { 1237 if (serializer === "GallerySerializable") { 1238 return "array of [file, label] tuples"; 1239 } else if (serializer === "ListStringSerializable") { 1240 return "array of strings"; 1241 } else if (serializer === "FileSerializable") { 1242 return "array of files or single file"; 1243 } 1244 return type.description; 1245} 1246function transform_api_info(api_info, config, api_map) { 1247 const new_data = { 1248 named_endpoints: {}, 1249 unnamed_endpoints: {} 1250 }; 1251 for (const key in api_info) { 1252 const cat = api_info[key]; 1253 for (const endpoint in cat) { 1254 const dep_index = config.dependencies[endpoint] ? endpoint : api_map[endpoint.replace("/", "")]; 1255 const info = cat[endpoint]; 1256 new_data[key][endpoint] = {}; 1257 new_data[key][endpoint].parameters = {}; 1258 new_data[key][endpoint].returns = {}; 1259 new_data[key][endpoint].type = config.dependencies[dep_index].types; 1260 new_data[key][endpoint].parameters = info.parameters.map( 1261 ({ label, component, type, serializer }) => ({ 1262 label, 1263 component, 1264 type: get_type(type, component, serializer, "parameter"), 1265 description: get_description(type, serializer) 1266 }) 1267 ); 1268 new_data[key][endpoint].returns = info.returns.map( 1269 ({ label, component, type, serializer }) => ({ 1270 label, 1271 component, 1272 type: get_type(type, component, serializer, "return"), 1273 description: get_description(type, serializer) 1274 }) 1275 ); 1276 } 1277 } 1278 return new_data; 1279} 1280async function get_jwt(space, token) { 1281 try { 1282 const r = await fetch(`https://huggingface.co/api/spaces/${space}/jwt`, { 1283 headers: { 1284 Authorization: `Bearer ${token}` 1285 } 1286 }); 1287 const jwt = (await r.json()).token; 1288 return jwt || false; 1289 } catch (e) { 1290 console.error(e); 1291 return false; 1292 } 1293} 1294function update_object(object, newValue, stack) { 1295 while (stack.length > 1) { 1296 object = object[stack.shift()]; 1297 } 1298 object[stack.shift()] = newValue; 1299} 1300async function walk_and_store_blobs(param, type = void 0, path = [], root = false, api_info = void 0) { 1301 if (Array.isArray(param)) { 1302 let blob_refs = []; 1303 await Promise.all( 1304 param.map(async (v, i) => { 1305 var _a; 1306 let new_path = path.slice(); 1307 new_path.push(i); 1308 const array_refs = await walk_and_store_blobs( 1309 param[i], 1310 root ? ((_a = api_info == null ? void 0 : api_info.parameters[i]) == null ? void 0 : _a.component) || void 0 : type, 1311 new_path, 1312 false, 1313 api_info 1314 ); 1315 blob_refs = blob_refs.concat(array_refs); 1316 }) 1317 ); 1318 return blob_refs; 1319 } else if (globalThis.Buffer && param instanceof globalThis.Buffer) { 1320 const is_image = type === "Image"; 1321 return [ 1322 { 1323 path, 1324 blob: is_image ? false : new NodeBlob([param]), 1325 type 1326 } 1327 ]; 1328 } else if (typeof param === "object") { 1329 let blob_refs = []; 1330 for (let key in param) { 1331 if (param.hasOwnProperty(key)) { 1332 let new_path = path.slice(); 1333 new_path.push(key); 1334 blob_refs = blob_refs.concat( 1335 await walk_and_store_blobs( 1336 param[key], 1337 void 0, 1338 new_path, 1339 false, 1340 api_info 1341 ) 1342 ); 1343 } 1344 } 1345 return blob_refs; 1346 } 1347 return []; 1348} 1349function skip_queue(id, config) { 1350 var _a, _b, _c, _d; 1351 return !(((_b = (_a = config == null ? void 0 : config.dependencies) == null ? void 0 : _a[id]) == null ? void 0 : _b.queue) === null ? config.enable_queue : (_d = (_c = config == null ? void 0 : config.dependencies) == null ? void 0 : _c[id]) == null ? void 0 : _d.queue) || false; 1352} 1353async function resolve_config(fetch_implementation, endpoint, token) { 1354 const headers = {}; 1355 if (token) { 1356 headers.Authorization = `Bearer ${token}`; 1357 } 1358 if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876" && !window.gradio_config.dev_mode) { 1359 const path = window.gradio_config.root; 1360 const config = window.gradio_config; 1361 config.root = resolve_root(endpoint, config.root, false); 1362 return { ...config, path }; 1363 } else if (endpoint) { 1364 let response = await fetch_implementation(`${endpoint}/config`, { 1365 headers 1366 }); 1367 if (response.status === 200) { 1368 const config = await response.json(); 1369 config.path = config.path ?? ""; 1370 config.root = endpoint; 1371 return config; 1372 } 1373 throw new Error("Could not get config."); 1374 } 1375 throw new Error("No config or app endpoint found"); 1376} 1377async function check_space_status(id, type, status_callback) { 1378 let endpoint = type === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${id}` : `https://huggingface.co/api/spaces/${id}`; 1379 let response; 1380 let _status; 1381 try { 1382 response = await fetch(endpoint); 1383 _status = response.status; 1384 if (_status !== 200) { 1385 throw new Error(); 1386 } 1387 response = await response.json(); 1388 } catch (e) { 1389 status_callback({ 1390 status: "error", 1391 load_status: "error", 1392 message: "Could not get space status", 1393 detail: "NOT_FOUND" 1394 }); 1395 return; 1396 } 1397 if (!response || _status !== 200) 1398 return; 1399 const { 1400 runtime: { stage }, 1401 id: space_name 1402 } = response; 1403 switch (stage) { 1404 case "STOPPED": 1405 case "SLEEPING": 1406 status_callback({ 1407 status: "sleeping", 1408 load_status: "pending", 1409 message: "Space is asleep. Waking it up...", 1410 detail: stage 1411 }); 1412 setTimeout(() => { 1413 check_space_status(id, type, status_callback); 1414 }, 1e3); 1415 break; 1416 case "PAUSED": 1417 status_callback({ 1418 status: "paused", 1419 load_status: "error", 1420 message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.", 1421 detail: stage, 1422 discussions_enabled: await discussions_enabled(space_name) 1423 }); 1424 break; 1425 case "RUNNING":
1426 case "RUNNING_BUILDING": 1427 status_callback({ 1428 status: "running", 1429 load_status: "complete", 1430 message: "", 1431 detail: stage 1432 }); 1433 break; 1434 case "BUILDING": 1435 status_callback({ 1436 status: "building", 1437 load_status: "pending", 1438 message: "Space is building...", 1439 detail: stage 1440 }); 1441 setTimeout(() => { 1442 check_space_status(id, type, status_callback); 1443 }, 1e3); 1444 break; 1445 default: 1446 status_callback({ 1447 status: "space_error", 1448 load_status: "error", 1449 message: "This space is experiencing an issue.", 1450 detail: stage, 1451 discussions_enabled: await discussions_enabled(space_name) 1452 }); 1453 break; 1454 } 1455} 1456function handle_message(data, last_status) { 1457 const queue = true; 1458 switch (data.msg) { 1459 case "send_data": 1460 return { type: "data" }; 1461 case "send_hash": 1462 return { type: "hash" }; 1463 case "queue_full": 1464 return { 1465 type: "update", 1466 status: { 1467 queue, 1468 message: QUEUE_FULL_MSG, 1469 stage: "error", 1470 code: data.code, 1471 success: data.success 1472 } 1473 }; 1474 case "heartbeat": 1475 return { 1476 type: "heartbeat" 1477 }; 1478 case "unexpected_error": 1479 return { 1480 type: "unexpected_error", 1481 status: { 1482 queue, 1483 message: data.message, 1484 stage: "error", 1485 success: false 1486 } 1487 }; 1488 case "estimation": 1489 return { 1490 type: "update", 1491 status: { 1492 queue, 1493 stage: last_status || "pending", 1494 code: data.code, 1495 size: data.queue_size, 1496 position: data.rank, 1497 eta: data.rank_eta, 1498 success: data.success 1499 } 1500 }; 1501 case "progress": 1502 return { 1503 type: "update", 1504 status: { 1505 queue, 1506 stage: "pending", 1507 code: data.code, 1508 progress_data: data.progress_data, 1509 success: data.success 1510 } 1511 }; 1512 case "log": 1513 return { type: "log", data }; 1514 case "process_generating": 1515 return { 1516 type: "generating", 1517 status: { 1518 queue, 1519 message: !data.success ? data.output.error : null, 1520 stage: data.success ? "generating" : "error", 1521 code: data.code, 1522 progress_data: data.progress_data, 1523 eta: data.average_duration 1524 }, 1525 data: data.success ? data.output : null 1526 }; 1527 case "process_completed": 1528 if ("error" in data.output) { 1529 return { 1530 type: "update", 1531 status: { 1532 queue, 1533 message: data.output.error, 1534 stage: "error", 1535 code: data.code, 1536 success: data.success 1537 } 1538 }; 1539 } 1540 return { 1541 type: "complete", 1542 status: { 1543 queue, 1544 message: !data.success ? data.output.error : void 0, 1545 stage: data.success ? "complete" : "error", 1546 code: data.code, 1547 progress_data: data.progress_data 1548 }, 1549 data: data.success ? data.output : null 1550 }; 1551 case "process_starts": 1552 return { 1553 type: "update", 1554 status: { 1555 queue, 1556 stage: "pending", 1557 code: data.code, 1558 size: data.rank, 1559 position: 0, 1560 success: data.success, 1561 eta: data.eta 1562 } 1563 }; 1564 } 1565 return { type: "none", status: { stage: "error", queue } }; 1566} 1567 1568function mount_css(url, target) { 1569 const base = new URL(import.meta.url).origin; 1570 const _url = new URL(url, base).href; 1571 const existing_link = document.querySelector(`link[href='${_url}']`); 1572 if (existing_link) 1573 return Promise.resolve(); 1574 const link = document.createElement("link"); 1575 link.rel = "stylesheet"; 1576 link.href = _url; 1577 return new Promise((res, rej) => { 1578 link.addEventListener("load", () => res()); 1579 link.addEventListener("error", () => { 1580 console.error(`Unable to preload CSS for ${_url}`); 1581 res(); 1582 }); 1583 target.appendChild(link); 1584 }); 1585} 1586function prefix_css(string, version, style_element = document.createElement("style")) { 1587 style_element.remove(); 1588 const stylesheet = new CSSStyleSheet(); 1589 stylesheet.replaceSync(string); 1590 const rules = stylesheet.cssRules; 1591 let css_string = ""; 1592 for (let i = 0; i < rules.length; i++) { 1593 const rule = rules[i]; 1594 if (rule instanceof CSSStyleRule) { 1595 const selector = rule.selectorText; 1596 if (selector) { 1597 const new_selector = selector.split(",").map( 1598 (s) => `gradio-app .gradio-container.gradio-container-${version} .contain ${s.trim()}` 1599 ).join(","); 1600 css_string += rule.cssText; 1601 css_string += rule.cssText.replace(selector, new_selector); 1602 } 1603 } 1604 } 1605 style_element.textContent = css_string; 1606 document.head.appendChild(style_element); 1607 return style_element; 1608} 1609 1610const ENTRY_CSS = "./assets/index-20519b4d.css"; 1611let FONTS; 1612FONTS = []; 1613let IndexComponent; 1614let _res; 1615let pending = new Promise((res) => { 1616 _res = res; 1617}); 1618async function get_index() { 1619 IndexComponent = (await __vitePreload(() => import('./Index-f4e7a341.js').then(n => n.I),true?["./Index-f4e7a341.js","./Index-c396162c.css"]:void 0,import.meta.url)).default; 1620 _res(); 1621}
1622function create_custom_element() { 1623 const o = { 1624 SvelteComponent: svelte.SvelteComponent 1625 }; 1626 for (const key in svelte) { 1627 if (key === "SvelteComponent") 1628 continue; 1629 if (key === "SvelteComponentDev") { 1630 o[key] = o["SvelteComponent"]; 1631 } else { 1632 o[key] = svelte[key]; 1633 } 1634 } 1635 window.__gradio__svelte__internal = o; 1636 class GradioApp extends HTMLElement { 1637 constructor() { 1638 super(); 1639 this.host = this.getAttribute("host"); 1640 this.space = this.getAttribute("space"); 1641 this.src = this.getAttribute("src"); 1642 this.control_page_title = this.getAttribute("control_page_title"); 1643 this.initial_height = this.getAttribute("initial_height") ?? "300px"; 1644 this.is_embed = this.getAttribute("embed") ?? "true"; 1645 this.container = this.getAttribute("container") ?? "true"; 1646 this.info = this.getAttribute("info") ?? true; 1647 this.autoscroll = this.getAttribute("autoscroll"); 1648 this.eager = this.getAttribute("eager"); 1649 this.theme_mode = this.getAttribute("theme_mode"); 1650 this.updating = false; 1651 this.loading = false; 1652 } 1653 async connectedCallback() { 1654 await get_index(); 1655 this.loading = true; 1656 if (this.app) { 1657 this.app.$destroy(); 1658 } 1659 if (typeof FONTS !== "string") { 1660 FONTS.forEach((f) => mount_css(f, document.head)); 1661 } 1662 await mount_css(ENTRY_CSS, document.head); 1663 const event = new CustomEvent("domchange", { 1664 bubbles: true, 1665 cancelable: false, 1666 composed: true 1667 }); 1668 const observer = new MutationObserver((mutations) => { 1669 this.dispatchEvent(event); 1670 }); 1671 observer.observe(this, { childList: true }); 1672 this.app = new IndexComponent({ 1673 target: this, 1674 props: { 1675 // embed source 1676 space: this.space ? this.space.trim() : this.space, 1677 src: this.src ? this.src.trim() : this.src, 1678 host: this.host ? this.host.trim() : this.host, 1679 // embed info 1680 info: this.info === "false" ? false : true, 1681 container: this.container === "false" ? false : true, 1682 is_embed: this.is_embed === "false" ? false : true, 1683 initial_height: this.initial_height, 1684 eager: this.eager === "true" ? true : false, 1685 // gradio meta info 1686 version: "4-16-0", 1687 theme_mode: this.theme_mode, 1688 // misc global behaviour 1689 autoscroll: this.autoscroll === "true" ? true : false, 1690 control_page_title: this.control_page_title === "true" ? true : false, 1691 // injectables 1692 client, 1693 upload_files, 1694 // for gradio docs 1695 // TODO: Remove -- i think this is just for autoscroll behavhiour, app vs embeds 1696 app_mode: window.__gradio_mode__ === "app" 1697 } 1698 }); 1699 if (this.updating) { 1700 this.setAttribute(this.updating.name, this.updating.value); 1701 } 1702 this.loading = false; 1703 } 1704 static get observedAttributes() { 1705 return ["src", "space", "host"]; 1706 } 1707 async attributeChangedCallback(name, old_val, new_val) { 1708 await pending; 1709 if ((name === "host" || name === "space" || name === "src") && new_val !== old_val) { 1710 this.updating = { name, value: new_val }; 1711 if (this.loading) 1712 return; 1713 if (this.app) { 1714 this.app.$destroy(); 1715 } 1716 this.space = null; 1717 this.host = null; 1718 this.src = null; 1719 if (name === "host") { 1720 this.host = new_val; 1721 } else if (name === "space") { 1722 this.space = new_val; 1723 } else if (name === "src") { 1724 this.src = new_val; 1725 } 1726 this.app = new IndexComponent({ 1727 target: this, 1728 props: { 1729 // embed source 1730 space: this.space ? this.space.trim() : this.space, 1731 src: this.src ? this.src.trim() : this.src, 1732 host: this.host ? this.host.trim() : this.host, 1733 // embed info 1734 info: this.info === "false" ? false : true, 1735 container: this.container === "false" ? false : true,
1736 is_embed: this.is_embed === "false" ? false : true, 1737 initial_height: this.initial_height, 1738 eager: this.eager === "true" ? true : false, 1739 // gradio meta info 1740 version: "4-16-0", 1741 theme_mode: this.theme_mode, 1742 // misc global behaviour 1743 autoscroll: this.autoscroll === "true" ? true : false, 1744 control_page_title: this.control_page_title === "true" ? true : false, 1745 // injectables 1746 client, 1747 upload_files, 1748 // for gradio docs 1749 // TODO: Remove -- i think this is just for autoscroll behavhiour, app vs embeds 1750 app_mode: window.__gradio_mode__ === "app" 1751 } 1752 }); 1753 this.updating = false; 1754 } 1755 } 1756 } 1757 if (!customElements.get("gradio-app")) 1758 customElements.define("gradio-app", GradioApp); 1759} 1760create_custom_element(); 1761 1762export { __vitePreload as _, prefix_css as a, get_fetchable_url_or_file as g, mount_css as m, normalise_file as n, prepare_files as p, upload as u }; 1763//# sourceMappingURL=index-546f83db.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.