Skip to content

Commit 8707607

Browse files
committed
fix(downsample): load sample input image into viewer in demo app
1 parent a3bd7f5 commit 8707607

File tree

3 files changed

+93
-54
lines changed

3 files changed

+93
-54
lines changed
Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
export default async function downsampleLoadSampleInputs (model, preRun=false) {
2-
const downsampleButton = document.querySelector('#downsampleBinShrinkInputs sl-button[name=input-file-button]')
1+
export default async function downsampleLoadSampleInputs(
2+
model,
3+
preRun = false,
4+
) {
5+
const downsampleButton = document.querySelector(
6+
"#downsampleBinShrinkInputs sl-button[name=input-file-button]",
7+
);
38
if (!preRun) {
4-
downsampleButton.loading = true
9+
downsampleButton.loading = true;
510
}
611

7-
const fileName = "cthead1.png"
8-
const response = await fetch(`https://bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua.ipfs.w3s.link/ipfs/bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua/input/${fileName}`)
9-
const data = new Uint8Array(await response.arrayBuffer())
10-
const inputFile = { data, path: fileName }
11-
const { image } = await globalThis.readImage(inputFile)
12+
const fileName = "cthead1.png";
13+
const response = await fetch(
14+
`https://bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua.ipfs.w3s.link/ipfs/bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua/input/${fileName}`,
15+
);
16+
const data = new Uint8Array(await response.arrayBuffer());
17+
const inputFile = { data, path: fileName };
18+
const { image } = await globalThis.readImage(inputFile);
1219

13-
model.inputs.set('input', image)
14-
model.options.set('shrinkFactors', [2, 2])
20+
model.inputs.set("input", image);
21+
model.options.set("shrinkFactors", [2, 2]);
1522

1623
if (!preRun) {
17-
const downsampleElement = document.getElementById('downsampleBinShrink-input-details')
18-
downsampleElement.innerHTML = `<pre>${globalThis.escapeHtml(inputFile.path)}</pre>`
19-
downsampleElement.disabled = false
24+
const downsampleElement = document.getElementById(
25+
"downsampleBinShrink-input-details",
26+
);
27+
downsampleElement.setImage(image);
28+
downsampleElement.disabled = false;
2029

21-
const shrinkFactorsElement = document.querySelector('#downsampleBinShrinkInputs sl-input[name=shrink-factors]')
22-
shrinkFactorsElement.value = JSON.stringify(model.options.get('shrinkFactors'))
30+
const shrinkFactorsElement = document.querySelector(
31+
"#downsampleBinShrinkInputs sl-input[name=shrink-factors]",
32+
);
33+
shrinkFactorsElement.value = JSON.stringify(
34+
model.options.get("shrinkFactors"),
35+
);
2336

24-
downsampleButton.loading = false
37+
downsampleButton.loading = false;
2538
}
2639

27-
return model
40+
return model;
2841
}
2942

3043
// Use this function to run the pipeline when this tab group is select.
3144
// This will load the web worker if it is not already loaded, download the wasm module, and allocate memory in the wasm model.
3245
// Set this to `false` if sample inputs are very large or sample pipeline computation is long.
33-
export const usePreRun = true
46+
export const usePreRun = true;
Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
export default async function downsampleLoadSampleInputs (model, preRun=false) {
2-
const downsampleButton = document.querySelector('#downsampleLabelImageInputs sl-button[name=input-file-button]')
1+
export default async function downsampleLoadSampleInputs(
2+
model,
3+
preRun = false,
4+
) {
5+
const downsampleButton = document.querySelector(
6+
"#downsampleLabelImageInputs sl-button[name=input-file-button]",
7+
);
38
if (!preRun) {
4-
downsampleButton.loading = true
9+
downsampleButton.loading = true;
510
}
611

7-
const fileName = "2th_cthead1.png"
8-
const response = await fetch(`https://bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua.ipfs.w3s.link/ipfs/bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua/input/${fileName}`)
9-
const data = new Uint8Array(await response.arrayBuffer())
10-
const inputFile = { data, path: fileName }
11-
const { image } = await globalThis.readImage(inputFile)
12+
const fileName = "2th_cthead1.png";
13+
const response = await fetch(
14+
`https://bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua.ipfs.w3s.link/ipfs/bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua/input/${fileName}`,
15+
);
16+
const data = new Uint8Array(await response.arrayBuffer());
17+
const inputFile = { data, path: fileName };
18+
const { image } = await globalThis.readImage(inputFile);
1219

13-
model.inputs.set('input', image)
14-
model.options.set('shrinkFactors', [2, 2])
20+
model.inputs.set("input", image);
21+
model.options.set("shrinkFactors", [2, 2]);
1522

1623
if (!preRun) {
17-
const downsampleElement = document.getElementById('downsampleLabelImage-input-details')
18-
downsampleElement.innerHTML = `<pre>${globalThis.escapeHtml(inputFile.path)}</pre>`
19-
downsampleElement.disabled = false
24+
const downsampleElement = document.getElementById(
25+
"downsampleLabelImage-input-details",
26+
);
27+
downsampleElement.setImage(image);
28+
downsampleElement.disabled = false;
2029

21-
const shrinkFactorsElement = document.querySelector('#downsampleLabelImageInputs sl-input[name=shrink-factors]')
22-
shrinkFactorsElement.value = JSON.stringify(model.options.get('shrinkFactors'))
30+
const shrinkFactorsElement = document.querySelector(
31+
"#downsampleLabelImageInputs sl-input[name=shrink-factors]",
32+
);
33+
shrinkFactorsElement.value = JSON.stringify(
34+
model.options.get("shrinkFactors"),
35+
);
2336

24-
downsampleButton.loading = false
37+
downsampleButton.loading = false;
2538
}
2639

27-
return model
40+
return model;
2841
}
2942

3043
// Use this function to run the pipeline when this tab group is select.
3144
// This will load the web worker if it is not already loaded, download the wasm module, and allocate memory in the wasm model.
3245
// Set this to `false` if sample inputs are very large or sample pipeline computation is long.
33-
export const usePreRun = true
46+
export const usePreRun = true;
Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
export default async function downsampleLoadSampleInputs (model, preRun=false) {
2-
const downsampleButton = document.querySelector('#downsampleInputs sl-button[name=input-file-button]')
1+
export default async function downsampleLoadSampleInputs(
2+
model,
3+
preRun = false,
4+
) {
5+
const downsampleButton = document.querySelector(
6+
"#downsampleInputs sl-button[name=input-file-button]",
7+
);
38
if (!preRun) {
4-
downsampleButton.loading = true
9+
downsampleButton.loading = true;
510
}
611

7-
const fileName = "cthead1.png"
8-
const response = await fetch(`https://bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua.ipfs.w3s.link/ipfs/bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua/input/${fileName}`)
9-
const data = new Uint8Array(await response.arrayBuffer())
10-
const inputFile = { data, path: fileName }
11-
const { image } = await globalThis.readImage(inputFile)
12+
const fileName = "cthead1.png";
13+
const response = await fetch(
14+
`https://bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua.ipfs.w3s.link/ipfs/bafybeih4fck4ndvsvgo6774xy5w7ip3bzcvh7x7e527m4yvazgrxdzayua/input/${fileName}`,
15+
);
16+
const data = new Uint8Array(await response.arrayBuffer());
17+
const inputFile = { data, path: fileName };
18+
const { image } = await globalThis.readImage(inputFile);
1219

13-
model.inputs.set('input', image)
14-
model.options.set('shrinkFactors', [2, 2])
20+
model.inputs.set("input", image);
21+
model.options.set("shrinkFactors", [2, 2]);
1522

1623
if (!preRun) {
17-
const downsampleElement = document.getElementById('downsample-input-details')
18-
downsampleElement.innerHTML = `<pre>${globalThis.escapeHtml(inputFile.path)}</pre>`
19-
downsampleElement.disabled = false
24+
const downsampleElement = document.getElementById(
25+
"downsample-input-details",
26+
);
27+
downsampleElement.setImage(image);
28+
downsampleElement.disabled = false;
2029

21-
const shrinkFactorsElement = document.querySelector('#downsampleInputs sl-input[name=shrink-factors]')
22-
shrinkFactorsElement.value = JSON.stringify(model.options.get('shrinkFactors'))
30+
const shrinkFactorsElement = document.querySelector(
31+
"#downsampleInputs sl-input[name=shrink-factors]",
32+
);
33+
shrinkFactorsElement.value = JSON.stringify(
34+
model.options.get("shrinkFactors"),
35+
);
2336

24-
downsampleButton.loading = false
37+
downsampleButton.loading = false;
2538
}
2639

27-
return model
40+
return model;
2841
}
2942

3043
// Use this function to run the pipeline when this tab group is select.
3144
// This will load the web worker if it is not already loaded, download the wasm module, and allocate memory in the wasm model.
3245
// Set this to `false` if sample inputs are very large or sample pipeline computation is long.
33-
export const usePreRun = true
46+
export const usePreRun = true;

0 commit comments

Comments
 (0)