Compare commits

...

2 Commits

Author SHA1 Message Date
Alex Yang f969f3af80 Merge branch 'main' into feat/update-clip-example 2024-04-22 01:41:59 -05:00
Thuc Pham 1f522d9f33 feat: use blob image in clip example 2024-04-22 11:24:11 +07:00
2 changed files with 13 additions and 1 deletions
+13 -1
View File
@@ -1,5 +1,16 @@
import * as fs from "fs";
import { ClipEmbedding, similarity, SimilarityType } from "llamaindex";
async function loadImageFromDisk(path: string) {
try {
const file = fs.readFileSync(path);
return new Blob([file]);
} catch (error) {
console.error(`Error loading image from disk: ${error}`);
return null;
}
}
async function main() {
const clip = new ClipEmbedding();
@@ -12,7 +23,8 @@ async function main() {
// Get image embedding
const image =
"https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg";
const imageEmbedding = await clip.getImageEmbedding(image);
const blobImage = await loadImageFromDisk("./data/football-match.jpg");
const imageEmbedding = await clip.getImageEmbedding(blobImage || image);
// Calc similarity
const sim1 = similarity(
Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB