Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Move dependency to HEAD (#1712)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukvmd authored Feb 11, 2024
2 parents 0dd22e7 + 75ae880 commit 98d7302
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 54 deletions.
3 changes: 2 additions & 1 deletion lib/services/remote_assets_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RemoteAssetsService {
}

Future<String> _getLocalPath(String remotePath) async {
return (await getTemporaryDirectory()).path +
return (await getApplicationSupportDirectory()).path +
"/assets/" +
_urlToFileName(remotePath);
}
Expand All @@ -53,5 +53,6 @@ class RemoteAssetsService {
await existingFile.delete();
}
await NetworkClient.instance.getDio().download(url, savePath);
_logger.info("Downloaded " + url);
}
}
55 changes: 7 additions & 48 deletions lib/services/semantic_search/frameworks/ml_framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<void> _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<String> _getLocalImageModelPath() async {
return (await getTemporaryDirectory()).path +
"/models/" +
basename(getImageModelRemotePath());
}

Future<String> _getLocalTextModelPath() async {
return (await getTemporaryDirectory()).path +
"/models/" +
basename(getTextModelRemotePath());
}

Future<void> _downloadFile(
String url,
String savePath, {
Expand Down Expand Up @@ -176,17 +148,6 @@ abstract class MLFramework {
return connectivityResult != ConnectivityResult.mobile ||
shouldDownloadOverMobileData;
}

Future<String> 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 {
Expand All @@ -198,10 +159,8 @@ class MLFrameworkInitializationUpdateEvent extends Event {
enum InitializationState {
notInitialized,
waitingForNetwork,
downloadingImageModel,
initializingImageModel,
initializedImageModel,
downloadingTextModel,
initializingTextModel,
initializedTextModel,
initialized,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 98d7302

Please sign in to comment.