ensureModel static method
Future<File>
ensureModel({
- String? directory,
- String? path,
- QLayaModelSpec? model,
- void onProgress(
- QLayaDownloadProgress progress
Ensures the model is downloaded and ready to use.
If already downloaded, returns the existing File immediately. Otherwise, downloads it from Hugging Face.
Implementation
static Future<File> ensureModel({
String? directory,
String? path,
QLayaModelSpec? model,
void Function(QLayaDownloadProgress progress)? onProgress,
}) async {
final spec = model ?? QLayaModels.int8;
if (isModelAvailable(path: path, directory: directory, model: spec)) {
final file = _resolveTargetFile(path: path, directory: directory, model: spec);
onProgress?.call(
QLayaDownloadProgress(
bytesReceived: file.lengthSync(),
totalBytes: file.lengthSync(),
),
);
return file;
}
return download(
model: spec,
destinationDir: directory,
destinationPath: path,
onProgress: onProgress,
);
}