π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Inline
Manav Rathia10d5a4ff5ca
diff --git a/web/apps/photos/src/constants/mlConfig.ts b/web/apps/photos/src/constants/mlConfig.tsindex 0ee2009420..e69de29bb2 100644--- a/web/apps/photos/src/constants/mlConfig.ts+++ b/web/apps/photos/src/constants/mlConfig.ts@@ -1,56 +0,0 @@-import { MLSearchConfig, MLSyncConfig } from "services/ml/types";-import { JobConfig } from "types/common/job";--export const DEFAULT_ML_SYNC_JOB_CONFIG: JobConfig = {- intervalSec: 5,- // TODO: finalize this after seeing effects on and from machine sleep- maxItervalSec: 960,- backoffMultiplier: 2,-};--export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {- batchSize: 200,- imageSource: "Original",- faceDetection: {- method: "YoloFace",- },- faceCrop: {- enabled: true,- method: "ArcFace",- padding: 0.25,- maxSize: 256,- blobOptions: {- type: "image/jpeg",- quality: 0.8,- },- },- faceAlignment: {- method: "ArcFace",- },- blurDetection: {- method: "Laplacian",- threshold: 15,- },- faceEmbedding: {- method: "MobileFaceNet",- faceSize: 112,- generateTsne: true,- },- faceClustering: {- method: "Hdbscan",- minClusterSize: 3,- minSamples: 5,- clusterSelectionEpsilon: 0.6,- clusterSelectionMethod: "leaf",- minInputSize: 50,- // maxDistanceInsideCluster: 0.4,- generateDebugInfo: true,- },- mlVersion: 3,-};--export const DEFAULT_ML_SEARCH_CONFIG: MLSearchConfig = {- enabled: false,-};--export const MAX_ML_SYNC_ERROR_COUNT = 1;diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 0e80d0df9f..16670b6e4b 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -67,7 +67,7 @@ import {import {getMLSearchConfig,updateMLSearchConfig,-} from "utils/machineLearning/config";+} from "services/machineLearning/machineLearningService";import {getUpdateAvailableForDownloadMessage,getUpdateReadyToInstallMessage,diff --git a/web/apps/photos/src/services/machineLearning/machineLearningService.ts b/web/apps/photos/src/services/machineLearning/machineLearningService.tsindex 3da84d8e06..99c9ddf98c 100644--- a/web/apps/photos/src/services/machineLearning/machineLearningService.ts+++ b/web/apps/photos/src/services/machineLearning/machineLearningService.ts@@ -2,7 +2,6 @@ import log from "@/next/log";import { APPS } from "@ente/shared/apps/constants";import ComlinkCryptoWorker from "@ente/shared/crypto";import { CustomError, parseUploadErrorCodes } from "@ente/shared/error";-import { MAX_ML_SYNC_ERROR_COUNT } from "constants/mlConfig";import downloadManager from "services/download";import { putEmbedding } from "services/embeddingService";import { getLocalFiles } from "services/fileService";@@ -11,19 +10,115 @@ import {Face,FaceDetection,Landmark,+ MLSearchConfig,+ MLSyncConfig,MLSyncContext,MLSyncFileContext,MLSyncResult,MlFileData,} from "services/ml/types";+import { JobConfig } from "types/common/job";import { EnteFile } from "types/file";-import { getMLSyncConfig } from "utils/machineLearning/config";-import mlIDbStorage from "utils/storage/mlIDbStorage";+import mlIDbStorage, {+ ML_SEARCH_CONFIG_NAME,+ ML_SYNC_CONFIG_NAME,+ ML_SYNC_JOB_CONFIG_NAME,+} from "utils/storage/mlIDbStorage";+import { isInternalUserForML } from "utils/user";import FaceService from "./faceService";import { MLFactory } from "./machineLearningFactory";import PeopleService from "./peopleService";import ReaderService from "./readerService";+export const DEFAULT_ML_SYNC_JOB_CONFIG: JobConfig = {+ intervalSec: 5,+ // TODO: finalize this after seeing effects on and from machine sleep+ maxItervalSec: 960,+ backoffMultiplier: 2,+};++export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {+ batchSize: 200,+ imageSource: "Original",+ faceDetection: {+ method: "YoloFace",+ },+ faceCrop: {+ enabled: true,+ method: "ArcFace",+ padding: 0.25,+ maxSize: 256,+ blobOptions: {+ type: "image/jpeg",+ quality: 0.8,+ },+ },+ faceAlignment: {+ method: "ArcFace",+ },+ blurDetection: {+ method: "Laplacian",+ threshold: 15,+ },+ faceEmbedding: {+ method: "MobileFaceNet",+ faceSize: 112,+ generateTsne: true,+ },+ faceClustering: {+ method: "Hdbscan",+ minClusterSize: 3,+ minSamples: 5,+ clusterSelectionEpsilon: 0.6,+ clusterSelectionMethod: "leaf",+ minInputSize: 50,+ // maxDistanceInsideCluster: 0.4,+ generateDebugInfo: true,+ },+ mlVersion: 3,+};++export const DEFAULT_ML_SEARCH_CONFIG: MLSearchConfig = {+ enabled: false,+};++export const MAX_ML_SYNC_ERROR_COUNT = 1;++export async function getMLSyncJobConfig() {+ return mlIDbStorage.getConfig(+ ML_SYNC_JOB_CONFIG_NAME,+ DEFAULT_ML_SYNC_JOB_CONFIG,+ );+}++export async function getMLSyncConfig() {+ return mlIDbStorage.getConfig(ML_SYNC_CONFIG_NAME, DEFAULT_ML_SYNC_CONFIG);+}++export async function getMLSearchConfig() {+ if (isInternalUserForML()) {+ return mlIDbStorage.getConfig(+ ML_SEARCH_CONFIG_NAME,+ DEFAULT_ML_SEARCH_CONFIG,+ );+ }+ // Force disabled for everyone else while we finalize it to avoid redundant+ // reindexing for users.+ return DEFAULT_ML_SEARCH_CONFIG;+}++export async function updateMLSyncJobConfig(newConfig: JobConfig) {+ return mlIDbStorage.putConfig(ML_SYNC_JOB_CONFIG_NAME, newConfig);+}++export async function updateMLSyncConfig(newConfig: MLSyncConfig) {+ return mlIDbStorage.putConfig(ML_SYNC_CONFIG_NAME, newConfig);+}++export async function updateMLSearchConfig(newConfig: MLSearchConfig) {+ return mlIDbStorage.putConfig(ML_SEARCH_CONFIG_NAME, newConfig);+}+class MachineLearningService {private localSyncContext: Promise<MLSyncContext>;private syncContext: Promise<MLSyncContext>;diff --git a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts b/web/apps/photos/src/services/machineLearning/mlWorkManager.tsindex c75d4b14a0..b383775731 100644--- a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts+++ b/web/apps/photos/src/services/machineLearning/mlWorkManager.ts@@ -5,13 +5,13 @@ import { eventBus, Events } from "@ente/shared/events";import { getToken, getUserID } from "@ente/shared/storage/localStorage/helpers";import debounce from "debounce";import PQueue from "p-queue";+import { getMLSyncJobConfig } from "services/machineLearning/machineLearningService";import { MLSyncResult } from "services/ml/types";import { JobResult } from "types/common/job";import { EnteFile } from "types/file";import { getDedicatedMLWorker } from "utils/comlink/ComlinkMLWorker";import { SimpleJob } from "utils/common/job";import { logQueueStats } from "utils/machineLearning";-import { getMLSyncJobConfig } from "utils/machineLearning/config";import mlIDbStorage from "utils/storage/mlIDbStorage";import { DedicatedMLWorker } from "worker/ml.worker";diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.tsindex 7c00dec724..27732e90a9 100644--- a/web/apps/photos/src/services/searchService.ts+++ b/web/apps/photos/src/services/searchService.ts@@ -17,7 +17,7 @@ import {import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";import { getUniqueFiles } from "utils/file";import { getAllPeople } from "utils/machineLearning";-import { getMLSyncConfig } from "utils/machineLearning/config";+import { getMLSyncConfig } from "services/machineLearning/machineLearningService";import { getFormattedDate } from "utils/search";import mlIDbStorage from "utils/storage/mlIDbStorage";import { clipService, computeClipMatchScore } from "./clip-service";diff --git a/web/apps/photos/src/utils/machineLearning/config.ts b/web/apps/photos/src/utils/machineLearning/config.tsdeleted file mode 100644index f47a96b055..0000000000--- a/web/apps/photos/src/utils/machineLearning/config.ts+++ /dev/null@@ -1,48 +0,0 @@-import {- DEFAULT_ML_SEARCH_CONFIG,- DEFAULT_ML_SYNC_CONFIG,- DEFAULT_ML_SYNC_JOB_CONFIG,-} from "constants/mlConfig";-import { MLSearchConfig, MLSyncConfig } from "services/ml/types";-import { JobConfig } from "types/common/job";-import mlIDbStorage, {- ML_SEARCH_CONFIG_NAME,- ML_SYNC_CONFIG_NAME,- ML_SYNC_JOB_CONFIG_NAME,-} from "utils/storage/mlIDbStorage";-import { isInternalUserForML } from "utils/user";--export async function getMLSyncJobConfig() {- return mlIDbStorage.getConfig(- ML_SYNC_JOB_CONFIG_NAME,- DEFAULT_ML_SYNC_JOB_CONFIG,- );-}--export async function getMLSyncConfig() {- return mlIDbStorage.getConfig(ML_SYNC_CONFIG_NAME, DEFAULT_ML_SYNC_CONFIG);-}--export async function getMLSearchConfig() {- if (isInternalUserForML()) {- return mlIDbStorage.getConfig(- ML_SEARCH_CONFIG_NAME,- DEFAULT_ML_SEARCH_CONFIG,- );- }- // Force disabled for everyone else while we finalize it to avoid redundant- // reindexing for users.- return DEFAULT_ML_SEARCH_CONFIG;-}--export async function updateMLSyncJobConfig(newConfig: JobConfig) {- return mlIDbStorage.putConfig(ML_SYNC_JOB_CONFIG_NAME, newConfig);-}--export async function updateMLSyncConfig(newConfig: MLSyncConfig) {- return mlIDbStorage.putConfig(ML_SYNC_CONFIG_NAME, newConfig);-}--export async function updateMLSearchConfig(newConfig: MLSearchConfig) {- return mlIDbStorage.putConfig(ML_SEARCH_CONFIG_NAME, newConfig);-}diff --git a/web/apps/photos/src/utils/storage/mlIDbStorage.ts b/web/apps/photos/src/utils/storage/mlIDbStorage.tsindex c90832df3d..90b2f4aa07 100644--- a/web/apps/photos/src/utils/storage/mlIDbStorage.ts+++ b/web/apps/photos/src/utils/storage/mlIDbStorage.ts@@ -1,11 +1,5 @@import { haveWindow } from "@/next/env";import log from "@/next/log";-import {- DEFAULT_ML_SEARCH_CONFIG,- DEFAULT_ML_SYNC_CONFIG,- DEFAULT_ML_SYNC_JOB_CONFIG,- MAX_ML_SYNC_ERROR_COUNT,-} from "constants/mlConfig";import {DBSchema,IDBPDatabase,@@ -15,6 +9,12 @@ import {openDB,} from "idb";import isElectron from "is-electron";+import {+ DEFAULT_ML_SEARCH_CONFIG,+ DEFAULT_ML_SYNC_CONFIG,+ DEFAULT_ML_SYNC_JOB_CONFIG,+ MAX_ML_SYNC_ERROR_COUNT,+} from "services/machineLearning/machineLearningService";import { Face, MLLibraryData, MlFileData, Person } from "services/ml/types";export interface IndexStatus {