ensureModel static method

Future<File> ensureModel({
  1. String? directory,
  2. String? path,
  3. QLayaModelSpec? model,
  4. void onProgress(
    1. 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,
  );
}