Skip to content

armgit / ente

Public Imported from GitHub
0

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

Annotate

Manav Rathi20dcf3e47375
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index b96c8f1e1a..6e7df7cdea 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -42,10 +42,10 @@ import {
import { convertToJPEG, generateImageThumbnail } from "./services/image";
import { logout } from "./services/logout";
import {
- clipImageEmbedding,
- clipTextEmbeddingIfAvailable,
+ computeCLIPImageEmbedding,
+ computeCLIPTextEmbeddingIfAvailable,
} from "./services/ml-clip";
-import { detectFaces, faceEmbeddings } from "./services/ml-face";
+import { computeFaceEmbeddings, detectFaces } from "./services/ml-face";
import { encryptionKey, saveEncryptionKey } from "./services/store";
import {
clearPendingUploads,
@@ -169,20 +169,22 @@ export const attachIPCHandlers = () => {
// - ML
- ipcMain.handle("clipImageEmbedding", (_, jpegImageData: Uint8Array) =>
- clipImageEmbedding(jpegImageData),
+ ipcMain.handle(
+ "computeCLIPImageEmbedding",
+ (_, jpegImageData: Uint8Array) =>
+ computeCLIPImageEmbedding(jpegImageData),
);
- ipcMain.handle("clipTextEmbeddingIfAvailable", (_, text: string) =>
- clipTextEmbeddingIfAvailable(text),
+ ipcMain.handle("computeCLIPTextEmbeddingIfAvailable", (_, text: string) =>
+ computeCLIPTextEmbeddingIfAvailable(text),
);
ipcMain.handle("detectFaces", (_, input: Float32Array) =>
detectFaces(input),
);
- ipcMain.handle("faceEmbeddings", (_, input: Float32Array) =>
- faceEmbeddings(input),
+ ipcMain.handle("computeFaceEmbeddings", (_, input: Float32Array) =>
+ computeFaceEmbeddings(input),
);
// - Upload
diff --git a/desktop/src/main/services/ml-clip.ts b/desktop/src/main/services/ml-clip.ts
index e3dd99204a..e0e07889fb 100644
--- a/desktop/src/main/services/ml-clip.ts
+++ b/desktop/src/main/services/ml-clip.ts
@@ -20,7 +20,7 @@ const cachedCLIPImageSession = makeCachedInferenceSession(
351468764 /* 335.2 MB */,
);
-export const clipImageEmbedding = async (jpegImageData: Uint8Array) => {
+export const computeCLIPImageEmbedding = async (jpegImageData: Uint8Array) => {
const tempFilePath = await makeTempFilePath();
const imageStream = new Response(jpegImageData.buffer).body;
await writeStream(tempFilePath, ensure(imageStream));
@@ -140,7 +140,7 @@ const getTokenizer = () => {
return _tokenizer;
};
-export const clipTextEmbeddingIfAvailable = async (text: string) => {
+export const computeCLIPTextEmbeddingIfAvailable = async (text: string) => {
const sessionOrStatus = await Promise.race([
cachedCLIPTextSession(),
"downloading-model",
diff --git a/desktop/src/main/services/ml-face.ts b/desktop/src/main/services/ml-face.ts
index 33157694fc..422f6d0230 100644
--- a/desktop/src/main/services/ml-face.ts
+++ b/desktop/src/main/services/ml-face.ts
@@ -32,7 +32,7 @@ const cachedFaceEmbeddingSession = makeCachedInferenceSession(
5286998 /* 5 MB */,
);
-export const faceEmbeddings = async (input: Float32Array) => {
+export const computeFaceEmbeddings = async (input: Float32Array) => {
// Dimension of each face (alias)
const mobileFaceNetFaceSize = 112;
// Smaller alias
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index 6ff01e59ea..537215c6b0 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -153,17 +153,17 @@ const ffmpegExec = (
// - ML
-const clipImageEmbedding = (jpegImageData: Uint8Array) =>
- ipcRenderer.invoke("clipImageEmbedding", jpegImageData);
+const computeCLIPImageEmbedding = (jpegImageData: Uint8Array) =>
+ ipcRenderer.invoke("computeCLIPImageEmbedding", jpegImageData);
-const clipTextEmbeddingIfAvailable = (text: string) =>
- ipcRenderer.invoke("clipTextEmbeddingIfAvailable", text);
+const computeCLIPTextEmbeddingIfAvailable = (text: string) =>
+ ipcRenderer.invoke("computeCLIPTextEmbeddingIfAvailable", text);
const detectFaces = (input: Float32Array) =>
ipcRenderer.invoke("detectFaces", input);
-const faceEmbeddings = (input: Float32Array) =>
- ipcRenderer.invoke("faceEmbeddings", input);
+const computeFaceEmbeddings = (input: Float32Array) =>
+ ipcRenderer.invoke("computeFaceEmbeddings", input);
// - Watch
@@ -337,10 +337,10 @@ contextBridge.exposeInMainWorld("electron", {
// - ML
- clipImageEmbedding,
- clipTextEmbeddingIfAvailable,
+ computeCLIPImageEmbedding,
+ computeCLIPTextEmbeddingIfAvailable,
detectFaces,
- faceEmbeddings,
+ computeFaceEmbeddings,
// - Watch
diff --git a/web/apps/photos/src/services/clip-service.ts b/web/apps/photos/src/services/clip-service.ts
index eb5d7ada59..915f9ae03e 100644
--- a/web/apps/photos/src/services/clip-service.ts
+++ b/web/apps/photos/src/services/clip-service.ts
@@ -184,7 +184,7 @@ class CLIPService {
};
getTextEmbeddingIfAvailable = async (text: string) => {
- return ensureElectron().clipTextEmbeddingIfAvailable(text);
+ return ensureElectron().computeCLIPTextEmbeddingIfAvailable(text);
};
private runClipEmbeddingExtraction = async (canceller: AbortController) => {
@@ -294,7 +294,7 @@ class CLIPService {
const file = await localFile
.arrayBuffer()
.then((buffer) => new Uint8Array(buffer));
- return await ensureElectron().clipImageEmbedding(file);
+ return await ensureElectron().computeCLIPImageEmbedding(file);
};
private encryptAndUploadEmbedding = async (
@@ -328,7 +328,8 @@ class CLIPService {
private extractFileClipImageEmbedding = async (file: EnteFile) => {
const thumb = await downloadManager.getThumbnail(file);
- const embedding = await ensureElectron().clipImageEmbedding(thumb);
+ const embedding =
+ await ensureElectron().computeCLIPImageEmbedding(thumb);
return embedding;
};
diff --git a/web/apps/photos/src/services/face/f-index.ts b/web/apps/photos/src/services/face/f-index.ts
index 2910772673..fb7a44a27d 100644
--- a/web/apps/photos/src/services/face/f-index.ts
+++ b/web/apps/photos/src/services/face/f-index.ts
@@ -625,7 +625,7 @@ const mobileFaceNetEmbeddingSize = 192;
const computeEmbeddings = async (
faceData: Float32Array,
): Promise<Float32Array[]> => {
- const outputData = await workerBridge.faceEmbeddings(faceData);
+ const outputData = await workerBridge.computeFaceEmbeddings(faceData);
const embeddingSize = mobileFaceNetEmbeddingSize;
const embeddings = new Array<Float32Array>(
diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts
index b965f3935b..806a00cd5e 100644
--- a/web/packages/next/types/ipc.ts
+++ b/web/packages/next/types/ipc.ts
@@ -297,7 +297,9 @@ export interface Electron {
*
* @returns A CLIP embedding.
*/
- clipImageEmbedding: (jpegImageData: Uint8Array) => Promise<Float32Array>;
+ computeCLIPImageEmbedding: (
+ jpegImageData: Uint8Array,
+ ) => Promise<Float32Array>;
/**
* Return a CLIP embedding of the given image if we already have the model
@@ -319,7 +321,7 @@ export interface Electron {
*
* @returns A CLIP embedding.
*/
- clipTextEmbeddingIfAvailable: (
+ computeCLIPTextEmbeddingIfAvailable: (
text: string,
) => Promise<Float32Array | undefined>;
@@ -337,7 +339,7 @@ export interface Electron {
* Both the input and output are opaque binary data whose internal structure
* is specific to our implementation and the model (MobileFaceNet) we use.
*/
- faceEmbeddings: (input: Float32Array) => Promise<Float32Array>;
+ computeFaceEmbeddings: (input: Float32Array) => Promise<Float32Array>;
// - Watch
diff --git a/web/packages/next/worker/comlink-worker.ts b/web/packages/next/worker/comlink-worker.ts
index cb90d85f8f..b388cd413c 100644
--- a/web/packages/next/worker/comlink-worker.ts
+++ b/web/packages/next/worker/comlink-worker.ts
@@ -47,8 +47,8 @@ const workerBridge = {
convertToJPEG: (imageData: Uint8Array) =>
ensureElectron().convertToJPEG(imageData),
detectFaces: (input: Float32Array) => ensureElectron().detectFaces(input),
- faceEmbeddings: (input: Float32Array) =>
- ensureElectron().faceEmbeddings(input),
+ computeFaceEmbeddings: (input: Float32Array) =>
+ ensureElectron().computeFaceEmbeddings(input),
};
export type WorkerBridge = typeof workerBridge;