Skip to content

Commit ed8be90

Browse files
Use latest lite wheel on website (#9500)
* use main wheel * fixes * formatting * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 324e8eb commit ed8be90

File tree

6 files changed

+51
-31
lines changed

6 files changed

+51
-31
lines changed

.changeset/tall-impalas-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"website": minor
3+
---
4+
5+
feat:Use latest lite wheel on website

js/_website/generate_jsons/generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def get_latest_release():
6767
"gradio_install": f"pip install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-{version}-py3-none-any.whl",
6868
"gradio_py_client_install": f"pip install 'gradio-client @ git+https://github.com/gradio-app/gradio@{sha}#subdirectory=client/python'",
6969
"gradio_js_client_install": f"npm install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-client-{js_client_version}.tgz",
70+
"gradio_lite_url": f"https://gradio-lite-previews.s3.amazonaws.com/{sha}"
7071
},
7172
j,
7273
)

js/_website/src/lib/components/Demos.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import WHEEL from "$lib/json/wheel.json";
3+
24
export let name: string;
35
export let code: string;
46
export let highlighted_code: string;
@@ -8,10 +10,7 @@
810
</script>
911

1012
<svelte:head>
11-
<link
12-
rel="stylesheet"
13-
href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css"
14-
/>
13+
<link rel="stylesheet" href="{WHEEL.gradio_lite_url}/dist/lite.css" />
1514
</svelte:head>
1615

1716
<div class="hidden lg:block py-2 max-h-[750px] overflow-y-scroll">

js/_website/src/lib/components/DemosLite.svelte

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { svgCheck } from "$lib/assets/copy.js";
99
import { browser } from "$app/environment";
1010
import { onMount } from "svelte";
11+
import WHEEL from "$lib/json/wheel.json";
1112
1213
export let demos: {
1314
name: string;
@@ -48,26 +49,42 @@
4849
4950
let debounced_run_code: Function | undefined;
5051
let debounced_install: Function | undefined;
51-
onMount(() => {
52-
controller = createGradioApp({
53-
target: document.getElementById("lite-demo"),
54-
requirements: demos[0].requirements,
55-
code: demos[0].code,
56-
info: true,
57-
container: true,
58-
isEmbed: true,
59-
initialHeight: "100%",
60-
eager: false,
61-
themeMode: null,
62-
autoScroll: false,
63-
controlPageTitle: false,
64-
appMode: true
52+
53+
function loadScript(src: string) {
54+
return new Promise((resolve, reject) => {
55+
const script = document.createElement("script");
56+
script.src = src;
57+
script.onload = () => resolve(script);
58+
script.onerror = () => reject(new Error(`Script load error for ${src}`));
59+
document.head.appendChild(script);
6560
});
66-
const debounce_timeout = 1000;
67-
debounced_run_code = debounce(controller.run_code, debounce_timeout);
68-
debounced_install = debounce(controller.install, debounce_timeout);
61+
}
6962
70-
mounted = true;
63+
onMount(async () => {
64+
try {
65+
await loadScript(WHEEL.gradio_lite_url + "/dist/lite.js");
66+
controller = createGradioApp({
67+
target: document.getElementById("lite-demo"),
68+
requirements: demos[0].requirements,
69+
code: demos[0].code,
70+
info: true,
71+
container: true,
72+
isEmbed: true,
73+
initialHeight: "100%",
74+
eager: false,
75+
themeMode: null,
76+
autoScroll: false,
77+
controlPageTitle: false,
78+
appMode: true
79+
});
80+
const debounce_timeout = 1000;
81+
debounced_run_code = debounce(controller.run_code, debounce_timeout);
82+
debounced_install = debounce(controller.install, debounce_timeout);
83+
84+
mounted = true;
85+
} catch (error) {
86+
console.error("Error loading Gradio Lite:", error);
87+
}
7188
});
7289
7390
let copied_link = false;
@@ -146,12 +163,10 @@
146163
</script>
147164

148165
<svelte:head>
149-
<link
150-
rel="stylesheet"
151-
href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css"
152-
/>
166+
<link rel="stylesheet" href="{WHEEL.gradio_lite_url}/dist/lite.css" />
153167
<link rel="stylesheet" href="https://gradio-hello-world.hf.space/theme.css" />
154168
</svelte:head>
169+
155170
<div class="flex flex-row" style="position: absolute; top: -6%; right: 0.4%">
156171
<button
157172
class="border border-gray-300 rounded-md mx-2 px-2 py-.5 my-[3px] text-md text-gray-600 hover:bg-gray-50 flex"

js/_website/src/routes/+layout.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import Header from "$lib/components/Header.svelte";
1717
import Footer from "$lib/components/Footer.svelte";
1818
19+
import WHEEL from "$lib/json/wheel.json";
20+
1921
import { media_query } from "../lib/utils";
2022
store = media_query();
2123
@@ -45,7 +47,7 @@
4547
}
4648
}
4749
const script = document.createElement("script");
48-
script.src = "https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js";
50+
script.src = WHEEL.gradio_lite_url + "/dist/lite.js";
4951
script.type = "module";
5052
document.head.appendChild(script);
5153
}

js/_website/src/routes/playground/+page.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { clickOutside } from "$lib/components/clickOutside.js";
1010
import Code from "@gradio/code";
1111
import version_json from "$lib/json/version.json";
12+
import WHEEL from "$lib/json/wheel.json";
1213
1314
export let data: {
1415
demos_by_category: {
@@ -70,10 +71,7 @@
7071
/>
7172

7273
<svelte:head>
73-
<script
74-
type="module"
75-
src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"
76-
></script>
74+
<script type="module" src="{WHEEL.gradio_lite_url}/dist/lite.js"></script>
7775
<link rel="stylesheet" href="https://gradio-hello-world.hf.space/theme.css" />
7876
<script
7977
id="gradio-js-script"

0 commit comments

Comments
 (0)