diff --git a/lib/services/remote_assets_service.dart b/lib/services/remote_assets_service.dart index 8a11f84a4..0e75b983d 100644 --- a/lib/services/remote_assets_service.dart +++ b/lib/services/remote_assets_service.dart @@ -27,7 +27,7 @@ class RemoteAssetsService { } Future _getLocalPath(String remotePath) async { - return (await getTemporaryDirectory()).path + + return (await getApplicationSupportDirectory()).path + "/assets/" + _urlToFileName(remotePath); } @@ -53,5 +53,6 @@ class RemoteAssetsService { await existingFile.delete(); } await NetworkClient.instance.getDio().download(url, savePath); + _logger.info("Downloaded " + url); } } diff --git a/lib/services/semantic_search/frameworks/ml_framework.dart b/lib/services/semantic_search/frameworks/ml_framework.dart index 3523c721e..35616b1b1 100644 --- a/lib/services/semantic_search/frameworks/ml_framework.dart +++ b/lib/services/semantic_search/frameworks/ml_framework.dart @@ -2,15 +2,13 @@ import "dart:async"; import "dart:io"; import "package:connectivity_plus/connectivity_plus.dart"; -import "package:flutter/services.dart"; import "package:logging/logging.dart"; -import "package:path/path.dart"; -import "package:path_provider/path_provider.dart"; import "package:photos/core/errors.dart"; import "package:photos/core/event_bus.dart"; import "package:photos/core/network/network.dart"; import "package:photos/events/event.dart"; +import "package:photos/services/remote_assets_service.dart"; abstract class MLFramework { static const kImageEncoderEnabled = true; @@ -105,46 +103,20 @@ abstract class MLFramework { return; } _initState = InitializationState.initializingImageModel; - final path = await _getLocalImageModelPath(); - if (await File(path).exists()) { - await loadImageModel(path); - } else { - _initState = InitializationState.downloadingImageModel; - final tempFile = File(path + ".temp"); - await _downloadFile(getImageModelRemotePath(), tempFile.path); - await tempFile.rename(path); - await loadImageModel(path); - } + final imageModel = + await RemoteAssetsService.instance.getAsset(getImageModelRemotePath()); + await loadImageModel(imageModel.path); _initState = InitializationState.initializedImageModel; } Future _initTextModel() async { - final path = await _getLocalTextModelPath(); _initState = InitializationState.initializingTextModel; - if (await File(path).exists()) { - await loadTextModel(path); - } else { - _initState = InitializationState.downloadingTextModel; - final tempFile = File(path + ".temp"); - await _downloadFile(getTextModelRemotePath(), tempFile.path); - await tempFile.rename(path); - await loadTextModel(path); - } + final textModel = + await RemoteAssetsService.instance.getAsset(getTextModelRemotePath()); + await loadTextModel(textModel.path); _initState = InitializationState.initializedTextModel; } - Future _getLocalImageModelPath() async { - return (await getTemporaryDirectory()).path + - "/models/" + - basename(getImageModelRemotePath()); - } - - Future _getLocalTextModelPath() async { - return (await getTemporaryDirectory()).path + - "/models/" + - basename(getTextModelRemotePath()); - } - Future _downloadFile( String url, String savePath, { @@ -176,17 +148,6 @@ abstract class MLFramework { return connectivityResult != ConnectivityResult.mobile || shouldDownloadOverMobileData; } - - Future getAccessiblePathForAsset( - String assetPath, - String tempName, - ) async { - final byteData = await rootBundle.load(assetPath); - final tempDir = await getTemporaryDirectory(); - final file = await File('${tempDir.path}/$tempName') - .writeAsBytes(byteData.buffer.asUint8List()); - return file.path; - } } class MLFrameworkInitializationUpdateEvent extends Event { @@ -198,10 +159,8 @@ class MLFrameworkInitializationUpdateEvent extends Event { enum InitializationState { notInitialized, waitingForNetwork, - downloadingImageModel, initializingImageModel, initializedImageModel, - downloadingTextModel, initializingTextModel, initializedTextModel, initialized, diff --git a/pubspec.lock b/pubspec.lock index 0811e0a2b..b71d5908f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1381,7 +1381,7 @@ packages: dependency: "direct main" description: path: "." - ref: isolates + ref: HEAD resolved-ref: "5f26aef45ed9f5e563c26f90c1e21b3339ed906d" url: "https://github.com/ente-io/onnxruntime.git" source: git diff --git a/pubspec.yaml b/pubspec.yaml index 1a5a9fcca..f2d90ab65 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ description: ente photos application # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.8.57+577 +version: 0.8.58+578 environment: sdk: ">=3.0.0 <4.0.0" @@ -118,9 +118,7 @@ dependencies: # open_file: ^3.2.1 onnxruntime: - git: - url: "https://github.com/ente-io/onnxruntime.git" - ref: "isolates" + git: "https://github.com/ente-io/onnxruntime.git" open_mail_app: ^0.4.5 package_info_plus: ^4.1.0 page_transition: ^2.0.2