PageSourceSearch

https://merve-owl-tracking.hf.space/assets/index-7f1ea29b.js

js merve-owl-tracking.hf.space collected 2026-10-03 10:19:16 UTC 61,250 bytes, 1,808 lines download raw bytes

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