DenisovAV / flutter_gemma

The Flutter plugin allows running the Gemma AI model locally on a device from a Flutter application.
MIT License
55 stars 17 forks source link

iOS models should be in app's document directory #16

Open hypen-flutter opened 2 months ago

hypen-flutter commented 2 months ago

The readme says that the model should be under the file's root directory, but the flutter_gemma plugin code refers to the app's document directory. I could run this plugin after manually moving the model file to the app's document. Here's the code I use to move the model file.

final docDir = await getApplicationDocumentsDirectory();
final model = await rootBundle.load('assets/model.bin');
final modelBytes = model.buffer.asUint8List(model.offsetInBytes, model.lengthInBytes);
await File(p.join(docDir.path, 'model.bin')).writeAsBytes(modelBytes);

And also, line 17 of ios/classes/InferenceModel.swift should be

self.inference = try! LlmInference(options: llmOptions)

or

Use do / catch 

in case the model file does not exist.

obutora commented 2 months ago

@hypen-flutter Thank you for providing detailed information! In my case, I tried your method on iOS simlator and it worked!

DenisovAV commented 1 day ago

Please check with new methods for loading model