π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Download ML models on MLService init if needed/possible
laurenspriemd5722417e331
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dartindex e27f685e63..1847eda981 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart@@ -71,7 +71,10 @@ class MLService {/// Only call this function once at app startup, after that you can directly call [runAllML]Future<void> init() async {- if (_isInitialized) return;+ if (_isInitialized) {+ unawaited(_maybePredownloadLocalModels());+ return;+ }_logger.info("init called");// Check if the device has enough RAM to run local indexing@@ -115,9 +118,30 @@ class MLService {});_isInitialized = true;+ unawaited(_maybePredownloadLocalModels());_logger.info('init done');}+ Future<void> _maybePredownloadLocalModels() async {+ if (!hasGrantedMLConsent) {+ return;+ }+ if (!localSettings.isMLLocalIndexingEnabled) {+ _logger.info(+ "Skipping ML model predownload because local indexing is disabled",+ );+ return;+ }+ if (MLIndexingIsolate.instance.areModelsDownloaded) {+ return;+ }+ try {+ await MLIndexingIsolate.instance.ensureDownloadedModels();+ } catch (e, s) {+ _logger.warning("Failed to predownload local ML models", e, s);+ }+ }+bool canFetch() {if (localSettings.isMLLocalIndexingEnabled) return true;if (lastRemoteFetch == null) {@@ -232,6 +256,9 @@ class MLService {try {_isIndexingOrClusteringRunning = true;_logger.info('starting image indexing');+ if (localSettings.isMLLocalIndexingEnabled) {+ await MLIndexingIsolate.instance.ensureDownloadedModels();+ }final Stream<List<FileMLInstruction>> instructionStream =fetchEmbeddingsAndInstructions(fileDownloadMlLimit, mode: mode);