Spaces:
Running
Running
Yang Gu
commited on
Commit
·
07cbb01
1
Parent(s):
ab4a702
Change sample to demo
Browse files
main.js
CHANGED
@@ -53,7 +53,7 @@ const pageCategories = [
|
|
53 |
{
|
54 |
title: `MediaPipe and TFLite`,
|
55 |
description: `MediaPipe and TFLite`,
|
56 |
-
|
57 |
gemma: {
|
58 |
name: 'Gemma',
|
59 |
description: `Gemma with MediaPipe and TFLite by Google, <a href=https://github.com/googlesamples/mediapipe/tree/main/examples/llm_inference/js>original code</a>, <a href=https://developers.googleblog.com/2024/03/running-large-language-models-on-device-with-mediapipe-andtensorflow-lite.html>more info.</a>`,
|
@@ -64,7 +64,7 @@ const pageCategories = [
|
|
64 |
{
|
65 |
title: 'Transformers.js',
|
66 |
description: 'Transformers.js',
|
67 |
-
|
68 |
benchmark: {
|
69 |
name: 'Benchmark',
|
70 |
description: `Benchmark by Transformers.js`,
|
@@ -88,7 +88,7 @@ const pageCategories = [
|
|
88 |
{
|
89 |
title: `TODO`,
|
90 |
description: `TODO`,
|
91 |
-
|
92 |
gemma: {
|
93 |
name: 'Stable Diffusion Turbo',
|
94 |
description: `Stable Diffusion Turbo`,
|
@@ -32353,7 +32353,7 @@ function switchToRelativeTab(offsetFromCurrentTab) {
|
|
32353 |
return tab;
|
32354 |
}
|
32355 |
|
32356 |
-
// The current
|
32357 |
let currentdemoInfo;
|
32358 |
// The current set of codeMirrorEditors
|
32359 |
const codeMirrorEditors = [];
|
@@ -32369,7 +32369,7 @@ darkMatcher.addEventListener('change', () => {
|
|
32369 |
}
|
32370 |
});
|
32371 |
/**
|
32372 |
-
* Change the iframe (and source editors) to the given
|
32373 |
*/
|
32374 |
function setSampleIFrame(demoInfo, search = '') {
|
32375 |
menuToggleElem.checked = false;
|
@@ -32393,34 +32393,34 @@ function setSampleIFrame(demoInfo, search = '') {
|
|
32393 |
const src = url || `${filename}${search}`;
|
32394 |
demoContainerElem.appendChild(createElem('iframe', { src }));
|
32395 |
demoContainerElem.style.height = '100%';
|
32396 |
-
// hide intro and show
|
32397 |
introElem.style.display = 'none';
|
32398 |
demoElem.style.display = '';
|
32399 |
}
|
32400 |
else {
|
32401 |
-
// hide intro and show
|
32402 |
introElem.style.display = '';
|
32403 |
demoElem.style.display = 'none';
|
32404 |
}
|
32405 |
}
|
32406 |
/**
|
32407 |
-
* Respond to the user clicking
|
32408 |
*/
|
32409 |
function setSampleIFrameURL(e, demoInfo) {
|
32410 |
e.preventDefault();
|
32411 |
const { filename } = demoInfo;
|
32412 |
const url = new URL(location.toString());
|
32413 |
url.hash = '';
|
32414 |
-
url.searchParams.set('
|
32415 |
setURL(url.toString());
|
32416 |
setSampleIFrame(demoInfo);
|
32417 |
}
|
32418 |
-
// Samples are looked up by `?
|
32419 |
-
// from those keys to each
|
32420 |
const samplesByKey = new Map();
|
32421 |
-
// Generate the list of
|
32422 |
-
for (const { title, description,
|
32423 |
-
for (const [key, demoInfo] of Object.entries(
|
32424 |
samplesByKey.set(key, demoInfo);
|
32425 |
}
|
32426 |
demoListElem.appendChild(createElem('ul', { className: 'exampleList' }, [
|
@@ -32432,7 +32432,7 @@ for (const { title, description, samples } of pageCategories) {
|
|
32432 |
dataset: { tooltip: description },
|
32433 |
}),
|
32434 |
]),
|
32435 |
-
...Object.entries(
|
32436 |
createElem('a', {
|
32437 |
href: demoInfo.filename,
|
32438 |
...(!demoInfo.openInNewTab && {
|
@@ -32469,8 +32469,8 @@ const registerResizeCallback = (() => {
|
|
32469 |
*/
|
32470 |
function parseURL() {
|
32471 |
const url = new URL(location.toString());
|
32472 |
-
const
|
32473 |
-
const sampleUrl = new URL(
|
32474 |
const demoInfo = samplesByKey.get(basename(sampleUrl.pathname));
|
32475 |
setSampleIFrame(demoInfo, sampleUrl.search);
|
32476 |
if (demoInfo) {
|
|
|
53 |
{
|
54 |
title: `MediaPipe and TFLite`,
|
55 |
description: `MediaPipe and TFLite`,
|
56 |
+
demos: {
|
57 |
gemma: {
|
58 |
name: 'Gemma',
|
59 |
description: `Gemma with MediaPipe and TFLite by Google, <a href=https://github.com/googlesamples/mediapipe/tree/main/examples/llm_inference/js>original code</a>, <a href=https://developers.googleblog.com/2024/03/running-large-language-models-on-device-with-mediapipe-andtensorflow-lite.html>more info.</a>`,
|
|
|
64 |
{
|
65 |
title: 'Transformers.js',
|
66 |
description: 'Transformers.js',
|
67 |
+
demos: {
|
68 |
benchmark: {
|
69 |
name: 'Benchmark',
|
70 |
description: `Benchmark by Transformers.js`,
|
|
|
88 |
{
|
89 |
title: `TODO`,
|
90 |
description: `TODO`,
|
91 |
+
demos: {
|
92 |
gemma: {
|
93 |
name: 'Stable Diffusion Turbo',
|
94 |
description: `Stable Diffusion Turbo`,
|
|
|
32353 |
return tab;
|
32354 |
}
|
32355 |
|
32356 |
+
// The current demo so we don't reload an iframe if the user picks the same demo.
|
32357 |
let currentdemoInfo;
|
32358 |
// The current set of codeMirrorEditors
|
32359 |
const codeMirrorEditors = [];
|
|
|
32369 |
}
|
32370 |
});
|
32371 |
/**
|
32372 |
+
* Change the iframe (and source editors) to the given demo or none
|
32373 |
*/
|
32374 |
function setSampleIFrame(demoInfo, search = '') {
|
32375 |
menuToggleElem.checked = false;
|
|
|
32393 |
const src = url || `${filename}${search}`;
|
32394 |
demoContainerElem.appendChild(createElem('iframe', { src }));
|
32395 |
demoContainerElem.style.height = '100%';
|
32396 |
+
// hide intro and show demo
|
32397 |
introElem.style.display = 'none';
|
32398 |
demoElem.style.display = '';
|
32399 |
}
|
32400 |
else {
|
32401 |
+
// hide intro and show demo
|
32402 |
introElem.style.display = '';
|
32403 |
demoElem.style.display = 'none';
|
32404 |
}
|
32405 |
}
|
32406 |
/**
|
32407 |
+
* Respond to the user clicking demo link.
|
32408 |
*/
|
32409 |
function setSampleIFrameURL(e, demoInfo) {
|
32410 |
e.preventDefault();
|
32411 |
const { filename } = demoInfo;
|
32412 |
const url = new URL(location.toString());
|
32413 |
url.hash = '';
|
32414 |
+
url.searchParams.set('demo', basename(filename));
|
32415 |
setURL(url.toString());
|
32416 |
setSampleIFrame(demoInfo);
|
32417 |
}
|
32418 |
+
// Samples are looked up by `?demo=key` so this is a map
|
32419 |
+
// from those keys to each demo.
|
32420 |
const samplesByKey = new Map();
|
32421 |
+
// Generate the list of demos
|
32422 |
+
for (const { title, description, demos } of pageCategories) {
|
32423 |
+
for (const [key, demoInfo] of Object.entries(demos)) {
|
32424 |
samplesByKey.set(key, demoInfo);
|
32425 |
}
|
32426 |
demoListElem.appendChild(createElem('ul', { className: 'exampleList' }, [
|
|
|
32432 |
dataset: { tooltip: description },
|
32433 |
}),
|
32434 |
]),
|
32435 |
+
...Object.entries(demos).map(([key, demoInfo]) => createElem('li', {}, [
|
32436 |
createElem('a', {
|
32437 |
href: demoInfo.filename,
|
32438 |
...(!demoInfo.openInNewTab && {
|
|
|
32469 |
*/
|
32470 |
function parseURL() {
|
32471 |
const url = new URL(location.toString());
|
32472 |
+
const demo = url.searchParams.get('demo') || '';
|
32473 |
+
const sampleUrl = new URL(demo, location.href);
|
32474 |
const demoInfo = samplesByKey.get(basename(sampleUrl.pathname));
|
32475 |
setSampleIFrame(demoInfo, sampleUrl.search);
|
32476 |
if (demoInfo) {
|