Skip to content

Commit

Permalink
build.dart updates
Browse files Browse the repository at this point in the history
  • Loading branch information
craiglabenz committed Oct 25, 2023
1 parent c986010 commit 60bd80e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
11 changes: 7 additions & 4 deletions packages/mediapipe-task-text/build.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';
import 'package:http/http.dart' as http;

const assetFilename = 'libtext_classifier.dylib';
const assetLocation =
'https://storage.cloud.google.com/random-storage-asdf/$assetFilename';
'https://storage.googleapis.com/random-storage-asdf/$assetFilename';

File outputFile = File(
'/Users/craiglabenz/Dev/git/google/flutter-mediapipe/packages/mediapipe-task-text/logs-build.txt');
Expand Down Expand Up @@ -37,12 +36,16 @@ Future<void> _build(List<String> args) async {
}
downloadedFile.createSync();
downloadedFile.writeAsBytes(downloadResponse.bodyBytes);
} else {
log('${downloadResponse.statusCode} :: ${downloadResponse.body}');
return;
}
buildOutput.dependencies.dependencies
.add(buildConfig.packageRoot.resolve('build.dart'));
buildOutput.assets.add(
Asset(
id: 'package:mediapipe_text/src/mediapipe_text_bindings.dart',
// What should this `id` be?
id: 'package:mediapipe_text/mediapipe_text.dart',
linkMode: LinkMode.dynamic,
target: Target.macOSArm64,
path: AssetAbsolutePath(downloadFileLocation),
Expand Down
52 changes: 26 additions & 26 deletions packages/mediapipe-task-text/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ class _MainAppState extends State<MainApp> {

// DefaultAssetBundle.of(context).

// final ByteData classifierBytes = await DefaultAssetBundle.of(context)
// .load('assets/bert_classifier.tflite');
final ByteData classifierBytes = await DefaultAssetBundle.of(context)
.load('assets/bert_classifier.tflite');

final dir = io.Directory(path.current);
final modelPath = path.joinAll(
[dir.absolute.path, 'assets/bert_classifier.tflite'],
);
_log.finest('modelPath: $modelPath');
if (io.File(modelPath).existsSync()) {
_log.fine('Successfully found model.');
} else {
_log.severe('Invalid model path $modelPath. Model not found.');
io.exit(1);
}
// final dir = io.Directory(path.current);
// final modelPath = path.joinAll(
// [dir.absolute.path, 'assets/bert_classifier.tflite'],
// );
// _log.finest('modelPath: $modelPath');
// if (io.File(modelPath).existsSync()) {
// _log.fine('Successfully found model.');
// } else {
// _log.severe('Invalid model path \n\t$modelPath.\n\nModel not found.');
// io.exit(1);
// }

final sdkPath = path.joinAll(
[dir.absolute.path, 'assets/libtext_classifier.dylib'],
);
_log.finest('sdkPath: $sdkPath');
if (io.File(sdkPath).existsSync()) {
_log.fine('Successfully found SDK.');
} else {
_log.severe('Invalid SDK path $sdkPath. SDK not found.');
io.exit(1);
}
// final sdkPath = path.joinAll(
// [dir.absolute.path, 'assets/libtext_classifier.dylib'],
// );
// _log.finest('sdkPath: $sdkPath');
// if (io.File(sdkPath).existsSync()) {
// _log.fine('Successfully found SDK.');
// } else {
// _log.severe('Invalid SDK path $sdkPath. SDK not found.');
// io.exit(1);
// }

_classifier = TextClassifier(
options: TextClassifierOptions.fromAssetPath(modelPath),
// options: TextClassifierOptions.fromAssetBuffer(
// Uint8List.view(classifierBytes.buffer)),
// options: TextClassifierOptions.fromAssetPath(modelPath),
options: TextClassifierOptions.fromAssetBuffer(
Uint8List.view(classifierBytes.buffer)),
// sdkPath: sdkPath,
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/mediapipe-task-text/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ flutter:

assets:
- assets/bert_classifier.tflite
- assets/libtext_classifier.dylib
1 change: 1 addition & 0 deletions packages/mediapipe-task-text/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
flutter:
sdk: flutter
logging: ^1.2.0
http: ^1.1.0
mediapipe_core:
path: ../mediapipe-core
native_assets_cli: ^0.3.0
Expand Down

0 comments on commit 60bd80e

Please sign in to comment.