loadModel function
Implementation
Future<ExecuTorchModel> loadModel(String modelPath) async {
final byteData = await rootBundle.load(modelPath);
final tempDir = await getTemporaryDirectory();
final modelTempName = modelPath.split('/').last;
// Avoid appending an extra .pte if modelPath already contains the extension
final file = File('${tempDir.path}/$modelTempName');
await file.writeAsBytes(byteData.buffer.asUint8List());
debugPrint('Loading model from: ${file.path}');
try {
final model = await ExecuTorchModel.load(file.path);
debugPrint('ExecuTorchModel.load returned: $model');
return model;
} catch (e) {
debugPrint('Erro ao carregar ExecuTorchModel: $e');
rethrow;
}
}