Skip to content

armgit / ente

Public Imported from GitHub
0

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

Duplicate for now

Manav Rathi7bf8912dbc32
diff --git a/desktop/src/main/services/ml-face.ts b/desktop/src/main/services/ml-face.ts
index c547885bb0..f88f432ee8 100644
--- a/desktop/src/main/services/ml-face.ts
+++ b/desktop/src/main/services/ml-face.ts
@@ -47,6 +47,36 @@ const faceDetectionSession = async () => {
return _faceDetectionSession;
};
+let activeFaceEmbeddingModelDownload: Promise<string> | undefined;
+
+const faceEmbeddingModelPathDownloadingIfNeeded = async () => {
+ try {
+ if (activeFaceEmbeddingModelDownload) {
+ log.info("Waiting for face embedding model download to finish");
+ await activeFaceEmbeddingModelDownload;
+ } else {
+ activeFaceEmbeddingModelDownload = modelPathDownloadingIfNeeded(
+ faceEmbeddingModelName,
+ faceEmbeddingModelByteSize,
+ );
+ return await activeFaceEmbeddingModelDownload;
+ }
+ } finally {
+ activeFaceEmbeddingModelDownload = undefined;
+ }
+};
+
+let _faceEmbeddingSession: Promise<ort.InferenceSession> | undefined;
+
+const faceEmbeddingSession = async () => {
+ if (!_faceEmbeddingSession) {
+ _faceEmbeddingSession =
+ faceEmbeddingModelPathDownloadingIfNeeded().then((modelPath) =>
+ createInferenceSession(modelPath),
+ );
+ }
+ return _faceEmbeddingSession;
+};
// export const clipImageEmbedding = async (jpegImageData: Uint8Array) => {
// const tempFilePath = await generateTempFilePath("");