Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update computeImageEmbedding to accept model param

Abhinav66ccae9314c7
diff --git a/src/api/clip.ts b/src/api/clip.ts
index 0ce673c6d3..2bc675c95c 100644
--- a/src/api/clip.ts
+++ b/src/api/clip.ts
@@ -2,8 +2,10 @@ import { ipcRenderer } from 'electron';
import { writeStream } from '../services/fs';
import { isExecError } from '../utils/error';
import { parseExecError } from '../utils/error';
+import { Model } from '../types';
export async function computeImageEmbedding(
+ model: Model,
imageData: Uint8Array
): Promise<Float32Array> {
let tempInputFilePath = null;
@@ -13,7 +15,8 @@ export async function computeImageEmbedding(
await writeStream(tempInputFilePath, imageStream);
const embedding = await ipcRenderer.invoke(
'compute-image-embedding',
- tempInputFilePath
+ model,
+ imageData
);
return embedding;
} catch (err) {
diff --git a/src/services/clipService.ts b/src/services/clipService.ts
index 88ea176459..487531fcf6 100644
--- a/src/services/clipService.ts
+++ b/src/services/clipService.ts
@@ -36,6 +36,7 @@ const TEXT_EMBEDDING_EXTRACT_CMD: string[] = [
const ort = require('onnxruntime-node');
import Tokenizer from '../utils/clip-bpe-ts/mod';
import { readFile } from 'promise-fs';
+import { Model } from '../types';
const TEXT_MODEL_DOWNLOAD_URL = {
ggml: 'https://models.ente.io/clip-vit-base-patch32_ggml-text-model-f16.gguf',
@@ -208,16 +209,14 @@ function getTokenizer() {
}
export async function computeImageEmbedding(
+ model: Model,
inputFilePath: string
): Promise<Float32Array> {
- const ggmlImageEmbedding = await computeGGMLImageEmbedding(inputFilePath);
- const onnxImageEmbedding = await computeONNXImageEmbedding(inputFilePath);
- const score = await computeClipMatchScore(
- ggmlImageEmbedding,
- onnxImageEmbedding
- );
- log.info('imageEmbeddingScore', score);
- return onnxImageEmbedding;
+ if (model === Model.GGML_CLIP) {
+ return await computeGGMLImageEmbedding(inputFilePath);
+ } else {
+ return await computeONNXImageEmbedding(inputFilePath);
+ }
}
export async function computeGGMLImageEmbedding(
diff --git a/src/types/index.ts b/src/types/index.ts
index 293274ab34..a40ad5477b 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -70,3 +70,8 @@ export interface AppUpdateInfo {
export interface GetFeatureFlagResponse {
desktopCutoffVersion?: string;
}
+
+export enum Model {
+ GGML_CLIP = 'ggml-clip',
+ ONNX_CLIP = 'onnx-clip',
+}
diff --git a/src/utils/ipcComms.ts b/src/utils/ipcComms.ts
index d6d1e7dcdb..ac7a51502b 100644
--- a/src/utils/ipcComms.ts
+++ b/src/utils/ipcComms.ts
@@ -175,8 +175,8 @@ export default function setupIpcComs(
setOptOutOfCrashReports(optOut);
updateOptOutOfCrashReports(optOut);
});
- ipcMain.handle('compute-image-embedding', (_, inputFilePath) => {
- return computeImageEmbedding(inputFilePath);
+ ipcMain.handle('compute-image-embedding', (_, model, inputFilePath) => {
+ return computeImageEmbedding(model, inputFilePath);
});
ipcMain.handle('compute-text-embedding', (_, text) => {
return computeTextEmbedding(text);