Cbphcr commited on
Commit
aa26f51
·
verified ·
1 Parent(s): 4e5edbb

Resolve browser assets from the current Space origin

Browse files
Files changed (2) hide show
  1. gradio-lite-worker.js +1 -1
  2. index.html +10 -5
gradio-lite-worker.js CHANGED
@@ -312,7 +312,7 @@ def unload_local_modules(target_dir_path: str = "."):
312
  for module_name in loaded_modules.values():
313
  if module_name is not None and module_name in sys.modules:
314
  del sys.modules[module_name]
315
- `;importScripts("https://cdn.jsdelivr.net/pyodide/v0.26.1/full/pyodide.js");let p,_,O,N,R,A;async function W(e,t){console.debug("Loading Pyodide."),t("Loading Pyodide"),p=await loadPyodide({stdout:console.debug,stderr:console.error}),console.debug("Pyodide is loaded."),console.debug("Loading micropip"),t("Loading micropip"),await p.loadPackage("micropip"),_=p.pyimport("micropip"),console.debug("micropip is loaded.");const o=["https://lamda-nesy-chinatravel.static.hf.space/huggingface_hub-0.25.2-py3-none-any.whl?v=1","https://lamda-nesy-chinatravel.static.hf.space/filelock-3.16.1-py3-none-any.whl?v=1","https://lamda-nesy-chinatravel.static.hf.space/gradio-5.0.2-py3-none-any.whl?v=1",e.gradioClientWheelUrl];console.debug("Loading Gradio wheels.",o),t("Loading Gradio wheels"),await p.loadPackage(["ssl","setuptools"]),await _.add_mock_package("ffmpy","0.3.0"),await _.install.callKwargs(["typing-extensions>=4.8.0","markdown-it-py[linkify]~=2.2.0","anyio==3.*","fastapi<0.111.0"],{keep_going:!0}),await _.install.callKwargs(o,{keep_going:!0}),console.debug("Gradio wheels are loaded."),console.debug("Mocking os module methods."),t("Mock os module methods"),await p.runPythonAsync(`
316
  import os
317
 
318
  os.link = lambda src, dst: None
 
312
  for module_name in loaded_modules.values():
313
  if module_name is not None and module_name in sys.modules:
314
  del sys.modules[module_name]
315
+ `;importScripts("https://cdn.jsdelivr.net/pyodide/v0.26.1/full/pyodide.js");let p,_,O,N,R,A;async function W(e,t){console.debug("Loading Pyodide."),t("Loading Pyodide"),p=await loadPyodide({stdout:console.debug,stderr:console.error}),console.debug("Pyodide is loaded."),console.debug("Loading micropip"),t("Loading micropip"),await p.loadPackage("micropip"),_=p.pyimport("micropip"),console.debug("micropip is loaded.");const o=[self.CHINATRAVEL_ASSET_BASE+"huggingface_hub-0.25.2-py3-none-any.whl?v=1",self.CHINATRAVEL_ASSET_BASE+"filelock-3.16.1-py3-none-any.whl?v=1",self.CHINATRAVEL_ASSET_BASE+"gradio-5.0.2-py3-none-any.whl?v=1",e.gradioClientWheelUrl];console.debug("Loading Gradio wheels.",o),t("Loading Gradio wheels"),await p.loadPackage(["ssl","setuptools"]),await _.add_mock_package("ffmpy","0.3.0"),await _.install.callKwargs(["typing-extensions>=4.8.0","markdown-it-py[linkify]~=2.2.0","anyio==3.*","fastapi<0.111.0"],{keep_going:!0}),await _.install.callKwargs(o,{keep_going:!0}),console.debug("Gradio wheels are loaded."),console.debug("Mocking os module methods."),t("Mock os module methods"),await p.runPythonAsync(`
316
  import os
317
 
318
  os.link = lambda src, dst: None
index.html CHANGED
@@ -11,9 +11,10 @@
11
  >
12
  <script>
13
  const nativeBlob = window.Blob;
 
14
  const localLiteWorker = new URL(
15
- "./gradio-lite-worker.js?v=7",
16
- window.location.href,
17
  ).href;
18
 
19
  window.Blob = class extends nativeBlob {
@@ -22,7 +23,7 @@
22
  if (typeof part !== "string" || !part.includes("webworker-Er6yXxw8.js")) {
23
  return part;
24
  }
25
- return `importScripts("${localLiteWorker}");`;
26
  });
27
  super(patchedParts, options);
28
  }
@@ -97,15 +98,19 @@ geopy>=2.4,<3
97
  </gradio-requirements>
98
  <gradio-file
99
  name="lite_runtime.zip"
100
- url="https://lamda-nesy-chinatravel.static.hf.space/lite_runtime.zip?v=2"
101
  ></gradio-file>
102
  <gradio-file
103
  name="lite_app.py"
104
- url="https://lamda-nesy-chinatravel.static.hf.space/lite_app.py?v=2"
105
  entrypoint
106
  ></gradio-file>
107
  </gradio-lite>
108
  <script>
 
 
 
 
109
  const app = document.querySelector("gradio-lite");
110
  const errorBox = document.querySelector("#boot-error");
111
  const showError = (event) => {
 
11
  >
12
  <script>
13
  const nativeBlob = window.Blob;
14
+ const assetRoot = new URL("./", window.location.href);
15
  const localLiteWorker = new URL(
16
+ "gradio-lite-worker.js?v=8",
17
+ assetRoot,
18
  ).href;
19
 
20
  window.Blob = class extends nativeBlob {
 
23
  if (typeof part !== "string" || !part.includes("webworker-Er6yXxw8.js")) {
24
  return part;
25
  }
26
+ return `self.CHINATRAVEL_ASSET_BASE=${JSON.stringify(assetRoot.href)};importScripts("${localLiteWorker}");`;
27
  });
28
  super(patchedParts, options);
29
  }
 
98
  </gradio-requirements>
99
  <gradio-file
100
  name="lite_runtime.zip"
101
+ url="lite_runtime.zip?v=2"
102
  ></gradio-file>
103
  <gradio-file
104
  name="lite_app.py"
105
+ url="lite_app.py?v=2"
106
  entrypoint
107
  ></gradio-file>
108
  </gradio-lite>
109
  <script>
110
+ for (const file of document.querySelectorAll("gradio-file[url]")) {
111
+ file.setAttribute("url", new URL(file.getAttribute("url"), assetRoot).href);
112
+ }
113
+
114
  const app = document.querySelector("gradio-lite");
115
  const errorBox = document.querySelector("#boot-error");
116
  const showError = (event) => {